view data_manager/bracken_build_database.xml @ 7:174a754bd3b6 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/data_managers/data_manager_build_bracken_database commit a108f20aebc04574a8bd0a90b955064439a50852
author iuc
date Wed, 05 Nov 2025 13:32:09 +0000
parents 84cc0dc92b0c
children
line wrap: on
line source

<tool id="bracken_build_database" name="Bracken Database Builder" tool_type="manage_data" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@">
    <description>bracken database builder</description>
    <macros>
        <token name="@TOOL_VERSION@">3.1</token>
        <token name="@VERSION_SUFFIX@">0</token>
        <token name="@PROFILE@">24.0</token>
    </macros>
    <requirements>
        <requirement type="package" version="@TOOL_VERSION@">bracken</requirement>
    </requirements>
    <command>
    <![CDATA[
        #set $db_dir = $out_file.extra_files_path
        mkdir '$db_dir' &&

        ## Create symlinks to the contents of the kraken database, since otherwise
        ## the DM tool (ie bracken-build) would write to the kraken DB folder. 
        ## 
        ## These symlinks will be part of the final db_dir which will be moved
        ## to the tool-data (except for some of the pre-exsting *mers.kraken
        ## and *mers.kmer_distrib which may be deleted -- depending on the
        ## choice of prebuilt).
        ## Hence the final db_dir will have
        ## - either a created mers.kmer_distrib file or a symlink pointing to the kraken2 db source  
         ## - either a created mers.kraken file or a symlink pointing to the kraken2 db source  
        ## - and symlinks to the krakenDB
        ## Note that in the data table entry only the path to mers.kmer_distrib file is used 
        ln -s '${kraken_db.fields.path}'/* '$db_dir/' &&

        #if $check_prebuilt.prebuilt == "no"
            ## remove any other pre-existing bracken-build results
            find '$db_dir' -maxdepth 1 -name "*mers*" -delete &&
            bracken-build
                -t "\${GALAXY_SLOTS:-1}"
                -k $check_prebuilt.kmer_len
                -l $check_prebuilt.read_len
                -d '$db_dir/'
        #else
            if [ ! -e '$db_dir/database${check_prebuilt.read_len}mers.kmer_distrib' ]; then
                >&2 echo "Have you chosen the correct k-mer length? file $db_dir/database${check_prebuilt.read_len}mers.kmer_distrib does not exist.";
                exit 1; 
            fi
            ## delete any other (links to) prebuilt bracken databases (except the one of the chosen read_len)
            && find '$db_dir' -maxdepth 1 -name "*mers.kraken" -a \! -name "*${check_prebuilt.read_len}mers.kraken" -delete
            && find '$db_dir' -maxdepth 1 -name "*mers.kmer_distrib" -a \! -name "*${check_prebuilt.read_len}mers.kmer_distrib" -delete
        #end if
        && cp '$dmjson' '$out_file'
    ]]>
    </command>
    <configfiles>
        <configfile name="dmjson"><![CDATA[#slurp
#import uuid
#set $database_value = str(uuid.uuid4())
#set $db_dir = $out_file.extra_files_path

#if $database_name == ""
    #if $check_prebuilt.prebuilt == "no"
        #set $database_name = $kraken_db.fields.name + " (k-mer length = " + str($check_prebuilt.kmer_len) +", read length = " + str($check_prebuilt.read_len) + ")"
    #else
        #set $database_name = $kraken_db.fields.name + " (Prebuilt bracken DB with read length = " + str($check_prebuilt.read_len) + ")"
    #end if
#end if
{
  "data_tables":{
    "bracken_databases":[
        {
          "value": "$database_value",
          "name": "$database_name",
          "path": "$db_dir/database${check_prebuilt.read_len}mers.kmer_distrib"
        }
    ]
  }
}]]></configfile>
    </configfiles>
    <inputs>
        <param name="kraken_db" type="select">
            <options from_data_table="kraken2_databases">
                <validator type="no_options" message="No Kraken2 databases are available" />
            </options>
        </param>
        <conditional name="check_prebuilt">
            <param name="prebuilt" type="select" label="Use Pre-built DB" help="Use existing pre-built DB. This only works for kraken DBs, that already contain additional bracken DBs. This is the case for DBs downloaded from https://benlangmead.github.io/aws-indexes/k2.">
                <option value="no">No</option>
                <option value="yes">Yes</option>
            </param>
            <when value="no">
                <param name="kmer_len" type="integer" min="8" max="256" value="35" label="K-mer length" help="The K-mer length of the bracken DB should be identical to the K-mer length used to build the kraken2 DB." />
                <param name="read_len" type="integer" min="8" max="1000" value="100" label="Read length" help="The read length of the bracken DB should be the same as the length of the reads to be analysis (one read in case of paired reads)." />
            </when>
            <when value="yes">
                <param name="read_len" type="select" label="Read length" help="The read length of the bracken DB should be the same as the length of the reads to be analysis (one read in case of paired reads). The prebuilt DBs where built using the same K-mer length as the kraken2 DB.">
                    <option value="50">50</option>
                    <option value="75">75</option>
                    <option value="100" selected="true">100</option>
                    <option value="150">150</option>
                    <option value="200">200</option>
                    <option value="250">250</option>
                    <option value="300">300</option>
                </param>
            </when>
	    </conditional>
    	<param name="database_name" type="text" label="Database Name" help="If left empty a name will be constructed from the name of the Kraken2 database suffixed by info on read and k-mer length. Otherwise please add a clear reference to the corresponding kraken2 DB the read length and kmer length to the name." />
    </inputs>
    <outputs>
        <data name="out_file" format="data_manager_json" />
    </outputs>
    <tests>
        <test>
            <param name="kraken_db" value="test_entry" />
            <param name="database_name" value="" />
            <conditional name="check_prebuilt">
                <param name="prebuilt" value="yes" />
                <param name="read_len" value="100" />
            </conditional>
            <output name="out_file">
                <assert_contents>
                    <has_text text="Prebuilt bracken DB with read length = 100" />
                    <has_text text="database100mers.kmer_distrib" />
                </assert_contents>
            </output>
        </test>
        <test>
            <param name="kraken_db" value="test_entry" />
            <param name="database_name" value="custom database name" />
            <conditional name="check_prebuilt">
                <param name="prebuilt" value="no" />
                <param name="read_len" value="150" />
            </conditional>
            <output name="out_file">
                <assert_contents>
                    <has_text text="custom database name" />
                    <has_text text="database150mers.kmer_distrib" />
                </assert_contents>
            </output>
        </test>
    </tests>
    <help>
A bracken DB can only be built as an addition to an existing kracken2 DB (see `Bracken docs`_).

.. _Bracken docs: https://github.com/jenniferlu717/Bracken?tab=readme-ov-file#step-1-generate-the-bracken-database-file-databasexmerskmer_distrib-1

======================================
Using prebuilt DBs
====================================== 

The prebuilt option does use existing bracken DBs, that are shipped with kraken2 DBs. This is the case for DBs downloaded from https://benlangmead.github.io/aws-indexes/k2.
All prebuilt databases contain a Kraken 2 database along with Bracken databases built for 50, 75, 100, 150, 200, 250 and 300 read lengths (referring to the length of the sequenced reads to be analysis using that database (one read in case of paired reads)).
In this case the data manager points to the same DB as the kracken2 DB.
Note the Kraken 2 / Bracken 16s DBs only contain the Bracken databases built for 100mers, 150mers, and 200mers.
**The prebuilt option must not be used for custom kraken2 DBs ! For this the bracken DB needs to be build.**

======================================
Building new DBs
======================================

Use the same K-mer length as the kraken2 DB and choose read lengths that are close to the read length of the analysis you want to perform (one read in case of paired reads).
    </help>
    <citations>
        <citation type="doi">10.7717/peerj-cs.104</citation>
    </citations>
</tool>