Mercurial > repos > goeckslab > cell_intensity_processing
changeset 0:34bb79f271fc draft
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/mti-utils commit 339f5497446066ca76c27460da2eef4f6e0fa36e
author | goeckslab |
---|---|
date | Thu, 29 Sep 2022 16:53:01 +0000 |
parents | |
children | 7a77ed0e579a |
files | macros.xml process_intensities.xml test-data/intensities.csv test-data/intensity_channels.csv test-data/rename_channels.csv test-data/rename_test.tiff |
diffstat | 6 files changed, 166 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/macros.xml Thu Sep 29 16:53:01 2022 +0000 @@ -0,0 +1,20 @@ +<?xml version="1.0"?> +<macros> + <xml name="requirements"> + <requirements> + <container type="docker">quay.io/goeckslab/mti_utils:0.0.1</container> + </requirements> + </xml> + + <xml name="version_cmd"> + <version_command>echo @VERSION@</version_command> + </xml> + <xml name="citations"> + <citations> + </citations> + </xml> + + <token name="@VERSION@">0.0.1</token> + <token name="@VERSION_SUFFIX@">1</token> + <token name="@PROFILE@">19.01</token> +</macros>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/process_intensities.xml Thu Sep 29 16:53:01 2022 +0000 @@ -0,0 +1,116 @@ +<tool id="cell_intensity_processing" name="Process single-cell intensities" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@"> + <description>Options to correct for exposure time, autofluorescence subtraction, or compute signal-to-background ratio.</description> + <macros> + <import>macros.xml</import> + </macros> + <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] < 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> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/intensities.csv Thu Sep 29 16:53:01 2022 +0000 @@ -0,0 +1,15 @@ +CellID,DNA_1,AF488,AF555,AF647,DNA_2,A488_background,A555_background,A647_background,DNA_3,FDX1,CD357,CD1D,Extent,Orientation +1,14308.90789,499.1973684,158.8947368,291.7960526,14838.375,330.3684211,115.8815789,330.2039474,7605.743421,849.8881579,528.7039474,722.6578947,0.812834225,0.077538976 +2,17899.1573,560.741573,178.3033708,302.3370787,17559.61798,334.6853933,129.0449438,331.3146067,8806.05618,739.247191,476.7752809,687.8426966,0.684615385,-0.383749081 +3,13548.68182,542.6477273,166.3295455,287.4659091,14924.98864,350.7386364,121.3636364,324.3295455,8227.102273,739.5909091,489.9772727,678.6704545,0.752136752,-0.233397964 +4,20397.52564,509.6410256,169.6794872,252.2051282,16952.11538,334.5128205,125.3589744,337.3589744,9884.935897,988.474359,526.525641,659.8589744,0.709090909,0.57603987 +5,9322.542857,487.7428571,152.8,266.6857143,11197.6,336.6,116.6,323.8857143,5387.914286,1030.685714,506.8285714,705.9714286,0.833333333,0.635330044 +6,18444.54321,528.6419753,175.0493827,261.654321,19074.02469,362.6049383,116.6790123,331.8888889,9755.012346,732.3703704,435.0123457,636.5185185,0.81,-0.802338719 +7,11192.79012,497.9012346,165.1851852,284.3950617,10417.59259,331.7530864,113.4938272,319.9259259,6038.296296,769.6666667,416.9012346,661.0740741,0.818181818,-0.067432427 +8,19044.81633,624.3877551,199.2244898,351.0306122,19464.2449,389.4183673,133.8673469,333.1632653,10691.5102,775.877551,538,729.2653061,0.742424242,-1.127518788 +9,13396.91892,454.0810811,155.4054054,255.2297297,13411.5,322.4054054,112.1081081,326.2432432,7380.040541,545.3243243,410.5810811,601.0675676,0.822222222,-0.190807793 +10,12986.30769,437.9326923,151.8365385,253.2115385,11942.25962,309.3653846,100.6442308,327.3076923,6417.875,723.6442308,425.7019231,588.8846154,0.787878788,1.183452058 +11,18147.53684,555.0210526,179.0210526,310.9789474,17723.72632,344.1473684,118.5894737,335.3052632,9508.273684,806.7789474,441.2736842,678.0842105,0.791666667,-0.345157473 +12,10102.03704,403.9259259,148.5925926,246.9814815,8981.555556,291.6296296,103.2037037,321.0185185,5171.62963,859.6481481,407.8518519,605.2037037,0.75,0.988871411 +13,14623.16667,697.0740741,238.4814815,440.4814815,15268.88889,430.7592593,146.8333333,329.7222222,8025.592593,899.3703704,591.2407407,810.8703704,0.75,-0.220438727 +14,11763.10891,549.6138614,187.6237624,360.7029703,10164.54455,300.0594059,102.3366337,329.2772277,6828.861386,765.049505,457.5247525,883.5841584,0.776923077,0.374877468 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/intensity_channels.csv Thu Sep 29 16:53:01 2022 +0000 @@ -0,0 +1,13 @@ +channel_number,marker_name,exposure_time,AF_channel +0,DNA_1,100,None +1,AF488,100,None +2,AF555,100,None +3,AF647,100,None +4,DNA_2,100,None +5,A488_background,100,AF488 +6,A555_background,100,AF555 +7,A647_background,100,AF647 +8,DNA_3,100,None +9,FDX1,100,AF488 +10,CD357,100,AF555 +11,CD1D,100,AF647 \ No newline at end of file