annotate rgedgeR/rgedgeRpaired.xml @ 2:a612f61ff3b6 draft

Uploaded
author fubar
date Sat, 27 Jul 2013 00:18:01 -0400
parents df4fea3be1b3
children f1e6a5f8a611
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
1 <tool id="rgDifferentialCount" name="Differential_Count" version="0.20">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
2 <description>models using BioConductor packages</description>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
3 <requirements>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
4 <requirement type="package" version="2.12">biocbasics</requirement>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
5 <requirement type="package" version="3.0.1">r3</requirement>
2
a612f61ff3b6 Uploaded
fubar
parents: 1
diff changeset
6 <requirement type="package" version="1.3">graphicsmagick</requirement>
1
df4fea3be1b3 Uploaded
fubar
parents: 0
diff changeset
7 <requirement type="package" version="9.07">ghostscript</requirement>
0
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
8 </requirements>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
9
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
10 <command interpreter="python">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
11 rgToolFactory.py --script_path "$runme" --interpreter "Rscript" --tool_name "DifferentialCounts"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
12 --output_dir "$html_file.files_path" --output_html "$html_file" --output_tab "$outtab" --make_HTML "yes"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
13 </command>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
14 <inputs>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
15 <param name="input1" type="data" format="tabular" label="Select an input matrix - rows are contigs, columns are counts for each sample"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
16 help="Use the HTSeq based count matrix preparation tool to create these matrices from BAM/SAM files and a GTF file of genomic features"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
17 <param name="title" type="text" value="Differential Counts" size="80" label="Title for job outputs"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
18 help="Supply a meaningful name here to remind you what the outputs contain">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
19 <sanitizer invalid_char="">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
20 <valid initial="string.letters,string.digits"><add value="_" /> </valid>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
21 </sanitizer>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
22 </param>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
23 <param name="treatment_name" type="text" value="Treatment" size="50" label="Treatment Name"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
24 <param name="Treat_cols" label="Select columns containing treatment." type="data_column" data_ref="input1" numerical="True"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
25 multiple="true" use_header_names="true" size="120" display="checkboxes">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
26 <validator type="no_options" message="Please select at least one column."/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
27 </param>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
28 <param name="control_name" type="text" value="Control" size="50" label="Control Name"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
29 <param name="Control_cols" label="Select columns containing control." type="data_column" data_ref="input1" numerical="True"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
30 multiple="true" use_header_names="true" size="120" display="checkboxes" optional="true">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
31 </param>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
32 <param name="subjectids" type="text" optional="true" size="120" value = ""
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
33 label="IF SUBJECTS NOT ALL INDEPENDENT! Enter integers to indicate sample pairing for every column in input"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
34 help="Leave blank if no pairing, but eg if data from sample id A99 is in columns 2,4 and id C21 is in 3,5 then enter '1,2,1,2'">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
35 <sanitizer>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
36 <valid initial="string.digits"><add value="," /> </valid>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
37 </sanitizer>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
38 </param>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
39 <param name="fQ" type="float" value="0.3" size="5" label="Non-differential contig count quantile threshold - zero to analyze all non-zero read count contigs"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
40 help="May be a good or a bad idea depending on the biology and the question. EG 0.3 = sparsest 30% of contigs with at least one read are removed before analysis"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
41 <param name="useNDF" type="boolean" truevalue="T" falsevalue="F" checked="false" size="1"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
42 label="Non differential filter - remove contigs below a threshold (1 per million) for half or more samples"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
43 help="May be a good or a bad idea depending on the biology and the question. This was the old default. Quantile based is available as an alternative"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
44
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
45 <conditional name="edgeR">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
46 <param name="doedgeR" type="select"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
47 label="Run this model using edgeR"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
48 help="edgeR uses a negative binomial model and seems to be powerful, even with few replicates">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
49 <option value="F">Do not run edgeR</option>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
50 <option value="T" selected="true">Run edgeR</option>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
51 </param>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
52 <when value="T">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
53 <param name="edgeR_priordf" type="integer" value="20" size="3"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
54 label="prior.df for tagwise dispersion - lower value = more emphasis on each tag's variance. Replaces prior.n and prior.df = prior.n * residual.df"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
55 help="0 = Use edgeR default. Use a small value to 'smooth' small samples. See edgeR docs and note below"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
56 </when>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
57 <when value="F"> </when>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
58 </conditional>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
59 <conditional name="DESeq2">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
60 <param name="doDESeq2" type="select"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
61 label="Run the same model with DESeq2 and compare findings"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
62 help="DESeq2 is an update to the DESeq package. It uses different assumptions and methods to edgeR">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
63 <option value="F" selected="true">Do not run DESeq2</option>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
64 <option value="T">Run DESeq2 (only works if NO second GLM factor supplied at present)</option>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
65 </param>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
66 <when value="T">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
67 <param name="DESeq_fitType" type="select">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
68 <option value="parametric" selected="true">Parametric (default) fit for dispersions</option>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
69 <option value="local">Local fit - use this if parametric fails</option>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
70 <option value="mean">Mean dispersion fit- use this if you really understand what you're doing - read the fine manual</option>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
71 </param>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
72 </when>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
73 <when value="F"> </when>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
74 </conditional>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
75 <param name="doVoom" type="select"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
76 label="Run the same model with Voom/limma and compare findings"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
77 help="The VOOM transformation allows analysis of count data using limma">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
78 <option value="F" selected="true">Do not run VOOM</option>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
79 <option value="T">Run VOOM</option>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
80 </param>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
81 <param name="fdrthresh" type="float" value="0.05" size="5" label="P value threshold for FDR filtering for amily wise error rate control"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
82 help="Conventional default value of 0.05 recommended"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
83 <param name="fdrtype" type="select" label="FDR (Type II error) control method"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
84 help="Use fdr or bh typically to control for the number of tests in a reliable way">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
85 <option value="fdr" selected="true">fdr</option>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
86 <option value="BH">Benjamini Hochberg</option>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
87 <option value="BY">Benjamini Yukateli</option>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
88 <option value="bonferroni">Bonferroni</option>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
89 <option value="hochberg">Hochberg</option>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
90 <option value="holm">Holm</option>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
91 <option value="hommel">Hommel</option>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
92 <option value="none">no control for multiple tests</option>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
93 </param>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
94 </inputs>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
95 <outputs>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
96 <data format="tabular" name="outtab" label="${title}.xls"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
97 <data format="html" name="html_file" label="${title}.html"/>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
98 </outputs>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
99 <stdio>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
100 <exit_code range="4" level="fatal" description="Number of subject ids must match total number of samples in the input matrix" />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
101 </stdio>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
102 <tests>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
103 <test>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
104 <param name='input1' value='test_bams2mx.xls' ftype='tabular' />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
105 <param name='treatment_name' value='case' />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
106 <param name='title' value='edgeRtest' />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
107 <param name='useNDF' value='' />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
108 <param name='doedgeR' value='T' />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
109 <param name='doVoom' value='T' />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
110 <param name='doDESeq2' value='T' />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
111 <param name='fdrtype' value='fdr' />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
112 <param name='edgeR_priordf' value="8" />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
113 <param name='fdrthresh' value="0.05" />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
114 <param name='control_name' value='control' />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
115 <param name='subjectids' value='' />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
116 <param name='Treat_cols' value='3,4,5,9' />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
117 <param name='Control_cols' value='2,6,7,8' />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
118 <output name='outtab' file='edgeRtest1out.xls' compare='diff' />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
119 <output name='html_file' file='edgeRtest1out.html' compare='diff' lines_diff='20' />
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
120 </test>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
121 </tests>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
122
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
123 <configfiles>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
124 <configfile name="runme">
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
125 <![CDATA[
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
126 #
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
127 # edgeR.Rscript
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
128 # updated npv 2011 for R 2.14.0 and edgeR 2.4.0 by ross
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
129 # Performs DGE on a count table containing n replicates of two conditions
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
130 #
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
131 # Parameters
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
132 #
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
133 # 1 - Output Dir
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
134
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
135 # Original edgeR code by: S.Lunke and A.Kaspi
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
136 reallybig = log10(.Machine\$double.xmax)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
137 reallysmall = log10(.Machine\$double.xmin)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
138 library('stringr')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
139 library('gplots')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
140 library('edgeR')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
141 hmap2 = function(cmat,nsamp=100,outpdfname='heatmap2.pdf', TName='Treatment',group=NA,myTitle='title goes here')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
142 {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
143 # Perform clustering for significant pvalues after controlling FWER
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
144 samples = colnames(cmat)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
145 gu = unique(group)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
146 if (length(gu) == 2) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
147 col.map = function(g) {if (g==gu[1]) "#FF0000" else "#0000FF"}
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
148 pcols = unlist(lapply(group,col.map))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
149 } else {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
150 colours = rainbow(length(gu),start=0,end=4/6)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
151 pcols = colours[match(group,gu)] }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
152 gn = rownames(cmat)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
153 dm = cmat[(! is.na(gn)),]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
154 # remove unlabelled hm rows
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
155 nprobes = nrow(dm)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
156 # sub = paste('Showing',nprobes,'contigs ranked for evidence of differential abundance')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
157 if (nprobes > nsamp) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
158 dm =dm[1:nsamp,]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
159 #sub = paste('Showing',nsamp,'contigs ranked for evidence for differential abundance out of',nprobes,'total')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
160 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
161 newcolnames = substr(colnames(dm),1,20)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
162 colnames(dm) = newcolnames
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
163 pdf(outpdfname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
164 heatmap.2(dm,main=myTitle,ColSideColors=pcols,col=topo.colors(100),dendrogram="col",key=T,density.info='none',
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
165 Rowv=F,scale='row',trace='none',margins=c(8,8),cexRow=0.4,cexCol=0.5)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
166 dev.off()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
167 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
168
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
169 hmap = function(cmat,nmeans=4,outpdfname="heatMap.pdf",nsamp=250,TName='Treatment',group=NA,myTitle="Title goes here")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
170 {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
171 # for 2 groups only was
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
172 #col.map = function(g) {if (g==TName) "#FF0000" else "#0000FF"}
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
173 #pcols = unlist(lapply(group,col.map))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
174 gu = unique(group)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
175 colours = rainbow(length(gu),start=0.3,end=0.6)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
176 pcols = colours[match(group,gu)]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
177 nrows = nrow(cmat)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
178 mtitle = paste(myTitle,'Heatmap: n contigs =',nrows)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
179 if (nrows > nsamp) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
180 cmat = cmat[c(1:nsamp),]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
181 mtitle = paste('Heatmap: Top ',nsamp,' DE contigs (of ',nrows,')',sep='')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
182 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
183 newcolnames = substr(colnames(cmat),1,20)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
184 colnames(cmat) = newcolnames
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
185 pdf(outpdfname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
186 heatmap(cmat,scale='row',main=mtitle,cexRow=0.3,cexCol=0.4,Rowv=NA,ColSideColors=pcols)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
187 dev.off()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
188 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
189
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
190 qqPlot = function(descr='qqplot',pvector, outpdf='qqplot.pdf',...)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
191 # stolen from https://gist.github.com/703512
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
192 {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
193 o = -log10(sort(pvector,decreasing=F))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
194 e = -log10( 1:length(o)/length(o) )
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
195 o[o==-Inf] = reallysmall
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
196 o[o==Inf] = reallybig
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
197 maint = descr
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
198 pdf(outpdf)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
199 plot(e,o,pch=19,cex=1, main=maint, ...,
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
200 xlab=expression(Expected~~-log[10](italic(p))),
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
201 ylab=expression(Observed~~-log[10](italic(p))),
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
202 xlim=c(0,max(e)), ylim=c(0,max(o)))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
203 lines(e,e,col="red")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
204 grid(col = "lightgray", lty = "dotted")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
205 dev.off()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
206 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
207
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
208 smearPlot = function(DGEList,deTags, outSmear, outMain)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
209 {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
210 pdf(outSmear)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
211 plotSmear(DGEList,de.tags=deTags,main=outMain)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
212 grid(col="lightgray", lty="dotted")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
213 dev.off()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
214 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
215
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
216 boxPlot = function(rawrs,cleanrs,maint,myTitle,pdfname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
217 { #
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
218 nc = ncol(rawrs)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
219 for (i in c(1:nc)) {rawrs[(rawrs[,i] < 0),i] = NA}
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
220 fullnames = colnames(rawrs)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
221 newcolnames = substr(colnames(rawrs),1,20)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
222 colnames(rawrs) = newcolnames
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
223 newcolnames = substr(colnames(cleanrs),1,20)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
224 colnames(cleanrs) = newcolnames
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
225 defpar = par(no.readonly=T)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
226 print.noquote('raw contig counts by sample:')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
227 print.noquote(summary(rawrs))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
228 print.noquote('normalised contig counts by sample:')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
229 print.noquote(summary(cleanrs))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
230 pdf(pdfname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
231 par(mfrow=c(1,2))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
232 boxplot(rawrs,varwidth=T,notch=T,ylab='log contig count',col="maroon",las=3,cex.axis=0.35,main=paste('Raw:',maint))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
233 grid(col="lightgray",lty="dotted")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
234 boxplot(cleanrs,varwidth=T,notch=T,ylab='log contig count',col="maroon",las=3,cex.axis=0.35,main=paste('After ',maint))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
235 grid(col="lightgray",lty="dotted")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
236 dev.off()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
237 pdfname = "sample_counts_histogram.pdf"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
238 nc = ncol(rawrs)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
239 print.noquote(paste('Using ncol rawrs=',nc))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
240 ncroot = round(sqrt(nc))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
241 if (ncroot*ncroot < nc) { ncroot = ncroot + 1 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
242 m = c()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
243 for (i in c(1:nc)) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
244 rhist = hist(rawrs[,i],breaks=100,plot=F)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
245 m = append(m,max(rhist\$counts))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
246 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
247 ymax = max(m)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
248 pdf(pdfname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
249 par(mfrow=c(ncroot,ncroot))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
250 for (i in c(1:nc)) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
251 hist(rawrs[,i], main=paste("Contig logcount",i), xlab='log raw count', col="maroon",
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
252 breaks=100,sub=fullnames[i],cex=0.8,ylim=c(0,ymax))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
253 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
254 dev.off()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
255 par(defpar)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
256
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
257 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
258
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
259 cumPlot = function(rawrs,cleanrs,maint,myTitle)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
260 { # updated to use ecdf
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
261 pdfname = "Filtering_rowsum_bar_charts.pdf"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
262 defpar = par(no.readonly=T)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
263 lrs = log(rawrs,10)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
264 lim = max(lrs)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
265 pdf(pdfname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
266 par(mfrow=c(2,1))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
267 hist(lrs,breaks=100,main=paste('Before:',maint),xlab="# Reads (log)",
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
268 ylab="Count",col="maroon",sub=myTitle, xlim=c(0,lim),las=1)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
269 grid(col="lightgray", lty="dotted")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
270 lrs = log(cleanrs,10)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
271 hist(lrs,breaks=100,main=paste('After:',maint),xlab="# Reads (log)",
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
272 ylab="Count",col="maroon",sub=myTitle,xlim=c(0,lim),las=1)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
273 grid(col="lightgray", lty="dotted")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
274 dev.off()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
275 par(defpar)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
276 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
277
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
278 cumPlot1 = function(rawrs,cleanrs,maint,myTitle)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
279 { # updated to use ecdf
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
280 pdfname = paste(gsub(" ","", myTitle , fixed=TRUE),"RowsumCum.pdf",sep='_')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
281 pdf(pdfname)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
282 par(mfrow=c(2,1))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
283 lastx = max(rawrs)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
284 rawe = knots(ecdf(rawrs))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
285 cleane = knots(ecdf(cleanrs))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
286 cy = 1:length(cleane)/length(cleane)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
287 ry = 1:length(rawe)/length(rawe)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
288 plot(rawe,ry,type='l',main=paste('Before',maint),xlab="Log Contig Total Reads",
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
289 ylab="Cumulative proportion",col="maroon",log='x',xlim=c(1,lastx),sub=myTitle)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
290 grid(col="blue")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
291 plot(cleane,cy,type='l',main=paste('After',maint),xlab="Log Contig Total Reads",
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
292 ylab="Cumulative proportion",col="maroon",log='x',xlim=c(1,lastx),sub=myTitle)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
293 grid(col="blue")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
294 dev.off()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
295 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
296
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
297
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
298
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
299 doGSEA = function(y=NULL,design=NULL,histgmt="",
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
300 bigmt="/data/genomes/gsea/3.1/Abetterchoice_nocgp_c2_c3_c5_symbols_all.gmt",
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
301 ntest=0, myTitle="myTitle", outfname="GSEA.xls", minnin=5, maxnin=2000,fdrthresh=0.05,fdrtype="BH")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
302 {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
303 sink('Camera.log')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
304 genesets = c()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
305 if (bigmt > "")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
306 {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
307 bigenesets = readLines(bigmt)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
308 genesets = bigenesets
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
309 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
310 if (histgmt > "")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
311 {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
312 hgenesets = readLines(histgmt)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
313 if (bigmt > "") {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
314 genesets = rbind(genesets,hgenesets)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
315 } else {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
316 genesets = hgenesets
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
317 } # use only history if no bi
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
318 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
319 print.noquote(paste("@@@read",length(genesets), 'genesets from',histgmt,bigmt))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
320 genesets = strsplit(genesets,'\t') # tabular. genesetid\tURLorwhatever\tgene_1\t..\tgene_n
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
321 outf = outfname
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
322 head=paste(myTitle,'edgeR GSEA')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
323 write(head,file=outfname,append=F)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
324 ntest=length(genesets)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
325 urownames = toupper(rownames(y))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
326 upcam = c()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
327 downcam = c()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
328 for (i in 1:ntest) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
329 gs = unlist(genesets[i])
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
330 g = gs[1] # geneset_id
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
331 u = gs[2]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
332 if (u > "") { u = paste("<a href=\'",u,"\'>",u,"</a>",sep="") }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
333 glist = gs[3:length(gs)] # member gene symbols
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
334 glist = toupper(glist)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
335 inglist = urownames %in% glist
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
336 nin = sum(inglist)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
337 if ((nin > minnin) && (nin < maxnin)) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
338 ### print(paste('@@found',sum(inglist),'genes in glist'))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
339 camres = camera(y=y,index=inglist,design=design)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
340 if (! is.null(camres)) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
341 rownames(camres) = g # gene set name
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
342 camres = cbind(GeneSet=g,URL=u,camres)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
343 if (camres\$Direction == "Up")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
344 {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
345 upcam = rbind(upcam,camres) } else {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
346 downcam = rbind(downcam,camres)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
347 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
348 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
349 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
350 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
351 uscam = upcam[order(upcam\$PValue),]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
352 unadjp = uscam\$PValue
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
353 uscam\$adjPValue = p.adjust(unadjp,method=fdrtype)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
354 nup = max(10,sum((uscam\$adjPValue < fdrthresh)))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
355 dscam = downcam[order(downcam\$PValue),]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
356 unadjp = dscam\$PValue
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
357 dscam\$adjPValue = p.adjust(unadjp,method=fdrtype)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
358 ndown = max(10,sum((dscam\$adjPValue < fdrthresh)))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
359 write.table(uscam,file=paste('camera_up',outfname,sep='_'),quote=F,sep='\t',row.names=F)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
360 write.table(dscam,file=paste('camera_down',outfname,sep='_'),quote=F,sep='\t',row.names=F)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
361 print.noquote(paste('@@@@@ Camera up top',nup,'gene sets:'))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
362 write.table(head(uscam,nup),file="",quote=F,sep='\t',row.names=F)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
363 print.noquote(paste('@@@@@ Camera down top',ndown,'gene sets:'))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
364 write.table(head(dscam,ndown),file="",quote=F,sep='\t',row.names=F)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
365 sink()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
366 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
367
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
368
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
369
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
370 edgeIt = function (Count_Matrix,group,outputfilename,fdrtype='fdr',priordf=5,
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
371 fdrthresh=0.05,outputdir='.', myTitle='Differential Counts',libSize=c(),useNDF=F,
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
372 filterquantile=0.2, subjects=c(),mydesign=NULL,
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
373 doDESeq2=T,doVoom=T,doCamera=T,doedgeR=T,org='hg19',
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
374 histgmt="", bigmt="/data/genomes/gsea/3.1/Abetterchoice_nocgp_c2_c3_c5_symbols_all.gmt",
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
375 doCook=F,DESeq_fitType="parameteric")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
376 {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
377 # Error handling
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
378 if (length(unique(group))!=2){
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
379 print("Number of conditions identified in experiment does not equal 2")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
380 q()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
381 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
382 require(edgeR)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
383 options(width = 512)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
384 mt = paste(unlist(strsplit(myTitle,'_')),collapse=" ")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
385 allN = nrow(Count_Matrix)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
386 nscut = round(ncol(Count_Matrix)/2)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
387 colTotmillionreads = colSums(Count_Matrix)/1e6
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
388 counts.dataframe = as.data.frame(c())
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
389 rawrs = rowSums(Count_Matrix)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
390 nonzerod = Count_Matrix[(rawrs > 0),] # remove all zero count genes
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
391 nzN = nrow(nonzerod)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
392 nzrs = rowSums(nonzerod)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
393 zN = allN - nzN
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
394 print('# Quantiles for non-zero row counts:',quote=F)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
395 print(quantile(nzrs,probs=seq(0,1,0.1)),quote=F)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
396 if (useNDF == "T")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
397 {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
398 gt1rpin3 = rowSums(Count_Matrix/expandAsMatrix(colTotmillionreads,dim(Count_Matrix)) >= 1) >= nscut
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
399 lo = colSums(Count_Matrix[!gt1rpin3,])
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
400 workCM = Count_Matrix[gt1rpin3,]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
401 cleanrs = rowSums(workCM)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
402 cleanN = length(cleanrs)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
403 meth = paste( "After removing",length(lo),"contigs with fewer than ",nscut," sample read counts >= 1 per million, there are",sep="")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
404 print(paste("Read",allN,"contigs. Removed",zN,"contigs with no reads.",meth,cleanN,"contigs"),quote=F)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
405 maint = paste('Filter >=1/million reads in >=',nscut,'samples')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
406 } else {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
407 useme = (nzrs > quantile(nzrs,filterquantile))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
408 workCM = nonzerod[useme,]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
409 lo = colSums(nonzerod[!useme,])
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
410 cleanrs = rowSums(workCM)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
411 cleanN = length(cleanrs)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
412 meth = paste("After filtering at count quantile =",filterquantile,", there are",sep="")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
413 print(paste('Read',allN,"contigs. Removed",zN,"with no reads.",meth,cleanN,"contigs"),quote=F)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
414 maint = paste('Filter below',filterquantile,'quantile')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
415 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
416 cumPlot(rawrs=rawrs,cleanrs=cleanrs,maint=maint,myTitle=myTitle)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
417 allgenes = rownames(workCM)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
418 reg = "^chr([0-9]+):([0-9]+)-([0-9]+)"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
419 genecards="<a href=\'http://www.genecards.org/index.php?path=/Search/keyword/"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
420 ucsc = paste("<a href=\'http://genome.ucsc.edu/cgi-bin/hgTracks?db=",org,sep='')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
421 testreg = str_match(allgenes,reg)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
422 if (sum(!is.na(testreg[,1]))/length(testreg[,1]) > 0.8) # is ucsc style string
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
423 {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
424 print("@@ using ucsc substitution for urls")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
425 contigurls = paste0(ucsc,"&amp;position=chr",testreg[,2],":",testreg[,3],"-",testreg[,4],"\'>",allgenes,"</a>")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
426 } else {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
427 print("@@ using genecards substitution for urls")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
428 contigurls = paste0(genecards,allgenes,"\'>",allgenes,"</a>")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
429 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
430 print.noquote("# urls")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
431 print.noquote(head(contigurls))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
432 print(paste("# Total low count contigs per sample = ",paste(lo,collapse=',')),quote=F)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
433 cmrowsums = rowSums(workCM)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
434 TName=unique(group)[1]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
435 CName=unique(group)[2]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
436 if (is.null(mydesign)) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
437 if (length(subjects) == 0)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
438 {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
439 mydesign = model.matrix(~group)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
440 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
441 else {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
442 subjf = factor(subjects)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
443 mydesign = model.matrix(~subjf+group) # we block on subject so make group last to simplify finding it
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
444 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
445 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
446 print.noquote(paste('Using samples:',paste(colnames(workCM),collapse=',')))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
447 print.noquote('Using design matrix:')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
448 print.noquote(mydesign)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
449 if (doedgeR) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
450 sink('edgeR.log')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
451 #### Setup DGEList object
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
452 DGEList = DGEList(counts=workCM, group = group)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
453 DGEList = calcNormFactors(DGEList)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
454
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
455 DGEList = estimateGLMCommonDisp(DGEList,mydesign)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
456 comdisp = DGEList\$common.dispersion
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
457 DGEList = estimateGLMTrendedDisp(DGEList,mydesign)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
458 if (edgeR_priordf > 0) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
459 print.noquote(paste("prior.df =",edgeR_priordf))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
460 DGEList = estimateGLMTagwiseDisp(DGEList,mydesign,prior.df = edgeR_priordf)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
461 } else {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
462 DGEList = estimateGLMTagwiseDisp(DGEList,mydesign)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
463 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
464 DGLM = glmFit(DGEList,design=mydesign)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
465 DE = glmLRT(DGLM,coef=ncol(DGLM\$design)) # always last one - subject is first if needed
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
466 efflib = DGEList\$samples\$lib.size*DGEList\$samples\$norm.factors
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
467 normData = (1e+06*DGEList\$counts/efflib)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
468 uoutput = cbind(
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
469 Name=as.character(rownames(DGEList\$counts)),
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
470 DE\$table,
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
471 adj.p.value=p.adjust(DE\$table\$PValue, method=fdrtype),
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
472 Dispersion=DGEList\$tagwise.dispersion,totreads=cmrowsums,normData,
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
473 DGEList\$counts
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
474 )
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
475 soutput = uoutput[order(DE\$table\$PValue),] # sorted into p value order - for quick toptable
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
476 goodness = gof(DGLM, pcutoff=fdrthresh)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
477 if (sum(goodness\$outlier) > 0) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
478 print.noquote('GLM outliers:')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
479 print(paste(rownames(DGLM)[(goodness\$outlier)],collapse=','),quote=F)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
480 } else {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
481 print('No GLM fit outlier genes found\n')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
482 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
483 z = limma::zscoreGamma(goodness\$gof.statistic, shape=goodness\$df/2, scale=2)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
484 pdf("edgeR_GoodnessofFit.pdf")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
485 qq = qqnorm(z, panel.first=grid(), main="tagwise dispersion")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
486 abline(0,1,lwd=3)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
487 points(qq\$x[goodness\$outlier],qq\$y[goodness\$outlier], pch=16, col="maroon")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
488 dev.off()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
489 estpriorn = getPriorN(DGEList)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
490 print(paste("Common Dispersion =",comdisp,"CV = ",sqrt(comdisp),"getPriorN = ",estpriorn),quote=F)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
491 efflib = DGEList\$samples\$lib.size*DGEList\$samples\$norm.factors
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
492 normData = (1e+06*DGEList\$counts/efflib)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
493 uniqueg = unique(group)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
494 #### Plot MDS
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
495 sample_colors = match(group,levels(group))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
496 sampleTypes = levels(factor(group))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
497 print.noquote(sampleTypes)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
498 pdf("edgeR_MDSplot.pdf")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
499 plotMDS.DGEList(DGEList,main=paste("edgeR MDS for",myTitle),cex=0.5,col=sample_colors,pch=sample_colors)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
500 legend(x="topleft", legend = sampleTypes,col=c(1:length(sampleTypes)), pch=19)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
501 grid(col="blue")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
502 dev.off()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
503 colnames(normData) = paste( colnames(normData),'N',sep="_")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
504 print(paste('Raw sample read totals',paste(colSums(nonzerod,na.rm=T),collapse=',')))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
505 nzd = data.frame(log(nonzerod + 1e-2,10))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
506 boxPlot(rawrs=nzd,cleanrs=log(normData,10),maint='TMM Normalisation',myTitle=myTitle,pdfname="edgeR_raw_norm_counts_box.pdf")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
507 write.table(soutput,outputfilename, quote=FALSE, sep="\t",row.names=F)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
508 tt = cbind(
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
509 Name=as.character(rownames(DGEList\$counts)),
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
510 DE\$table,
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
511 adj.p.value=p.adjust(DE\$table\$PValue, method=fdrtype),
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
512 Dispersion=DGEList\$tagwise.dispersion,totreads=cmrowsums
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
513 )
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
514 print.noquote("# edgeR Top tags\n")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
515 tt = cbind(tt,URL=contigurls) # add to end so table isn't laid out strangely
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
516 tt = tt[order(DE\$table\$PValue),]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
517 print.noquote(tt[1:50,])
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
518 deTags = rownames(uoutput[uoutput\$adj.p.value < fdrthresh,])
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
519 nsig = length(deTags)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
520 print(paste('#',nsig,'tags significant at adj p=',fdrthresh),quote=F)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
521 deColours = ifelse(deTags,'red','black')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
522 pdf("edgeR_BCV_vs_abundance.pdf")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
523 plotBCV(DGEList, cex=0.3, main="Biological CV vs abundance")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
524 dev.off()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
525 dg = DGEList[order(DE\$table\$PValue),]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
526 #normData = (1e+06 * dg\$counts/expandAsMatrix(dg\$samples\$lib.size, dim(dg)))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
527 efflib = dg\$samples\$lib.size*dg\$samples\$norm.factors
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
528 normData = (1e+06*dg\$counts/efflib)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
529 outpdfname="edgeR_heatmap.pdf"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
530 hmap2(normData,nsamp=100,TName=TName,group=group,outpdfname=outpdfname,myTitle=myTitle)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
531 outSmear = "edgeR_smearplot.pdf"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
532 outMain = paste("Smear Plot for ",TName,' Vs ',CName,' (FDR@',fdrthresh,' N = ',nsig,')',sep='')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
533 smearPlot(DGEList=DGEList,deTags=deTags, outSmear=outSmear, outMain = outMain)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
534 qqPlot(descr=paste(myTitle,'edgeR QQ plot'),pvector=DE\$table\$PValue,outpdf='edgeR_qqplot.pdf')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
535 norm.factor = DGEList\$samples\$norm.factors
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
536 topresults.edgeR = soutput[which(soutput\$adj.p.value < fdrthresh), ]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
537 edgeRcountsindex = which(allgenes %in% rownames(topresults.edgeR))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
538 edgeRcounts = rep(0, length(allgenes))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
539 edgeRcounts[edgeRcountsindex] = 1 # Create venn diagram of hits
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
540 sink()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
541 } ### doedgeR
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
542 if (doDESeq2 == T)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
543 {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
544 sink("DESeq2.log")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
545 # DESeq2
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
546 require('DESeq2')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
547 library('RColorBrewer')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
548 pdata = data.frame(Name=colnames(workCM),Rx=group,row.names=colnames(workCM))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
549 deSEQds = DESeqDataSetFromMatrix(countData = workCM, colData = pdata, design = formula(~ Rx))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
550 #DESeq2 = DESeq(deSEQds,fitType='local',pAdjustMethod=fdrtype)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
551 #rDESeq = results(DESeq2)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
552 #newCountDataSet(workCM, group)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
553 deSeqDatsizefac = estimateSizeFactors(deSEQds)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
554 deSeqDatdisp = estimateDispersions(deSeqDatsizefac,fitType=DESeq_fitType)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
555 resDESeq = nbinomWaldTest(deSeqDatdisp, pAdjustMethod=fdrtype)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
556 rDESeq = as.data.frame(results(resDESeq))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
557 rDESeq = cbind(Contig=rownames(workCM),rDESeq,NReads=cmrowsums,URL=contigurls)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
558 srDESeq = rDESeq[order(rDESeq\$pvalue),]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
559 qqPlot(descr=paste(myTitle,'DESeq2 qqplot'),pvector=rDESeq\$pvalue,outpdf='DESeq2_qqplot.pdf')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
560 cat("# DESeq top 50\n")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
561 print.noquote(srDESeq[1:50,])
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
562 write.table(srDESeq,paste(mt,'DESeq2_TopTable.xls',sep='_'), quote=FALSE, sep="\t",row.names=F)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
563 topresults.DESeq = rDESeq[which(rDESeq\$padj < fdrthresh), ]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
564 DESeqcountsindex = which(allgenes %in% rownames(topresults.DESeq))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
565 DESeqcounts = rep(0, length(allgenes))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
566 DESeqcounts[DESeqcountsindex] = 1
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
567 pdf("DESeq2_dispersion_estimates.pdf")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
568 plotDispEsts(resDESeq)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
569 dev.off()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
570 ysmall = abs(min(rDESeq\$log2FoldChange))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
571 ybig = abs(max(rDESeq\$log2FoldChange))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
572 ylimit = min(4,ysmall,ybig)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
573 pdf("DESeq2_MA_plot.pdf")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
574 plotMA(resDESeq,main=paste(myTitle,"DESeq2 MA plot"),ylim=c(-ylimit,ylimit))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
575 dev.off()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
576 rlogres = rlogTransformation(resDESeq)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
577 sampledists = dist( t( assay(rlogres) ) )
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
578 sdmat = as.matrix(sampledists)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
579 pdf("DESeq2_sample_distance_plot.pdf")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
580 heatmap.2(sdmat,trace="none",main=paste(myTitle,"DESeq2 sample distances"),
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
581 col = colorRampPalette( rev(brewer.pal(9, "RdBu")) )(255))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
582 dev.off()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
583 sink()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
584 result = try( (ppca = plotPCA( varianceStabilizingTransformation(deSeqDatdisp,blind=T), intgroup=c("Rx","Name")) ) )
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
585 if ("try-error" %in% class(result)) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
586 print.noquote('DESeq2 plotPCA failed.')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
587 } else {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
588 pdf("DESeq2_PCA_plot.pdf")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
589 #### wtf - print? Seems needed to get this to work
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
590 print(ppca)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
591 dev.off()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
592 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
593 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
594
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
595 if (doVoom == T) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
596 sink('VOOM.log')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
597 pdf("VOOM_mean_variance_plot.pdf")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
598 dat.voomed = voom(DGEList, mydesign, plot = TRUE, lib.size = colSums(workCM) * norm.factor)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
599 dev.off()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
600 # Use limma to fit data
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
601 fit = lmFit(dat.voomed, mydesign)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
602 fit = eBayes(fit)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
603 rvoom = topTable(fit, coef = length(colnames(mydesign)), adj = fdrtype, n = Inf, sort="none")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
604 qqPlot(descr=paste(myTitle,'VOOM-limma QQ plot'),pvector=rvoom\$P.Value,outpdf='VOOM_qqplot.pdf')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
605 rownames(rvoom) = rownames(workCM)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
606 rvoom = cbind(rvoom,NReads=cmrowsums,URL=contigurls)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
607 srvoom = rvoom[order(rvoom\$P.Value),]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
608 write.table(srvoom,paste(mt,'VOOM_topTable.xls',sep='_'), quote=FALSE, sep="\t",row.names=F)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
609 # Use an FDR cutoff to find interesting samples for edgeR, DESeq and voom/limma
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
610 topresults.voom = srvoom[which(rvoom\$adj.P.Val < fdrthresh), ]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
611 voomcountsindex = which(allgenes %in% topresults.voom\$ID)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
612 voomcounts = rep(0, length(allgenes))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
613 voomcounts[voomcountsindex] = 1
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
614 cat("# VOOM top 50\n")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
615 print(srvoom[1:50,])
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
616 sink()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
617 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
618
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
619 if (doCamera) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
620 doGSEA(y=DGEList,design=mydesign,histgmt=histgmt,bigmt=bigmt,ntest=20,myTitle=myTitle,
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
621 outfname=paste(mt,"GSEA.xls",sep="_"),fdrthresh=fdrthresh,fdrtype=fdrtype)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
622 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
623
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
624 if ((doDESeq2==T) || (doVoom==T) || (doedgeR==T)) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
625 if ((doVoom==T) && (doDESeq2==T) && (doedgeR==T)) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
626 vennmain = paste(mt,'Voom,edgeR and DESeq2 overlap at FDR=',fdrthresh)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
627 counts.dataframe = data.frame(edgeR = edgeRcounts, DESeq2 = DESeqcounts,
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
628 VOOM_limma = voomcounts, row.names = allgenes)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
629 } else if ((doDESeq2==T) && (doedgeR==T)) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
630 vennmain = paste(mt,'DESeq2 and edgeR overlap at FDR=',fdrthresh)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
631 counts.dataframe = data.frame(edgeR = edgeRcounts, DESeq2 = DESeqcounts, row.names = allgenes)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
632 } else if ((doVoom==T) && (doedgeR==T)) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
633 vennmain = paste(mt,'Voom and edgeR overlap at FDR=',fdrthresh)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
634 counts.dataframe = data.frame(edgeR = edgeRcounts, VOOM_limma = voomcounts, row.names = allgenes)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
635 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
636
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
637 if (nrow(counts.dataframe > 1)) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
638 counts.venn = vennCounts(counts.dataframe)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
639 vennf = "Venn_significant_genes_overlap.pdf"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
640 pdf(vennf)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
641 vennDiagram(counts.venn,main=vennmain,col="maroon")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
642 dev.off()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
643 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
644 } #### doDESeq2 or doVoom
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
645 #Return our main table
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
646 uoutput
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
647
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
648 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
649 #### Done
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
650
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
651 ###sink(stdout(),append=T,type="message")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
652 builtin_gmt=""
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
653 history_gmt=""
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
654 doDESeq2 = $DESeq2.doDESeq2 # make these T or F
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
655 doVoom = $doVoom
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
656 doCamera = F
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
657 doedgeR = $edgeR.doedgeR
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
658 edgeR_priordf = 0
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
659
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
660 #if $DESeq2.doDESeq2 == "T"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
661 DESeq_fitType = "$DESeq2.DESeq_fitType"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
662 #end if
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
663 #if $edgeR.doedgeR == "T"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
664 edgeR_priordf = $edgeR.edgeR_priordf
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
665 #end if
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
666
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
667
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
668 Out_Dir = "$html_file.files_path"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
669 Input = "$input1"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
670 TreatmentName = "$treatment_name"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
671 TreatmentCols = "$Treat_cols"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
672 ControlName = "$control_name"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
673 ControlCols= "$Control_cols"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
674 outputfilename = "$outtab"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
675 org = "$input1.dbkey"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
676 if (org == "") { org = "hg19"}
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
677 fdrtype = "$fdrtype"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
678 fdrthresh = $fdrthresh
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
679 useNDF = "$useNDF"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
680 fQ = $fQ # non-differential centile cutoff
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
681 myTitle = "$title"
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
682 subjects = c($subjectids)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
683 nsubj = length(subjects)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
684 if (nsubj > 0) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
685 if (doDESeq2) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
686 print('WARNING - cannot yet use DESeq2 for 2 way anova - see the docs')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
687 doDESeq2 = F
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
688 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
689 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
690 TCols = as.numeric(strsplit(TreatmentCols,",")[[1]])-1
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
691 CCols = as.numeric(strsplit(ControlCols,",")[[1]])-1
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
692 cat('Got TCols=')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
693 cat(TCols)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
694 cat('; CCols=')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
695 cat(CCols)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
696 cat('\n')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
697 useCols = c(TCols,CCols)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
698 if (file.exists(Out_Dir) == F) dir.create(Out_Dir)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
699 Count_Matrix = read.table(Input,header=T,row.names=1,sep='\t') #Load tab file assume header
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
700 snames = colnames(Count_Matrix)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
701 nsamples = length(snames)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
702 if (nsubj > 0 & nsubj != nsamples) {
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
703 options("show.error.messages"=T)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
704 mess = paste('Fatal error: Supplied subject id list',paste(subjects,collapse=','),
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
705 'has length',nsubj,'but there are',nsamples,'samples',paste(snames,collapse=','))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
706 write(mess, stderr())
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
707 quit(save="no",status=4)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
708 }
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
709
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
710 Count_Matrix = Count_Matrix[,useCols] ### reorder columns
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
711 if (length(subjects) != 0) {subjects = subjects[useCols]}
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
712 rn = rownames(Count_Matrix)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
713 islib = rn %in% c('librarySize','NotInBedRegions')
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
714 LibSizes = Count_Matrix[subset(rn,islib),][1] # take first
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
715 Count_Matrix = Count_Matrix[subset(rn,! islib),]
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
716 group = c(rep(TreatmentName,length(TCols)), rep(ControlName,length(CCols)) ) #Build a group descriptor
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
717 group = factor(group, levels=c(ControlName,TreatmentName))
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
718 colnames(Count_Matrix) = paste(group,colnames(Count_Matrix),sep="_") #Relable columns
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
719 results = edgeIt(Count_Matrix=Count_Matrix,group=group,outputfilename=outputfilename,
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
720 fdrtype='BH',priordf=edgeR_priordf,fdrthresh=0.05,outputdir='.',
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
721 myTitle=myTitle,useNDF=F,libSize=c(),filterquantile=fQ,subjects=c(),
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
722 doDESeq2=doDESeq2,doVoom=doVoom,doCamera=doCamera,doedgeR=doedgeR,org=org,
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
723 histgmt=history_gmt,bigmt=builtin_gmt,DESeq_fitType=DESeq_fitType)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
724 sessionInfo()
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
725 ]]>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
726 </configfile>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
727 </configfiles>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
728 <help>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
729
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
730 ----
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
731
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
732 **What it does**
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
733
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
734 Allows short read sequence counts from controlled experiments to be analysed for differentially expressed genes.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
735 Optionally adds a term for subject if not all samples are independent or if some other factor needs to be blocked in the design.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
736
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
737 **Input**
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
738
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
739 Requires a count matrix as a tabular file. These are best made using the companion HTSeq_ based counter Galaxy wrapper
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
740 and your fave gene model to generate inputs. Each row is a genomic feature (gene or exon eg) and each column the
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
741 non-negative integer count of reads from one sample overlapping the feature.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
742 The matrix must have a header row uniquely identifying the source samples, and unique row names in
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
743 the first column. Typically the row names are gene symbols or probe ids for downstream use in GSEA and other methods.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
744
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
745 **Specifying comparisons**
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
746
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
747 This is basically dumbed down for two factors - case vs control.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
748
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
749 More complex interfaces are possible but painful at present.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
750 Probably need to specify a phenotype file to do this better.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
751 Work in progress. Send code.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
752
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
753 If you have (eg) paired samples and wish to include a term in the GLM to account for some other factor (subject in the case of paired samples),
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
754 put a comma separated list of indicators for every sample (whether modelled or not!) indicating (eg) the subject number or
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
755 A list of integers, one for each subject or an empty string if samples are all independent.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
756 If not empty, there must be exactly as many integers in the supplied integer list as there are columns (samples) in the count matrix.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
757 Integers for samples that are not in the analysis *must* be present in the string as filler even if not used.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
758
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
759 So if you have 2 pairs out of 6 samples, you need to put in unique integers for the unpaired ones
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
760 eg if you had 6 samples with the first two independent but the second and third pairs each being from independent subjects. you might use
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
761 8,9,1,1,2,2
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
762 as subject IDs to indicate two paired samples from the same subject in columns 3/4 and 5/6
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
763
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
764 **Methods available**
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
765
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
766 You can run 3 popular Bioconductor packages available for count data.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
767
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
768 edgeR - see edgeR_ for details
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
769
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
770 VOOM/limma - see limma_VOOM_ for details
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
771
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
772 DESeq2 - see DESeq2_ for details
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
773
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
774 and optionally camera in edgeR which works better if MSigDB is installed.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
775
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
776 **Outputs**
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
777
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
778 Some helpful plots and analysis results. Note that most of these are produced using R code
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
779 suggested by the excellent documentation and vignettes for the Bioconductor
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
780 packages invoked. The Tool Factory is used to automatically lay these out for you to enjoy.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
781
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
782 ***old rant on changes to Bioconductor package variable names between versions***
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
783
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
784 The edgeR authors made a small cosmetic change in the name of one important variable (from p.value to PValue)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
785 breaking this and all other code that assumed the old name for this variable,
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
786 between edgeR2.4.4 and 2.4.6 (the version for R 2.14 as at the time of writing).
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
787 This means that all code using edgeR is sensitive to the version. I think this was a very unwise thing
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
788 to do because it wasted hours of my time to track down and will similarly cost other edgeR users dearly
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
789 when their old scripts break. This tool currently now works with 2.4.6.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
790
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
791 **Note on prior.N**
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
792
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
793 http://seqanswers.com/forums/showthread.php?t=5591 says:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
794
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
795 *prior.n*
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
796
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
797 The value for prior.n determines the amount of smoothing of tagwise dispersions towards the common dispersion.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
798 You can think of it as like a "weight" for the common value. (It is actually the weight for the common likelihood
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
799 in the weighted likelihood equation). The larger the value for prior.n, the more smoothing, i.e. the closer your
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
800 tagwise dispersion estimates will be to the common dispersion. If you use a prior.n of 1, then that gives the
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
801 common likelihood the weight of one observation.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
802
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
803 In answer to your question, it is a good thing to squeeze the tagwise dispersions towards a common value,
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
804 or else you will be using very unreliable estimates of the dispersion. I would not recommend using the value that
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
805 you obtained from estimateSmoothing()---this is far too small and would result in virtually no moderation
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
806 (squeezing) of the tagwise dispersions. How many samples do you have in your experiment?
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
807 What is the experimental design? If you have few samples (less than 6) then I would suggest a prior.n of at least 10.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
808 If you have more samples, then the tagwise dispersion estimates will be more reliable,
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
809 so you could consider using a smaller prior.n, although I would hesitate to use a prior.n less than 5.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
810
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
811
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
812 From Bioconductor Digest, Vol 118, Issue 5, Gordon writes:
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
813
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
814 Dear Dorota,
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
815
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
816 The important settings are prior.df and trend.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
817
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
818 prior.n and prior.df are related through prior.df = prior.n * residual.df,
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
819 and your experiment has residual.df = 36 - 12 = 24. So the old setting of
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
820 prior.n=10 is equivalent for your data to prior.df = 240, a very large
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
821 value. Going the other way, the new setting of prior.df=10 is equivalent
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
822 to prior.n=10/24.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
823
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
824 To recover old results with the current software you would use
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
825
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
826 estimateTagwiseDisp(object, prior.df=240, trend="none")
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
827
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
828 To get the new default from old software you would use
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
829
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
830 estimateTagwiseDisp(object, prior.n=10/24, trend=TRUE)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
831
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
832 Actually the old trend method is equivalent to trend="loess" in the new
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
833 software. You should use plotBCV(object) to see whether a trend is
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
834 required.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
835
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
836 Note you could also use
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
837
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
838 prior.n = getPriorN(object, prior.df=10)
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
839
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
840 to map between prior.df and prior.n.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
841
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
842 ----
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
843
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
844 **Attributions**
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
845
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
846 edgeR - edgeR_
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
847
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
848 VOOM/limma - limma_VOOM_
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
849
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
850 DESeq2 - DESeq2_ for details
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
851
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
852 See above for Bioconductor package documentation for packages exposed in Galaxy by this tool and app store package.
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
853
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
854 Galaxy_ (that's what you are using right now!) for gluing everything together
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
855
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
856 Otherwise, all code and documentation comprising this tool was written by Ross Lazarus and is
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
857 licensed to you under the LGPL_ like other rgenetics artefacts
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
858
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
859 .. _LGPL: http://www.gnu.org/copyleft/lesser.html
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
860 .. _HTSeq: http://www-huber.embl.de/users/anders/HTSeq/doc/index.html
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
861 .. _edgeR: http://www.bioconductor.org/packages/release/bioc/html/edgeR.html
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
862 .. _DESeq2: http://www.bioconductor.org/packages/release/bioc/html/DESeq2.html
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
863 .. _limma_VOOM: http://www.bioconductor.org/packages/release/bioc/html/limma.html
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
864 .. _Galaxy: http://getgalaxy.org
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
865 </help>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
866
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
867 </tool>
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
868
2122e630b13a Initial commit of replacement for edger_test
fubar
parents:
diff changeset
869