Skip to content

Commit fc9887d

Browse files
authored
Force full-length ivar consensus builds (#5115)
* Force full-length ivar consensus builds This requires the -a option of samtools mpileup or zero-coverage regions at the ref sequence ends will silently be dropped and a truncated consensus be produced. * More fixes to the consensus tool - Protect params against integer overflow - Make "-n -" option work and simplify choice of min depth threshold action
1 parent 381e8b8 commit fc9887d

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

tools/ivar/ivar_consensus.xml

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<tool id="ivar_consensus" name="ivar consensus" version="@TOOL_VERSION@+galaxy1" profile="@PROFILE@">
1+
<tool id="ivar_consensus" name="ivar consensus" version="@TOOL_VERSION@+galaxy2" profile="@PROFILE@">
22
<description>Call consensus from aligned BAM file</description>
33
<macros>
44
<import>macros.xml</import>
@@ -9,21 +9,20 @@
99
#import re
1010
#set $clean_name = re.sub('[^\w\-]', '_', str($input_bam.element_identifier))
1111
ln -s '$input_bam' sorted.bam &&
12-
samtools mpileup -A -d 0 -Q 0 sorted.bam | ivar consensus
12+
samtools mpileup -A -a -d 0 -Q 0 sorted.bam | ivar consensus
1313
-p consensus
1414
-q $min_qual
1515
-t $min_freq
1616
-m $min_depth
17-
$filter_depth
18-
#if $gap
19-
-n N
20-
#end if
17+
$depth_action
2118
&&
2219
sed -i "s|consensus|$clean_name|" consensus.fa
23-
]]> </command>
20+
]]></command>
2421
<inputs>
2522
<param name="input_bam" type="data" format="bam" label="Bam file" help="Aligned reads, to trim primers and quality"/>
26-
<param name="min_qual" argument="-q" type="integer" min="0" value="20" label="Minimum quality score threshold to count base"/>
23+
<!-- Warning: integer params in the following define a max of 255 intentionally
24+
because the underlying C++ code of ivar defines them as uint8 and does not check for overflow! -->
25+
<param name="min_qual" argument="-q" type="integer" min="0" max="255" value="20" label="Minimum quality score threshold to count base"/>
2726
<param name="min_freq" argument="-t" type="float" min="0" max="1" value="0.0" label="Minimum frequency threshold">
2827
<help>
2928
<![CDATA[
@@ -35,17 +34,19 @@
3534
]]>
3635
</help>
3736
</param>
38-
<param name="min_depth" argument="-m" type="integer" min="1" value="10" label="Minimum depth to call consensus"/>
39-
<param name="filter_depth" argument="-k" type="boolean" truevalue="-k" falsevalue="" checked="false" label="Exclude regions with smaller depth than the minimum threshold"/>
40-
<param name="gap" argument="-n" type="boolean" truevalue="true" falsevalue="false" checked="false" label="Use N instead of - for regions with less than minimum coverage"/>
37+
<param name="min_depth" argument="-m" type="integer" min="1" max="255" value="10" label="Minimum depth to call consensus"/>
38+
<param name="depth_action" type="select" label="How to represent positions with coverage less than the minimum depth threshold">
39+
<option value="-k">Drop from output (-k)</option>
40+
<option value="-n N" selected="true">Represent as N (-n N)</option>
41+
<option value="-n -">Represent as - (-n -)</option>
42+
</param>
4143
</inputs>
4244
<outputs>
4345
<data name="consensus" format="fasta" label="${tool.name} on ${on_string} Consensus" from_work_dir="consensus.fa"/>
4446
</outputs>
4547
<tests>
4648
<test>
4749
<param name="input_bam" value="covid19/PC00101P_sub.trimmed.sorted.bam" />
48-
<param name="gap" value="true" />
4950
<output name="consensus" file="covid19/PC00101P_sub.fa" ftype="fasta" compare="contains" lines_diff="1"/>
5051
</test>
5152
</tests>
@@ -55,20 +56,23 @@
5556
To generate a consensus sequence iVar uses the output of samtools mpileup
5657
command. The mpileup output must be piped into ivar consensus
5758
58-
The command for this wrapper is from https://github.com/andersen-lab/ivar/blob/master/pipeline_consensus/Snakefile :
59+
The command formed by this wrapper is :
5960
60-
samtools mpileup -A -d 0 -Q 0 sorted.bam | ivar consensus [options]
61+
samtools mpileup -A -a -d 0 -Q 0 sorted.bam | ivar consensus [options]
6162
62-
There are five parameters that can be set:
63+
There are four parameters that can be set:
6364
64-
- Minimum quality (Default: 20): the minimum quality of a base to be considered in calculations of variant frequencies at a given position
65+
- **Minimum quality**: the minimum quality of a base to be considered in calculations of variant frequencies at a given position
6566
66-
- Minimum frequency threshold (Default: 0): the minimum frequency that a base must match to be called as the consensus base at a position.
67+
- **Minimum frequency threshold**: the minimum frequency that the most likely base must surpass to be called as the consensus base at a position.
6768
68-
- Minimum depth to call a consensus (Default: 1): the minimum required depth to call a consensus
69+
- **Minimum depth to call consensus**: the minimum required depth to call a consensus base
70+
71+
- **How to represent positions with coverage less than the minimum depth threshold**: for positions for which the above minimum depth to call a consensus base is not reached, you can choose one of three different actions:
6972
70-
- Filter depth is a flag to exclude nucleotides from regions with depth less than the minimum depth and a character to call in regions with coverage lower than the speicifed minimum depth(Default: '-'). If this flag is set then these regions are not included in the consensus sequence. If it is not set then by default, a '-' is called in these regions.
71-
- You can also specfy which character you want to add to the consensus to cover regions with depth less than the minimum depth. This can be done using gap option. It takes of two values: '-' or 'N'.
73+
- Drop the position from the output entirely (-> the consensus sequence can become shorter than the reference used to produce the input BAM!)
74+
- Use an ``N``, or
75+
- Use a ``-`` to represent the position
7276
]]> </help>
7377
<expand macro="citations" />
7478
</tool>

0 commit comments

Comments
 (0)