Skip to content

bt.io.prep() --> AttributeError: 'dict' object has no attribute 'to_scale_vector' #180

@amitjavilaventura

Description

@amitjavilaventura

Dear Yeo Lab members,

Thank you for developping this tool.

I am trying to run bento with several Xenium samples and I am facing a problem when running the "Main Guide" tutorial with my own data.

In the main guide, you use MERFISH data in zarr format and I have been able to run all the tutorials with this data. To use my xenium data I read it using spatialdata_io.xenium and then I write it to zarr in order to import it as in your tutorial, I perform spatialdata.bounding_box_query and then bento.io.prep(), which gives an error.

sdata = xenium("/home/amitjavila/projects/pic_variation/0data/private/Xenium_B6CAST/output-XETG00289__0052444__M1__20250213__120501")
sdata.write("xenium_M1.zarr")
# sdata = sd.read_zarr("../../spatialdata/4technology_xenium/data.zarr/")
sdata = sd.read_zarr("xenium_M1.zarr")
sdata

sdata = sd.bounding_box_query(
    sdata,
    axes=["x", "y"],
    min_coordinate=[0, 0],
    max_coordinate=[6000, 6000],
    target_coordinate_system="global",
)

sdata = bt.io.prep(sdata)

The sdata object is structured as follows:

SpatialData object, with associated Zarr store: /home/amitjavila/Desktop/tutorials/bento/main_guide_with_my_data/xenium_M1.zarr
├── Images
│     └── 'morphology_focus': DataTree[cyx] (5, 20508, 19975), (5, 10254, 9987), (5, 5127, 4993), (5, 2563, 2496), (5, 1281, 1248)
├── Labels
│     ├── 'cell_labels': DataTree[yx] (20508, 19975), (10254, 9987), (5127, 4993), (2563, 2496), (1281, 1248)
│     └── 'nucleus_labels': DataTree[yx] (20508, 19975), (10254, 9987), (5127, 4993), (2563, 2496), (1281, 1248)
├── Points
│     └── 'transcripts': DataFrame with shape: (<Delayed>, 13) (3D points)
├── Shapes
│     ├── 'cell_boundaries': GeoDataFrame shape: (56662, 1) (2D shapes)
│     ├── 'cell_circles': GeoDataFrame shape: (56662, 2) (2D shapes)
│     └── 'nucleus_boundaries': GeoDataFrame shape: (55850, 1) (2D shapes)
└── Tables
      └── 'table': AnnData (56662, 294)
with coordinate systems:
    ▸ 'global', with elements:
        morphology_focus (Images), cell_labels (Labels), nucleus_labels (Labels), transcripts (Points), cell_boundaries (Shapes), cell_circles (Shapes), nucleus_boundaries (Shapes)

The error is the following one:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/amitjavila/.conda/envs/bento/lib/python3.10/site-packages/bento/io/_io.py", line 72, in prep
    scale=transform.to_scale_vector(["x", "y"]), axes=["x", "y"]
AttributeError: 'dict' object has no attribute 'to_scale_vector'

I tried to reduce the "max_coordinate" argument form bounding_box_query() to a smaller number (e.g., 10 or 1000) and the error changes:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/amitjavila/.conda/envs/bento/lib/python3.10/site-packages/bento/io/_io.py", line 65, in prep
    "global": sd.transformations.get_transformation(sdata.points[points_key])
  File "/home/amitjavila/.conda/envs/bento/lib/python3.10/collections/__init__.py", line 1106, in __getitem__
    raise KeyError(key)
KeyError: 'transcripts'

Do you know how can I solve this?

This is my session info:

-----
bento               2.1.4.post2
matplotlib          3.10.1
session_info        1.0.0
spatialdata         0.3.0
spatialdata_io      0.1.7
-----
Python 3.10.16 | packaged by conda-forge | (main, Dec  5 2024, 14:16:10) [GCC 13.3.0]
Linux-5.15.0-134-generic-x86_64-with-glibc2.31
-----
Session information updated at 2025-03-14 15:06

Thank you very much

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions