Skip to content

Question about applying this method across multiple images #6

@srivarra

Description

@srivarra

Hello, cool method! I would like to know how to apply this method across multiple images. For example, if I have $N$ images (samples), or an AnnData object with a sample categorical column in obs, how can I use this method across all of them to get similar clusters across multiple images correctly? Currently if I run the method across multiple images at once, each image gets essentially gets labeled with one cluster. I would like to see the same "subpopulations" appearing across multiple field of views.

My code for reference, maybe I did something wrong here?
nbl_adata: ad.AnnData
sc.pp.neighbors(
    nbl_adata,
    n_neighbors=15,
    key_added="sc_neighbors",
    transformer=AnnoyTransformer(n_neighbors=15, n_trees=100),
)
sq.gr.spatial_neighbors(
    nbl_adata, spatial_key="spatial", library_key="region", coord_type="generic", key_added="sq_spatial", n_neighs=15
)

nbl_adata.obsm["X_msPCA"] = MultispatiPCA(n_components=2, connectivity=nbl_adata.obsp["sq_spatial_connectivities"]).fit_transform(nbl_adata.X)

sc.pp.neighbors(
    nbl_adata,
    n_neighbors=15,
    key_added="msPCA_neighbors",
    use_rep="X_msPCA",
    transformer=AnnoyTransformer(n_neighbors=6, n_trees=100),
)

sl.spatialleiden(
    nbl_adata, # All fields of view
    layer_ratio=1.8,
    directed=(True, False),
    latent_distance_key="msPCA_neighbors_connectivities",
    spatial_distance_key="sq_spatial_connectivities",
    key_added="spatialleiden",
)

...

sl.spatialleiden(
    nbl_fov, # subset the AnnData on a single Field of View
    layer_ratio=3,
    directed=(True, False),
    latent_distance_key="sc_neighbors_connectivities",
    spatial_distance_key="sq_spatial_connectivities",
    key_added="spatialleiden",
)

For the following 2 figures I have subset on a cell type and ran the clustering algorithm on just those cells. I've plotted the FOV with the numerical spatialleiden clusters, and the other cell types present in the FOV.

One FOV after running SpatialLeiden across all FOVs

image

One FOV after running SpatialLeiden on just this FOV

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions