Mercurial > repos > goeckslab > rename_tiff_channels
comparison rename_tiff_channels.xml @ 5:61fd94c7ce42 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:10 +0000 |
parents | d2c59a1ac0c4 |
children | 4763362914f4 |
comparison
equal
deleted
inserted
replaced
4:55bc102d7709 | 5:61fd94c7ce42 |
---|---|
31 <configfiles> | 31 <configfiles> |
32 <configfile name = "script"> | 32 <configfile name = "script"> |
33 import os | 33 import os |
34 import sys | 34 import sys |
35 import argparse | 35 import argparse |
36 from itertools import cycle | |
36 import pandas as pd | 37 import pandas as pd |
37 import ome_types | 38 import ome_types |
38 from ome_types.model import channel | 39 from ome_types.model import channel, Color |
39 from tifffile import tiffcomment | 40 from tifffile import tiffcomment |
41 | |
42 # setting default colors to match avivator | |
43 colors = [ | |
44 (0,0,255,1.0), # blue | |
45 (0,255,0,1.0), # green | |
46 (255,0,255,1.0), # magenta | |
47 (255,255,0,1.0), # yellow | |
48 (255,127,0,1.0), # orange | |
49 (0,255,255,1.0), # cyan | |
50 (255,255,255,1.0), # white | |
51 (255,0,0,1.0) # red | |
52 ] | |
53 | |
54 # convert to repeatable object of primitive int colors | |
55 color_cycle = cycle([Color(c).as_int32() for c in colors]) | |
40 | 56 |
41 cwd = os.getcwd() | 57 cwd = os.getcwd() |
42 | 58 |
43 channels_df = pd.read_csv(os.path.join(cwd, 'channels.csv')) | 59 channels_df = pd.read_csv(os.path.join(cwd, 'channels.csv')) |
44 | 60 |
49 | 65 |
50 for c_idx, channel in enumerate(level.pixels.channels): | 66 for c_idx, channel in enumerate(level.pixels.channels): |
51 | 67 |
52 new_name = channels_df.loc[c_idx, 'marker_name'] | 68 new_name = channels_df.loc[c_idx, 'marker_name'] |
53 channel.name = new_name | 69 channel.name = new_name |
70 channel.color = next(color_cycle) | |
54 | 71 |
55 if l_idx == 0: | 72 if l_idx == 0: |
56 | 73 |
57 print(f"Channel {c_idx} renamed to {new_name}") | 74 print(f"Channel {c_idx} renamed to {new_name}") |
58 | 75 |
70 <outputs> | 87 <outputs> |
71 <data name="renamed_image" format="ome.tiff" from_work_dir="renamed_image.ome.tiff" label="${tool.name} on ${on_string}"/> | 88 <data name="renamed_image" format="ome.tiff" from_work_dir="renamed_image.ome.tiff" label="${tool.name} on ${on_string}"/> |
72 </outputs> | 89 </outputs> |
73 <tests> | 90 <tests> |
74 <test> | 91 <test> |
75 <param name="image" value="rename_test.tiff" /> | 92 <param name="image" value="rename_test.ome.tiff" /> |
76 <param name="channel_csv" value="rename_channels.csv" /> | 93 <param name="channel_csv" value="rename_channels.csv" /> |
77 <output name="renamed_image" ftype="ome.tiff"> | 94 <output name="renamed_image" ftype="ome.tiff"> |
78 <assert_contents> | 95 <assert_contents> |
79 <has_size value="44000" delta="1000" /> | 96 <has_size value="899000" delta="50000" /> |
80 </assert_contents> | 97 </assert_contents> |
81 </output> | 98 </output> |
82 <assert_stdout> | 99 <assert_stdout> |
83 <has_text text="Channel 0 renamed to DNA_6" /> | 100 <has_text text="Channel 0 renamed to DNA_6" /> |
84 <has_text text="Updated OME-TIFF metadata" /> | 101 <has_text text="Updated OME-TIFF metadata" /> |