Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -950,8 +950,8 @@ is the first suspect.
embedding canvas the read could not have built, and no duplicate spatial one; it prints
a `[skip]` line when that fixture is absent. A third pass needs no fixture: it writes a
SpatialData `.zarr.zip` shaped like an instrument export (two wells placed in a shared
`global` system, region-local coordinates stored as an `X`/`Y` data frame, a points
element, several tables with the cell table not first, the store one folder down in
`global` system, region-local coordinates stored as an `X`/`Y` data frame, a text
data frame in another `obsm` entry, a points element, several tables with the cell table not first, the store one folder down in
the archive) and reads it as the workflow's `spatialdata` type does, asserting the
points are left out, the session and the sidecar open on the chosen table, and the
wells are stitched into `obsm['spatial_global']` (and that world coordinates already
Expand Down
5 changes: 4 additions & 1 deletion backend/app/sessions/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ def world_space(sdata, table) -> tuple[str, str | None]:
if key == "spatial":
continue
arr = np.asarray(table.obsm[key])
if arr.ndim != 2 or arr.shape[0] != world.shape[0] or arr.shape[1] < 2:
# An obsm entry may be a data frame of text (an Element export's per-cell guide
# assignment), which can't hold coordinates and won't convert to float.
if (not np.issubdtype(arr.dtype, np.number) or arr.ndim != 2
or arr.shape[0] != world.shape[0] or arr.shape[1] < 2):
continue
if np.abs(arr[:, :2].astype(float) - world).max() <= 1e-3 * span:
return key, system
Expand Down
4 changes: 4 additions & 0 deletions backend/app/transport/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ def describe_fields(adata, sdata) -> dict:
obsm = []
for k, v in adata.obsm.items():
a = np.asarray(v)
# A data frame of text (a per-cell guide assignment) is neither coordinates nor an
# embedding, and `resolve_field` cannot draw it.
if not np.issubdtype(a.dtype, np.number):
continue
obsm.append({"name": k, "n_components": int(a.shape[1]) if a.ndim > 1 else 1})
return {
"obs": obs,
Expand Down
9 changes: 9 additions & 0 deletions backend/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ def write_foreign_store(tmp: str) -> str:
obs=obs[["region_key", "cell_id"]].assign(
region_key=lambda o: o["region_key"].astype("category")))
cells.obsm["spatial"] = obs[["X", "Y"]]
# Other obsm entries can be data frames of text, such as each cell's assigned guide.
cells.obsm["target_assignment"] = pd.DataFrame(
{"guide": [f"CTNNB1_{i % 3}" for i in range(len(obs))], "n_reads": 1}, index=obs.index)
region = list(labels)
tables = {
"a-guides": TableModel.parse(cells[:, :2].copy(), region=region,
Expand Down Expand Up @@ -204,6 +207,12 @@ def check_foreign_store(cli) -> int:
print("[ok] region-local coordinates stitched into obsm['spatial_global'], "
"and the canvas draws those")

from app.transport.arrow import describe_fields
offered = [f["name"] for f in describe_fields(table, sdata)["obsm"]]
assert "target_assignment" not in offered and "spatial_global" in offered, offered
print(f"[ok] a text obsm entry is skipped as coordinates and not offered in pickers "
f"(offered: {offered})")

# A writer that already put world coordinates in obsm['spatial'] is left alone.
from app.sessions.transform import stitch_world_coordinates
table.obsm["spatial"] = np.asarray(table.obsm.pop("spatial_global"))
Expand Down
Loading