<tool id="falco-call" name="falco-call" version="0.0.1">
  
  <requirements>
    
    <requirement type="package" version="0.1.19">samtools</requirement>
    <requirement type="package" version="3.0.1">R</requirement>
    <requirement type="set_environment">FALCO_PATH</requirement>
    
  </requirements>

  <description>FALCO: Amplicon Analysis Pipeline</description>

  <command interpreter="bash">
    falco-call.sh $falco_cfg \$FALCO_PATH;
  </command>

  <stdio>
    <!-- Anything higher than 0 means the bash script didnt finish -->
    <exit_code range="1:" level="fatal" description="Bash script didnt finish correctly, check log" />
  </stdio>
  
  <inputs>
    <!-- ==================== -->
    <!-- General inputs -->
    <!-- ==================== -->
    <param name="jobName" type="text" optional="false" label="Analysis/ouput name" help="Supply a name for the outputs to remind you what they contain. The string entered here will also be the sample-name in the VCF" value="TEST">
      <validator type="empty_field" />
      <validator type="regex" message="This field may contain only non-whitespace characters">\S+</validator>
    </param>

    <conditional name="genomeSource">
      <param name="refGenomeSource" type="select" label="You can select a reference genome from your history or use a built-in index">
        <option value="indexed">Use a built-in index</option>
        <option value="history">Use one from history</option>
      </param>
      <when value="indexed">
        <param name="indices" type="select" label="Select a reference genome">
          <options from_data_table="all_fasta">
            <filter type="sort_by" column="2" />
            <validator type="no_options" message="No indexes are available in table" />
          </options>
        </param>
      </when>
      <when value="history">
        <param name="ownFile" type="data" format="fasta" metadata_name="dbkey" label="Select a reference from history" />
      </when>
    </conditional>

    <param name="bam" type="data" multiple="false" optional="false" format="bam" label="Input BAM" help="Select BAM file" />

    <param format="tabular" name="filter_file" optional="True" type="data" label="FILTER File" help="When left empty, built-in list of genomic positions is used"/>
    <param format="txt" name="manifest_file" optional="True" type="data" label="MANIFEST File" help="When left empty, built-in panel is used (TruSeq Amplicon Cancer Panel)"/>

    <!-- ==================== -->
    <!-- Optional hisotry output: copynumber TXT file -->
    <!-- ==================== -->
    <param name="txt2history" type="select" label="Also output falco specific TXT files to history" help="These text files are much larger but are required for the falco-report tool, so usually you only want these in a workflow and auto-delete them at the end">
      <option value="false">no</option>
      <option value="true">yes</option>
    </param>

    <!-- ==================== -->
    <!-- Option to perform a test run with built in data -->
    <!-- ==================== -->
    <param name="testRun" type="select" label="Run with test data" help="Use built-in HCT116 data instead of input BAMs. This dataset contains only one amplicon.">
      <option value="false">no</option>
      <option value="true">yes</option>
    </param>
  
  </inputs>
  
  <!-- ==================== -->
  <!-- This config is sourced by tool -->
  <!-- ==================== -->
  <configfiles>
    <configfile name="falco_cfg">
      filter_file=$filter_file
      manifest_file=$manifest_file
      bam_file=$bam
      bam_name=$bam.name
      html_out=$html_output
      vcf_out=$vcf_output
      qc_ann_qual_out=$qc_ann_qual_output
      qc2_ann_txt_out=$qc2_ann_txt_output
      qc_targets_txt_out=$qc_targets_txt_output
      also_output_txt=$txt2history
      test_run=$testRun

      out_path=${html_output.files_path}
      job_name=$jobName
      ## reference source
      REF_SOURCE="${genomeSource.refGenomeSource}"
      #if $genomeSource.refGenomeSource == "history":
        ##build index on the fly
        REF_FILE="${genomeSource.ownFile}"
        DB_KEY="${dbkey}"
      #else:
        ##use precomputed indexes
        REF_FILE="${genomeSource.indices.fields.path}"
      #end if
    </configfile>
  </configfiles>

  <!-- ==================== -->
  <!-- Main output is an html based report, additional on request -->
  <!-- ==================== -->
  <outputs>
    <data format="html" name="html_output" label="FALCO-calling (${jobName})">
      <filter>(txt2history == 'true')</filter>
    </data>
    <data format="vcf" name="vcf_output" label="FALCO-calling (${jobName}): VCF" />
    <data format="tabular" name="qc_ann_qual_output" label="FALCO-calling (${jobName}): qc_ann_qual">
      <filter>(txt2history == 'true')</filter>
    </data>
    <data format="tabular" name="qc2_ann_txt_output" label="FALCO-calling (${jobName}): qc2_ann">
      <filter>(txt2history == 'true')</filter>
    </data>
    <data format="tabular" name="qc_targets_txt_output" label="FALCO-calling (${jobName}): qc_targets">
      <filter>(txt2history == 'true')</filter>
    </data>
  </outputs>

  <!-- ==================== -->
  <!-- Tests still to be done -->
  <!-- ==================== -->

  <!-- 
  <tests>
    <test>
      <param name="input1" value="input1" />   
      <param name="input2" value="input2" />   
    </test>
  </tests>
  -->

  <help>
.. class:: infomark

**Introduction**

This tool is a wrapper for the variant caller FALCO_ which is part of the Amplicon Analysis Pipeline (AAP)

.. _FALCO: https://github.com/tgac-vumc/falco/

Calls and annotates genomic variants for each amplicon in a design.

**Notes**

Because each amplicon is analysed separately, when two amplicons overlap this can cause the same variant position to be present twice in the output VCF. This is intentional, you can use this to evaluate the quality of the variant call beyond the amplicon reads.

-----

**Citation**

For the underlying tool please cite: Daoud Sie et al. Performance of amplicon-based next generation DNA sequencing for diagnostic gene mutation profiling in oncopathology (Cell Oncol 2014 Oct;37(5):353-61). Pubmed_

.. _Pubmed: http://www.ncbi.nlm.nih.gov/pubmed/25209392

  </help>

</tool>
