changeset 0:18f6be63414c 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:36 +0000
parents
children 09e240a12897
files macros.xml rename_tiff_channels.xml test-data/intensities.csv test-data/intensity_channels.csv test-data/rename_channels.csv test-data/rename_test.tiff
diffstat 6 files changed, 136 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:36 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/rename_tiff_channels.xml	Thu Sep 29 16:53:36 2022 +0000
@@ -0,0 +1,86 @@
+<tool id="rename_tiff_channels" name="Rename OME-TIFF Channels" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@">
+    <description>Change the channel names in the XML metadata of OME-TIFF images</description>
+    <macros>
+        <import>macros.xml</import>
+    </macros>
+ 
+    <expand macro="requirements"/>
+    <expand macro="version_cmd"/>
+
+    <stdio>
+        <regex match=".*XMLSyntaxError.*"
+               source="stderr"
+               level="fatal"
+               description="XML metadata does not adhere to OME format. Considering converting image to OME-TIFF" />
+    </stdio>
+
+    <command detect_errors="aggressive"><![CDATA[
+
+        cp '$image' ./renamed_image.ome.tiff && 
+
+        ln -s '$channel_csv' ./channels.csv &&
+
+        python '$script'
+
+    ]]></command>
+    <configfiles>
+        <configfile name = "script">
+import os
+import sys 
+import argparse
+import pandas as pd
+import ome_types
+from ome_types.model import channel
+from tifffile import tiffcomment
+
+cwd = os.getcwd()
+
+channels_df = pd.read_csv(os.path.join(cwd, 'channels.csv'))
+
+original_ome_xml = tiffcomment(os.path.join(cwd, 'renamed_image.ome.tiff'))
+working_ome = ome_types.from_xml(original_ome_xml, parser = 'lxml')
+
+for l_idx, level in enumerate(working_ome.images):
+
+    for c_idx, channel in enumerate(level.pixels.channels):
+
+        new_name = channels_df.loc[c_idx, 'marker_name']
+        channel.name = new_name
+
+        if l_idx == 0:
+
+            print(f"Channel {c_idx} renamed to {new_name}")
+
+updated_ome_xml = working_ome.to_xml()
+tiffcomment(os.path.join(cwd, 'renamed_image.ome.tiff'), updated_ome_xml)
+
+print("Updated OME-TIFF metadata:")
+print(tiffcomment(os.path.join(cwd, 'renamed_image.ome.tiff')))
+        </configfile>
+    </configfiles>
+    <inputs>
+        <param name="image" type="data" format="ome.tiff" label="Input image in OME-tiff format"/>
+        <param name="channel_csv" type="data" format="csv" label="Channel Metadata CSV"/>
+    </inputs>
+    <outputs>
+        <data name="renamed_image" format="ome.tiff" from_work_dir="renamed_image.ome.tiff" label="${tool.name} on ${on_string}"/>
+    </outputs>
+    <tests>
+        <test>
+            <param name="image" value="rename_test.tiff" />
+            <param name="channel_csv" value="rename_channels.csv" />
+            <output name="renamed_image" ftype="ome.tiff">
+                <assert_contents>
+                    <has_size value="44000" delta="1000" />
+                </assert_contents>
+            </output>
+            <assert_stdout>
+                <has_text text="Channel 0 renamed to DNA_6" />
+                <has_text text="Updated OME-TIFF metadata" />
+            </assert_stdout>
+        </test>
+    </tests>
+    <help><![CDATA[
+    ]]></help>
+    <expand macro="citations" />
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/intensities.csv	Thu Sep 29 16:53:36 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:36 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/rename_channels.csv	Thu Sep 29 16:53:36 2022 +0000
@@ -0,0 +1,2 @@
+channel_number,cycle_number,marker_name,Filter,excitation_wavelength,emission_wavelength
+0,6,DNA_6,DAPI,395,431
\ No newline at end of file
Binary file test-data/rename_test.tiff has changed