Answering "ok" to bio-formats error message

Hello,

I have written a script that batch processes my data, but am working on making it more robust to different errors that sometimes come up (the thought being, skip over them for now and I will manually come back to them later). One error is that when I stop the microscope manually (instead of letting it run through an entire t-series), the last frame or stack of the series is partially cut off, and so the .xml file is not complete. When I open the hyperstack in Fiji, bioformats throws an error that the series “X” is missing metadata, with an option to “OK”.

My script can move on through most errors that come up, but this one halts everything and waits for the user to press “OK.” Once I do, the script can move on to the next folder. Ideally I’d love to resolve the error of the partial slices in the .xml file, but in the meantime, can someone help me figure out how to answer this dialogue box automatically in the script? My script is written in Python.

Thanks so much!
Ani

There is a plugin to control other programs via clicking and key presses.

See:

1 Like

Hi @anivarj, what format are the files in? Also what is the exact message you are seeing in the dialog?

Hello @dgault,

The files are saved as individual .ome.tifs and then there is also a .xml file that contains all of the metadata. The instrument is a Bruker microscope that is running PrairieView software. I’ve attached the .xml file here 197-008_GFP-rGBD_Ect2-dNLS_ArhGAP11a.2_E-001.xml (249.5 KB) .

The exact message I am seeing in Fiji is a bio-formats importer dialogue box that says “Sorry, there was a problem during import”. In the log window, the first line says “loci.formats.FormatException: No metadata for series #47”.

There actually is a full series #47, but the microscope had just started setting up to acquire series #48 when I stopped it, so that’s where the problem lies I think. In the .xml file you can see a short chunk at the end that looks like this:

  <Sequence type="TSeries ZSeries Element" cycle="48" time="16:39:18.1167068" bidirectionalZ="False" xYStageGridDefined="False" xYStageGridNumXPositions="4" xYStageGridNumYPositions="4" xYStageGridOverlapPercentage="15" xYStageGridXOverlap="88.2302405498282" xYStageGridYOverlap="88.2302405498282">
    <PVStateShard>
      <PVStateValue key="positionCurrent">
        <SubindexedValues index="XAxis">
          <SubindexedValue subindex="0" value="449.8" />
        </SubindexedValues>
        <SubindexedValues index="YAxis">
          <SubindexedValue subindex="0" value="1959.8" />
        </SubindexedValues>
        <SubindexedValues index="ZAxis">
          <SubindexedValue subindex="0" value="1019.725" />
        </SubindexedValues>
      </PVStateValue>
    </PVStateShard>
  </Sequence>

If you compare this to the cycle #47 above it, you can see that cycle #48 is just a header and there are no frames with it (because I stopped it). If I delete this section of the .xml manually, the bio-formats importer will load the data without a problem. So my current issue is, how to handle this exception without stopping the script, but more long-term, how to avoid/fix it in the future?

This might be a really beginner question, but is there a way to catch a loci formats exception in my script? I tried writing a “try/except” portion, but I think I’m missing some kind of step that lets the code know what a loci.formats.FormatException is. I’m pretty new to coding, and I can’t seem to figure it out!

Thanks so much,
Ani

I should also mention, the reason I am stopping the microscope manually is because I often set up a time-course that is longer than I actually need. This way, if the cells are doing something interesting, I can let it continue on until I see a good stopping point.

Thanks Ani, you should also be able to suppress the exception in the ImporterOptions. Without knowing what your script looks like, Im assuming you are using smething similar to the below example. In which case setting the value of setQuiet to True should stop the pop up from being displayed.

from loci.plugins.in import ImporterOptions
options = ImporterOptions()
options.setQuiet(True)
options.setId(file)
imps = BF.openImagePlus(options)
2 Likes

Thank you so much for this! I am actually quite a coding newbie, and so my code for that part simply called bio-formats through the GUI using:

IJ.run("Bio-Formats Importer", "open=[" + initiatorFilePath + "] color_mode=Grayscale concatenate_series open_all_series rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT")

And it just fills in the path to the first .tif in the scan folder (initiatorFilePath).

I’ve been wanting to upgrade my script to move away from these IJ.run commands and more into actually utilizing the python aspect, so I will look into setting up bio-formats this way.
Thanks so much for your help! I’ll try it out and let you know if anything else comes up.

-Ani

To use the quiet mode option via your script simply add quiet into the list of options as below:

IJ.run("Bio-Formats Importer", "open=[" + initiatorFilePath + "] color_mode=Grayscale concatenate_series open_all_series quiet rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT")

1 Like