changeset 0:8969e16f3701 draft

planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/mti-utils commit bc438db690e41823909b32b693f297d942433a43
author goeckslab
date Thu, 11 Jul 2024 22:41:17 +0000
parents
children 815efbdbb7b2
files macros.xml scale_cell_coordinates.py scale_cell_coordinates.xml test-data/intensities.csv test-data/intensity_channels.csv test-data/pixels.h5ad test-data/rename_channels.csv test-data/rename_test.ome.tiff test-data/test.xml
diffstat 9 files changed, 163 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/macros.xml	Thu Jul 11 22:41:17 2024 +0000
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<macros>
+    <xml name="requirements">
+        <requirements>
+            <container type="docker">quay.io/goeckslab/mti_utils:@TOOL_VERSION@</container>
+        </requirements>
+    </xml>
+
+    <xml name="version_cmd">
+        <version_command>echo @TOOL_VERSION@</version_command>
+    </xml>
+    <xml name="citations">
+        <citations>
+        <citation type="doi">10.1101/2022.08.18.504436</citation>
+        </citations>
+    </xml>
+    
+    <token name="@TOOL_VERSION@">0.0.2</token>
+    <token name="@VERSION_SUFFIX@">0</token>
+    <token name="@PROFILE@">19.01</token>
+</macros>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scale_cell_coordinates.py	Thu Jul 11 22:41:17 2024 +0000
@@ -0,0 +1,50 @@
+import argparse
+import json
+import warnings
+
+import anndata as ad
+
+
+def main(inputs, output):
+
+    """
+    inputs : str
+        File path to galaxy tool JSON inputs config file
+    output: str
+        File path to save the output h5ad file
+    """
+    warnings.simplefilter('ignore')
+
+    # read inputs JSON
+    with open(inputs, 'r') as param_handler:
+        params = json.load(param_handler)
+
+    # read input anndata file
+    adata = ad.read_h5ad(params['anndata'])
+
+    # scale coords
+    unit = params['unit']
+    new_col_names = []
+    for c in [params['x_coord'], params['y_coord']]:
+        scaled_col_name = f'{c}_{unit}'
+        adata.obs[scaled_col_name] = adata.obs[c] * params['resolution']
+        new_col_names.append(scaled_col_name)
+
+    # overwrite adata.obsm['spatial'] with scaled coordinates
+    adata.obsm['spatial'] = adata.obs[scaled_col_name].values
+
+    # write out anndata to h5ad file
+    adata.write_h5ad(output)
+
+
+if __name__ == '__main__':
+
+    aparser = argparse.ArgumentParser()
+    aparser.add_argument(
+        "-i", "--inputs", dest="inputs", required=True)
+    aparser.add_argument(
+        "-o", "--output", dest="output", required=False)
+
+    args = aparser.parse_args()
+
+    main(args.inputs, args.output)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scale_cell_coordinates.xml	Thu Jul 11 22:41:17 2024 +0000
@@ -0,0 +1,59 @@
+<tool id="scale_cell_coordinates" name="Scale cell coordinates" 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[
+        python '$__tool_directory__/scale_cell_coordinates.py'
+            --inputs '$inputs'
+            --output '$output'
+        ]]>
+    </command>
+    <configfiles>
+        <inputs name="inputs" data_style="paths"/>
+    </configfiles>
+    <inputs>
+        <param name="anndata" type="data" format="h5ad" label="Input anndata file" />
+        <param name="x_coord" type="text" value="X_centroid" label="Key for X spatial coordinate in adata.obs" />
+        <param name="y_coord" type="text" value="Y_centroid" label="Key for Y spatial coordinate in adata.obs" />
+        <param name="resolution" type="float" value="" min="0.01" max="1.0" label="Value to multiply pixel coordinates by" help="Units would be target_unit/pixel (Example: um/pixel)" />
+        <param name="unit" type="text" value="um" optional="true" label="Unit for scaled coordinates" help="Will be appended to new column name (Example: 'X_centroid_um')" />
+    </inputs>
+    <outputs>
+        <data format="h5ad" name="output" label="Cell coordinate scaling on ${on_string}" />
+    </outputs>
+    <tests>
+        <test>
+            <param name="anndata" value="pixels.h5ad" />
+            <param name="resolution" value="0.65" />
+            <output name="output" ftype="h5ad">
+                <assert_contents>
+                    <has_h5_keys keys="obs/X_centroid_um,obs/Y_centroid_um" />
+                </assert_contents>
+            </output>
+        </test>
+    </tests>
+    <help>
+        <![CDATA[
+
+This tool allows a user to scale x,y pixel coordinates to the physical distance (microns, for example)
+
+**Inputs**
+- anndata h5ad file with x,y coordinates in pixels 
+- column names for pixel coordinates in adata.obs 
+- Physical resolution of the image (microns per pixel, for example)
+- Unit for the resulting physical distance ('um', for example)
+
+**Outputs**
+- anndata h5ad file with new columns, with column names formatted with 
+the existing column name and physical distance appended ('X_centroid_um', for example)
+
+        ]]>
+    </help>
+    <expand macro="citations" />
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/intensities.csv	Thu Jul 11 22:41:17 2024 +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 Jul 11 22:41:17 2024 +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
Binary file test-data/pixels.h5ad has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/rename_channels.csv	Thu Jul 11 22:41:17 2024 +0000
@@ -0,0 +1,3 @@
+channel_number,cycle_number,marker_name,Filter,excitation_wavelength,emission_wavelength
+0,6,DNA_6,DAPI,395,431
+0,6,DNA_7,DAPI,395,431
\ No newline at end of file
Binary file test-data/rename_test.ome.tiff has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/test.xml	Thu Jul 11 22:41:17 2024 +0000
@@ -0,0 +1,2 @@
+<?xml version='1.0' encoding='utf-8'?>
+<OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" UUID="urn:uuid:be7b96c1-399b-41a1-a9f8-ab50da05159b" xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd"><Image ID="Image:0"><Pixels BigEndian="false" DimensionOrder="XYZCT" ID="Pixels:0" PhysicalSizeX="0.6499999761581421" PhysicalSizeXUnit="µm" PhysicalSizeY="0.6499999761581421" PhysicalSizeYUnit="µm" SizeC="32" SizeT="1" SizeX="13720" SizeY="9420" SizeZ="1" Type="uint16"><Channel ID="Channel:0:0" Name="DNA" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:1" Name="Control-488nm" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:2" Name="Control-555nm" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:3" Name="Control-647nm" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:4" Name="DNA (2)" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:5" Name="ERK-1 (pT202; pY204)" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:6" Name="ERK-1 (pT202; pY204) (2)" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:7" Name="hRAD51" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:8" Name="DNA (3)" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:9" Name="G1/S-specific cyclin-D1" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:10" Name="Vimentin" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:11" Name="Aortic smooth muscle actin" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:12" Name="DNA (4)" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:13" Name="E-cadherin" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:14" Name="ER" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:15" Name="PR" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:16" Name="DNA (5)" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:17" Name="Epidermal growth factor receptor" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:18" Name="Rb (pS807; pS811)" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:19" Name="CD45" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:20" Name="DNA (6)" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:21" Name="Antigen Ki67" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:22" Name="CK-19" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:23" Name="p21" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:24" Name="DNA (7)" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:25" Name="CK-14" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:26" Name="Androgen Receptor" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:27" Name="Cleaved PARP-1" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:28" Name="DNA (8)" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:29" Name="CK-17" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:30" Name="CK-7" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:31" Name="HER2" SamplesPerPixel="1"><LightPath /></Channel><TiffData IFD="0" PlaneCount="32" /><Plane TheC="0" TheT="0" TheZ="0" /><Plane TheC="1" TheT="0" TheZ="0" /><Plane TheC="2" TheT="0" TheZ="0" /><Plane TheC="3" TheT="0" TheZ="0" /><Plane TheC="4" TheT="0" TheZ="0" /><Plane TheC="5" TheT="0" TheZ="0" /><Plane TheC="6" TheT="0" TheZ="0" /><Plane TheC="7" TheT="0" TheZ="0" /><Plane TheC="8" TheT="0" TheZ="0" /><Plane TheC="9" TheT="0" TheZ="0" /><Plane TheC="10" TheT="0" TheZ="0" /><Plane TheC="11" TheT="0" TheZ="0" /><Plane TheC="12" TheT="0" TheZ="0" /><Plane TheC="13" TheT="0" TheZ="0" /><Plane TheC="14" TheT="0" TheZ="0" /><Plane TheC="15" TheT="0" TheZ="0" /><Plane TheC="16" TheT="0" TheZ="0" /><Plane TheC="17" TheT="0" TheZ="0" /><Plane TheC="18" TheT="0" TheZ="0" /><Plane TheC="19" TheT="0" TheZ="0" /><Plane TheC="20" TheT="0" TheZ="0" /><Plane TheC="21" TheT="0" TheZ="0" /><Plane TheC="22" TheT="0" TheZ="0" /><Plane TheC="23" TheT="0" TheZ="0" /><Plane TheC="24" TheT="0" TheZ="0" /><Plane TheC="25" TheT="0" TheZ="0" /><Plane TheC="26" TheT="0" TheZ="0" /><Plane TheC="27" TheT="0" TheZ="0" /><Plane TheC="28" TheT="0" TheZ="0" /><Plane TheC="29" TheT="0" TheZ="0" /><Plane TheC="30" TheT="0" TheZ="0" /><Plane TheC="31" TheT="0" TheZ="0" /></Pixels></Image></OME>