comparison 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
comparison
equal deleted inserted replaced
5:ca46ad51fe5a 6:3ce32282f6a4
1 #!/usr/bin/env Rscript
2 # setup R error handling to go to stderr
3 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
4
5 # we need that to not crash galaxy with an UTF8 error on German LC settings.
6 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
7
8 library("optparse")
9
10 ##### Read options
11 option_list=list(
12 make_option("--id",type="character",default=NULL,help="GSE ID from GEO databse (required)"),
13 make_option("--report",type="character",default=NULL,help="Text file summarizing conditions of the experiment")
14
15 );
16
17 opt_parser = OptionParser(option_list=option_list);
18 opt = parse_args(opt_parser);
19
20 if(is.null(opt$id)){
21 print_help(opt_parser)
22 stop("Recount id required.", call.=FALSE)
23 }
24
25 #loading libraries
26 suppressPackageStartupMessages(require(recount))
27
28 studyID=opt$id
29 reportFile=opt$report
30
31 dir.create("./split", showWarnings = TRUE, recursive = FALSE)
32
33 url <- download_study(studyID)
34 load(file.path(studyID, 'rse_gene.Rdata'))
35 rse <- scale_counts(rse_gene)
36 counts=assay(rse)
37 conditions=rse$title
38
39 for (i in 1:ncol(counts))
40 {
41 currentCount=as.data.frame(counts[,i])
42 sampleID=colnames(counts)[i]
43 #colnames(currentCount)=sampleID
44 write.table(x=currentCount,file=paste0("./split/",sampleID,"_",conditions[i],'.tabular'),sep="\t",row.names = T, col.names = F)
45 }
46
47 write.table(as.data.frame(cbind(sampleID=colnames(counts),title=conditions)),quote = FALSE,col.names =TRUE, row.names=FALSE,file=reportFile,sep="\t")