2
|
1 <?xml version="1.0" encoding="UTF-8"?>
|
|
2 <tool id="edger_dge" name="edgeR Differential GeneExpression Analysis">
|
|
3 <description>RNA-Seq expression analysis using edgeR (R package)</description>
|
|
4
|
|
5 <command>
|
|
6 <!--
|
|
7 The following script is written in the "Cheetah" language:
|
|
8 http://www.cheetahtemplate.org/docs/users_guide_html_multipage/contents.html
|
|
9 -->
|
|
10
|
4
|
11 R CMD BATCH --vanilla --slave '--args
|
2
|
12 $design_matrix
|
|
13 $contrast
|
|
14
|
|
15 $output_count_edgeR
|
|
16 $output_cpm
|
|
17 output_FPXM
|
|
18 $output_raw_counts
|
|
19
|
|
20 $qc
|
|
21 $output_MDSplot
|
|
22 $output_BCVplot
|
|
23 $output_MAplot
|
|
24 smearPlot '
|
4
|
25 $R_script $output_R
|
2
|
26 </command>
|
|
27
|
|
28 <inputs>
|
|
29 <param name="design_matrix" type="data" format="tabular" help="Design matrix" />
|
|
30
|
|
31 <param name="contrast" type="text" label="Contrast (biological question)" help="e.g. 'tumor-normal' or '(G1+G2)/2-G3' using the factors chosen in the design matrix. Read the 'makeContrasts' manual from Limma package for more info." />
|
|
32
|
|
33 <param name="qc" type="select" label="Quality control reports">
|
|
34 <option value="true">Yes</option>
|
|
35 <option value="false" selected="true">No</option>
|
|
36 </param>
|
|
37
|
|
38 <param name="debug" type="select" label="R Debug output">
|
|
39 <option value="true" selected="true"> Yes</option>
|
|
40 <option value="false">No</option>
|
|
41 </param>
|
|
42 </inputs>
|
|
43
|
4
|
44 <configfiles>
|
|
45 <configfile name="R_script">
|
|
46 library(edgeR)
|
|
47
|
|
48 ## Fetch commandline arguments
|
6
|
49 args <- commandArgs(trailingOnly = TRUE)
|
4
|
50 designmatrix = args[1]
|
|
51 contrast = args[2]
|
|
52
|
|
53 output_1 = args[3]
|
|
54 output_2 = args[4]
|
|
55 output_3 = args[5] ##FPKM file - to be implemented
|
|
56 output_4 = args[6]
|
|
57
|
|
58 QC = nchar(args[7]) > 0
|
|
59
|
|
60 output_5 = args[8]
|
|
61 output_6 = args[9]
|
|
62 output_7 = args[10]
|
|
63
|
|
64 output_8 = args[11]
|
|
65
|
|
66
|
|
67 library(edgeR)
|
6
|
68 raw_data <- read.delim(designmatrix,header=T,stringsAsFactors=T)
|
4
|
69
|
|
70 ## Obtain read-counts
|
|
71 read_counts = read.delim(as.character(raw_data[1,1]),header=F,stringsAsFactors=F,row.names=1)
|
|
72 for(i in 2:length(raw_data[,1])) {
|
|
73 print("parsing counts from:")
|
|
74 print(raw_data[i,1])
|
11
|
75
|
|
76 header = read.delim(as.character(raw_data[i,1]),header=F,stringsAsFactors=F,row.names=1,nrows=1)
|
|
77 has_header = (class(header[1,1]) == "character")
|
|
78
|
|
79 read_counts = cbind(read_counts,read.delim(as.character(raw_data[i,1]),header=has_header,stringsAsFactors=F,row.names=1))
|
4
|
80 print(i)
|
|
81 }
|
|
82
|
|
83
|
|
84
|
|
85 ## Filter for HTSeq predifined counts:
|
|
86 exclude_HTSeq = c("no_feature","ambiguous","too_low_aQual","not_aligned","alignment_not_unique")
|
|
87 exclude_DEXSeq = c("_ambiguous","_empty","_lowaqual","_notaligned")
|
|
88
|
|
89 exclude = match(c(exclude_HTSeq, exclude_DEXSeq),rownames(read_counts))
|
|
90 exclude = exclude[is.na(exclude)==0]
|
|
91 if(length(exclude) != 0) {
|
|
92 read_counts = read_counts[-exclude,]
|
|
93 }
|
|
94
|
|
95
|
|
96
|
|
97
|
|
98
|
|
99
|
|
100
|
|
101
|
|
102
|
|
103 colnames(read_counts) = raw_data[,2]
|
|
104 dge = DGEList(counts=read_counts,genes=rownames(read_counts))
|
|
105
|
6
|
106 design_tmp <- raw_data[3:length(raw_data)]
|
|
107 rownames(design_tmp) <- colnames(dge)
|
4
|
108 formula = paste(c("~0",colnames(design_tmp)),collapse = " + ")
|
6
|
109 design <- model.matrix(as.formula(formula),design_tmp)
|
4
|
110
|
|
111 prefixes = colnames(design_tmp)[attr(design,"assign")]
|
|
112 avoid = nchar(prefixes) == nchar(colnames(design))
|
|
113 replacements = substr(colnames(design),nchar(prefixes)+1,nchar(colnames(design)))
|
|
114 replacements[avoid] = colnames(design)[avoid]
|
|
115 colnames(design) = replacements
|
|
116
|
|
117
|
|
118
|
|
119 print("Calculating normalization factors...")
|
|
120 dge = calcNormFactors(dge)
|
|
121 print("Estimating common dispersion...")
|
|
122 dge = estimateGLMCommonDisp(dge,design)
|
|
123 print("Estimating trended dispersion...")
|
|
124 dge = estimateGLMTrendedDisp(dge,design)
|
|
125 print("Estimating tagwise dispersion...")
|
|
126 dge = estimateGLMTagwiseDisp(dge,design)
|
|
127
|
|
128
|
|
129
|
|
130
|
|
131 if (QC == TRUE) {
|
|
132 print("Creating QC plots...")
|
|
133 #### MDS Plot
|
|
134 pdf(output_5)
|
|
135 plotMDS(dge, main="edgeR MDS Plot")
|
|
136 dev.off()
|
|
137 #### Biological coefficient of variation plot
|
|
138 pdf(output_6)
|
|
139 plotBCV(dge, cex=0.4, main="edgeR: Biological coefficient of variation (BCV) vs abundance")
|
|
140 dev.off()
|
|
141 }
|
|
142
|
|
143
|
|
144
|
|
145 print("Fitting GLM...")
|
|
146 fit = glmFit(dge,design)
|
|
147
|
|
148 print(paste("Performing likelihood ratio test: ",contrast,sep=""))
|
6
|
149 cont <- c(contrast)
|
|
150 cont <- makeContrasts(contrasts=cont, levels=design)
|
4
|
151
|
6
|
152 lrt <- glmLRT(fit, contrast=cont[,1])
|
4
|
153 print(paste("Exporting to file: ",output_1,sep=""))
|
7
|
154 write.table(file=output_1,topTags(lrt,n=nrow(read_counts))\$table,sep="\t",row.names=T)
|
4
|
155 write.table(file=output_2,cpm(dge,normalized.lib.sizes=TRUE),sep="\t")
|
|
156 ## todo EXPORT FPKM
|
7
|
157 write.table(file=output_4,dge\$counts,sep="\t")
|
4
|
158
|
|
159
|
|
160
|
|
161 if (QC == TRUE) {
|
|
162 print("Creating MA plots...")
|
|
163
|
|
164
|
7
|
165 etable <- topTags(lrt, n=nrow(dge))\$table
|
|
166 etable <- etable[order(etable\$FDR), ]
|
4
|
167 pdf(output_7)
|
|
168 with(etable, plot(logCPM, logFC, pch=20, main="edgeR: Fold change vs abundance"))
|
6
|
169 with(subset(etable, FDR<0.05), points(logCPM, logFC, pch=20, col="red"))
|
4
|
170 abline(h=c(-1,1), col="blue")
|
|
171 dev.off()
|
|
172 }
|
|
173 print("Done!")
|
|
174 </configfile>
|
|
175 </configfiles>
|
|
176
|
2
|
177 <outputs>
|
|
178 <data format="tabular" name="output_count_edgeR" label="edgeR DGE on ${design_matrix.hid}: ${design_matrix.name} - table" />
|
|
179 <data format="tabular" name="output_cpm" label="edgeR DGE on ${design_matrix.hid}: ${design_matrix.name} - CPM" />
|
|
180 <data format="tabular" name="output_raw_counts" label="edgeR DGE on ${design_matrix.hid}: ${design_matrix.name} - raw counts" />
|
|
181
|
|
182 <data format="txt" name="output_R" label="edgeR DGE on ${design_matrix.hid}: ${design_matrix.name} - R output" >
|
|
183 <filter>(debug == "true")</filter>
|
|
184 </data>
|
|
185
|
|
186 <data format="pdf" name="output_MDSplot" label="edgeR DGE on ${design_matrix.hid}: ${design_matrix.name} - MDS-plot">
|
|
187 <filter>(qc == "true")</filter>
|
|
188 </data>
|
|
189
|
|
190 <data format="pdf" name="output_BCVplot" label="edgeR DGE on ${design_matrix.hid}: ${design_matrix.name} - BCV-plot">
|
|
191 <filter>(qc == "true")</filter>
|
|
192 </data>
|
|
193
|
|
194 <data format="pdf" name="output_MAplot" label="edgeR DGE on ${design_matrix.hid}: ${design_matrix.name} - MA-plot">
|
|
195 <filter>(qc == "true")</filter>
|
|
196 </data>
|
|
197 </outputs>
|
|
198
|
|
199 <help>
|
|
200 input: Design matrix using "create Design matrix" tool
|
|
201 input: contrast
|
|
202 </help>
|
|
203 </tool>
|