scverse / scverse/spatialdata

Merging multiple samples into a single SpatialData object + single merged table

Open
#1,025 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
394
Forks
95
Avg merge
4d 3h
Merged PRs (30d)
7

Description

Hello!

I am trying to merge several samples into a single spatialdata object, and currently this is what I'm doing:

adatas = {
    "square_002um": [],
    "square_008um": [],
    "square_016um": [],
}
images = {}

for sample in sample_folders:
    sdata = spatialdata_io.visium_hd(
        f"{outs}/{sample}/outs",
        dataset_id=sample,
        fullres_image_file=id_to_image[sample],
    )
    # Collect tables
    for size, table in sdata.tables.items():
        table.var_names_make_unique()
        table.obs[f"sample_id"] = sample
        #Add mapping from dictionary above:
        table.obs["sfh_id"] = sample_mapping[sample]
        adatas.setdefault(size, []).append(table)

    # Collect images
    for name, img in sdata.images.items():
        images[f"{sample}_{name}"] = img

# Build one SpatialData object with merged table + all images
merged_bin_sizes = {}
for size, adata in adatas.items():
    temp_merged = ad.concat(adata, join="outer", label="sample_id", fill_value=0)
    merged_bin_sizes[size] = temp_merged
sdata_merged = SpatialData(
    images=images,
    tables=merged_bin_sizes
)

Which ultimately gives me this:

Image

To me it seems like the way to go, but I was wondering if this is recommended or if there is another specific way of doing things to easy the downstream analysis? Perhaps even split things a bit further with the tables between 02,08 and 16 mu? Thanks

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the spatialdata_io.visium_hd entry point and the SpatialData construction shown in the issue, focusing on how tables at different bin sizes and images are represented. Determine whether the proposed merged structure is supported for downstream analysis and document the recommended organization, including what “done” means for the 02, 08, and 16 μm tables.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.