Bio-Formats Input Options

I am trying to automate opening of a .lif file. The file contains multiple types of images…there are Z stacks, 3 channel images, and what are actually snapshots of a maximum projection. I would like to only open the snapshot images, which all have the word Snapshot in them. Here’s an example of the naming: Series 6: Series011Snapshot1:1067 x 1067; 3 planes (3C). So basically in the Bio-Formats Series Options window, I would like to chose all series that have the word “Snapshot” in them but this needs to be automated as part of a macro. When I execute [run(“Bio-Formats”);] and it brings up the Bio-Formats open window, I would like everything with “Snapshot” to be selected for opening and the other series to not be selected. Is that possible? If not, what’s the work around? There are many lif files to get through and to go through the list of about 80 series for each and select the Snapshots will be very time consuming. I did consider opening all series and then closing the unwanted ones but two problems there. First, it takes a lot longer to open each lif file and second I couldn’t figure out how to close only the unwanted windows and keep everything that was a Snapshot open. Thanks in advance for the advice.

Hi @Tala_Kaplinovsky,

You can acheieve this using the IJ1 macro language. Have you used macros before? The lines below should let you choose a LIF file and will open all series containing ‘Snapshot’.

run("Bio-Formats Macro Extensions");

filePath = File.openDialog("Choose a LIF file");
Ext.setId(filePath);
Ext.getSeriesCount(seriesCount);

for (s = 0; s < seriesCount; s++){
	Ext.setSeries(s);
	Ext.getSeriesName(seriesName);
	if (matches(seriesName, ".*Snapshot.*")) {
		run("Bio-Formats Importer", "open=" + filePath + " autoscale color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT series_" + s);
	}
}

Let us know if you need more help.

Laura

2 Likes

Hi Laura,
Thank you for your help. I think it’ll work but I get this error…

Any further thoughts?

Hi @Tala_Kaplinovsky, that error looks as though the file was unable to be located, probably due to spaces being present in the file path or file name, if you add square brackets around the filepath then it should be fine:

run("Bio-Formats Importer", "open=[" + filePath + "] autoscale color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT series_" + s);

2 Likes

So the macro as it stands now is:

run("Bio-Formats Macro Extensions");

filePath = File.openDialog("Choose a LIF file");
Ext.setId(filePath);
Ext.getSeriesCount(seriesCount);

for (s = 0; s < seriesCount; s++){
	Ext.setSeries(s);
	Ext.getSeriesName(seriesName);
	if (matches(seriesName, ".*Snapshot.*")) {
		run("Bio-Formats Importer", "open=[" + filePath + "] autoscale color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT series_" + s);
	}
}

It works, except it opens everything but the series with the word “Snapshot”…the other series in there are Z stacks and they all opened

Thanks in advance

To add to this, is it possible to select the series with the word “Snapshot” and select the channels that will open? Currently having to do all that manually. Thanks again

So it is opening all of the series except for the one you want? Is that correct?

To access the channels separately you can add split_channels into the run command, but it will still open all of them individually. If you only want a single channel open for example then you can do so using c_begin_1=2 c_end_1=2 c_step_1=1, which will open the second channel only or c_begin_1=2 c_end_1=3 c_step_1=1 which will open the second and third channels.

There are 2 types of series in there (it’s a lif file). One type of series are Z stacks. The other type are snapshots of a maximum projection. I want to open only all the snapshots. They all share “Snapshots” in the series name. With the code above, for some reason all the Z stacks opened instead.

Thank you for the suggestion re the channels. I will try that.

In that case it will need to be modified slightly to find a unique property that can be used to directly identify the Snapshots.

Hi @Tala_Kaplinovsky.

I can’t really say why you get this results, there’s nothing in the code based on what you’ve told us, why the Z-stacks would open but not the maximum projections.

One idea maybe, if you don’t always use an uppercase s, you could change to the below which would pick up both lower case and upper case s.

".*Snapshot|snapshot.*"