Mercurial > repos > sblanck > smagexp
annotate ImportDataFromMatrix.R @ 38:c08b824e40cc draft
planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 86c0c3bb957558f14e9400171640bf5a5c6605c9
author | sblanck |
---|---|
date | Mon, 25 Jun 2018 05:25:40 -0400 |
parents | 25b828010ca9 |
children |
rev | line source |
---|---|
8 | 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("--input",type="character",default="NULL",help="rdata object containing eset object"), | |
13 make_option("--normalization",type="character",default=NULL,help="log2 transformation"), | |
14 make_option("--annotations",type="character",default="NULL",help="rdata object containing eset object"), | |
15 make_option("--rdataoutput",type="character",default="NULL",help="output rdata object containing eset object"), | |
16 make_option("--htmloutput",type="character",default=NULL,help="Output html report"), | |
17 make_option("--htmloutputpath",type="character",default="NULL",help="Path of output html report"), | |
18 make_option("--htmltemplate",type="character",default="NULL",help="html template)") | |
19 | |
20 | |
21 ); | |
22 | |
23 | |
24 opt_parser = OptionParser(option_list=option_list); | |
25 opt = parse_args(opt_parser); | |
2 | 26 |
8 | 27 if(is.null(opt$input)){ |
28 print_help(opt_parser) | |
29 stop("input required.", call.=FALSE) | |
30 } | |
31 | |
32 | |
33 | |
34 #loading libraries | |
35 suppressPackageStartupMessages(require(Biobase)) | |
36 suppressPackageStartupMessages(require(limma)) | |
37 suppressPackageStartupMessages(require(jsonlite)) | |
38 suppressPackageStartupMessages(require(affy)) | |
39 suppressPackageStartupMessages(require(dplyr)) | |
40 suppressPackageStartupMessages(require(affyPLM)) | |
41 | |
42 dataFile=opt$input | |
43 normalization=opt$normalization | |
44 conditionsFile=opt$conditions | |
45 annotation=opt$annotations | |
46 result_export_eset=opt$rdataoutput | |
47 result=opt$htmloutput | |
48 result.path=opt$htmloutputpath | |
49 result.template=opt$htmltemplate | |
2 | 50 |
51 dir.create(result.path, showWarnings = TRUE, recursive = FALSE) | |
52 | |
8 | 53 data=as.matrix(read.table(file = dataFile,row.names=1,header=TRUE)) |
38
c08b824e40cc
planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 86c0c3bb957558f14e9400171640bf5a5c6605c9
sblanck
parents:
37
diff
changeset
|
54 #conditions=read.table(file=conditionsFile,sep = "\t",row.names=1) |
2 | 55 htmlfile=readChar(result.template, file.info(result.template)$size) |
56 | |
38
c08b824e40cc
planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 86c0c3bb957558f14e9400171640bf5a5c6605c9
sblanck
parents:
37
diff
changeset
|
57 #colnames(conditions)=c("source_name_ch1","description") |
c08b824e40cc
planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 86c0c3bb957558f14e9400171640bf5a5c6605c9
sblanck
parents:
37
diff
changeset
|
58 #phenodata<-new("AnnotatedDataFrame",data=conditions) |
2 | 59 |
38
c08b824e40cc
planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 86c0c3bb957558f14e9400171640bf5a5c6605c9
sblanck
parents:
37
diff
changeset
|
60 eset=ExpressionSet(assayData=data,annotation=annotation) |
2 | 61 |
62 if (normalization == "quantile") { | |
37
25b828010ca9
planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit bfd179bd7fb4796e21183e0e4de2fcf78ca35b7d
sblanck
parents:
8
diff
changeset
|
63 eset <- normalize.ExpressionSet.quantiles(eset, transfn="log") |
2 | 64 } else if (normalization == "log2") { |
65 exprs(eset) = log2(exprs(eset)) | |
66 } | |
67 | |
68 boxplotnorm="boxplotnorm.png" | |
69 png(boxplotnorm,width=800,height = 400) | |
70 par(mar=c(7,5,1,1)) | |
71 boxplot(data.frame(exprs(eset)),las=2,outline=FALSE) | |
72 dev.off() | |
73 htmlfile=gsub(x=htmlfile,pattern = "###BOXPLOTNORM###",replacement = boxplotnorm, fixed = TRUE) | |
74 file.copy(boxplotnorm,result.path) | |
75 | |
76 plotMAnorm="plotMAnorm.png" | |
77 nblines=length(colnames(data))%/%3 + as.numeric((length(colnames(data))%%3)!=0) | |
78 png(plotMAnorm,width=800,height =300*nblines ) | |
79 par(mfrow=c(nblines,3)) | |
8 | 80 ##for (i in 1:length(colnames(data))){ |
2 | 81 MAplot(eset) |
82 #} | |
83 | |
84 dev.off() | |
85 htmlfile=gsub(x=htmlfile,pattern = "###PLOTMANORM###",replacement = plotMAnorm, fixed = TRUE) | |
86 file.copy(plotMAnorm,result.path) | |
87 #write.table(tolower(c(condition1Name,condition2Name)),quote = FALSE,col.names = FALSE, row.names=FALSE,file=result_export_conditions) | |
88 #saveConditions=c(condition1Name,condition2Name) | |
89 save(eset,file=result_export_eset) | |
90 write(htmlfile,result) | |
91 | |
92 #l=list() | |
93 #for(i in 1:length(esets)) | |
94 #{ | |
95 # l[[paste("study",i,sep="")]]<-res[[i]] | |
96 #} | |
97 #l[["Meta"]]=res[[length(res)-1]] | |
98 #showVenn(res,file.path(temp.files.path,"venn.png")) | |
99 #writeLines(c("<h2>Venn diagram</h2>"),file.conn) | |
100 #writeLines(c("<img src='venn.png'><br/><br/>"),file.conn) | |
101 #writeLines(c("</body></html>"),file.conn) | |
38
c08b824e40cc
planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 86c0c3bb957558f14e9400171640bf5a5c6605c9
sblanck
parents:
37
diff
changeset
|
102 #close(file.conn) |