## ----setup--------------------------------------------------------------------
#| message: false
#| warning: false
#| echo: false
library(GEOquery)
library(knitr)


## -----------------------------------------------------------------------------
#| eval: false
# BiocManager::install('GEOquery')


## -----------------------------------------------------------------------------
library(GEOquery)


## -----------------------------------------------------------------------------
# Download GSE2553
gse <- getGEO("GSE2553")
class(gse)


## -----------------------------------------------------------------------------
length(gse)
gse[[1]]


## -----------------------------------------------------------------------------
#| tbl-cap: "Available GEO search fields."
#| label: tbl-search-fields
# What fields can we search?
fields <- searchFieldsGEO()
kable(fields)


## -----------------------------------------------------------------------------
#| label: tbl-example-search
#| tbl-cap: "Top search results for studies related to COVID-19 in humans with GEO-calculated RNA-seq counts available."
# Find RNA-seq studies related to COVID-19 in humans
results <- searchGEO('covid-19[All Fields] AND "rnaseq counts"[Filter] AND Homo sapiens[ORGN]')
results |>
  dplyr::mutate(Summary=paste(strtrim(Summary,120), '...')) |>
  dplyr::mutate(Title = paste(strtrim(Title, 120), '...')) |>
  head() |>
  kable()


## -----------------------------------------------------------------------------
# Check if RNA-seq quantifications are available
has_quant <- hasRNASeqQuantifications("GSE164073")
has_quant


## -----------------------------------------------------------------------------
#| eval: false
# # Get genome build and species information
# genome_info <- getRNASeqQuantGenomeInfo("GSE164073")
# genome_info


## -----------------------------------------------------------------------------
#| eval: false
# # Download and construct a SummarizedExperiment
# se <- getRNASeqData("GSE164073")
# se


## -----------------------------------------------------------------------------
# List available supplementary files without downloading
supp_files <- getGEOSuppFiles('GSE63137', fetch_files = FALSE)
head(supp_files)


## -----------------------------------------------------------------------------
# Find all text files
txt_files <- getGEOSuppFiles('GSE63137', fetch_files = FALSE, 
                             filter_regex = 'txt')
head(txt_files)


## -----------------------------------------------------------------------------
#| eval: false
# # Download all supplementary files for a sample
# getGEOSuppFiles('GSM15789') # Files saved to a new directory


## -----------------------------------------------------------------------------
#| eval: false
# # Get the URL for a GEO accession
# url <- urlForAccession("GSE262484")
# url
# 
# # Open a browser to the GEO page
# browseGEOAccession("GSE262484")


## -----------------------------------------------------------------------------
#| eval: false
# browseWebsiteRNASeqSearch()


## -----------------------------------------------------------------------------
# Download a GDS dataset
gds <- getGEO("GDS507")
gds


## -----------------------------------------------------------------------------
# Convert to ExpressionSet (with log2 transformation)
eset <- GDS2eSet(gds, do.log2=TRUE)
eset


## -----------------------------------------------------------------------------
# Or to a limma MAList
malist <- GDS2MA(gds)
class(malist)


## -----------------------------------------------------------------------------
# Get data tables from GSE3494
dt_list <- getGSEDataTables("GSE3494")
names(dt_list)
head(dt_list[[1]])


## -----------------------------------------------------------------------------
# Get a platform record
gpl <- getGEO("GPL96")
head(Table(gpl)[, 1:5])


## -----------------------------------------------------------------------------
#| eval: false
# # Get GSE with GPL annotation
# gse_with_gpl <- getGEO("GSE2553", AnnotGPL=TRUE)
# head(fData(gse_with_gpl[[1]]))


## -----------------------------------------------------------------------------
citation("GEOquery")


## -----------------------------------------------------------------------------
sessionInfo()

