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