<tool id="flexynesis_plot" name="Flexynesis plot" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@">
    <description>tool for visualizing flexynesis results</description>
    <macros>
        <import>macros.xml</import>
    </macros>
    <expand macro="requirements"/>
    <required_files>
        <include path="flexynesis_plot.py" />
    </required_files>
    <command detect_errors="exit_code"><![CDATA[
        @CHECK_NON_COMMERCIAL_USE@
        mkdir -p inputs/ plots/ &&
        #if str($plot_conditional.plot_type) != 'cox_plot':
            ln -s '$plot_conditional.labels' inputs/labels.tabular &&
        #end if
        #if $plot_conditional.plot_type == "dimred":
            ln -s '$plot_conditional.embeddings' inputs/embeddings.tabular &&
        #end if
        #if $plot_conditional.plot_type == "km_plot":
            ln -s '$plot_conditional.survival_data' inputs/survival_data.tabular &&
            survival_event=`'$__tool_directory__/index_to_name.py' inputs/survival_data.tabular $plot_conditional.surv_event_var` &&
            ## check if survival variable is numerical
            echo "Survival event variable: \$survival_event" &&
            python '$__tool_directory__/flexynesis_utils.py' --util validate_survival --clin inputs/survival_data.tabular --clin_variable \$survival_event &&
            survival_time=`'$__tool_directory__/index_to_name.py' inputs/survival_data.tabular $plot_conditional.surv_time_var` &&
            echo "Survival time variable: \$survival_time" &&
        #end if
        #if $plot_conditional.plot_type == "cox_plot":
            ln -s '$plot_conditional.important_features' inputs/important_features.tabular &&
            ln -s '$plot_conditional.clinical_train' inputs/clinical_train.tabular &&
            ln -s '$plot_conditional.clinical_test' inputs/clinical_test.tabular &&
            ln -s '$plot_conditional.omics_train' inputs/omics_train.tabular &&
            ln -s '$plot_conditional.omics_test' inputs/omics_test.tabular &&
            survival_event=`'$__tool_directory__/index_to_name.py' inputs/clinical_train.tabular $plot_conditional.surv_event_var` &&
            ## check if survival variable is numerical
            echo "Survival event variable: \$survival_event" &&
            python '$__tool_directory__/flexynesis_utils.py' --util validate_survival --clin inputs/clinical_train.tabular --clin_variable \$survival_event &&
            survival_time=`'$__tool_directory__/index_to_name.py' inputs/clinical_train.tabular $plot_conditional.surv_time_var` &&
            echo "Survival time variable: \$survival_time" &&
            #if str($plot_conditional.clinical_variables) != 'None':
                covars=`'$__tool_directory__/index_to_name.py' inputs/clinical_train.tabular $plot_conditional.clinical_variables` &&
                ## check if survival variable is numerical
                echo "Clinical variables: \$covars" &&
                python '$__tool_directory__/flexynesis_utils.py' --util validate_covariate --clin inputs/clinical_train.tabular --clin_variable \$covars &&
            #end if
        #end if
        #if $plot_conditional.plot_type == "dimred":
            ## set target variables
            color_col=`'$__tool_directory__/index_to_name.py' inputs/labels.tabular $plot_conditional.color` &&
            echo "Color: \$color_col" &&
            python '$__tool_directory__/flexynesis_plot.py'
                --plot_type dimred
                --embeddings inputs/embeddings.tabular
                --labels inputs/labels.tabular
                --method $plot_conditional.method
                --color \$color_col
                --output_dir plots
                --format $plot_conditional.format
                --dpi $plot_conditional.dpi

        #else if $plot_conditional.plot_type == "scatter":
            #if $plot_conditional.true_label and $plot_conditional.predicted_label:
                true_label_col=`'$__tool_directory__/index_to_name.py' inputs/labels.tabular $plot_conditional.true_label` &&
                echo "True label: \$true_label_col" &&
                python '$__tool_directory__/flexynesis_utils.py' --util validate_covariate --clin inputs/labels.tabular --clin_variable \$true_label_col &&

                predicted_label_col=`'$__tool_directory__/index_to_name.py' inputs/labels.tabular $plot_conditional.predicted_label` &&
                echo "Predicted label: \$predicted_label_col" &&
                python '$__tool_directory__/flexynesis_utils.py' --util validate_covariate --clin inputs/labels.tabular --clin_variable \$predicted_label_col &&
            #end if
            python '$__tool_directory__/flexynesis_plot.py'
                --plot_type scatter
                --labels inputs/labels.tabular
                #if $plot_conditional.true_label and $plot_conditional.predicted_label:
                    --true_label \$true_label_col
                    --predicted_label \$predicted_label_col
                #end if
                --output_dir plots
                --format $plot_conditional.format
                --dpi $plot_conditional.dpi
        #else if $plot_conditional.plot_type == "concordance_heatmap":
            #if $plot_conditional.true_label and $plot_conditional.predicted_label:
                true_label_col=`'$__tool_directory__/index_to_name.py' inputs/labels.tabular $plot_conditional.true_label` &&
                predicted_label_col=`'$__tool_directory__/index_to_name.py' inputs/labels.tabular $plot_conditional.predicted_label` &&
                echo "True label: \$true_label_col" &&
                echo "Predicted label: \$predicted_label_col" &&
            #end if
            python '$__tool_directory__/flexynesis_plot.py'
                --plot_type concordance_heatmap
                --labels inputs/labels.tabular
                #if $plot_conditional.true_label and $plot_conditional.predicted_label:
                    --true_label \$true_label_col
                    --predicted_label \$predicted_label_col
                #end if
                --output_dir plots
                --format $plot_conditional.format
                --dpi $plot_conditional.dpi
        #else if $plot_conditional.plot_type == "pr_curve":
            python '$__tool_directory__/flexynesis_plot.py'
                --plot_type pr_curve
                --labels inputs/labels.tabular
                --output_dir plots
                --format $plot_conditional.format
                --dpi $plot_conditional.dpi
        #else if $plot_conditional.plot_type == "roc_curve":
            python '$__tool_directory__/flexynesis_plot.py'
                --plot_type roc_curve
                --labels inputs/labels.tabular
                --output_dir plots
                --format $plot_conditional.format
                --dpi $plot_conditional.dpi
        #else if $plot_conditional.plot_type == "box_plot":
            python '$__tool_directory__/flexynesis_plot.py'
                --plot_type box_plot
                --labels inputs/labels.tabular
                --output_dir plots
                --format $plot_conditional.format
                --dpi $plot_conditional.dpi
        #else if $plot_conditional.plot_type == "km_plot":
            python '$__tool_directory__/flexynesis_plot.py'
                --plot_type kaplan_meier
                --labels inputs/labels.tabular
                --survival_data inputs/survival_data.tabular
                --surv_event_var \$survival_event
                --surv_time_var \$survival_time
                --output_dir plots
                --format $plot_conditional.format
                --dpi $plot_conditional.dpi
        #else if $plot_conditional.plot_type == "cox_plot":
            python '$__tool_directory__/flexynesis_plot.py'
                --plot_type cox
                --important_features inputs/important_features.tabular
                --clinical_train inputs/clinical_train.tabular
                --clinical_test inputs/clinical_test.tabular
                --omics_train inputs/omics_train.tabular
                --omics_test inputs/omics_test.tabular
                --layer '$plot_conditional.layer'
                --surv_time_var \$survival_time
                --surv_event_var \$survival_event
                #if str($plot_conditional.clinical_variables) != 'None':
                    --clinical_variables \$covars
                #end if
                --top_features $plot_conditional.top_features
                #if str($plot_conditional.crossval_conditional.crossval) == 'yes':
                    --crossval
                #end if
                #if str($plot_conditional.crossval_conditional.crossval) == 'yes':
                    --n_splits $plot_conditional.crossval_conditional.n_splits
                #end if
                --random_state 42
                --output_dir plots
                --format $plot_conditional.format
                --dpi $plot_conditional.dpi
        #end if
    ]]></command>
    <inputs>
        <expand macro="commercial_use_param"/>
        <conditional name="plot_conditional">
            <param name="plot_type" type="select" label="Flexynesis plot">
                <option value="dimred">Dimensionality reduction</option>
                <option value="scatter">Scatter plot of known vs predicted labels</option>
                <option value="concordance_heatmap">Label concordance heatmap</option>
                <option value="pr_curve">Precision-recall curves</option>
                <option value="roc_curve">ROC curves</option>
                <option value="box_plot">Box plot</option>
                <option value="km_plot">Kaplan-Meier plot</option>
                <option value="cox_plot">Cox proportional hazards plot</option>
            </param>
            <when value="dimred">
                <expand macro="plots_common_param_svg">
                    <expand macro="plots_common_input"/>
                    <param argument="--embeddings" type="data" format="tabular" label="Embeddings" help="Generated by flexynesis"/>
                    <param argument="--color" type="data_column" data_ref="labels" label="Column in the labels file to use for coloring the points in the plot"/>
                    <param name="method" type="select" label="Transformation method">
                        <option value="pca" selected="true">PCA</option>
                        <option value="umap">UMAP</option>
                    </param>
                </expand>
            </when>
            <when value="scatter">
                <expand macro="plots_common_param_svg">
                    <expand macro="plots_common_input"/>
                    <param argument="--true_label" type="data_column" data_ref="labels" optional="true" label="Column in the labels file to use for true labels"/>
                    <param argument="--predicted_label" type="data_column" data_ref="labels" optional="true" label="Column in the labels file to use for predicted labels"/>
                </expand>
            </when>
            <when value="concordance_heatmap">
                <expand macro="plots_common_param_svg">
                    <expand macro="plots_common_input"/>
                    <param argument="--true_label" type="data_column" data_ref="labels" optional="true" label="Column in the labels file to use for true labels"/>
                    <param argument="--predicted_label" type="data_column" data_ref="labels" optional="true" label="Column in the labels file to use for predicted labels"/>
                </expand>
            </when>
            <when value="pr_curve">
                <expand macro="plots_common_param_svg">
                    <expand macro="plots_common_input"/>
                </expand>
            </when>
            <when value="roc_curve">
                <expand macro="plots_common_param_svg">
                    <expand macro="plots_common_input"/>
                </expand>
            </when>
            <when value="box_plot">
                <expand macro="plots_common_param_svg">
                    <expand macro="plots_common_input"/>
                </expand>
            </when>
            <when value="km_plot">
                <expand macro="plots_common_param_svg">
                    <expand macro="plots_common_input"/>
                    <param argument="--survival_data" type="data" format="tabular" label="Survival data"/>
                    <param argument="--surv_event_var" type="data_column" data_ref="survival_data" label="Column in the survival data to use as survival event"/>
                    <param argument="--surv_time_var" type="data_column" data_ref="survival_data" label="Column in the survival data to use as survival time"/>
                </expand>
            </when>
            <when value="cox_plot">
                <expand macro="plots_common_param_svg">
                    <param argument="--important_features" type="data" format="tabular" label="Important features file"/>
                    <param argument="--clinical_train" type="data" format="tabular" label="Clinical training data"/>
                    <param argument="--clinical_test" type="data" format="tabular" label="Clinical test data"/>
                    <param argument="--omics_train" type="data" format="tabular" label="Omics training data"/>
                    <param argument="--omics_test" type="data" format="tabular" label="Omics test data"/>
                    <param name="layer" type="text" optional="false" label="The class label to use from important features file" help="This corresponds to assay name in flexynesis tool.">
                        <expand macro="sanitizer_letters"/>
                    </param>
                    <param argument="--surv_event_var" type="data_column" data_ref="clinical_train" label="Column in the clinical training data to use as survival event"/>
                    <param argument="--surv_time_var" type="data_column" data_ref="clinical_train" label="Column in the clinical training data to use as survival time"/>
                    <param argument="--clinical_variables" type="data_column" data_ref="clinical_train" optional="true" multiple="true" label="Columns in the train clinical data to use as clinical covariates and include in the Cox model (e.g SEX, AGE, ...), multiple covariates are allowed"/>
                    <param argument="--top_features" type="integer" min="1" value="20" label="Number of top important features to include in Cox model"/>
                    <conditional name="crossval_conditional">
                        <param name="crossval" type="select" label="Performs K-fold cross-validation?">
                            <option value="yes">Yes</option>
                            <option value="no" selected="true">No</option>
                        </param>
                        <when value="yes">
                            <param name="n_splits" type="integer" min="2" value="5" label="Number of folds for cross-validation"/>
                        </when>
                        <when value="no"/>
                    </conditional>
                </expand>
            </when>
        </conditional>
    </inputs>
    <outputs>
        <collection name="plot_out" type="list" label="${tool.name} on ${on_string}: ${plot_conditional.plot_type} - ${plot_conditional.format}">
            <discover_datasets pattern="__name_and_ext__" directory="plots/"/>
            <filter>plot_conditional['format'] != 'svg'</filter>
        </collection>
        <!-- other types can be sniffed correctly by galaxy -->
        <collection name="plot_out_svg" format="svg" type="list" label="${tool.name} on ${on_string}: ${plot_conditional.plot_type} - svg">
            <discover_datasets pattern="__name_and_ext__" directory="plots/"/>
            <filter>plot_conditional['format'] == 'svg'</filter>
        </collection>
    </outputs>
    <tests>
        <!-- test 1: dimred -->
        <test expect_num_outputs="1">
            <param name="non_commercial_use" value="True"/>
            <conditional name="plot_conditional">
                <param name="plot_type" value="dimred"/>
                <param name="embeddings" value="embeddings.tabular"/>
                <param name="color" value="6"/>
                <param name="method" value="pca"/>
                <param name="labels" value="labels.tabular"/>
                <param name="format" value="jpg"/>
                <param name="dpi" value="300"/>
            </conditional>
            <output_collection name="plot_out" type="list" count="1">
                <element name="embeddings_pca_predicted_label">
                    <assert_contents>
                        <has_image_center_of_mass center_of_mass="970,731" eps="20"/>
                        <has_image_channels channels="3"/>
                        <has_image_height height="1460" delta="20"/>
                        <has_image_width width="1940" delta="20"/>
                    </assert_contents>
                </element>
            </output_collection>
        </test>
        <!-- test 2: scatter -->
        <test expect_num_outputs="1">
            <param name="non_commercial_use" value="True"/>
            <conditional name="plot_conditional">
                <param name="plot_type" value="scatter"/>
                <param name="labels" value="labels_scatter.tabular"/>
                <param name="format" value="jpg"/>
                <param name="dpi" value="300"/>
            </conditional>
            <output_collection name="plot_out" type="list" count="1">
                <element name="labels_scatter_CLAUDIN_SUBTYPE">
                    <assert_contents>
                        <has_image_center_of_mass center_of_mass="969,732" eps="20"/>
                        <has_image_channels channels="3"/>
                        <has_image_height height="1460" delta="20"/>
                        <has_image_width width="1941" delta="20"/>
                    </assert_contents>
                </element>
            </output_collection>
        </test>
        <!-- test 3: concordance_heatmap -->
        <test expect_num_outputs="1">
            <param name="non_commercial_use" value="True"/>
            <conditional name="plot_conditional">
                <param name="plot_type" value="concordance_heatmap"/>
                <param name="labels" value="labels.tabular"/>
                <param name="format" value="jpg"/>
                <param name="dpi" value="300"/>
            </conditional>
            <output_collection name="plot_out" type="list" count="1">
                <element name="labels_concordance_CLAUDIN_SUBTYPE">
                    <assert_contents>
                        <has_image_center_of_mass center_of_mass="1450,1306" eps="20"/>
                        <has_image_channels channels="3"/>
                        <has_image_height height="2558" delta="20"/>
                        <has_image_width width="2768" delta="20"/>
                    </assert_contents>
                </element>
            </output_collection>
        </test>
        <!-- test 4: pr_curve -->
        <test expect_num_outputs="1">
            <param name="non_commercial_use" value="True"/>
            <conditional name="plot_conditional">
                <param name="plot_type" value="pr_curve"/>
                <param name="labels" value="labels_pr.tabular"/>
                <param name="format" value="jpg"/>
                <param name="dpi" value="300"/>
            </conditional>
            <output_collection name="plot_out" type="list" count="1">
                <element name="labels_pr_curves_CLAUDIN_SUBTYPE">
                    <assert_contents>
                        <has_image_center_of_mass center_of_mass="965,733" eps="20"/>
                        <has_image_channels channels="3"/>
                        <has_image_height height="1461" delta="20"/>
                        <has_image_width width="1941" delta="20"/>
                    </assert_contents>
                </element>
            </output_collection>
        </test>
        <!-- test 5: roc_curve -->
        <test expect_num_outputs="1">
            <param name="non_commercial_use" value="True"/>
            <conditional name="plot_conditional">
                <param name="plot_type" value="roc_curve"/>
                <param name="labels" value="labels_pr.tabular"/>
                <param name="format" value="jpg"/>
                <param name="dpi" value="300"/>
            </conditional>
            <output_collection name="plot_out" type="list" count="1">
                <element name="labels_roc_curves_CLAUDIN_SUBTYPE">
                    <assert_contents>
                        <has_image_center_of_mass center_of_mass="971,732" eps="20"/>
                        <has_image_channels channels="3"/>
                        <has_image_height height="1461" delta="20"/>
                        <has_image_width width="1941" delta="20"/>
                    </assert_contents>
                </element>
            </output_collection>
        </test>
        <!-- test 6: box_plot -->
        <test expect_num_outputs="1">
            <param name="non_commercial_use" value="True"/>
            <conditional name="plot_conditional">
                <param name="plot_type" value="box_plot"/>
                <param name="labels" value="labels_pr.tabular"/>
                <param name="format" value="jpg"/>
                <param name="dpi" value="300"/>
            </conditional>
            <output_collection name="plot_out" type="list" count="7">
                <element name="labels_box_plot_CLAUDIN_SUBTYPE_Basal">
                    <assert_contents>
                        <has_image_center_of_mass center_of_mass="1485,882" eps="20"/>
                        <has_image_channels channels="3"/>
                        <has_image_height height="1766" delta="20"/>
                        <has_image_width width="2967" delta="20"/>
                    </assert_contents>
                </element>
                <element name="labels_box_plot_CLAUDIN_SUBTYPE_Her2">
                    <assert_contents>
                        <has_image_center_of_mass center_of_mass="1485,882" eps="20"/>
                        <has_image_channels channels="3"/>
                        <has_image_height height="1766" delta="20"/>
                        <has_image_width width="2967" delta="20"/>
                    </assert_contents>
                </element>
                <element name="labels_box_plot_CLAUDIN_SUBTYPE_LumA">
                    <assert_contents>
                        <has_image_center_of_mass center_of_mass="1485,882" eps="20"/>
                        <has_image_channels channels="3"/>
                        <has_image_height height="1766" delta="20"/>
                        <has_image_width width="2967" delta="20"/>
                    </assert_contents>
                </element>
                <element name="labels_box_plot_CLAUDIN_SUBTYPE_LumB">
                    <assert_contents>
                        <has_image_center_of_mass center_of_mass="1485,882" eps="20"/>
                        <has_image_channels channels="3"/>
                        <has_image_height height="1766" delta="20"/>
                        <has_image_width width="2967" delta="20"/>
                    </assert_contents>
                </element>
                <element name="labels_box_plot_CLAUDIN_SUBTYPE_NC">
                    <assert_contents>
                        <has_image_center_of_mass center_of_mass="1485,875" eps="20"/>
                        <has_image_channels channels="3"/>
                        <has_image_height height="1766" delta="20"/>
                        <has_image_width width="2967" delta="20"/>
                    </assert_contents>
                </element>
                <element name="labels_box_plot_CLAUDIN_SUBTYPE_Normal">
                    <assert_contents>
                        <has_image_center_of_mass center_of_mass="1485,878" eps="20"/>
                        <has_image_channels channels="3"/>
                        <has_image_height height="1766" delta="20"/>
                        <has_image_width width="2967" delta="20"/>
                    </assert_contents>
                </element>
                <element name="labels_box_plot_CLAUDIN_SUBTYPE_claudin-low">
                    <assert_contents>
                        <has_image_center_of_mass center_of_mass="1485,882" eps="20"/>
                        <has_image_channels channels="3"/>
                        <has_image_height height="1765" delta="20"/>
                        <has_image_width width="2967" delta="20"/>
                    </assert_contents>
                </element>
            </output_collection>
        </test>
        <!-- test 7: dimred png-->
        <test expect_num_outputs="1">
            <param name="non_commercial_use" value="True"/>
            <conditional name="plot_conditional">
                <param name="plot_type" value="dimred"/>
                <param name="embeddings" value="embeddings.tabular"/>
                <param name="color" value="6"/>
                <param name="method" value="pca"/>
                <param name="labels" value="labels.tabular"/>
                <param name="format" value="png"/>
                <param name="dpi" value="300"/>
            </conditional>
            <output_collection name="plot_out" type="list" count="1">
                <element name="embeddings_pca_predicted_label">
                    <assert_contents>
                        <has_image_center_of_mass center_of_mass="970,730" eps="20"/>
                        <has_image_channels channels="4"/>
                        <has_image_height height="1461" delta="20"/>
                        <has_image_width width="1941" delta="20"/>
                    </assert_contents>
                </element>
            </output_collection>
        </test>
        <!-- test 8: roc_curve svg-->
        <test expect_num_outputs="1">
            <param name="non_commercial_use" value="True"/>
            <conditional name="plot_conditional">
                <param name="plot_type" value="roc_curve"/>
                <param name="labels" value="labels_pr.tabular"/>
                <param name="format" value="svg"/>
                <param name="dpi" value="300"/>
            </conditional>
            <output_collection name="plot_out_svg" type="list" count="1">
                <element name="labels_roc_curves_CLAUDIN_SUBTYPE">
                    <assert_contents>
                        <has_text_matching expression="ROC Curve"/>
                        <has_text_matching expression="True Positive Rate"/>
                    </assert_contents>
                </element>
            </output_collection>
        </test>
        <!-- test 9: km_plot -->
        <test expect_num_outputs="1">
            <param name="non_commercial_use" value="True"/>
            <conditional name="plot_conditional">
                <param name="plot_type" value="km_plot"/>
                <param name="labels" value="labels_survival.tabular"/>
                <param name="survival_data" value="test/clin"/>
                <param name="surv_event_var" value="15"/>
                <param name="surv_time_var" value="14"/>
                <param name="format" value="jpg"/>
                <param name="dpi" value="300"/>
            </conditional>
            <output_collection name="plot_out" type="list" count="1">
                <element name="survival_data_km_km_risk_subtypes">
                    <assert_contents>
                        <has_image_center_of_mass center_of_mass="970,730" eps="20"/>
                        <has_image_channels channels="3"/>
                        <has_image_height height="1460" delta="20"/>
                        <has_image_width width="1940" delta="20"/>
                    </assert_contents>
                </element>
            </output_collection>
        </test>
        <!-- test 10: cox_plot -->
        <test expect_num_outputs="1">
            <param name="non_commercial_use" value="True"/>
            <conditional name="plot_conditional">
                <param name="plot_type" value="cox_plot"/>
                <param name="important_features" value="feature_importance.tabular"/>
                <param name="clinical_train" value="train/clin"/>
                <param name="clinical_test" value="test/clin"/>
                <param name="omics_train" value="train/gex"/>
                <param name="omics_test" value="test/gex"/>
                <param name="layer" value="gex"/>
                <param name="surv_event_var" value="15"/>
                <param name="surv_time_var" value="14"/>
                <param name="clinical_variables" value="3,4"/>
                <param name="top_features" value="10"/>
                <param name="format" value="jpg"/>
                <param name="dpi" value="300"/>
            </conditional>
            <output_collection name="plot_out" type="list" count="1">
                <element name="important_features_cox_hazard_ratios">
                    <assert_contents>
                        <has_image_center_of_mass center_of_mass="970,730" eps="20"/>
                        <has_image_channels channels="3"/>
                        <has_image_height height="1460" delta="20"/>
                        <has_image_width width="1940" delta="20"/>
                    </assert_contents>
                </element>
            </output_collection>
        </test>
        <!-- test 11: km_plot should fail because of non numeric target -->
        <test expect_failure="true">
            <param name="non_commercial_use" value="True"/>
            <conditional name="plot_conditional">
                <param name="plot_type" value="km_plot"/>
                <param name="labels" value="labels_survival.tabular"/>
                <param name="survival_data" value="test/clin"/>
                <param name="surv_event_var" value="16"/>
                <param name="surv_time_var" value="14"/>
                <param name="format" value="jpg"/>
                <param name="dpi" value="300"/>
            </conditional>
            <assert_stderr>
                <has_text_matching expression="Error: Non-numeric values found in column 'class': Unable to parse string &quot;buz&quot; at position 0"/>
            </assert_stderr>
        </test>
        <!-- test 12: cox_plot should fail because of non numeric target -->
        <test expect_failure="true">
            <param name="non_commercial_use" value="True"/>
            <conditional name="plot_conditional">
                <param name="plot_type" value="cox_plot"/>
                <param name="important_features" value="feature_importance.tabular"/>
                <param name="clinical_train" value="train/clin"/>
                <param name="clinical_test" value="test/clin"/>
                <param name="omics_train" value="train/gex"/>
                <param name="omics_test" value="test/gex"/>
                <param name="layer" value="gex"/>
                <param name="surv_event_var" value="15"/>
                <param name="surv_time_var" value="14"/>
                <param name="clinical_variables" value="3,4,16"/>
                <param name="top_features" value="10"/>
                <param name="format" value="jpg"/>
                <param name="dpi" value="300"/>
            </conditional>
            <assert_stderr>
                <has_text_matching expression="Error: Non-numeric values found in column 'class': Unable to parse string &quot;buz&quot; at position 0"/>
            </assert_stderr>
        </test>
        <!-- test 13: scatter unsupervised -->
        <test expect_num_outputs="1">
            <param name="non_commercial_use" value="True"/>
            <conditional name="plot_conditional">
                <param name="plot_type" value="scatter"/>
                <param name="labels" value="non_flexy_label.tabular"/>
                <param name="true_label" value="11"/>
                <param name="predicted_label" value="12"/>
                <param name="format" value="jpg"/>
                <param name="dpi" value="300"/>
            </conditional>
            <output_collection name="plot_out" type="list" count="1">
                <element name="labels_scatter">
                    <assert_contents>
                        <has_image_center_of_mass center_of_mass="970,730" eps="20"/>
                        <has_image_channels channels="3"/>
                        <has_image_height height="1460" delta="20"/>
                        <has_image_width width="1941" delta="20"/>
                    </assert_contents>
                </element>
            </output_collection>
        </test>
        <!-- test 14: concordance_heatmap unsupervised -->
        <test expect_num_outputs="1">
            <param name="non_commercial_use" value="True"/>
            <conditional name="plot_conditional">
                <param name="plot_type" value="concordance_heatmap"/>
                <param name="labels" value="non_flexy_label.tabular"/>
                <param name="true_label" value="10"/>
                <param name="predicted_label" value="12"/>
                <param name="format" value="jpg"/>
                <param name="dpi" value="300"/>
            </conditional>
            <output_collection name="plot_out" type="list" count="1">
                <element name="labels_concordance">
                    <assert_contents>
                        <has_image_center_of_mass center_of_mass="1445,1306" eps="20"/>
                        <has_image_channels channels="3"/>
                        <has_image_height height="2558" delta="20"/>
                        <has_image_width width="3051" delta="20"/>
                    </assert_contents>
                </element>
            </output_collection>
        </test>
    </tests>
    <help><![CDATA[
@COMMON_HELP@

Flexynesis plot is a comprehensive visualization tool designed to create various types of plots for analyzing machine learning results from the Flexynesis framework. This tool supports multiple visualization types to help researchers understand their data and model performance.

Available plot types include:

- **Dimensionality Reduction:** Visualizes high-dimensional data in a lower-dimensional space using methods like PCA or UMAP.
- **Scatter Plot:** Compares known and predicted labels to assess model performance.
- **Label Concordance Heatmap:** Displays the agreement between true and predicted labels in a heatmap format.
- **Precision-Recall Curves:** Plots precision against recall to evaluate the trade-off between these metrics.
- **ROC Curves:** Visualizes the true positive rate against the false positive rate to assess model discrimination.
- **Box Plot:** Shows the distribution of predicted probabilities across different classes, highlighting medians and quartiles.


**Input Files**

Main common input file is the labels file, which is the predicted labels file generated by Flexynesis. It should contain the following columns:

- `sample_id`: Unique identifier for each sample.
- `variable`: The target variable used for the analysis.
- `class_label`: The class labels for the samples, used in box plots.
- `probability`: The predicted probabilities for the labels.
- `known_label`: The true labels for the samples, used in scatter plots and concordance heatmaps.
- `predicted_label`: The labels predicted by the Flexynesis model, used in scatter plots and concordance heatmaps.


For dimensionality reduction plots, an additional embeddings file is required, which contains the reduced-dimensional representations of the samples. This file is generated by Flexynesis.


.. class:: warningmark

PR and ROC curves can only be applied on classification tasks!


.. _Documentation: https://bimsbstatic.mdc-berlin.de/akalin/buyar/flexynesis/site/
.. _copyright holders: https://github.com/BIMSBbioinfo/flexynesis
    ]]></help>
    <expand macro="creator"/>
    <expand macro="citations"/>
</tool>