diff Recount.R @ 6:3ce32282f6a4 draft

planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 228bd64b01f184d5d8ebc9f65fe0add2d45ed4fe
author sblanck
date Tue, 26 Jun 2018 08:54:45 -0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Recount.R	Tue Jun 26 08:54:45 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(recount))
+
+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],'.tabular'),sep="\t",row.names = T, col.names = F)
+}
+
+write.table(as.data.frame(cbind(sampleID=colnames(counts),title=conditions)),quote = FALSE,col.names =TRUE, row.names=FALSE,file=reportFile,sep="\t")