view COBRAxy/flux_simulation_beta.xml @ 432:c37a68e34a1c draft

Uploaded
author francesco_lapi
date Wed, 10 Sep 2025 15:04:57 +0000
parents 5d9c220b3238
children 28c4f64adcaa
line wrap: on
line source

<tool id="fluxSimulation - Beta" name="Flux Simulation - BETA" version="2.0.0">
    
    <macros>
        <import>marea_macros.xml</import>
    </macros>

    <requirements>
        <requirement type="package" version="1.24.4">numpy</requirement>
        <requirement type="package" version="2.0.3">pandas</requirement>
        <requirement type="package" version="0.29.0">cobra</requirement>
        <requirement type="package" version="5.2.2">lxml</requirement>
        <requirement type="package" version="1.4.2">joblib</requirement>
        <requirement type="package" version="1.11">scipy</requirement>
    </requirements>

    <command detect_errors="exit_code">
        <![CDATA[
        python $__tool_directory__/flux_simulation_beta.py
        --tool_dir $__tool_directory__
        --model_and_bounds $model_and_bounds.model_and_bounds
        
        #if $model_and_bounds.model_and_bounds == 'True':
            --model_upload $model_and_bounds.model_upload
            --input "${",".join(map(str, $model_and_bounds.inputs))}"
            #set $names = ""
            #for $input_temp in $model_and_bounds.inputs:
                #set $names = $names + $input_temp.element_identifier + ","
            #end for
            --name $names
        #else:
            --input "${",".join(map(str, $model_and_bounds.model_files))}"
            #set $names = ""
            #for $input_temp in $model_and_bounds.model_files:
                #set $names = $names + $input_temp.element_identifier + ","
            #end for
            --name $names
        #end if
        
        --thinning 0
        #if $algorithm_param.algorithm == 'OPTGP':
            --thinning $algorithm_param.thinning
        #end if
        --algorithm $algorithm_param.algorithm
        --n_batches $n_batches
        --n_samples $n_samples
        --seed $seed
        #if 'FVA' in str($output_types_analysis_cond.output_types_analysis).split(',')
            --perc_opt $output_types_analysis_cond.fva_fraction
        #end if
        --output_type "${",".join(map(str, $output_types))}"
        --output_type_analysis "${",".join(map(str, $output_types_analysis_cond.output_types_analysis))}"
        --out_log $log
        ]]>
    </command>

    <inputs>
        <conditional name="model_and_bounds">
            <param name="model_and_bounds" argument="--model_and_bounds" type="select" label="Upload mode:" help="Choose whether to upload the model and bounds in separate files or to upload multiple complete model files.">
                <option value="True" selected="true">Model + bounds (separate files)</option>
                <option value="False">Multiple complete models</option>
            </param>

            <when value="True">
                <param name="model_upload" argument="--model_upload" type="data" format="csv,tsv,tabular"
                    label="Model (rules) file:"
                    help="Upload a CSV/TSV file that contains the model reaction rules. Recommended columns: ReactionID, Reaction (formula), Rule (GPR). Optional columns: name, lower_bound, upper_bound, InMedium. If bounds are present here they may be overridden by separate bound files." />

                <param name="inputs" argument="--inputs" multiple="true" type="data" format="tabular,csv,tsv"
                    label="Bound file(s):"
                    help="Upload one or more CSV/TSV files containing reaction bounds. Each file must include at least: ReactionID, lower_bound, upper_bound. Files are applied in the order provided; later files override earlier ones for the same ReactionID." />
            </when>

            <when value="False">
                <param name="model_files" argument="--model_files" multiple="true" type="data" format="csv,tsv,tabular"
                    label="Complete model files:"
                    help="Upload one or more CSV/TSV files, each containing both model rules and reaction bounds for different contexts/cells. Required columns: ReactionID, Reaction, Rule, lower_bound, upper_bound." />
            </when>
        </conditional>

        <conditional name="algorithm_param">
            <param name="algorithm" argument="--algorithm" type="select" label="Choose sampling algorithm:">
                <option value="CBS" selected="true">CBS</option>
                <option value="OPTGP">OPTGP</option>
            </param>
            <when value="OPTGP">
                <param name="thinning" argument="--thinning" type="integer" label="Thinning:" value="100" help="Number of iterations to wait before taking a sample."/>
            </when>
        </conditional>

        <param name="n_samples" argument="--n_samples" type="integer" label="Samples:" value="1000"/>
        <param name="n_batches" argument="--n_batches" type="integer" label="Batches:" value="1" help="This is useful for computational performances."/>
        <param name="seed" argument="--seed" type="integer" label="Seed:" value="0" help="Random seed."/>

        <param type="select" argument="--output_types" multiple="true" name="output_types" label="Desired outputs from sampling">
            <option value="mean" selected="true">Mean</option>
            <option value="median" selected="true">Median</option>
            <option value="quantiles" selected="true">Quantiles</option>
            <option value="fluxes" selected="false">All fluxes</option>
        </param>

        <conditional name="output_types_analysis_cond">
            <param type="select" argument="--output_types_analysis" multiple="true" name="output_types_analysis" label="Desired outputs from flux analysis">
                <option value="pFBA" selected="false">pFBA</option>
                <option value="FVA" selected="false">FVA</option>
                <option value="sensitivity" selected="false">Sensitivity reaction knock-out (Biomass)</option>
            </param>

            <when value_contains="FVA">
                <param name="fva_fraction" argument="--fva_fraction" type="float"
                        label="FVA fraction of optimality (0-1):"
                        value="0.9"
                        min="0.0" max="1.0"
                        help="Fraction of the optimal objective value to consider for FVA. 0.9 = 90%"/>
            </when>

        </conditional>
    </inputs>

    <outputs>
        <data format="txt" name="log" label="Flux Simulation - Log" />
        <data name="output" format="tabular" label="Flux Simulation - Output">
            <discover_datasets pattern="__name_and_ext__" directory="flux_simulation" visible="true" />
        </data>
    </outputs>

    <help>
    <![CDATA[
What it does
-------------

This tool generates flux samples starting from metabolic models using CBS (Corner-based sampling) or OPTGP (Improved Artificial Centering Hit-and-Run sampler) algorithms.

Two upload modes are supported:
1. **Model + bounds**: Upload one base model and multiple bound files (one per context/cell type)
2. **Multiple complete models**: Upload multiple complete model files, each with integrated bounds

It can return sampled fluxes by applying summary statistics: 
   - mean
   - median
   - quantiles (0.25, 0.50, 0.75)

Flux analysis can be performed over the metabolic model:
   - parsimonious-FBA (optimized by Biomass)
   - FVA
   - Biomass sensitivity analysis (single reaction knock-out)

Output:
-------------

The tool generates:
   - Samples: reporting the sampled fluxes for each reaction (reaction names on the rows and sample names on the columns). Format: tab-separated.
   - a log file (.txt).

**TIP**: The Batches parameter helps maintain memory efficiency. For 10,000 samples, use n_samples=1,000 and n_batches=10.
**TIP**: The Thinning parameter for OPTGP helps converge to stationary distribution.
]]>
    </help>
    <expand macro="citations_fluxes" />
</tool>