<tool id="extract_metaphlan_database" name="Extract the marker sequences and metadata" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@">
    <description>from the MetaPhlAn database</description>
    <macros>
        <import>macros.xml</import>
    </macros>
    <expand macro="edam_ontology"/>
    <expand macro="requirements"/>
    <version_command>metaphlan -v</version_command>
    <command detect_errors="aggressive"><![CDATA[
bowtie2-inspect
    '${cached_db.fields.path}/${cached_db.fields.dbkey}'
    > '$sequences'

&&

python '$__tool_directory__/customizemetadata.py'
    transform_pkl_to_json
    --pkl '${cached_db.fields.path}/${cached_db.fields.dbkey}.pkl'
    --json '$metadata'
    ]]></command>
    <inputs>
        <param name="cached_db" label="Cached database with clade-specific marker genes" type="select">
            <options from_data_table="@IDX_DATA_TABLE@">
                <filter type="static_value" column="4" value="@IDX_VERSION@"/>
                <validator message="No MetaPhlAn database is available" type="no_options"/>
            </options>
        </param>
    </inputs>
    <outputs>
        <data name="sequences" format="fasta" label="${tool.name} on ${on_string}: Marker seqeunces from MetaPhlAn database"/>
        <data name="metadata" format="json" label="${tool.name} on ${on_string}: Marker metadata from MetaPhlAn database"/>
    </outputs>
    <tests>
        <test expect_num_outputs="2">
            <param name="cached_db" value="test-db-20210409"/>
            <output name="sequences" file="test-db.fasta" ftype="fasta" compare="sim_size">
                <assert_contents>
                    <has_line line=">13076__A0A2I1PE66__CYJ72_10760 UniRef90_A0A2I1PE66;k__Bacteria|p__Firmicutes|c__Bacilli|o__Lactobacillales|f__Aerococcaceae|g__Globicatella|s__Globicatella_sanguinis;GCA_002847845"/>
                </assert_contents>
            </output>
            <output name="metadata" file="test-db.json" ftype="json" compare="sim_size">
                <assert_contents>
                    <has_text text="13076__A0A2I1PE66__CYJ72_10760"/>
                    <has_text text="k__Bacteria|p__Firmicutes|c__Bacilli|o__Lactobacillales|f__Aerococcaceae|g__Globicatella|s__Globicatella_sanguinis"/>
                    <has_text text="GCA_002847845"/>
                    <has_text text="clade"/>
                    <has_text text="ext"/>
                    <has_text text="len"/>
                    <has_text text="taxon"/>
                    <has_text text="markers"/>
                    <has_text text="taxonomy"/>
                    <has_text text="merged_taxon"/>
                </assert_contents>
            </output>
        </test>
    </tests>
    <help><![CDATA[
What it does
============

Reconstruct the marker sequences (in fasta format) and metadata (in JSON) from the MetaPhlAn BowTie2 database

Outputs
=======

- Fasta file with marker sequences.

    This file can be used to add new marker sequences and then customizing the database.

- JSON file with marker metadata

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