Mercurial > repos > sblanck > smagexp
diff Recount.R @ 33:2d7595c8041d draft
planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit d42088af604c5a01e1ccebba1d59f7a28a976f71
author | sblanck |
---|---|
date | Thu, 21 Jun 2018 10:06:23 -0400 |
parents | |
children | 0a74b8de4c10 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Recount.R Thu Jun 21 10:06:23 2018 -0400 @@ -0,0 +1,47 @@ +#!/usr/bin/env Rscript +# setup R error handling to go to stderr +options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } ) + +# we need that to not crash galaxy with an UTF8 error on German LC settings. +loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") + +library("optparse") + +##### Read options +option_list=list( + make_option("--id",type="character",default=NULL,help="GSE ID from GEO databse (required)"), + make_option("--report",type="character",default=NULL,help="Text file summarizing conditions of the experiment") + +); + +opt_parser = OptionParser(option_list=option_list); +opt = parse_args(opt_parser); + +if(is.null(opt$id)){ + print_help(opt_parser) + stop("Recount id required.", call.=FALSE) +} + +#loading libraries +suppressPackageStartupMessages(require(GEOquery)) + +studyID=opt$id +reportFile=opt$report + +dir.create("./split", showWarnings = TRUE, recursive = FALSE) + +url <- download_study(studyID) +load(file.path(studyID, 'rse_gene.Rdata')) +rse <- scale_counts(rse_gene) +counts=assay(rse) +conditions=rse$title + +for (i in 1:ncol(counts)) +{ + currentCount=as.data.frame(counts[,i]) + sampleID=colnames(counts)[i] + colnames(currentCount)=sampleID + write.table(x=currentCount,file=paste0("./split/",sampleID,"_",conditions[i]),sep="\t",row.names = T, col.names = T) +} + +write.table(as.data.frame(cbind(sampleID=colnames(counts),title=conditions)),quote = FALSE,col.names =TRUE, row.names=FALSE,file=reportFile,sep="\t") \ No newline at end of file