DownloadProtocol_v3.R
3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env Rscript
library("optparse")
library("GEOquery")
source("/home/egaytan/automatic-extraction-growth-conditions/extraction-geo/bin/download_functions_v3.R")
#-------------------------------------------------------------------------------
# Objective
# download GSEnnn.soft.gz files for a list of GSE ids
#
# Input parameters
# --d download dir
# --i GSE information file
#
# Paramenters example
# -d ../download/srr_galagan/
# -o ../outputs/srr_galagan
# -i ../input/normalized_srr-gsm_des_v4.tsv
# -b ../input/listMetaCampo.txt
# -r ../reports/srr_galagan/extract_report.txt
#
# Examples
# nohup Rscript DownloadProtocol_v2.R -d ../download/srr_galagan/ -i ../input/normalized_srr-gsm_des_v4.tsv -r ../reports/srr_galagan/download_report.txt > download_nohup.out
# nohup Rscript DownloadProtocol_v2.R -d ../download/all_srr/ -i ../input/all_srr_geo_rnaseq.txt -r ../reports/all_srr/download_report.txt > download_nohup.out
# nohup Rscript DownloadProtocol_v3.R -d ../download/srr_htregulondb/ -i ../input/srr_htregulondb/SRR_GEO_RNASeq_Expressed.txt -r ../reports/srr_htregulondb/download_report.txt > download_nohup.out &
#######################################################################################
#-----------------------------------------ARGS-----------------------------------------
#######################################################################################
option_list = list( make_option(c("-d", "--downloadPath"),
type="character",
default=NULL,
help="download directory",
metavar="character"),
make_option(c("-i", "--infoFile"),
type="character",
default=NULL,
help="GSE id information file",
metavar="character"),
make_option(c("-r", "--report"),
type="character",
default=NULL,
help="download report file",
metavar="character")
);
opt_parser = OptionParser(option_list=option_list);
opt = parse_args(opt_parser);
if (!length(opt)){
print_help(opt_parser)
stop("At least one argument must be supplied (input file).n", call.=FALSE)
}
#######################################################################################
#-----------------------------------------MAIN-----------------------------------------
#######################################################################################
## Input files and output directories
infoFile <- opt$infoFile
if (!"gse" %in% names(gseInfo)){
stop("include at least gse column")
}
if (!"gsm" %in% names(gseInfo)){
gseInfor$gsm <- "GSM"
}
## Load main variables
# GSE-GSM
gseInfo <- read.table( infoFile,header = T, sep = "\t" )
gseInfo <- gseInfo[grep("GSE", gseInfo$gse, value=F), ]
gseInfo <- gseInfo[grep("GSM", gseInfo$gsm, value=F), ]
gseInfo <- gseInfo[complete.cases(gseInfo),]
ngse <- length(unique(gseInfo$gse))
ngsm <- length(unique(gseInfo$gsm))
message("Required GSE: ", ngse)
message("Required GSM: ", ngsm)
#gseInfo
## Download GSE-list
sink(opt$report, append = FALSE, split = FALSE)
cat("total gse id: ", (length(unique(gseInfo$gse))), "\n")
ngse_down=0
for (geoid in unique(gseInfo$gse)) {
print(geoid)
report <- tryCatch(
DownloadGEO( geoid, opt$downloadPath ),
error = function( e ) return( "download failed" ) )
print(report)
if(report == "successful download"){
ngse_down = ngse_down + 1
}
}
cat("download id: ", length(list.dirs(opt$downloadPath, recursive = FALSE)))
message("Required GSE: ", ngse_down)