BodenmillerGroup / steinbock

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

Strange invalid literal error.. #259

Open paulrbuckley-kcl opened 5 months ago

paulrbuckley-kcl commented 5 months ago

Hi

I'm having a strange error, using code and an image which i've previously preprocessed before .. any advice would be really greatly appreciated.

Commands I am using are as follows. This is a snakemake pipeline running steinbock via singularity. Has always worked in the past ! Can't work out for the life of me what is wrong.

steinbock="singularity run -B /output_data/{wildcards.file}:/data --env STEINBOCK_MASK_DTYPE=uint32 docker://ghcr.io/bodenmillergroup/steinbock:0.15.0" echo "Running preprocessing of external images" $steinbock preprocess external images --img /data/ --imgout /data/images --infoout /data/images/images.csv $steinbock segment deepcell --minmax --img /data/images --panel /data/panel.csv -o /data/masks/ $steinbock measure intensities --img /data/images --masks /data/masks --panel /data/panel.csv -o /data/intensities/ $steinbock measure regionprops --img /data/images --masks /data/masks -o /data/regionprops/

The panel.csv file is in the structure of:

Screenshot 2024-05-09 at 18 07 22
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/app/steinbock/steinbock/__main__.py", line 17, in <module>
    steinbock_cmd_group(prog_name="steinbock")
  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 99, in images_cmd
    channel_indices = panel["channel"].astype(int).sub(1).tolist()
  File "/opt/venv/lib/python3.8/site-packages/pandas/core/generic.py", line 5912, in astype
    new_data = self._mgr.astype(dtype=dtype, copy=copy, errors=errors)
  File "/opt/venv/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 419, in astype
    return self.apply("astype", dtype=dtype, copy=copy, errors=errors)
  File "/opt/venv/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 304, in apply
    applied = getattr(b, f)(**kwargs)
  File "/opt/venv/lib/python3.8/site-packages/pandas/core/internals/blocks.py", line 580, in astype
    new_values = astype_array_safe(values, dtype, copy=copy, errors=errors)
  File "/opt/venv/lib/python3.8/site-packages/pandas/core/dtypes/cast.py", line 1292, in astype_array_safe
    new_values = astype_array(values, dtype, copy=copy)
  File "/opt/venv/lib/python3.8/site-packages/pandas/core/dtypes/cast.py", line 1234, in astype_array
    values = values.astype(dtype, copy=copy)
  File "/opt/venv/lib/python3.8/site-packages/pandas/core/arrays/string_.py", line 453, in astype
    return super().astype(dtype, copy)
  File "/opt/venv/lib/python3.8/site-packages/pandas/core/arrays/base.py", line 584, in astype
    return np.array(self, dtype=dtype, copy=copy)
  File "/opt/venv/lib/python3.8/site-packages/pandas/core/arrays/numpy_.py", line 129, in __array__
    return np.asarray(self._ndarray, dtype=dtype)
ValueError: invalid literal for int() with base 10: 'C1'
Milad4849 commented 4 months ago

Hi @paulrbuckley-kcl Sorry for the late reply. To be honest I have not come across this bit of the steinbock code before. It appears to expect only numerical characters in the 'channel' column of the panel for external images. I am surprised that it worked before for you, since .astype(int) would fail if there are any characters in the column entries. You can get around it by removing the 'C's in your panel['channel'] entries. But then again that should not be expected format of panel['channel']. @jwindhager could you please comment?

jwindhager commented 4 months ago

This is a bug