comparison stack_buildXml.groovy @ 1:3c942429f610 draft default tip

planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/incucyte_stack_and_upload_omero commit de447190f0743b7f6a3b85e13f712fc07682af3c
author lldelisle
date Thu, 21 Dec 2023 17:04:46 +0000
parents e1cba36becb2
children
comparison
equal deleted inserted replaced
0:e1cba36becb2 1:3c942429f610
24 * Code written by Rémy Dornier, EPFL - SV - PTECH - BIOP 24 * Code written by Rémy Dornier, EPFL - SV - PTECH - BIOP
25 * and Romain Guiet, EPFL - SV - PTECH - BIOP 25 * and Romain Guiet, EPFL - SV - PTECH - BIOP
26 * and Lucille Delisle, EPFL - SV - UPDUB 26 * and Lucille Delisle, EPFL - SV - UPDUB
27 * and Pierre Osteil, EPFL - SV - UPDUB 27 * and Pierre Osteil, EPFL - SV - UPDUB
28 * 28 *
29 * Last modification: 2023-12-19 29 * Last modification: 2023-12-21
30 * 30 *
31 * = COPYRIGHT = 31 * = COPYRIGHT =
32 * © All rights reserved. ECOLE POLYTECHNIQUE FEDERALE DE LAUSANNE, Switzerland, BioImaging And Optics Platform (BIOP), 2023 32 * © All rights reserved. ECOLE POLYTECHNIQUE FEDERALE DE LAUSANNE, Switzerland, BioImaging And Optics Platform (BIOP), 2023
33 * 33 *
34 * Licensed under the BSD-3-Clause License: 34 * Licensed under the BSD-3-Clause License:
118 118
119 /** global variable for index to letter conversion */ 119 /** global variable for index to letter conversion */
120 LETTERS = new String("ABCDEFGHIJKLMNOP") 120 LETTERS = new String("ABCDEFGHIJKLMNOP")
121 121
122 // Version number = date of last modif 122 // Version number = date of last modif
123 VERSION = "20231219" 123 VERSION = "20231221"
124 124
125 /** Key-Value pairs namespace */ 125 /** Key-Value pairs namespace */
126 GENERAL_ANNOTATION_NAMESPACE = "openmicroscopy.org/omero/client/mapAnnotation" 126 GENERAL_ANNOTATION_NAMESPACE = "openmicroscopy.org/omero/client/mapAnnotation"
127 annotations = new StructuredAnnotations() 127 annotations = new StructuredAnnotations()
128 128
320 ImagePlus first_imp = Opener.openUsingBioFormats(files_matching[0].getAbsolutePath()) 320 ImagePlus first_imp = Opener.openUsingBioFormats(files_matching[0].getAbsolutePath())
321 // We check if we can read the infos 321 // We check if we can read the infos
322 first_image_infos = Opener.getTiffFileInfo(files_matching[0].getAbsolutePath()) 322 first_image_infos = Opener.getTiffFileInfo(files_matching[0].getAbsolutePath())
323 // We define the imageplus object 323 // We define the imageplus object
324 ImagePlus single_channel_imp 324 ImagePlus single_channel_imp
325 ImageStack stack
325 if (first_image_infos == null) { 326 if (first_image_infos == null) {
326 // They are raw from incucyte 327 // They are raw from incucyte
327 // We need to open images one by one and add them to the stack 328 // We need to open images one by one and add them to the stack
328 ImageStack stack = new ImageStack(first_imp.width, first_imp.height); 329 stack = new ImageStack(first_imp.width, first_imp.height);
329 files_matching.each{ 330 files_matching.each{
330 ImagePlus single_imp = (new Opener()).openUsingBioFormats(it.getAbsolutePath()) 331 ImagePlus single_imp = (new Opener()).openUsingBioFormats(it.getAbsolutePath())
331 String new_title = single_imp.getTitle().split(" - ")[0] 332 String new_title = it.getName()
333 // println "Title of slice: " + new_title
332 stack.addSlice(new_title, single_imp.getProcessor()) 334 stack.addSlice(new_title, single_imp.getProcessor())
333 } 335 }
334 single_channel_imp = new ImagePlus(FilenameUtils.getBaseName(folder_list.get(i).getAbsolutePath()), stack); 336 single_channel_imp = new ImagePlus(FilenameUtils.getBaseName(folder_list.get(i).getAbsolutePath()), stack);
335 } else { 337 } else {
336 // They are regular tif file 338 // They are regular tif file
338 single_channel_imp = FolderOpener.open(folder_list.get(i).getAbsolutePath(), " filter=_"+ input_wellId + "_"+wellSampleId+"_") 340 single_channel_imp = FolderOpener.open(folder_list.get(i).getAbsolutePath(), " filter=_"+ input_wellId + "_"+wellSampleId+"_")
339 } 341 }
340 // Phase are 8-bit and need to be changed to 16-bit 342 // Phase are 8-bit and need to be changed to 16-bit
341 // Other are already 16-bit but it does not hurt 343 // Other are already 16-bit but it does not hurt
342 IJ.run(single_channel_imp, "16-bit", "") 344 IJ.run(single_channel_imp, "16-bit", "")
343
344 // check frame size 345 // check frame size
345 if (nT == 0) { 346 if (nT == 0) {
346 // This is the first channel with images 347 // This is the first channel with images
347 nT = single_channel_imp.getNSlices() 348 nT = single_channel_imp.getNSlices()
348 first_channel = channels_list.get(i) 349 first_channel = channels_list.get(i)
349 // Process all dates: 350 // Process all dates:
350 Pattern date_pattern = Pattern.compile(REGEX_FOR_DATE) 351 Pattern date_pattern = Pattern.compile(REGEX_FOR_DATE)
351 ImageStack stack = single_channel_imp.getStack() 352 // The IJ.run 16-bit seems to remove the name of the stack
353 // When there is only one stack
354 if (nT !=1 || stack == null) {
355 stack = single_channel_imp.getStack()
356 }
352 // Go to the first time (which is slice) 357 // Go to the first time (which is slice)
353 single_channel_imp.setSlice(1) 358 single_channel_imp.setSlice(1)
354 int currentSlice = single_channel_imp.getCurrentSlice() 359 int currentSlice = single_channel_imp.getCurrentSlice()
355 String label = stack.getSliceLabel(currentSlice) 360 String label = stack.getSliceLabel(currentSlice)
356 LocalDateTime dateTime_ref = getDate(label, date_pattern) 361 LocalDateTime dateTime_ref = getDate(label, date_pattern)
842 return -1 847 return -1
843 } 848 }
844 849
845 // Returns a date from a label and a date_pattern 850 // Returns a date from a label and a date_pattern
846 def getDate(String label, Pattern date_pattern){ 851 def getDate(String label, Pattern date_pattern){
847 // println "Trying to get date from " + label 852 // println "Trying to get date from " + label
848 Matcher date_m = date_pattern.matcher(label) 853 Matcher date_m = date_pattern.matcher(label)
849 LocalDateTime dateTime 854 LocalDateTime dateTime
850 if (date_m.matches()) { 855 if (date_m.matches()) {
851 if (date_m.groupCount() == 5) { 856 if (date_m.groupCount() == 5) {
852 dateTime = LocalDateTime.parse(date_m.group(1) + "-" + date_m.group(2) + "-" + date_m.group(3) + "T" + date_m.group(4) + ":" + date_m.group(5)) 857 dateTime = LocalDateTime.parse(date_m.group(1) + "-" + date_m.group(2) + "-" + date_m.group(3) + "T" + date_m.group(4) + ":" + date_m.group(5))
853 } else { 858 } else {
854 dateTime = LocalDateTime.parse("1970-01-" + 1 + (date_m.group(1) as int) + "T" + date_m.group(2) + ":" + date_m.group(3)) 859 dateTime = LocalDateTime.parse("1970-01-" + 1 + (date_m.group(1) as int) + "T" + date_m.group(2) + ":" + date_m.group(3))
855 } 860 }
856 } 861 }
857 // println "Found " + dateTime 862 // println "Found " + dateTime
858 return dateTime 863 return dateTime
859 } 864 }
860 865
861 // Returns the number of hours 866 // Returns the number of hours
862 def getHoursFromImp(ImagePlus imp, ImageStack stack, LocalDateTime dateTime_ref, Pattern date_pattern){ 867 def getHoursFromImp(ImagePlus imp, ImageStack stack, LocalDateTime dateTime_ref, Pattern date_pattern){