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