BodenmillerGroup / steinbock

A toolkit for processing multiplexed tissue images
https://bodenmillergroup.github.io/steinbock
MIT License
49 stars 14 forks source link

Converting external .ome.tiff file #181

Closed mjseignon closed 1 year ago

mjseignon commented 1 year ago

I'm working with .ome.tiff file from CODEX and I get this error when I try to run the conversion for steinbock compatibility.

 steinbock preprocess external images --img external --panel segmt_markers.csv --infoout img_info.csv

Command exit status:
  1

Command output:
  (empty)

Command error:
  Traceback (most recent call last):
    File "/opt/venv/bin/steinbock", line 8, in <module>
      sys.exit(steinbock_cmd_group())
    File "/opt/venv/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
      return self.main(*args, **kwargs)
    File "/opt/venv/lib/python3.8/site-packages/click/core.py", line 1055, in main
      rv = self.invoke(ctx)
    File "/opt/venv/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
      return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "/opt/venv/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
      return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "/opt/venv/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
      return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "/opt/venv/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
      return ctx.invoke(self.callback, **ctx.params)
    File "/opt/venv/lib/python3.8/site-packages/click/core.py", line 760, in invoke
      return __callback(*args, **kwargs)
    File "/app/steinbock/steinbock/_cli/utils.py", line 35, in wrapper
      return func(*args, **kwargs)
    File "/app/steinbock/steinbock/preprocessing/_cli/external.py", line 116, in images_cmd
      img_file = io._as_path_with_suffix(
    File "/app/steinbock/steinbock/io.py", line 32, in _as_path_with_suffix
      return path.with_suffix(suffix)
    File "/usr/lib/python3.8/pathlib.py", line 869, in with_suffix
      raise ValueError("Invalid suffix %r" % (suffix))
  ValueError: Invalid suffix 'SampleID_codex.tiff'

This might be a problem with steinbock/steinbock/preprocessing/_cli/external.py Where at line 116/117 we have : img_file = io._as_path_with_suffix( Path(img_dir) / Path(ext_img_file).name, ".tiff" ) instead of :

img_file = io._as_path_with_suffix( Path(img_dir) / Path(ext_img_file).stem, ".tiff" )

Let me know if more detail is needed.

jwindhager commented 1 year ago

Hi @mjseignon, thanks so much for reporting this!

The lines in external.py you mention are correct. However, there seems to be a bug in the io._as_path_with_suffix function: for .ome.tiff files, this function erroneously overrides the provided suffix function argument with e.g. "tiff" (without a prefix dot, which is why the the error message indicates an invalid suffix). https://github.com/BodenmillerGroup/steinbock/blob/66e9717db847c9680f92b48bfc09ba310ffdce41/steinbock/io.py#L23-L32

We'll release a bugfix asap!