changeset 0:1106501acbac draft

"planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/mti-utils/rename_tiff_channels commit 5d94d863b6edd7c4435a132a6315517f84b9f8b1"
author watsocam
date Wed, 06 Apr 2022 19:45:29 +0000
parents
children 2d1368111ac6
files macros.xml output.xml rename_tiff_channels.py rename_tiff_channels.xml
diffstat 4 files changed, 96 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/macros.xml	Wed Apr 06 19:45:29 2022 +0000
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+<macros>
+    <xml name="requirements">
+        <requirements>
+            <container type="docker">quay.io/goeckslab/rename_tiff_channels: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="@CMD_BEGIN@">python3 ${__tool_directory__}/rename_tiff_channels.py</token>
+</macros>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/output.xml	Wed Apr 06 19:45:29 2022 +0000
@@ -0,0 +1,1 @@
+<?xml version="1.0" encoding="UTF-8"?><!-- Warning: this comment is an OME-XML metadata block, which contains crucial dimensional parameters and other important metadata. Please edit cautiously (if at all), and back up the original data before doing so. For more information, see the OME-TIFF web site: https://docs.openmicroscopy.org/latest/ome-model/ome-tiff/. --><OME xmlns:ome="http://www.openmicroscopy.org/Schemas/OME/2016-06" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" UUID="urn:uuid:93bcd401-833c-4b86-92b5-015f4409e382" 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.32499998807907104" PhysicalSizeXUnit="µm" PhysicalSizeY="0.32499998807907104" PhysicalSizeYUnit="µm" SizeC="36" SizeT="1" SizeX="14371" SizeY="6071" SizeZ="1" Type="uint16"><Channel ID="Channel:0:0" Name="Uno" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:1" Name="Due" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:2" Name="Tre" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:3" Name="Quattro" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:4" Name="Cinque" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:5" Name="Sei" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:6" Name="Sette" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:7" Name="Otto" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:8" Name="Nove" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:9" Name="Dieci" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:10" Name="Undici" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:11" Name="Dodici" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:12" Name="Tredici" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:13" Name="Quattordic" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:14" Name="Quindici" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:15" Name="Sedici" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:16" Name="Diciassette" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:17" Name="Diciotto" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:18" Name="Diciannove" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:19" Name="Venti" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:20" Name="Ventuno" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:21" Name="Ventidue" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:22" Name="Ventitre" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:23" Name="Ventiquattro" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:24" Name="Venticinque" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:25" Name="Ventisei" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:26" Name="Ventisette" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:27" Name="Ventotto" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:28" Name="Ventinove" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:29" Name="Trenta" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:30" Name="Trentuno" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:31" Name="Trentidue" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:32" Name="Trentitre" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:33" Name="Treniquattro" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:34" Name="Trenticinque" SamplesPerPixel="1"><LightPath /></Channel><Channel ID="Channel:0:35" Name="Tretisei" SamplesPerPixel="1"><LightPath /></Channel><TiffData IFD="0" PlaneCount="36" /><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" /><Plane TheC="32" TheT="0" TheZ="0" /><Plane TheC="33" TheT="0" TheZ="0" /><Plane TheC="34" TheT="0" TheZ="0" /><Plane TheC="35" TheT="0" TheZ="0" /></Pixels></Image></OME>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rename_tiff_channels.py	Wed Apr 06 19:45:29 2022 +0000
@@ -0,0 +1,48 @@
+import sys
+import pandas
+import click
+import tifffile
+import bioformats
+import javabridge
+
+@click.command()
+@click.argument('input_tiff', type=str)
+@click.argument('channels_csv', type=str)
+@click.argument('output_name', type=str)
+def rename_tiff_channels(input_tiff, channels_csv, output_name):
+    '''
+    Tool for renaming the channel XML elements in an OME-TIFF image
+    '''
+    # Process channels_csv
+    channels_df = pandas.read_csv(channels_csv)
+
+    # The JavaBridge approaches..
+    javabridge.start_vm(class_path=bioformats.JARS)
+
+    # Get the file metadata and pixel values
+    with tifffile.TiffFile(input_tiff) as tif:
+        md = tif.ome_metadata
+
+    # Create the OMEXML object
+    xml_obj = bioformats.OMEXML(md)
+
+    # Iterate through the channels and change their names
+    for channel_index in range(xml_obj.image().Pixels.get_channel_count()):
+        new_name = channels_df.loc[channel_index, 'marker_name']
+        xml_obj.image().Pixels.channel(channel_index).set_Name(new_name)
+
+    # This is a header for writing the XML out
+    header = '<?xml version="1.0" encoding="UTF-8"?><!-- Warning: this comment is an OME-XML metadata block, which contains crucial dimensional parameters and other important metadata. Please edit cautiously (if at all), and back up the original data before doing so. For more information, see the OME-TIFF web site: https://docs.openmicroscopy.org/latest/ome-model/ome-tiff/. -->'
+    # Set up the xml to write and do that
+    xml_str = xml_obj.to_xml()
+    removed_ome = '<'.join(xml_str.split('<ome:'))
+    removed_ome = '/'.join(removed_ome.split('/ome:'))
+    with open(output_name, "w") as out_tiff:
+        out_tiff.write(header+removed_ome)
+
+    # Slay the evil JavaBridge
+    javabridge.kill_vm()
+
+
+if __name__ == "__main__":
+    rename_tiff_channels()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rename_tiff_channels.xml	Wed Apr 06 19:45:29 2022 +0000
@@ -0,0 +1,28 @@
+<tool id="rename_tiff_channels" name="Rename OME-TIFF Channels" version="@VERSION@.1" profile="17.09">
+    <description>A simple script to change the channel names in the XML metadata of OME-TIFF images</description>
+    <macros>
+        <import>macros.xml</import>
+    </macros>
+ 
+    <expand macro="requirements"/>
+    @VERSION_CMD@
+
+    <command detect_errors="exit_code"><![CDATA[
+        cp "$image" "$renamed_image" ; 
+        @CMD_BEGIN@ "$image" "$channel_csv" out.xml ;
+        tiffcomment -set out.xml "$renamed_image" ;
+    ]]></command>
+
+    <inputs>
+        <param name="image" type="data" format="tiff" label="Input Pyramidal OME-TIFF"/>
+        <param name="channel_csv" type="data" format="csv" label="Channel Metadata CSV"/>
+    </inputs>
+
+    <outputs>
+        <data name="renamed_image" format="tiff" label="${tool.name} on ${on_string}"/>
+    </outputs>
+    
+    <help><![CDATA[
+    ]]></help>
+    <expand macro="citations" />
+</tool>