Mercurial > repos > goeckslab > rename_tiff_channels
comparison rename_tiff_channels.xml @ 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 | d2c59a1ac0c4 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:18f6be63414c |
---|---|
1 <tool id="rename_tiff_channels" name="Rename OME-TIFF Channels" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@"> | |
2 <description>Change the channel names in the XML metadata of OME-TIFF images</description> | |
3 <macros> | |
4 <import>macros.xml</import> | |
5 </macros> | |
6 | |
7 <expand macro="requirements"/> | |
8 <expand macro="version_cmd"/> | |
9 | |
10 <stdio> | |
11 <regex match=".*XMLSyntaxError.*" | |
12 source="stderr" | |
13 level="fatal" | |
14 description="XML metadata does not adhere to OME format. Considering converting image to OME-TIFF" /> | |
15 </stdio> | |
16 | |
17 <command detect_errors="aggressive"><![CDATA[ | |
18 | |
19 cp '$image' ./renamed_image.ome.tiff && | |
20 | |
21 ln -s '$channel_csv' ./channels.csv && | |
22 | |
23 python '$script' | |
24 | |
25 ]]></command> | |
26 <configfiles> | |
27 <configfile name = "script"> | |
28 import os | |
29 import sys | |
30 import argparse | |
31 import pandas as pd | |
32 import ome_types | |
33 from ome_types.model import channel | |
34 from tifffile import tiffcomment | |
35 | |
36 cwd = os.getcwd() | |
37 | |
38 channels_df = pd.read_csv(os.path.join(cwd, 'channels.csv')) | |
39 | |
40 original_ome_xml = tiffcomment(os.path.join(cwd, 'renamed_image.ome.tiff')) | |
41 working_ome = ome_types.from_xml(original_ome_xml, parser = 'lxml') | |
42 | |
43 for l_idx, level in enumerate(working_ome.images): | |
44 | |
45 for c_idx, channel in enumerate(level.pixels.channels): | |
46 | |
47 new_name = channels_df.loc[c_idx, 'marker_name'] | |
48 channel.name = new_name | |
49 | |
50 if l_idx == 0: | |
51 | |
52 print(f"Channel {c_idx} renamed to {new_name}") | |
53 | |
54 updated_ome_xml = working_ome.to_xml() | |
55 tiffcomment(os.path.join(cwd, 'renamed_image.ome.tiff'), updated_ome_xml) | |
56 | |
57 print("Updated OME-TIFF metadata:") | |
58 print(tiffcomment(os.path.join(cwd, 'renamed_image.ome.tiff'))) | |
59 </configfile> | |
60 </configfiles> | |
61 <inputs> | |
62 <param name="image" type="data" format="ome.tiff" label="Input image in OME-tiff format"/> | |
63 <param name="channel_csv" type="data" format="csv" label="Channel Metadata CSV"/> | |
64 </inputs> | |
65 <outputs> | |
66 <data name="renamed_image" format="ome.tiff" from_work_dir="renamed_image.ome.tiff" label="${tool.name} on ${on_string}"/> | |
67 </outputs> | |
68 <tests> | |
69 <test> | |
70 <param name="image" value="rename_test.tiff" /> | |
71 <param name="channel_csv" value="rename_channels.csv" /> | |
72 <output name="renamed_image" ftype="ome.tiff"> | |
73 <assert_contents> | |
74 <has_size value="44000" delta="1000" /> | |
75 </assert_contents> | |
76 </output> | |
77 <assert_stdout> | |
78 <has_text text="Channel 0 renamed to DNA_6" /> | |
79 <has_text text="Updated OME-TIFF metadata" /> | |
80 </assert_stdout> | |
81 </test> | |
82 </tests> | |
83 <help><![CDATA[ | |
84 ]]></help> | |
85 <expand macro="citations" /> | |
86 </tool> |