This is an old revision of the document!
Table of Contents
Command Line: LIF to Tiff conversion
LIF is a grouped-stack file format containing multiple stacks. One could access each stack by LOCI Bio-Format plugin installed to ImageJ, but when file size is huge and data is in data server, data transfer rate becomes a bottle neck for the progress of work.
TO avoid this, one could do the file conversion via command line. This could be done by "bfconvert" command line tool available from Bio-format web site. Following command will do the job, converting all.
sh /g/almf/software/bftools/bfconvert <filename.lif> converted_%s_%n_C%c.tiff
One missing function with this CL tool is that physical scales in x, y and z are not read out from LIF so that resulting Tiff stacks are devoid of these parameters. In addition, dimensional values such as number of slices per time point, and number of time points are not converted.
For this reason, following shell script was created to transfer physical scales in together with conversion.
sh /g/almf/software/ij/lifcon.sh </full/path/to/file.lif>
This script will extract metadata from LIF, convert each stack to Tiff stack, and set the physical parameters of the image by extracting these values from metadata. Tiff stack will be saved under a newly created directly where the LIF is located. Name of the directory will be
<file.lif>_tifStack
A text file named
<filename.lif>.meta.txt
is also generated, where extracted metadata is stored.
How Metadata is Extracted
Bioformat commandline tool “showinf” is used to save metadata as a text file. Then During the extraction of tiff stacks, physical scales and dimensionality information is extracted from the text and applied to the tiff stack.
Since macro command run(“Properties…”, arg1, arg2) does not work when IJ is headless since Properties command uses AWT. To avoid this, a small plugin (that does not appear in the menu) was created for setting image properties. This plugin is called from macro to set physical scales.
Link for the Image Property setter.
Shell Script lifcon.sh
<sxh shell> #!/bin/sh #script for converting Lif file to tif, and set physical scale. # imgfullpath=$1
# path to IJ jar file IJJARS=“/g/almf/software/ij”
# path to image IMGFILE=“${imgfullpath##*/}” IMGPATH=“${imgfullpath% TODO: scale should be set as the propertiy of tiff file. reading out of the scale from LIF is somehow not working, unlike it was done in 2009 metadata of .lif file would be saved as <filename.lif>.meta.txt will be saved in the same directory. TODO: program might return error if sequence is terminated abruptly. for setting scale, plugin ” ImpProp.class“ is required.
srcfile = getArgument(); //cui
srcfile = File.openDialog(“Select a LIF File”); gui
requires("1.43d"); run("Bio-Formats Macro Extensions");
path = srcfile; name = File.getName(path); dir = File.getParent(path); DAPIch = 0;//getNumber("DAPI ch=?", 0); FISHch = 1;//getNumber("FISH ch=?", 1); metaname = name + ".meta.txt";
q = File.separator; //090912 metafullpath = dir+q+metaname; metastr = File.openAsString(metafullpath); workdir = File.getParent(srcfile); //getDirectory("Choose a work space directory to save resulting files");
//create "tiffStack" folder under the gene folder (tiff stacks will have series No. and channel so no overlaps) pathtifstack = workdir + q + name+ "_tifStack"; print(pathtifstack ); if (File.isDirectory(pathtifstack)==0) File.makeDirectory(pathtifstack);
Ext.setId(path); Ext.getSeriesCount(seriesCount); Ext.getCurrentFile(file); Ext.close(); print("File:"+ file); print("series total number" + seriesCount);
for (s=0; s<seriesCount; s++) {
seriesNum = s; //Ext.setId(path); //out 090925 v4n //Ext.setSeries(seriesNum); //Ext.getSeriesName(seriesName); //Ext.close(); //out 090925 v4n
if (s>0) refresh =0;
seriesName = OpenLIFSeriesOneChannel(path, name, seriesNum, DAPIch, 0, metastr); //modified 090925 G_GID = getImageID(); savepath = pathtifstack + q+getTitle(); print(savepath); saveAs("tiff", savepath); close();
OpenLIFSeriesOneChannel(path, name, seriesNum, FISHch, 0, metastr); G_RID = getImageID(); savepath = pathtifstack + q+ getTitle(); print(savepath); saveAs("tiff", savepath); close(); }
working maybe memory flashing problem, but not sure. /* 090907 090908 - save tif file in a specified directory - problem with DAPI appearance in the resulting window. —> seperate 2D analysis files in other macro? */ function OpenLIFSeriesOneChannel(id, name, seriesNum, ch, datasetOpened, metastr){ run(“Bio-Formats Macro Extensions”); if (datasetOpened ==0) Ext.setId(id);
Ext.setId(id); Ext.setSeries(seriesNum); Ext.getSeriesName(seriesName); print(seriesName); Ext.getSizeZ(sizeZ); Ext.getSizeC(sizeC); Ext.getSizeT(sizeT); Ext.getImageCount(imageCount); print("ImageCount:"+imageCount); calculatedCount = sizeZ*sizeC*sizeT; print("...calculated"+sizeZ*sizeC*sizeT); if (imageCount != calculatedCount) { print(); exit(); } sizeT = imageCount/sizeC/sizeZ; print("C:"+sizeC+" Z:"+sizeZ+" T:"+sizeT); newname = name+"_"+seriesNum+"_ch"+ch+".tif"; setBatchMode(true); for (j=0; j<sizeT; j++){ for (i=0; i<sizeZ; i++){ currentZch0 = i*sizeC; currentPlane = j*sizeZ*sizeC + i*sizeC; Ext.openImage("t"+j+"_z"+i, currentPlane+ch); if ((i==0) && (j==0)) stackID=getImageID(); else { run("Copy"); close; selectImage(stackID); run("Add Slice"); run("Paste"); } //print(currentPlane); } } rename(newname); xscale = returnXscale(metastr); yscale = returnYscale(metastr); zscale = returnZscale(metastr); tscale = 1;//returnTscale(metastr); xscalemicron = parseFloat(xscale) * pow(10, 6); yscalemicron = parseFloat(yscale) * pow(10, 6); zscalemicron = parseFloat(zscale) * pow(10, 6); op = "channels=1 slices="+sizeZ+" frames="+sizeT+" unit=micron pixel_width="+xscalemicron +" pixel_height="+yscalemicron +" voxel_depth="+zscalemicron +" frame=[0 sec] origin=0,0"; //since run("Properties...", op); cannot be used (AWT problem in headless) //follwoing is a new plugin for setting image properties. // ImpProp.class SsizeC = ""+1; SsizeZ = ""+sizeZ; SsizeT = ""+sizeT; Sxscalemicron = ""+xscalemicron; Syscalemicron = ""+yscalemicron; Szscalemicron = ""+zscalemicron; call("ImpProps.setCalibration", SsizeC, SsizeZ, SsizeT, "micron", Sxscalemicron, Syscalemicron, Szscalemicron);
setBatchMode(false); //if (datasetOpened ==0) Ext.close(); Ext.close(); return seriesName;
}
zscale in micron function returnZscale(metastr){ metaA = split(metastr, “\n”); zscale = 1; for (i=0; i<metaA.length; i++){ if (startsWith(metaA[i], “HardwareSetting|ScannerSettingRecord|dblStepSize”)){ lineA = split(metaA[i], ” “); for (j=0; j<lineA.length; j++)print(lineA[j]);
if (lineA.length>=3) { zscale = parseFloat(lineA[2]); print(zscale); } } } return zscale;
}
Xscale in micron function returnXscale(metastr){ metaA = split(metastr, “\n”); xscale = 1; for (i=0; i<metaA.length; i++){ if (startsWith(metaA[i], “HardwareSetting|ScannerSettingRecord|dblVoxelX”)){ lineA = split(metaA[i], ” “); for (j=0; j<lineA.length; j++)print(lineA[j]);
if (lineA.length>=3) { xscale = parseFloat(lineA[2]); print(xscale); } } } return xscale;
}
function returnYscale(metastr){
metaA = split(metastr, "\n"); yscale = 1; for (i=0; i<metaA.length; i++){ if (startsWith(metaA[i], "HardwareSetting|ScannerSettingRecord|dblVoxelY")){ lineA = split(metaA[i], " "); //for (j=0; j<lineA.length; j++)print(lineA[j]); if (lineA.length>=3){ yscale = parseFloat(lineA[2]); print(yscale); } } } return yscale;
}
function returnTscale(){
metaA = split(metastr, "\n"); for (i=0; i<metaA.length; i++){ if (startsWith(metaA[i], "HardwareSetting|ScannerSettingRecord|dblStepSize")){ lineA = split(metaA[i], " "); //for (j=0; j<lineA.length; j++)print(lineA[j]); if (lineA.length>=3) print(parseFloat(lineA[2])); } }
} </code>