<tool profile="16.07" id="mothur_remove_lineage" name="Remove.lineage" version="@WRAPPER_VERSION@.0">
    <description>Picks by taxon</description>
    <macros>
        <import>macros.xml</import>
    </macros>
    <expand macro="requirements"/>
    <expand macro="stdio"/>
    <expand macro="version_command"/>
    <command><![CDATA[
        @SHELL_OPTIONS@

        #import re
        ## create symlinks to input datasets
        ln -s "$file.taxonomy" file.taxonomy.dat &&
        #if $file.filetype == "useconstaxonomy":
            ln -s "$file.shared" file.shared.dat &&
            ln -s "$file.list" file.list.dat &&
        #end if
        ln -s "$fasta_in" fasta_in.dat &&
        ln -s "$group_in" group_in.dat &&
        ln -s "$alignreport_in" alignreport_in.dat &&
        ln -s "$list_in" list_in.dat &&
        ln -s "$name_in" name_in.dat &&
        ln -s "$count" count.dat &&

        echo 'remove.lineage(
            #if $file.filetype == "usetaxonomy":
                taxonomy=file.taxonomy.dat
            #else
                constaxonomy=file.taxonomy.dat
                #if $file.shared:
                    ,shared=file.shared.dat
                #end if
                #if $file.list:
                    ,list=file.list.dat
                #end if
            #end if
            #if $file.taxons:
                #set taxonstring=str($file.taxons).replace(",","-")
                ,taxon='"'$re.sub("(\s|,)+",",",$re.sub("\(\d+\)","", $taxonstring ))'"'
            #elif $taxon:
                ,taxon='"'$re.sub("(\s|,)+",",",$re.sub("\(\d+\)","", $taxon.value )).replace(",","-")'"'
            #end if
            #if $fasta_in:
                ,fasta=fasta_in.dat
            #end if
            #if $group_in:
                ,group=group_in.dat
            #end if
            #if $alignreport_in:
                ,alignreport=alignreport_in.dat
            #end if
            #if $list_in:
                ,list=list_in.dat
            #end if
            #if $name_in:
                ,name=name_in.dat
                ,dups=$dups
            #end if
            #if $count:
                ,count=count.dat
            #end if
        )'
        | sed 's/ //g'  ## mothur trips over whitespace
        | mothur
        | tee mothur.out.log
    ]]></command>
    <inputs>
        <conditional name="file">
            <param name="filetype" type="select" label="choose which file is used">
                <option value="usetaxonomy" selected="true">taxonomy</option>
                <option value="useconstaxonomy">constaxonomy</option>
            </param>
            <when value="usetaxonomy">
                <param name="taxonomy" type="data" format="mothur.seq.taxonomy" label="taxonomy - Taxonomy" help="please make sure your file has no quotation marks in it"/>
                <param name="taxons" type="select" size="120" optional="true" multiple="true" label="Browse Taxons from Taxonomy">
                    <options from_dataset="taxonomy">
                        <column name="name" index="1"/>
                        <column name="value" index="1"/>
                        <filter type="unique_value" name="unique_taxon" column="1"/>
                        <filter type="sort_by" name="sorted_taxon" column="1"/>
                    </options>
                    <sanitizer>
                        <valid initial="default">
                            <add preset="string.printable"/>
                            <add value=";"/>
                            <remove value="&quot;"/>
                            <remove value="&apos;"/>
                        </valid>
                    </sanitizer>
                </param>
            </when>
            <when value="useconstaxonomy">
                <param name="taxonomy" type="data" format="mothur.cons.taxonomy" label="constaxonomy - Constaxonomy file. Provide either a constaxonomy file or a taxonomy file" help="please make sure your file has no quotation marks in it"/>
                <param name="taxons" type="select" size="120" optional="true" multiple="true" label="Browse Taxons from Taxonomy">
                    <options from_dataset="taxonomy">
                        <column name="name" index="2"/>
                        <column name="value" index="2"/>
                        <filter type="unique_value" name="unique_taxon" column="2"/>
                        <filter type="sort_by" name="sorted_taxon" column="2"/>
                    </options>
                    <sanitizer>
                        <valid initial="default">
                            <add preset="string.printable"/>
                            <add value=";"/>
                            <remove value="&quot;"/>
                            <remove value="&apos;"/>
                        </valid>
                    </sanitizer>
                </param>
                <param name="shared" type="data" format="mothur.shared" label="shared - shared file" optional="true"/>
                <param name="list" type="data" format="mothur.list" label="list - list file" optional="true"/>
            </when>
        </conditional>
        <param name="taxon" type="text" area="True" size="5x120" label="taxon - Manually select Taxons for filtering" help="If no taxons selected from file, Enter 1 or more taxons separated by dashes here, e.g. Bacteria;Firmicutes;-Bacteria;Actinobacteria; "/>
        <param name="fasta_in" type="data" format="fasta" optional="true" label="fasta - Fasta Sequences"/>
        <param name="group_in" type="data" format="mothur.groups" optional="true" label="group - Groups"/>
        <param name="alignreport_in" type="data" format="mothur.align.report" optional="true" label="alignreport - Align Report"/>
        <param name="list_in" type="data" format="mothur.list" optional="true" label="list - OTU List"/>
        <param name="name_in" type="data" format="mothur.names" optional="true" label="name - Sequences Name reference"/>
        <param name="dups" type="boolean" truevalue="true" falsevalue="false" checked="true" label="dups - Apply to duplicate names"/>
        <param name="count" type="data" format="mothur.count_table" optional="true" help="The count file is similar to the name file in that it is used to represent the number of duplicate sequences for a given representative sequence. It can also contain group information"/>
    </inputs>
    <outputs>
        <expand macro="logfile-output"/>
        <data name="taxonomy_out" format="mothur.seq.taxonomy" from_work_dir="file.taxonomy*.pick.*" label="${tool.name} on ${on_string}: pick.taxonomy"/>
        <data format_source="fasta_in" name="fasta_out" from_work_dir="fasta_in*.pick.*" label="${tool.name} on ${on_string}: pick.fasta">
            <filter>fasta_in</filter>
        </data>
        <data name="group_out" format="mothur.groups" from_work_dir="group_in*.pick.*" label="${tool.name} on ${on_string}: pick.group">
            <filter>group_in</filter>
        </data>
        <data name="count_out" format="mothur.count_table" from_work_dir="count*.pick.*" label="${tool.name} on ${on_string}: pick.count_table">
            <filter>count</filter>
        </data>
        <collection name="list_out" type="list" label="${tool.name} on ${on_string}: pick.list">
            <filter>list_in</filter>
            <discover_datasets pattern="list_in.*?\.(?P&lt;designation&gt;.*)\.pick.*" format="mothur.list"/>
        </collection>
        <data name="name_out" format="mothur.names" from_work_dir="name_in*.pick.*" label="${tool.name} on ${on_string}: pick.name">
            <filter>name_in</filter>
        </data>
        <data name="alignreport_out" format="mothur.align.report" from_work_dir="alignreport_in*.pick.*" label="${tool.name} on ${on_string}: pick.align.report">
            <filter>alignreport_in</filter>
        </data>
    </outputs>
    <tests>
        <test><!-- test with defaults and single taxon -->
            <param name="filetype" value="usetaxonomy"/>
            <param name="taxonomy" value="abrecovery.pds.wang.taxonomy" ftype="mothur.seq.taxonomy"/>
            <param name="taxon" value="Bacteria;Firmicutes;"/>
            <param name="count" value="amazon.count_table"/>
            <output name="taxonomy_out" md5="a2a72b7f53ef6c907b8c4db906fcf03e"/>
            <output name="count_out" md5="6f89b3b99f337414d98f70fcda4b248e"/>
        </test>
        <test><!-- test with multiple taxons and all additional files -->
            <param name="filetype" value="usetaxonomy"/>
            <param name="taxonomy" value="abrecovery.pds.wang.taxonomy" ftype="mothur.seq.taxonomy"/>
            <param name="taxon" value="Bacteria;Firmicutes;,Bacteria;Actinobacteria;"/>
            <param name="group_in" value="abrecovery.groups" ftype="mothur.groups"/>
            <param name="fasta_in" value="abrecovery.fasta" ftype="fasta"/>
            <param name="name_in" value="abrecovery.names" ftype="mothur.names"/>
            <param name="alignreport_in" value="Mock_S280_L001_R1_001_small.contigs.report" ftype="mothur.align.report"/>
            <param name="list_in" value="amazon.an.list" ftype="mothur.list"/>
            <output name="taxonomy_out" md5="449200280fa6c332854204fe78a9bd12"/>
            <output name="group_out" md5="119a2642bd730aad03f7d6c1f8b57a0b" ftype="mothur.groups"/>
            <output name="fasta_out" md5="2c8415a797011e15f19ad85a9c994551" ftype="fasta"/>
            <output name="name_out" md5="712b28c3a84d3c16ef202340717e3a91" ftype="mothur.names"/>
            <output name="alignreport_out" md5="d94be921c3ad1786db3e60dc23c3bc04" ftype="mothur.align.report"/>
            <output_collection name="list_out" count="36">
                <element name="0.05" md5="5d4195793e2fc50979b377df468c436a" ftype="mothur.list"/>
            </output_collection>
        </test>
        <test><!-- test with taxons from file -->
            <param name="filetype" value="usetaxonomy"/>
            <param name="taxonomy" value="abrecovery.pds.wang.taxonomy" ftype="mothur.seq.taxonomy"/>
            <param name="taxons" value="Bacteria(100);Firmicutes(100);Clostridia(100);Clostridiales(100);Lachnospiraceae(100);Dorea(99);,Bacteria(100);Firmicutes(100);Clostridia(100);Clostridiales(100);Lachnospiraceae(100);Roseburia(47);"/>
            <output name="taxonomy_out" md5="57b4ab4e5b68f8c7d88a0f591c4fe4a1"/>
        </test>
        <test><!-- test with constaxonomy file -->
            <param name="filetype" value="useconstaxonomy"/>
            <param name="taxonomy" value="example.constaxonomy" ftype="mothur.cons.taxonomy"/>
            <param name="taxon" value="Bacteria;Bacteroidetes;"/>
            <output name="taxonomy_out" md5="751fd9b99828998dd909115634027e5e"/>
        </test>
        <test><!-- test with constaxonomy file and taxons from file -->
            <param name="filetype" value="useconstaxonomy"/>
            <param name="taxonomy" value="example.constaxonomy" ftype="mothur.cons.taxonomy"/>
            <param name="taxons" value="Bacteria(100);Firmicutes(100);Clostridia(70);Clostridiales(70);Lachnospiraceae(51);unclassified;,Bacteria(100);Proteobacteria(100);Gammaproteobacteria(100);unclassified;unclassified;unclassified;"/>
            <output name="taxonomy_out" md5="017f53dd82f3e1afcf48778034b51685"/>
        </test>
    </tests>
    <help>
<![CDATA[

@MOTHUR_OVERVIEW@

**Command Documentation**

The remove.lineage_ command reads a taxonomy_ file and a taxon and generates a new file that contains only the sequences in the that are not from that taxon. You may also include either a fasta, name_, group_, list_, or align.report_ file to this command and mothur will generate new files for each of those containing only the selected sequences.

.. _taxonomy: https://www.mothur.org/wiki/Taxonomy_outline
.. _name: https://www.mothur.org/wiki/Name_file
.. _group: https://www.mothur.org/wiki/Group_file
.. _list: https://www.mothur.org/wiki/List_file
.. _align.report: https://www.mothur.org/wiki/Align.seqs
.. _remove.lineage: https://www.mothur.org/wiki/Remove.lineage

]]>
    </help>
    <expand macro="citations"/>
</tool>
