Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Bug]AssertionError: Channel names must be strings, not object #114

Closed
sunshx-bioinfo opened this issue Aug 27, 2024 · 6 comments
Closed

Comments

@sunshx-bioinfo
Copy link

Hi,

When i run sopa read with phonecycler data, i got an error: AssertionError: Channel names must be strings, not object.

Here is my code and log:

(sopa) [sunsx@localhost 730]$ sopa read image/AO0730_Scan1.qptiff --technology phenocycler
[INFO] (sopa.io.reader.phenocycler) Found channel names ['DAPI' 'CD8' 'HLA-A' 'LAG3' 'Ki67' 'SMA' 'CD40' 'CD45RO' 'Vimentin'
 'TCF-1' 'Granzyme B' 'CD79a' 'HIF1A' 'IFNG' 'CD20' 'FOXP3' 'CD163' 'CD31'
 'PD-L1' 'MPO' 'CD4' 'T-bet/TBX21' 'CD68' 'CD56' 'CD11c' 'CD44' 'ICOS'
 'CD14' 'HLA-DR' 'CD3e' 'LIF' 'CD45']
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /data/sunsx/software/miniconda3/envs/sopa/lib/python3.10/site-packages/sopa/cli/app.py:95 in     │
│ read                                                                                             │
│                                                                                                  │
│    92 │   ), f"Technology {technology} unknown. Currently available: xenium, merscope, cosmx,    │
│    93 │                                                                                          │
│    94sdata = getattr(io, technology)(data_path, **kwargs)                                   │
│ ❱  95io.write_standardized(sdata, sdata_path, delete_table=True)                            │
│    96                                                                                            │
│    97                                                                                            │
│    98 @app.command()                                                                             │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ config_path = None                                                                           │ │
│ │   data_path = 'image/AO0730_Scan1.qptiff'                                                    │ │
│ │          io = <module 'sopa.io' from                                                         │ │
│ │               '/data/sunsx/software/miniconda3/envs/sopa/lib/python3.10/site-packages/sopa/… │ │
│ │      kwargs = {}                                                                             │ │
│ │        Path = <class 'pathlib.Path'>                                                         │ │
│ │       sdata = SpatialData object                                                             │ │
│ │               └── Images                                                                     │ │
│ │               │     └── 'AO0730_Scan1': DataTree[cyx] (32, 29520, 27840), (32, 14760,        │ │
│ │               13920), (32, 7380, 6960), (32, 3690, 3480), (32, 1845, 1740)                   │ │
│ │               with coordinate systems:                                                       │ │
│ │               │   ▸ 'pixels', with elements:                                                 │ │
│ │               │   │   AO0730_Scan1 (Images)                                                  │ │
│ │  sdata_path = PosixPath('image/AO0730_Scan1.zarr')                                           │ │
│ │  technology = 'phenocycler'                                                                  │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /data/sunsx/software/miniconda3/envs/sopa/lib/python3.10/site-packages/sopa/io/standardize.py:61 │
│ in write_standardized                                                                            │
│                                                                                                  │
│   58                                                                                             │
│   59                                                                                             │
│   60 def write_standardized(sdata: SpatialData, sdata_path: str, delete_table: bool = False):    │
│ ❱ 61sanity_check(sdata, delete_table)                                                       │
│   62 │                                                                                           │
│   63assert (                                                                                │
│   64 │   │   SopaKeys.TABLE not in sdata.tables                                                  │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ delete_table = True                                                                          │ │
│ │        sdata = SpatialData object                                                            │ │
│ │                └── Images                                                                    │ │
│ │                │     └── 'AO0730_Scan1': DataTree[cyx] (32, 29520, 27840), (32, 14760,       │ │
│ │                13920), (32, 7380, 6960), (32, 3690, 3480), (32, 1845, 1740)                  │ │
│ │                with coordinate systems:                                                      │ │
│ │                │   ▸ 'pixels', with elements:                                                │ │
│ │                │   │   AO0730_Scan1 (Images)                                                 │ │
│ │   sdata_path = PosixPath('image/AO0730_Scan1.zarr')                                          │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /data/sunsx/software/miniconda3/envs/sopa/lib/python3.10/site-packages/sopa/io/standardize.py:31 │
│ in sanity_check                                                                                  │
│                                                                                                  │
│   28 │   │   )                                                                                   │
│   29 │                                                                                           │
│   30c_coords = get_channel_names(image)                                                     │
│ ❱ 31assert is_string_dtype(c_coords), f"Channel names must be strings, not {c_coords.dty    │
│   32 │                                                                                           │
│   33if SopaKeys.TABLE in sdata.tables:                                                      │
│   34 │   │   if delete_table:                                                                    │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │     c_coords = array(['DAPI', 'CD8', 'HLA-A', 'LAG3', 'Ki67', 'SMA', 'CD40', 'CD45RO',       │ │
│ │                │      'Vimentin', 'TCF-1', 'Granzyme B', 'CD79a', 'HIF1A', 'IFNG',           │ │
│ │                │      'CD20', 'FOXP3', 'CD163', 'CD31', 'PD-L1', 'MPO', 'CD4',               │ │
│ │                │      'T-bet/TBX21', 'CD68', 'CD56', 'CD11c', 'CD44', 'ICOS', 'CD14',        │ │
│ │                │      'HLA-DR', 'CD3e', 'LIF', 'CD45'], dtype=object)                        │ │
│ │ delete_table = True                                                                          │ │
│ │        image = <xarray.DataArray 'image' (c: 32, y: 29520, x: 27840)> Size: 26GB             │ │
│ │                dask.array<rechunk-merge, shape=(32, 29520, 27840), dtype=uint8,              │ │
│ │                chunksize=(1, 1024, 1024), chunktype=numpy.ndarray>                           │ │
│ │                Coordinates:                                                                  │ │
│ │                  * c        (c) object 256B 'DAPI' 'CD8' 'HLA-A' 'LAG3' ... 'CD3e' 'LIF'     │ │
│ │                'CD45'                                                                        │ │
│ │                  * y        (y) float64 236kB 0.5 1.5 2.5 3.5 ... 2.952e+04 2.952e+04        │ │
│ │                2.952e+04                                                                     │ │
│ │                  * x        (x) float64 223kB 0.5 1.5 2.5 3.5 ... 2.784e+04 2.784e+04        │ │
│ │                2.784e+04                                                                     │ │
│ │                Attributes:                                                                   │ │
│ │                │   transform:  {'pixels': Identity }                                         │ │
│ │        sdata = SpatialData object                                                            │ │
│ │                └── Images                                                                    │ │
│ │                │     └── 'AO0730_Scan1': DataTree[cyx] (32, 29520, 27840), (32, 14760,       │ │
│ │                13920), (32, 7380, 6960), (32, 3690, 3480), (32, 1845, 1740)                  │ │
│ │                with coordinate systems:                                                      │ │
│ │                │   ▸ 'pixels', with elements:                                                │ │
│ │                │   │   AO0730_Scan1 (Images)                                                 │ │
│ │         warn = False                                                                         │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
AssertionError: Channel names must be strings, not object

As the error log shows, there is some wrong with my channel names. But i don't know where is wrong and how to fix it.

@amir1387aht

This comment was marked as abuse.

@sunshx-bioinfo
Copy link
Author

@amir1387aht @jia6214876 , thank you.

I guess this is qptiff editor, i will try it later. And can you give me the another issue link ? I want to see more about this question.

Thanks.

@quentinblampey
Copy link
Collaborator

Hello @sunshx-bioinfo, the channel names should indeed be strings, but I should tolerate object also.
I'll have a look to the phenocycler reader to understand why you received an object dtype, but I'll also modify the is_string_dtype to accept object dtypes!

NB: indeed, the post from Amir seems highly suspicious; I reported it and temporarily hid it.

@sunshx-bioinfo
Copy link
Author

OK, thx. @quentinblampey

I chose a region from this qptiff image and saved it as tif format and when i run same command with the tif file, everything was ok.
But when the sample code is applied on qptiff image, it throws me this error. It seems that this error is related with format. Hope this is helpful.

@quentinblampey
Copy link
Collaborator

Yes, when reading a qptiff image, the channel names have the object dtype, while when reading the tif format the dtype was string. They are both valid formats, but I have a "sanity check" in the CLI, and it was returning an error because the dtype was not a string dtype.
Now I updated the is_string_dtype function to not throw an error.

You can try this fix on the dev branch, else you can also wait for the next sopa release (it usually takes a few weeks, because I prefer to wait to add other features before making a new release)

@sunshx-bioinfo
Copy link
Author

@quentinblampey , I've tried it and the problem is fixed.

Thx!

@quentinblampey
Copy link
Collaborator

Great, I'm closing the issue!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@sunshx-bioinfo @quentinblampey @amir1387aht and others