view process_intensities.xml @ 2:7f93f472a242 draft

planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/mti-utils commit 130ef7e8ae6cab35866b72617e53d35acc11475a
author goeckslab
date Wed, 28 Feb 2024 20:52:16 +0000
parents 34bb79f271fc
children 4f5abe01531c
line wrap: on
line source

<tool id="cell_intensity_processing" name="Process single-cell intensities" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@">
    <description></description>
    <macros>
        <import>macros.xml</import>
    </macros>
    <edam_operations>
        <edam_operation>operation_3443</edam_operation>
    </edam_operations>
    <expand macro="requirements" />
    <command detect_errors="aggressive"><![CDATA[
        
        ln -s '$quant_table' ./quant.csv &&

        python '$script'

    ]]></command>
    <configfiles>
        <configfile name = "script">
import os
import numpy as np
import pandas as pd

cwd = os.getcwd()
quant = pd.read_csv(os.path.join(cwd, 'quant.csv'), index_col = 0)
marker_df = pd.read_csv('$channel_csv')

markers_to_normalize = marker_df['marker_name'].to_list()

for marker in markers_to_normalize:

#if $exp.exposure == 'correct_exposure':
    exp_time = marker_df.loc[marker_df['marker_name'] == marker, '${exp.exp_col}'].values[0]
    quant[marker] = quant[marker] / exp_time
#end if

#if $AF_method.select_method == 'dont_adjust':
    pass
#elif $AF_method.select_method == 'subtract':
    current_AF_channel = marker_df.loc[marker_df['marker_name'] == marker, '${AF_method.AF_col}'].values[0]
    if current_AF_channel in markers_to_normalize:
        quant[marker] = quant[marker] - quant[current_AF_channel]
        quant[marker] = np.where(quant[marker] &lt; 0, 0, quant[marker])
#elif $AF_method.select_method == 'SBR':
    current_AF_channel = marker_df.loc[marker_df['marker_name'] == marker, '${AF_method.AF_col}'].values[0]
    if current_AF_channel in markers_to_normalize:
        quant[marker] = quant[marker] / quant[current_AF_channel]
#end if

quant.to_csv(os.path.join(cwd, 'processed_quant.csv'))
        </configfile>
    </configfiles>
    <inputs>
        <param name="quant_table" type="data" format="csv" label="Input quantification table (csv)" />
        <param name="channel_csv" type="data" format="csv" label="Channel Metadata (csv)" />
        <conditional name="exp">
            <param name="exposure" type="select" label="Select whether to divide intensities by exposure times">
                <option value="dont_correct_exposure">No exposure correction</option>
                <option value="correct_exposure">Exposure correction</option>
            </param>
            <when value="dont_correct_exposure" />
            <when value="correct_exposure">
                <param name="exp_col" type="text" value="exposure_time" label="Name of column in markers file containing exposure times" />
            </when>
        </conditional>
        <conditional name="AF_method">
            <param name="select_method" type="select" label="Select method of autofluorescence/background adjustment">
                <option value="dont_adjust">No AF/background adjustment</option>
                <option value="subtract">Autofluorescence subtraction</option>
                <option value="SBR">Signal-to-background ratio</option>
            </param>
            <when value="dont_adjust" />
            <when value="subtract">
                <param name="AF_col" type="text" value="AF_channel" label="Name of column in markers file containing respective AF channel for each marker" />
            </when>
            <when value="SBR">
                <param name="AF_col" type="text" value="AF_channel" label="Name of column in markers file containing respective AF channel for each marker" />
            </when>
        </conditional>
    </inputs>
    <outputs>
        <data name="processed_quant" from_work_dir="processed_quant.csv" format="csv"/>
    </outputs>
    <tests>
        <test>
            <param name="quant_table" value="intensities.csv" />
            <param name="channel_csv" value="intensity_channels.csv" />
            <conditional name="exp">
                <param name="exposure" value="correct_exposure" />
            </conditional>
            <conditional name="AF_method">
                <param name="select_method" value="SBR" />
            </conditional>
            <output name="processed_quant" ftype="csv">
                <assert_contents>
                    <has_n_columns n="15" sep="," />
                    <has_n_lines n="15" />
                </assert_contents>
            </output>
        </test>
    </tests>
    <help><![CDATA[
This tool can be used to perform several different common signal processing operations for single-cell mean marker intensities from multiplex
tissue imaging data.

**Inputs**
1. Comma-separated feature observation matrix that is generated by **MCQuant**
2. Comma-separated channel metadata file that maps marker names to exposure times (optional) and respective AF/bg channels (optional)

**Options**
1. Exposure correction - Divide single-cell intensities by respective exposure time in channel metadata
2. Background subtraction - Subtract single-cell mmean marker intensities by respective AF/bg channel mean intensity specified in channel metadata
3. Signal-to-background ratio - Divide single-cell mmean marker intensities by respective AF/bg channel mean intensity specified in channel metadata

**Outputs**
1. Feature observation matrix with processed intensities for all markers in channel metadata file. CellIDs, centroids, and morphological data remain unchanged.
    ]]></help>
    <expand macro="citations" />
</tool>