I am trying to download Single Cell matrices from a data set from the Gene Expression Omnibus but all the links have unique addresses. I wrote a function to try a combination of numbers in the URL until if found. The addresses differ by one number so I wrote this.
file_number <- as.character(29:38) # SRA file numbers
for (i in 1:10)
{
data <- tryCatch(
lapply(file_number[1], function(x) {
base_url <- paste0(
'ftp://ftp.ncbi.nlm.nih.gov/geo/samples/GSM4715nnn/GSM47154', x,
'/suppl/GSM47154', x,'%5FP', i,
'%2Eexpression%5Fmatrix%2Etxt%2Egz')
# Download data to temporary directory
temp <- tempfile()
download.file(base_url, temp)
gzfile(temp, 'rt')
counts <- read.table(file = temp, row.names = 1)
unlink(temp)}),
error = function(e) { skip_to_next <<- TRUE})
if(skip_to_next) { next }
else print(data)
}
The code runs but it will not return the data frame from the correct link which should be ftp://ftp.ncbi.nlm.nih.gov/geo/samples/GSM4715nnn/GSM4715429/suppl/GSM4715429%5FP1%2Eexpression%5Fmatrix%2Etxt%2Egz .