Skip to content

match shapes by their column named after the table's instance key - #292

Open
CuiweiG wants to merge 1 commit into
HelenaLC:develfrom
CuiweiG:fix-252-shape-sync
Open

CuiweiG wants to merge 1 commit into
HelenaLC:develfrom
CuiweiG:fix-252-shape-sync

Conversation

@CuiweiG

@CuiweiG CuiweiG commented Nov 11, 2026

Copy link
Copy Markdown

Refs #252.

.sync_shapes_on_drop() matches instances(t) against instances(y), which is seq_len(nrow(y)) for a shape element without an instance_key, so ids that start at 0 are compared with row positions and the last shape is dropped. On devel, reading merfish.zarr.zip from the BiocSpatialData OSN bucket leaves 2,388 of 2,389 cells, and visium_associated_xenium_io_aligned.zip 4,991 of 4,992 spots. crop() reattaches the tables through the same function: a box with 151 MERFISH cells comes back with 151 observations in the table and no cells.

In both stores the ids are in a column named after the table's instance key (cell_id, spot_id). For an element without an instance_key, the function now matches on that column when the element has it, as .sync_tables_on_crop() and getTable() do. If the table already has all of instances(y), the element is put back as is, so a whole table numbered by row position keeps all shapes.

A subset of such a table is matched on the column, though, and can keep the wrong shapes. setTable() numbers a table by row position if the shapes have no instance_key and no column named ik, also when the table comes with an instance_key that names one of their columns, and mask() does if j has no instance_key. I've left both as they are, because they number by the element's instance_key, and an element with several tables has only one. That looks like a question for #195.

Not changed: an element with an instance_key, or without such a column, is matched as before, so the blobs_circles example in #252, whose parquet file has only a range index, still loses a row. I've left that to #195 as well. query() also still filters the shapes by position before it attaches the table: on MERFISH, query(x, cell_id %% 2 == 0) keeps none of the 1,195 cells.

The test in test-sync.R fails on devel. devtools::check() on the Bioconductor devel Docker image (R 4.6.1) gives 0 errors, 0 warnings and the same 4 notes as devel, and lintr is clean on the changed files.

#267 changes the same lines and adds an early exit there, so I'm happy to rebase onto it or fold this into it.

`.sync_shapes_on_drop()` matched a table's instances against
`instances(y)`, which is `seq_len(nrow(y))` for a shape element without
an `instance_key`. Shape elements that do carry the ids, in a column
named after the table's instance key, were still matched by row
position: with ids from 0, attaching the table dropped the last shape,
and attaching a subset of the table kept the wrong shapes.

For an element without an `instance_key`, that column is now used when
the element has it, as in `.sync_tables_on_crop()` and `getTable()`. If
the table already has all of `instances(y)`, nothing is dropped and the
element is put back as is, so a whole table numbered by row position
keeps all shapes even if the element has a column named after the
table's instance key, as can happen with `setTable()` and `mask()`. A
subset of such a table is matched on the column. Other elements are
matched as before.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant