Mercurial > repos > sblanck > smagexp
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 32:2c0df656094a | 33:2d7595c8041d |
|---|---|
| 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(GEOquery)) | |
| 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]),sep="\t",row.names = T, col.names = T) | |
| 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") |
