<tool id="autobigs-cli" name="autoBIGS.cli" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="21.05">
	<description>Automated MLST typing from PubMLST and InstitutPasteur.</description>
	<macros>
		<token name="@TOOL_VERSION@">0.5.0</token>
		<token name="@VERSION_SUFFIX@">0</token>
    	<import>autobigs-cli_macros.xml</import>
	    <expand macro="bio_tools"/>
	</macros>

	<requirements>
		<requirement type="package" version="@TOOL_VERSION@">autobigs-cli</requirement>
	</requirements>

	<command detect_errors="exit_code"><![CDATA[
			#if $mode.operation == "info":
				#if $mode.select_info.retrieved == "schemes":
					autoBIGS info --retrieve-bigsdb-schemas#for $scheme in $mode.select_info.schemes_list# '${scheme.selected_db}' #end for# --csv $info_schemes_out
				#else if $mode.select_info.retrieved == "databases":
					autoBIGS info --retrieve-bigsdbs --csv $info_db_out
				#end if
			#else if $mode.operation == "st":
				autoBIGS st#for $fasta in $mode.fastas_list# '${fasta.fasta}' #end for#"$seqdefdb" $schema "$mlst_profiles_output" $stop_on_fail
			#end if
	]]></command>
	<inputs>
		<conditional name="mode">
			<param name="operation" label="Operation" type="select">
				<option value="info">Retrieve Database Information</option>
				<option value="st">Perform Sequence Typing</option>
			</param>
			<when value="info">
				<conditional name="select_info">
					<param name="retrieved" label="Schemes or Database List" type="select">
						<option value="schemes">Available Schemas for Database</option>
						<option value="databases">Available Databases</option>
					</param>
					<when value="schemes">
						<repeat name="schemes_list" title="Schemes" min="1">
							<param name="selected_db" argument="--retrieve-bigsdb-schemas" label="Database to retrieve schemes from" type="text"/>
						</repeat>
					</when>
					<when value="databases">

					</when>
				</conditional>
			</when>
			<when value="st">
				<repeat name="fastas_list" title="Fasta" min="1">
					<param name="fasta" label="FASTA file" type="data" format="fasta,fas,fa,fna,ffn,faa,mpfa,frn"/>
				</repeat>
				<param name="seqdefdb" label="BIGSdb SeqDef Name" type="text" optional="false"/>
				<param name="schema" label="BIGSdb SeqDef Schema ID" type="integer" min="0"/>
				<param name="stop_on_fail" label="Stop on failure to match" truevalue="--sof" falsevalue="" value="false" type="boolean"/>
			</when>
		</conditional>
	</inputs>
	<outputs>
		<data name="mlst_profiles_output" label="${tool.name} on ${on_string}" format="csv">
			<filter>mode['operation'] == 'st'</filter>
		</data>
		<data name="info_db_out" label="${tool.name} supported Databases" format="csv">
			<filter>mode['operation'] == 'info' and mode['select_info']['retrieved'] == 'databases'</filter>
		</data>
		<data name="info_schemes_out" label="${tool.name} supported Schemes" format="csv">
			<filter>mode['operation'] == 'info' and mode['select_info']['retrieved'] == 'schemes'</filter>
		</data>
	</outputs>
    <tests>
        <test expect_num_outputs="1">
            <param name="operation" value="st" />
			<repeat name="fastas_list">
	            <param name="fasta" value="tohama_I_bpertussis_wgs.fasta" />
			</repeat>
            <param name="seqdefdb" value="pubmlst_bordetella_seqdef" />
            <param name="schema" value="3" />
            <output name="mlst_profiles_output" file="tohama_I_bpertussis_wgs_typed.csv" ftype="csv" />
        </test>
        <test expect_num_outputs="1">
            <param name="operation" value="info" />
            <param name="retrieved" value="databases" />
            <output name="info_db_out">
				<assert_contents>
					<has_text text="BIGSdb Names,Source"/>
					<has_text text="pubmlst_bordetella_seqdef,https://bigsdb.pasteur.fr/api"/>
				</assert_contents>
			</output>
        </test>
        <test expect_num_outputs="1">
            <param name="operation" value="info" />
			<repeat name="schemes_list">
            	<param name="selected_db" value="pubmlst_bordetella_seqdef" />
			</repeat>
            <output name="info_schemes_out">
				<assert_contents>
					<has_text text="Name,ID"/>
					<has_text text="MLST,3"/>
				</assert_contents>
			</output>
        </test>
    </tests>
	<help><![CDATA[

usage: autoBIGS info [-h] [--retrieve-bigsdbs] [--retrieve-bigsdb-schemas LIST_BIGSDB_SCHEMAS [LIST_BIGSDB_SCHEMAS ...]] [--csv CSV_OUTPUT]

Fetches the latest BIGSdb MLST database definitions.

options:
  -h, --help            show this help message and exit
  --retrieve-bigsdbs, -l
                        Lists all known BIGSdb MLST databases (fetched from known APIs and cached).
  --retrieve-bigsdb-schemas LIST_BIGSDB_SCHEMAS
                        Lists the known schema IDs for a given BIGSdb sequence definition database name. The name, and then the ID of the schema is given.
  --csv, -o CSV_OUTPUT  Output list as CSV at a given path. A suffix is added depending on the action taken.

usage: autoBIGS st [-h] [--stop-on-fail] fastas [fastas ...] seqdefdb schema out

Returns MLST exact profile matches.

positional arguments:
  fastas                The FASTA files to process. Multiple can be listed.
  seqdefdb              The BIGSdb seqdef database to use for typing.
  schema                The BIGSdb seqdef database schema ID (integer) to use for typing.
  out                   The output CSV name (.csv will be appended).

options:
  -h, --help            show this help message and exit
  --stop-on-fail, -sof  Should the algorithm stop in the case there are no matches (or partial matches when expecting exact matches).
	]]></help>
    <citations>
        <citation type="bibtex">
@book{Deng2025RealYHD,
title = {Syph-and-VPD-Lab/autoBIGS.cli},
url = {https://github.com/Syph-and-VPD-Lab/autoBIGS.cli},
author = {Deng, Harrison},
date = {2025-01-24},
year = {2025},
month = {1},
day = {24},
}
        </citation>
    </citations>
</tool>
