comparison stack_max_projs.groovy @ 1:9be687213bc9 draft

planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/max_projections_stack_and_upload_omero commit 39c8ae77d15d77ddcd8a0bb70f46d1be1531e9cc
author lldelisle
date Fri, 13 Dec 2024 07:58:28 +0000
parents a02156aa8bda
children 3fd95c753cff
comparison
equal deleted inserted replaced
0:a02156aa8bda 1:9be687213bc9
27 * ********************************************* DO NOT MODIFY **************************************************** 27 * ********************************************* DO NOT MODIFY ****************************************************
28 * **************************************************************************************************************** 28 * ****************************************************************************************************************
29 */ 29 */
30 30
31 // Version number = date of last modif 31 // Version number = date of last modif
32 VERSION = "20241212" 32 VERSION = "20241213"
33 33
34 /** 34 /**
35 * ***************************************************************************************************************** 35 * *****************************************************************************************************************
36 * **************************************** Beginning of the script *********************************************** 36 * **************************************** Beginning of the script ***********************************************
37 * **************************************************************************************************************** 37 * ****************************************************************************************************************
95 FolderOpener.open( 95 FolderOpener.open(
96 current_directory.getAbsolutePath(), 96 current_directory.getAbsolutePath(),
97 " filter=" + fluo_pattern_list[i] 97 " filter=" + fluo_pattern_list[i]
98 ) 98 )
99 ) 99 )
100 // println samplesMap.get(unique_identifier).get(fluo_channels_list[i]).getDimensions()
100 if (!GraphicsEnvironment.isHeadless()){ 101 if (!GraphicsEnvironment.isHeadless()){
101 samplesMap.get(unique_identifier).get( 102 samplesMap.get(unique_identifier).get(fluo_channels_list[i]).show()
102 fluo_channels_list[i]).show()
103 } 103 }
104 } 104 }
105 } 105 }
106 } else { 106 } else {
107 // It is easy as all images are used 107 // It is easy as all images are used
108 println "Processing " + unique_identifier + " Greys" 108 println "Processing " + unique_identifier + " Greys"
109 samplesMap.get(unique_identifier).put(final_color, FolderOpener.open(current_directory.getAbsolutePath())) 109 samplesMap.get(unique_identifier).put(final_color, FolderOpener.open(current_directory.getAbsolutePath()))
110 // println samplesMap.get(unique_identifier).get(final_color).getDimensions()
110 if (!GraphicsEnvironment.isHeadless()){ 111 if (!GraphicsEnvironment.isHeadless()){
111 samplesMap.get(unique_identifier).get( 112 samplesMap.get(unique_identifier).get(final_color).show()
112 final_color).show()
113 } 113 }
114 } 114 }
115 } 115 }
116 116
117 // Explore the HashMap and save to tiff 117 // Explore the HashMap and save to tiff
118 for(String unique_identifier : samplesMap.keySet()){ 118 for(String unique_identifier : samplesMap.keySet()){
119 // get the channel map 119 // get the channel map
120 Map<String, ImagePlus> channelsMap = samplesMap.get(unique_identifier) 120 Map<String, ImagePlus> channelsMap = samplesMap.get(unique_identifier)
121 ArrayList<String> channels = [] 121 ArrayList<String> channels = []
122 ArrayList<ImagePlus> current_images = [] 122 ArrayList<ImagePlus> current_images = []
123 int ref_nT = 0
124 boolean all_compatibles = true
123 125
124 for(String channel : channelsMap.keySet()){ 126 for(String channel : channelsMap.keySet()){
125 channels.add(channel) 127 channels.add(channel)
126 current_images.add(channelsMap.get(channel)) 128 current_images.add(channelsMap.get(channel))
127 } 129 if (ref_nT == 0) {
128 // Get number of time: 130 ref_nT = channelsMap.get(channel).nSlices
129 int nT = current_images[0].nSlices 131 } else {
130 132 if (ref_nT != channelsMap.get(channel).nSlices) {
131 // Merge all 133 all_compatibles = false
132 ImagePlus merged_imps = Concatenator.run(current_images as ImagePlus[]) 134 }
133 // Re-order to make a multi-channel, time-lapse image 135 }
134 ImagePlus final_imp 136 }
135 if (channels.size() == 1 && nT == 1) { 137
136 final_imp = merged_imps 138 if (all_compatibles) {
139 // Merge all
140 ImagePlus merged_imps = Concatenator.run(current_images as ImagePlus[])
141 // Re-order to make a multi-channel, time-lapse image
142 ImagePlus final_imp
143 if (channels.size() == 1 && nT == 1) {
144 final_imp = merged_imps
145 } else {
146 try {
147 final_imp = HyperStackConverter.toHyperStack(merged_imps, channels.size() , 1, ref_nT, "xytcz", "Color")
148 // set LUTs
149 (0..channels.size()-1).each{
150 final_imp.setC(it + 1)
151 IJ.run(final_imp, channels[it], "")
152 final_imp.resetDisplayRange()
153 }
154 } catch(Exception e) {
155 println "Could not create the hyperstack for " + unique_identifier + ": " + e
156 continue
157 }
158 }
137 } else { 159 } else {
138 final_imp = HyperStackConverter.toHyperStack(merged_imps, channels.size() , 1, nT, "xytcz", "Color") 160 println "Not all channels have the same number of slices:"
139 } 161 (0..channels.size()-1).each{
140 // set LUTs 162 println "Channel " + channels[it] + " has " + current_images[it].getDimensions() + " whCZT."
141 (0..channels.size()-1).each{ 163 }
142 final_imp.setC(it + 1) 164 if (channelsMap.containsKey("Greys")) {
143 IJ.run(final_imp, channels[it], "") 165 println "Will keep only Greys channel"
166 final_imp = channelsMap.get("Greys")
167 } else {
168 println "Will keep only " + channels[0] + " channel"
169 final_imp = current_images[0]
170 IJ.run(final_imp, channels[0], "")
171 }
144 final_imp.resetDisplayRange() 172 final_imp.resetDisplayRange()
145 } 173 }
146 // Save to tiff 174 // Save to tiff
147 final_imp.setTitle(unique_identifier) 175 final_imp.setTitle(unique_identifier)
148 176