<commit_before><tool name="tximport" id="tximport" version="0.1">
    <description> Summarize transcript-level estimates for gene-level analysis </description>
    <requirements>
        <requirement type="package">bioconductor-tximport</requirement>
        <requirement type="package" version="1.34.1">bioconductor-genomicfeatures</requirement>
        <requirement type="package" version="1.20.2">r-getopt</requirement>
        <requirement type="package" version="0.2.20">r-rjson</requirement>
    </requirements>

    <stdio>
        <exit_code range="1:" level="fatal" description="Error code returned" />
        <regex match="is not TRUE"
           source="both"
           level="fatal"
           description="Execution halted." />
    </stdio>

<command>
 <![CDATA[
#import json
#if $gene_id_source_selector.gene_id_source == 'external_file':
    #if $gene_id_source_selector.gff_source_selector.gff_source == 'history':
        #if $gene_id_source_selector.gff_source_selector.gff_tx2gene_selector.mapping_file_option == 'gff_gtf':
            ln -s '$gene_id_source_selector.gff_source_selector.gff_tx2gene_selector.own_gff' mapping.gff &&
        #else:
            ln -s '$gene_id_source_selector.gff_source_selector.gff_tx2gene_selector.own_tx2gene' mapping.tab &&
        #end if
    #end if
#end if

Rscript '${__tool_directory__}/tximport.R'
    --base_dir $__tool_directory__
    --format $input_source_selector.input_source
    #if $input_source_selector.input_source == 'none':
        --txIdCol $input_source_selector.tx_id_col
        --abundanceCol '$input_source_selector.abundance_col'
        --countsCol '$input_source_selector.counts_col'
        --lengthCol '$input_source_selector.length_col'
    #end if
    #if $gene_id_source_selector.gene_id_source == 'gene_id_column_option':
        --geneIdCol '$gene_id_source_selector.gene_id_column'
    #else
        #if $gene_id_source_selector.gff_source_selector.gff_source == "history":
            #if $gene_id_source_selector.gff_source_selector.gff_tx2gene_selector.mapping_file_option == 'tx2gene':
                    --tx2gene mapping.tab
            #else
                --gff_file mapping.gff
            #end if
        #else:
            --tx2gene $gene_id_source_selector.gff_source_selector.tx2gene.fields.path
        #end if
    #end if

    --countsFromAbundance $counts_from_abundance 
    #set $count_files = list()
    #for $file in $counts_file:
        #set $filename_to_element_identifiers = {}
        $filename_to_element_identifiers.__setitem__('id',str($file.element_identifier))
        $filename_to_element_identifiers.__setitem__('path',str($file))
        $count_files.append(filename_to_element_identifiers)
    #end for
    #set $samples_dict = {}
    $samples_dict.__setitem__('samples',$count_files)
    --countsFiles '#echo json.dumps(samples_dict)#'
    --out_file '${gene_level_values}' 

]]></command>



    <inputs>
        <conditional name="input_source_selector">
            <param name="input_source" type ="select" label="Select the source of the quantification file">
                <option value="salmon" selected="True">Salmon</option>
                <option value="sailfish">Sailfish</option>
                <option value="alevin">Alevin</option>
                <option value="kallisto">Kallisto</option>
                <option value="rsem">RSEM</option>
                <option value="stringtie">Stringtie</option>
                <option value="none">Custom format (specify the columns)</option>
            </param>
            <when value="none"> 
                <param name="tx_id_col" type="text" label="Name of the txID columns"/>
                <param name="abundance_col" type="text" label="Name of the abundance column"/>
                <param name="counts_col" type="text" label="Name of the counts column"/>
                <param name="length_col" type="text" label="Name of the length column"/>
            </when>
            <when value="salmon"/>
            <when value="sailfish"/>
            <when value="alevin"/>
            <when value="kallisto"/>
            <when value="rsem"/>
            <when value="stringtie"/>
        </conditional> 
        <conditional name="gene_id_source_selector" >
            <param name="gene_id_source" type="select" label="Is the gene id part of the counts file or will be obtained from an external file?">
                <option value="external_file" selected="True">Use an external file to map transcript to gene names</option>
                <option value="gene_id_column_option">Gene name is a column of the input file</option>
            </param>
            <when value="gene_id_column_option"> 
                <param name="gene_id_column" type="text" label="Name of the column containing the geneID"/>
            </when>
            <when value="external_file">
                <conditional name="gff_source_selector">
                    <param name="gff_source" type="select" label="Select a tx-to-gene table/GFF from your history or use a built-in file?">
                        <option value="built-in" selected="True">Use a built-in file</option>
                        <option value="history" >Use one from the history</option>
                    </param>
                    <when value="built-in">
                        <param name="tx2gene" type="select" label="Select an annotation version" help="If the build of your interest is not listed contact your Galaxy admin">
                            <options from_data_table="tx2gene_table">
                                <filter type="sort_by" column="1"/>
                                <validator type="no_options" message="No files are available for the selected input dataset"/>
                            </options>
                        </param>
                    </when>  
                    <when value="history"> 
                        <conditional name="gff_tx2gene_selector">
                            <param name="mapping_file_option" type="select" label="Will you provide a tx2gene or a GFF/GTF file?">
                                <option value="tx2gene" selected="True">TranscriptID to GeneID table</option>
                                <option value="gff_gtf">GTF/GFF file</option>
                            </param>
                            <when value="gff_gtf">
                                <param name="own_gff" type="data" format="gff" label="Select your GFF file"/>
                            </when>
                            <when value="tx2gene"><commit_msg>Update tools/tximport/tximport.xml<commit_after><tool name="tximport" id="tximport" version="0.1">
    <description> Summarize transcript-level estimates for gene-level analysis </description>
    <requirements>
        <requirement type="package">bioconductor-tximport</requirement>
        <requirement type="package" version="1.34.1">bioconductor-genomicfeatures</requirement>
        <requirement type="package" version="1.20.2">r-getopt</requirement>
        <requirement type="package" version="0.2.20">r-rjson</requirement>
    </requirements>

    <stdio>
        <exit_code range="1:" level="fatal" description="Error code returned" />
        <regex match="is not TRUE"
           source="both"
           level="fatal"
           description="Execution halted." />
    </stdio>

<command>
 <![CDATA[
#import json
#if $gene_id_source_selector.gene_id_source == 'external_file':
    #if $gene_id_source_selector.gff_source_selector.gff_source == 'history':
        #if $gene_id_source_selector.gff_source_selector.gff_tx2gene_selector.mapping_file_option == 'gff_gtf':
            ln -s '$gene_id_source_selector.gff_source_selector.gff_tx2gene_selector.own_gff' mapping.gff &&
        #else:
            ln -s '$gene_id_source_selector.gff_source_selector.gff_tx2gene_selector.own_tx2gene' mapping.tab &&
        #end if
    #end if
#end if

Rscript '${__tool_directory__}/tximport.R'
    --base_dir $__tool_directory__
    --format $input_source_selector.input_source
    #if $input_source_selector.input_source == 'none':
        --txIdCol $input_source_selector.tx_id_col
        --abundanceCol '$input_source_selector.abundance_col'
        --countsCol '$input_source_selector.counts_col'
        --lengthCol '$input_source_selector.length_col'
    #end if
    #if $gene_id_source_selector.gene_id_source == 'gene_id_column_option':
        --geneIdCol '$gene_id_source_selector.gene_id_column'
    #else
        #if $gene_id_source_selector.gff_source_selector.gff_source == "history":
            #if $gene_id_source_selector.gff_source_selector.gff_tx2gene_selector.mapping_file_option == 'tx2gene':
                    --tx2gene mapping.tab
            #else
                --gff_file mapping.gff
            #end if
        #else:
            --tx2gene $gene_id_source_selector.gff_source_selector.tx2gene.fields.path
        #end if
    #end if

    --countsFromAbundance $counts_from_abundance 
    #set $count_files = list()
    #for $file in $counts_file:
        #set $filename_to_element_identifiers = {}
        $filename_to_element_identifiers.__setitem__('id',str($file.element_identifier))
        $filename_to_element_identifiers.__setitem__('path',str($file))
        $count_files.append(filename_to_element_identifiers)
    #end for
    #set $samples_dict = {}
    $samples_dict.__setitem__('samples',$count_files)
    --countsFiles '#echo json.dumps(samples_dict)#'
    --out_file '${gene_level_values}' 

]]></command>



    <inputs>
        <conditional name="input_source_selector">
            <param name="input_source" type ="select" label="Select the source of the quantification file">
                <option value="salmon" selected="True">Salmon</option>
                <option value="sailfish">Sailfish</option>
                <option value="alevin">Alevin</option>
                <option value="kallisto">Kallisto</option>
                <option value="rsem">RSEM</option>
                <option value="stringtie">Stringtie</option>
                <option value="none">Custom format (specify the columns)</option>
            </param>
            <when value="none"> 
                <param name="tx_id_col" type="text" label="Name of the txID columns"/>
                <param name="abundance_col" type="text" label="Name of the abundance column"/>
                <param name="counts_col" type="text" label="Name of the counts column"/>
                <param name="length_col" type="text" label="Name of the length column"/>
            </when>
            <when value="salmon"/>
            <when value="sailfish"/>
            <when value="alevin"/>
            <when value="kallisto"/>
            <when value="rsem"/>
            <when value="stringtie"/>
        </conditional> 
        <conditional name="gene_id_source_selector" >
            <param name="gene_id_source" type="select" label="Is the gene id part of the counts file or will be obtained from an external file?">
                <option value="external_file" selected="True">Use an external file to map transcript to gene names</option>
                <option value="gene_id_column_option">Gene id is a column of the input file</option>
            </param>
            <when value="gene_id_column_option"> 
                <param name="gene_id_column" type="text" label="Name of the column containing the geneID"/>
            </when>
            <when value="external_file">
                <conditional name="gff_source_selector">
                    <param name="gff_source" type="select" label="Select a tx-to-gene table/GFF from your history or use a built-in file?">
                        <option value="built-in" selected="True">Use a built-in file</option>
                        <option value="history" >Use one from the history</option>
                    </param>
                    <when value="built-in">
                        <param name="tx2gene" type="select" label="Select an annotation version" help="If the build of your interest is not listed contact your Galaxy admin">
                            <options from_data_table="tx2gene_table">
                                <filter type="sort_by" column="1"/>
                                <validator type="no_options" message="No files are available for the selected input dataset"/>
                            </options>
                        </param>
                    </when>  
                    <when value="history"> 
                        <conditional name="gff_tx2gene_selector">
                            <param name="mapping_file_option" type="select" label="Will you provide a tx2gene or a GFF/GTF file?">
                                <option value="tx2gene" selected="True">TranscriptID to GeneID table</option>
                                <option value="gff_gtf">GTF/GFF file</option>
                            </param>
                            <when value="gff_gtf">
                                <param name="own_gff" type="data" format="gff" label="Select your GFF file"/>
                            </when>
                            <when value="tx2gene">
{'fraction_non_alphanumeric': 0.11527093596059114, 'fraction_numerical': 0.004698749526335733, 'mean_word_length': 2.3180789539854163, 'pattern_counts': {'":': 2, '<': 181, '<?xml version=': 0, '>': 181, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4411868', 'n_tokens_mistral': 3879, 'n_tokens_neox': 3662, 'n_words': 784}