// save tiff images from lif files // // This groovy script reads lif files in a folder, extracts each series/tif stack, //Option to save the stack and/or the max projection // Max projection is saved in the parent folder of the lifs in a subfolder: Max Projection // Image stacks are saved in the parent folder of the lifs in a subfolder: stack // Author: Pradeep Rajasekhar // July 2020 // License: BSD3 // // Copyright 2020 Pradeep Rajasekhar, Monash Institute of Pharmaceutical Sciences // // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: // 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. // 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. // 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // import ij.IJ import loci.plugins.in.ImporterOptions import loci.plugins.BF import static groovy.io.FileType.FILES //import loci.formats.ChannelSeparator //Helper class for managing Bio-Formats Importer options. Gets default parameter values from IJ_Prefs.txt. ImporterOptions options = new ImporterOptions(); options.setAutoscale(true); options.setCrop(false); options.setSplitFocalPlanes(false); options.setSplitChannels(false); options.setSplitTimepoints(false); options.setColorMode(ImporterOptions.COLOR_MODE_COMPOSITE); options.setStackFormat(ImporterOptions.VIEW_HYPERSTACK); options.setStackOrder(ImporterOptions.ORDER_XYCZT); options.setUngroupFiles(true); //ChannelSeparator to manage series and getseries counts //cs=new ChannelSeparator(); #@ File input_dir (label="Select a folder of lif files",style="directory") #@ Boolean (label="Do you want to create max projection/s?") max_project #@ Boolean (label="Do you want to save the image stack/s?") stack_save // Names with extension .lif nameFilter = ~/.*.lif/ input_dir_str=input_dir.toString(); //convert file class to string // Output directory output_dir_max = input_dir_str+"\\max_projection" output_dir_stack = input_dir_str+"\\stack" if (max_project) new File(output_dir_max).mkdir() //creates a object output_dir of File classs and then mkdir if (stack_save) new File(output_dir_stack).mkdir() if (!max_project && !stack_save) {IJ.log("No save method selected.Exiting!") IJ.error("No save method selected. Please check a box") return //exits } // List all files with extension ".lif" def inputFiles = new ArrayList() //initialise arraylist with files input_dir.eachFileMatch(nameFilter) {inputFiles.add(it)} IJ.run("Close All", ""); //inputFile=inputFiles[0]; //test with first file inputFiles.each { inputFile-> inputFile=inputFile.toString(); IJ.log("Processing ${inputFile}"); //println ; options.setId(inputFile); options.setOpenAllSeries(true); //opens all the series;; if larger images; then use setseries //get series number using channel separator //cs.setId(inputFile); //ser=cs.getSeriesCount(); //println ser; imps = BF.openImagePlus(options); //println imps; imps.each{ imp-> println "Processing ${imp}"; //} //options.setSeriesOn(it,true); to setseries on a number save_name=imp.getTitle(); if(max_project) { IJ.run(imp, "Z Project...", "projection=[Max Intensity]");//max_intensity max=IJ.getImage(); // //using << to concatenate strings max_save_name="max_"<