DownloadProtocol_v1.R 1.83 KB
library(GEOquery)
DownloadGEO    <- function( geoid, ddir ){
  # Work directory
  wdir <- file.path( ddir, geoid, fsep = "/" )
  # Create individual folder
  if ( !dir.exists( wdir ) ) {
    dir.create( wdir )
  }
  print("Saving...")
  print(ddir)  
  # Removing downloaded files for geo ID
  file.remove( list.files( wdir, pattern = geoid, full.names = TRUE ) )  
  # Download GSE without neither expression values nor platform info
  GEO  <- getGEO( 
    GEO       = geoid,
    destdir   = wdir,
    AnnotGPL  = FALSE,
    getGPL    = FALSE,
    GSEMatrix = FALSE)  
  return("successful download")
}

#######################################################################################
#-----------------------------------------MAIN-----------------------------------------
#######################################################################################


## Input files and output directories

# Download dir

ddir     <- "/export/storage/users/egaytan/GEO-MetaData/download"
#ddir     <- "/home/egaytan/automatic-extraction-growth-conditions/Extraction/download"
#ddir     <- "/home/egaytan/Documentos/EGAYTAN-GROWTH-CONDITIONS/GEO/download"
# GSE information file
infofile <- "/export/storage/users/egaytan/GEO-MetaData/input/gsm-gse-count_v4.txt"
#infofile <- "/home/egaytan/automatic-extraction-growth-conditions/Extraction/input/gsm-gse-count_v4.txt"
#infofile <- "/home/egaytan/Documentos/EGAYTAN-GROWTH-CONDITIONS/extraccion/gsm-gse-count_v4.txt"


## Load main variables

# GSE-GSM
gseInfo  <- read.table( infofile,header = T, sep = "," )
gseInfo  <- gseInfo[complete.cases(gseInfo),]


## Download GSE-list

sink("download_report.txt", append = FALSE, split = FALSE)
for (geoid in unique(gseInfo$gse)) {
  print(geoid)
  report <- tryCatch( 
   DownloadGEO( geoid, ddir ), 
   error = function( e ) return( "download failed" ) )
  print(report) 
}