Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Comparisons between groups of samples #784

Open
grst opened this issue Dec 15, 2023 · 5 comments
Open

Comparisons between groups of samples #784

grst opened this issue Dec 15, 2023 · 5 comments
Labels
squidpy2.0 Everything releated to a Squidpy 2.0 release workstream Major workstreams for the Squidpy 2.0 release

Comments

@grst
Copy link
Contributor

grst commented Dec 15, 2023

Most functions in squidpy seem to be centered around analyzing a single sample.
For me, in the context of clinical trials, it would be important to compare between sample groups. The usual variables of interest are

  • comparisons of samples over time (pre-treatment vs. on-treatment), i.e. "how does our drug influence the tissue?" and
  • comparisons of responders vs. non-responders, i.e. "What could explain treatment failure?"

A few things that came to my mind

  • Differential ligand/receptor interactions between groups
  • Differential neighborhood analysis (e.g. tumor more infiltrated after treatment?)
  • differential spatial distance (e.g. tumor and certain immune cells closer together in responders?)

Would be great to have dedicated functions for this, and happy about further ideas!

CC @Zethson, because this is basically "spatial pertpy"


Example data

Collection of use-cases and implementation ideas

Differential neighborhood enrichment

Sharing here a very simple approach that estimates for each "niche" (e.g. tumor spots), the average neighborhood (i.e. across all spots of that niche, what's the fraction of neighboring niches). This allows to distinguish, for instance, between immune-infiltrated and immune-excluded tumors.

# adata_vis -> AnnData with visium data, contains multiple samples
# "niche_leiden" -> categorical annotation of niches
res2 = []
for sample in samples:
    tmp_ad = select_slide(adata_vis, sample)
    sq.gr.spatial_neighbors(tmp_ad)

    res = []
    for spot in range(tmp_ad.shape[0]):
        spot_neighbors = tmp_ad.obsp["spatial_distances"][spot, :].todense().A1.astype(bool)
        current_niche = tmp_ad.obs["niche_leiden"][spot]
        res.append(tmp_ad.obs["niche_leiden"][spot_neighbors].value_counts().to_frame().T.assign(current_niche = current_niche))

    res_df = pd.concat(res).groupby("current_niche").agg("mean").assign(sample = sample)
    res2.append(res_df)

neighbors_per_sample = pd.concat(res2).reset_index(drop=False).set_index(["current_niche", "sample"]).pipe(lambda x: x.div(np.sum(x, axis=1), axis=0))

This results in something like this (each column a sample):
image

Statistics between groups of samples can be computed using a standard linear model.

Visualization idea:
image
(but instead color heatmap by enriched/depleted)

@Zethson
Copy link
Member

Zethson commented Dec 15, 2023

I'd like to CC @AnnaChristina here who's also been working on this AFAIK.

@grst

This comment was marked as off-topic.

@Zethson

This comment was marked as off-topic.

@giovp

This comment was marked as off-topic.

@timtreis timtreis added squidpy2.0 Everything releated to a Squidpy 2.0 release workstream Major workstreams for the Squidpy 2.0 release labels Jan 8, 2024
@grst grst changed the title spatial perturbation analysis Comparisons between groups of samples Jan 10, 2024
@grst
Copy link
Contributor Author

grst commented May 3, 2024

cellcharter already has a function for differential neighborhood enrichment that does statistics on the sample level: https://github.com/CSOgroup/cellcharter/blob/396c415f706e46ce5d9b82df062d0b6509aa526e/src/cellcharter/gr/_nhood.py#L136

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
squidpy2.0 Everything releated to a Squidpy 2.0 release workstream Major workstreams for the Squidpy 2.0 release
Projects
None yet
Development

No branches or pull requests

4 participants