Group images with bioformats in Java code

bio-formats
imagej
plugin

#1

I need to group files using bioformats based on the pattern string in my code. It nicely works with the GUI, but I can not reproduce it in my plugin.

The code below groups files based on automatically identified pattern:

ImporterOptions options = new ImporterOptions();
options.setGroupFiles(true);
		
options.setId(pathToImageFile);
ImagePlus img=BF.openImagePlus(options)[0];

But I need to specify pattern for grouped files myself like in GUI. So I expected to find setPattern(pathRegExp) command, but there is no such method in ImporterOptions.

One solution, of course,would be recording command with macro recorder and then parsing regular expression string to the argument of IJ.run(). But I am hoping to find more proper solution.

Thanks in advance!


#2

Good day Aliaksandr Halavatyi,

did you know that the recoder also records Java code?

Just select “Record: Java” form the drop down menu of the recoder window.

But perhaps you are looking for a different solution.

Regards

Herbi


#3

I am aware that it does.

But the recorded line is very long and “unhandy”:

IJ.run("Bio-Formats", "open=C:\\tempdat\\raw_data\\xxx--W00015--P00001--Z00000--T00000--A568.tif color_mode=Default group_files rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT dimensions axis_1_number_of_images=3 axis_1_axis_first_image=1 axis_1_axis_increment=1 axis_2_number_of_images=5 axis_2_axis_first_image=0 axis_2_axis_increment=1 contains=[] name=C:\\tempDat\\\\raw_data\\xxx--W00015--P00001--Z0000[0-4]--T00000--A568.tif");

And it is just not convenient to work in this way, always combining the long string as an argument.


#4

You may write your own code that sets the various string components according to your needs and you a free to do this in a convenient manner.

Have success

Herbie


#5

Dear Herbie,

Thanks a lot for suggestion.

Unfortunately it does not work when I develop my plugin in Eclipse. IJ.run("Bio-Formats",...) fails, because commends which are not defined in core ij are somehow not visible when debugging with IDE.

Regards,
Aliaksandr


#6

The old macro language implicitly loads the ij.IJ package, so in Java (or any of the newer scripting languages) you’ll have to import directly.

Looking at the importer plugin source code that regex management might not be scriptable as they seem to parse manually from the dialog.
[https://github.com/openmicroscopy/bioformats/blob/develop/components/bio-formats-plugins/src/loci/plugins/in/FilePatternDialog.java]


#7

This is because ImageJ 1.x plugins are not visible unless you set the plugins.dir system property, due to how ImageJ1 plugin class loading works. (We addressed this in ImageJ2 with a different plugin discovery mechanism that discovers plugins from whatever is on the classpath. See also this thread which discusses this same issue.)

Indeed. This would be a nice addition to the ImporterOptions API, so I created a PR for it: openmicroscopy/bioformats#3019. We’ll see what the Bio-Formats maintainers think about it.

/cc @s.besson @dgault @melissa


#8

Thanks @ctrueden

Indeed, proper ImporterOptions API interface covering this application will be very useful.

For now, I found two ways to set plugins.dir system property when testing with Eclipse:

  1. In the code:

     public static void main(String[] args)throws Exception{
     	
     	//http://imagej.net/docs/menus/plugins.html#dir
     	System.getProperties().setProperty("plugins.dir", "C:/Halavatyi_Work/running soft/Fiji.app_new/plugins");
     	new ImageJ();
     	
     	IJ.run("Bio-Formats", "open=C:\\tempDat\\test--W00015--P00003--Z00002--T00000--GFP.tif autoscale color_mode=Default group_files rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT axis_1_number_of_images=3 axis_1_axis_first_image=1 axis_1_axis_increment=1 axis_2_number_of_images=5 axis_2_axis_first_image=0 axis_2_axis_increment=1 contains=[] name=C:\\tempDat\\test--W00015--P00002--Z0000<0-4>--T00000--GFP.tif");
     }
    
  2. In Run Configurations dialog (https://stackoverflow.com/questions/862391/how-to-pass-the-d-system-properties-while-testing-on-eclipse)


#9

@Alex_H Great! FYI, your first solution is what’s outlined in the Fiji Main class launcher here. Glad to hear that is good enough for you.