Skip to content

Instantly share code, notes, and snippets.

@Jfortin1
Created November 16, 2014 17:13
Show Gist options
  • Save Jfortin1/41b9fa919ba7096ce83a to your computer and use it in GitHub Desktop.
Save Jfortin1/41b9fa919ba7096ce83a to your computer and use it in GitHub Desktop.
To obtain metadata from GSM**** files
library(GEOquery)
extractMetaGsm <- function(GEO){
require(GEOquery)
GSElimits=NULL
AnnotGPL=FALSE
destdir <- tempdir()
meta <- list()
for (i in 1:length(GEO)){
filename <- my.getGEOfile(GEO[i],destdir=destdir,AnnotGPL=AnnotGPL)
txt <- read.csv(filename, nrow=100)[1:100,1]
meta[[i]] <- GEOquery:::parseGeoMeta(txt)
cat(i)
cat("\n")
}
meta
}
my.getGEOfile <- function(GEO,destdir=tempdir(),AnnotGPL=FALSE,
amount=c('full','brief','quick','data'))
{
amount <- match.arg(amount)
geotype <- toupper(substr(GEO,1,3))
mode <- 'wb'
GEO <- toupper(GEO)
stub = gsub('\\d{1,3}$','nnn',GEO,perl=TRUE)
if (geotype == 'GDS') {
gdsurl <- 'ftp://ftp.ncbi.nlm.nih.gov/geo/datasets/%s/%s/soft/%s'
myurl <- sprintf(gdsurl,stub,GEO,paste0(GEO,'.soft.gz'))
destfile <- file.path(destdir,paste0(GEO,'.soft.gz'))
}
if (geotype == 'GSE' & amount=='full') {
gseurl <- 'ftp://ftp.ncbi.nlm.nih.gov/geo/series/%s/%s/soft/%s'
myurl <- sprintf(gseurl,stub,GEO,paste0(GEO,'_family.soft.gz'))
destfile <- file.path(destdir,paste(GEO,'.soft.gz',sep=""))
}
if (geotype == 'GSE' & amount!='full' & amount!='table') {
gseurl <- "http://www.ncbi.nlm.nih.gov/geo/query/acc.cgi"
myurl <- paste(gseurl,'?targ=self&acc=',GEO,'&form=text&view=',amount,sep='')
destfile <- file.path(destdir,paste(GEO,'.soft',sep=""))
mode <- 'w'
}
if (geotype == 'GSM') {
gseurl <- "http://www.ncbi.nlm.nih.gov/geo/query/acc.cgi"
myurl <- paste(gseurl,'?targ=self&acc=',GEO,'&form=text&view=',amount,sep='')
destfile <- file.path(destdir,paste(GEO,'.soft',sep=""))
mode <- 'w'
}
if(!file.exists(destfile)) {
download.file(myurl,destfile,mode=mode,quiet=TRUE,method=getOption('download.file.method.GEOquery'))
}
invisible(destfile)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment