0
|
1 <tool id="Readmap" name="Generate readmap and histograms from alignment files" version="1.0.0">
|
|
2 <description>from sRbowtie aligment</description>
|
|
3 <requirements>
|
|
4 <requirement type="package" version="0.12.7">bowtie</requirement>
|
|
5 <requirement type="package" version="0.1.18">samtools</requirement>
|
|
6 <requirement type="package" version="0.7.7">pysam</requirement>
|
|
7 <requirement type="package" version="2.14">biocbasics</requirement>
|
|
8 <requirement type="package" version="3.0.3">R</requirement>
|
1
|
9 <requirement type="package" version="1.9">numpy</requirement>
|
|
10 <requirement type="package" version="0.14">scipy</requirement>
|
0
|
11 </requirements>
|
|
12 <command interpreter="python">
|
|
13 readmap.py
|
|
14 #if $refGenomeSource.genomeSource == "history":
|
|
15 --reference_fasta ## sys.argv[2]
|
|
16 $refGenomeSource.ownFile ## index source
|
|
17 #else:
|
|
18 #silent reference= filter( lambda x: str( x[0] ) == str( $refGenomeSource.series[0].input.dbkey ), $__app__.tool_data_tables[ 'bowtie_indexes' ].get_fields() )[0][-1]
|
|
19 --reference_bowtie_index
|
|
20 $reference
|
|
21 #end if
|
|
22 --rcode
|
|
23 $plotCode
|
|
24 --output_readmap
|
|
25 $readmap_dataframe
|
|
26 --output_size_distribution
|
|
27 $size_distribution_dataframe
|
|
28 --minquery
|
|
29 $minquery
|
|
30 --maxquery
|
|
31 $maxquery
|
|
32 --input
|
|
33 #for $i in $refGenomeSource.series
|
|
34 $i.input
|
|
35 #end for
|
|
36 --ext
|
|
37 #for $i in $refGenomeSource.series
|
|
38 $i.input.ext
|
|
39 #end for
|
|
40 --label
|
|
41 #for $i in $refGenomeSource.series
|
|
42 "$i.input.name"
|
|
43 #end for
|
|
44 --normalization_factor
|
|
45 #for $i in $refGenomeSource.series
|
|
46 $i.norm
|
|
47 #end for
|
|
48 #if $gff:
|
|
49 --gff
|
|
50 $gff
|
|
51 #end if
|
|
52
|
|
53 </command>
|
|
54 <inputs>
|
|
55 <conditional name="refGenomeSource">
|
|
56 <param name="genomeSource" type="select" label="Will you select a reference genome from your history or use a built-in index?" help="Built-ins were indexed using default options">
|
|
57 <option value="indexed">Use a built-in index</option>
|
|
58 <option value="history">Use one from the history</option>
|
|
59 </param>
|
|
60 <when value="indexed">
|
|
61 <repeat name="series" title="Add alignment files">
|
|
62 <param name="input" type="data" label="Select multiple alignments to parse">
|
|
63 <validator type="dataset_metadata_in_data_table" table_name="bowtie_indexes" metadata_name="dbkey" metadata_column="0" message="database not set for this bowtie output. Select the database(=genome used for matching) manually, or select a reference fasta from your history."/>
|
|
64 </param>
|
|
65 <param name="norm" type="float" value="1" label="Indicate a normalization factor to compare multiple aligments"/>
|
|
66 </repeat>
|
|
67 </when>
|
|
68 <when value="history">
|
|
69 <param name="ownFile" type="data" format="fasta" label="Select a fasta file, that served as the reference index for the alignments" />
|
|
70 <repeat name="series" title="Add alignment files">
|
|
71 <param name="input" type="data" label="Select multiple alignments to parse"/>
|
|
72 <param name="norm" type="float" value="1" label="Indicate a normalization factor to compare multiple aligments"/>
|
|
73 </repeat>
|
|
74 </when>
|
|
75 </conditional>
|
|
76 <param name="gff" type="data" format="gff3" optional="true" label="Optional: select a GFF to investigate regions of interest" help="GFF must match genome build"/>
|
|
77 <!-- <validator type="dataset_metadata_in_data_table" table_name="bowtie_indexes" metadata_name="dbkey" metadata_column="0" message="GFF database and alignment file databse do not match!"/> -->
|
|
78 <param name="minquery" type="integer" size="3" value="18" label="Min size of query small RNAs" help="'18' = 18 nucleotides"/>
|
|
79 <param name="maxquery" type="integer" size="3" value="28" label="Max size of query small RNAs" help="'28' = 28 nucleotides"/>
|
|
80 <param name="title" type="text" size="15" value= "Readmaps and size distributions" label="Main Titles"/>
|
|
81 <param name="xlabel" type="text" size="15" value="Coordinates/read size" label="x axis label"/>
|
|
82 <param name="ylabel" type="text" size="15" value="Number of reads" label="y axis label"/>
|
|
83 <param name="rows_per_page" type="text" size="9" value="8" label="How many items to display per page?">
|
|
84 <validator type="in_range" min="6" max="20" message="Select between 6 and 20 rows, as the readability will suffer otherwise."/>
|
|
85 </param>
|
|
86 </inputs>
|
|
87 <configfiles>
|
|
88 <configfile name="plotCode">
|
|
89 ## Setup R error handling to go to stderr
|
|
90 options( show.error.messages=F,
|
|
91 error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
|
|
92 library(RColorBrewer)
|
|
93 library(lattice)
|
|
94 library(latticeExtra)
|
|
95 library(grid)
|
|
96 library(gridExtra)
|
|
97
|
|
98 ## data frames implementation
|
|
99
|
|
100 rm=read.delim("${readmap_dataframe}", header=T, row.names=NULL)
|
|
101 n_samples=length(unique(rm\$sample))
|
|
102 genes=unique(levels(rm\$gene))
|
|
103 per_gene_readmap=lapply(genes, function(x) subset(rm, gene==x)) ####### ?
|
|
104 n_genes=length(per_gene_readmap)
|
|
105
|
|
106 size=read.delim("${size_distribution_dataframe}", header=T, row.names=NULL)
|
|
107 per_gene_size=lapply(genes, function(x) subset(size, gene==x)) ###### ?
|
|
108
|
|
109 ## end of data frames implementation
|
|
110
|
|
111 ## functions
|
|
112
|
|
113 plot_readmap=function(df, ...) {
|
|
114 combineLimits(xyplot(count~coord|factor(sample, levels=unique(sample))+reorder(gene, count, function(x) -sum(abs(x))),
|
|
115 data=df,
|
|
116 type='h',
|
|
117 scales= list(relation="free", x=list(rot=0, cex=0.7, axs="i", tck=0.5), y=list(tick.number=4, rot=90, cex=0.7)),
|
|
118 xlab=NULL, main=NULL, ylab=NULL,
|
|
119 as.table=T,
|
|
120 origin = 0,
|
|
121 horizontal=FALSE,
|
|
122 group=polarity,
|
|
123 col=c("red","blue"),
|
|
124 par.strip.text = list(cex=0.7),
|
|
125 ...))
|
|
126 }
|
|
127
|
|
128 plot_size_distribution= function(df, ...) {
|
|
129 smR.prepanel=function(x,y,...){; yscale=c(-max(abs(y)), max(abs(y)));list(ylim=yscale);}
|
|
130 bc= barchart(count~as.factor(size)|factor(sample, levels=unique(sample))+gene, data = df, origin = 0,
|
|
131 horizontal=FALSE,
|
|
132 group=polarity,
|
|
133 stack=TRUE,
|
|
134 col=c('red', 'blue'),
|
|
135 cex=0.75,
|
|
136 scales=list(y=list(tick.number=4, rot=90, relation="free", cex=0.7), x=list(cex=0.7) ),
|
|
137 prepanel=smR.prepanel,
|
|
138 xlab = NULL,
|
|
139 ylab = NULL,
|
|
140 main = NULL,
|
|
141 as.table=TRUE,
|
|
142 newpage = T,
|
|
143 par.strip.text = list(cex=0.7),
|
|
144 ...)
|
|
145 combineLimits(bc)
|
|
146 }
|
|
147
|
|
148 ## end of functions
|
|
149
|
|
150 ## function parameters'
|
|
151
|
|
152 par.settings.readmap=list(layout.heights=list(top.padding=0, bottom.padding=-2.5), strip.background = list(col=c("lightblue","lightgreen")) )
|
|
153 par.settings.size=list(layout.heights=list(top.padding=-1, bottom.padding=-2.5), strip.background = list(col=c("lightblue","lightgreen")) )
|
|
154 par.settings.combination.readmap=list(layout.heights=list(top.padding=0, bottom.padding=-3), strip.background=list(col=c("lightblue","lightgreen")) )
|
|
155 par.settings.combination.size=list(layout.heights=list(top.padding=-2, bottom.padding=-0.5), strip.background=list(col=c("lightblue", "lightgreen")) )
|
|
156
|
|
157 ## end of function parameters'
|
|
158
|
|
159 ## GRAPHS
|
|
160
|
|
161 if (n_genes > 7) {page_height_simple = 11.69; page_height_combi=11.69; rows_per_page=${rows_per_page}; extrarow=0 } else {
|
|
162 rows_per_page= n_genes; page_height_simple = 11.69/n_genes/4; page_height_combi=11.69/(n_genes*2); extrarow=1 }
|
|
163 if (n_samples > 4) {page_width = 8.2677*n_samples/4} else {page_width = 8.2677*n_samples/3} # to test
|
|
164
|
|
165 pdf(file="${readmap_PDF}", paper="special", height=page_height_simple, width=page_width)
|
|
166 for (i in seq(1,n_genes,rows_per_page)) {
|
|
167 start=i
|
|
168 end=i+rows_per_page-1
|
|
169 if (end>n_genes) {end=n_genes}
|
|
170 readmap_plot.list=lapply(per_gene_readmap[start:end], function(x) plot_readmap(x, par.settings=par.settings.readmap))
|
|
171 args.list=c(readmap_plot.list, list(nrow=rows_per_page, ncol=1,
|
|
172 main=textGrob("Read Maps (nucleotide coordinates)", gp=gpar(cex=1), just="top"),
|
|
173 left=textGrob("${ylabel}", gp=gpar(cex=1), vjust=1, rot=90)
|
|
174 #sub=textGrob("readmap coordinates", gp=gpar(cex=.75), just="bottom")
|
|
175 )
|
|
176 )
|
|
177 do.call(grid.arrange, args.list)
|
|
178 }
|
|
179 devname=dev.off()
|
|
180
|
|
181
|
|
182 pdf(file="${size_PDF}", paper="special", height=page_height_simple, width=page_width)
|
|
183 for (i in seq(1,n_genes,rows_per_page)) {
|
|
184 start=i
|
|
185 end=i+rows_per_page-1
|
|
186 if (end>n_genes) {end=n_genes}
|
|
187 plot.list=lapply(per_gene_size[start:end], function(x) plot_size_distribution(x, par.settings=par.settings.size) )
|
|
188 args.list=c(plot.list, list(nrow=rows_per_page, ncol=1,
|
|
189 main=textGrob("Size distributions (in nucleotides)", gp=gpar(cex=1), just="top"),
|
|
190 left=textGrob("${ylabel}", gp=gpar(cex=1), vjust=1, rot=90)
|
|
191 #sub="readsize in nucleotides"
|
|
192 )
|
|
193 )
|
|
194 do.call(grid.arrange, args.list)
|
|
195 }
|
|
196 devname=dev.off()
|
|
197
|
|
198 pdf(file="${combi_PDF}", paper="special", height=page_height_combi, width=page_width)
|
|
199 for (i in seq(1,n_genes,rows_per_page/2)) {
|
|
200 start=i
|
|
201 end=i+rows_per_page/2-1
|
|
202 if (end>n_genes) {end=n_genes}
|
|
203 read_plot.list=lapply(per_gene_readmap[start:end], function(x) plot_readmap(x, par.settings=par.settings.combination.readmap))
|
|
204 size_plot.list=lapply(per_gene_size[start:end], function(x) plot_size_distribution(x, strip=FALSE, par.settings=par.settings.combination.size))
|
|
205 plot.list=rbind(read_plot.list, size_plot.list )
|
|
206 args.list=c(plot.list, list(nrow=rows_per_page + extrarow, ncol=1,
|
|
207 main=textGrob("${title}", gp=gpar(cex=1), just="top"),
|
|
208 left=textGrob("${ylabel}", gp=gpar(cex=1), vjust=1, rot=90),
|
|
209 sub=textGrob("${xlabel}", gp=gpar(cex=1), just="bottom")
|
|
210 )
|
|
211 )
|
|
212 do.call(grid.arrange, args.list)
|
|
213 }
|
|
214 devname=dev.off()
|
|
215
|
|
216
|
|
217 </configfile>
|
|
218 </configfiles>
|
|
219
|
|
220 <outputs>
|
|
221 <data format="tabular" name="readmap_dataframe" label="Readmap dataframe"/>
|
|
222 <data format="tabular" name="size_distribution_dataframe" label="Size distribution dataframe"/>
|
|
223 <data format="pdf" name="readmap_PDF" label="Readmaps"/>
|
|
224 <data format="pdf" name="size_PDF" label="Size distribution"/>
|
|
225 <data format="pdf" name="combi_PDF" label="Size distribution and Readmaps"/>
|
|
226 </outputs>
|
|
227 <help>
|
|
228
|
|
229 **What it does**
|
|
230
|
|
231 Takes one or more alignment files (BAM, SAM or tabular bowtie output) as input and produces a "Readmap",
|
|
232 where by default for each "chromosome" the position of the read is recorded on the x-axis, and the y-axis indicates
|
|
233 the number of reads per position. Reads that map in sense are on the top, reads that map antisense are on the bottom.
|
|
234
|
|
235
|
|
236 .. class:: warningmark
|
|
237
|
|
238 '''TIP''' The input data can be produced using the sRbowtie tool.
|
|
239
|
|
240 ----
|
|
241
|
|
242 '''Example'''
|
|
243
|
|
244 Query sequence::
|
|
245 For a SAM file as the following:
|
|
246
|
|
247 5 16 2L_79 24393 255 17M * 0 0 CCTTCATCTTTTTTTTT IIIIIIIIIIIIIIIII XA:i:0 MD:Z:17 NM:i:0
|
|
248
|
|
249 11 0 2R_1 12675 255 21M * 0 0 AAAAAAAACGCGTCCTTGTGC IIIIIIIIIIIIIIIIIIIII XA:i:0 MD:Z:21 NM:i:0
|
|
250
|
|
251 2 16 2L_5 669 255 23M * 0 0 TGTTGCTGCATTTCTTTTTTTTT IIIIIIIIIIIIIIIIIIIIIII XA:i:0 MD:Z:23 NM:i:0
|
|
252
|
|
253 produce a plot like this:
|
|
254
|
|
255 ----
|
|
256
|
|
257 .. image:: static/images/readmap.png
|
|
258 :height: 800
|
|
259 :width: 500
|
|
260
|
|
261 </help>
|
1
|
262 <tests>
|
0
|
263 <test>
|
|
264 <param name="genomeSource" value="history" />
|
|
265 <param name="ownFile" value ="transposons.fasta" ftype="fasta" />
|
1
|
266 <param name="series_0|input" value="sample1.srbowtie_out" ftype="tabular"/>
|
|
267 <param name="series_0|norm" value="1" />
|
|
268 <param name="series_1|input" value="sample2.srbowtie_out" ftype="tabular"/>
|
|
269 <param name="series_1|norm" value="1" />
|
|
270 <param name="series_2|input" value="sample3.srbowtie_out" ftype="tabular"/>
|
|
271 <param name="series_2|norm" value="1" />
|
0
|
272 <param name="minquery" value="20" />
|
|
273 <param name="maxquery" value="30" />
|
|
274 <param name="title" value="Readmaps and size distributions" />
|
|
275 <param name="xlabel" value="Coordinates/read size" />
|
|
276 <param name="ylabel" value="Number of reads" />
|
|
277 <param name="rows_per_page" value="8" />
|
1
|
278 <output name="readmap_dataframe" ftype="tabular" file="Readmap_dataframe.tab" />
|
|
279 <output name="size_distribution_dataframe" ftype="tabular" file="Size_distribution_dataframe.tab" />
|
|
280 <output name="readmap_PDF" ftype="pdf" file="Readmaps.pdf" />
|
|
281 <output name="size_PDF" ftype="pdf" file="Size_distribution.pdf" />
|
|
282 <output name="combi_PDF" ftype="pdf" file="Size_distribution_and_Readmaps.pdf" />
|
0
|
283 </test>
|
1
|
284 </tests>
|
0
|
285 </tool>
|