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

Question about applying this method across multiple images #6

Open
srivarra opened this issue Nov 22, 2024 · 3 comments
Open

Question about applying this method across multiple images #6

srivarra opened this issue Nov 22, 2024 · 3 comments

Comments

@srivarra
Copy link

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

@niklasmueboe
Copy link
Collaborator

Hi, thanks for interest in our package!

Multi-sample integration/clustering is definitely an interesting application. Unfortunately, I haven't had the time to look into that so far, but we will investigate it during SpaceHack in december. So maybe there will be more info after that.

@naveedishaque
Copy link

Some comments:

  • that region you are analyzing looks really small. We have only really tested the SpatialLeiden package on larger datasets
  • it could be that there might be strong batch effects across your samples. Check the distribution of transcripts in each FOV to make sure they are comparable, and maybe remove any that seem to be FOV specific
  • the second image looks like the layer_ratio is too high. It reminds me when we set the value to very high in our Figure S4 of the biorxiv
    image
  • as Niklas says, watch this space! We will be looking into multi-sample support next week!

@srivarra
Copy link
Author

srivarra commented Dec 4, 2024

@naveedishaque Hi, thanks for your feedback!

that region you are analyzing looks really small. We have only really tested the SpatialLeiden package on larger datasets

Yeah my images are rather small, I have a set of 107 FOVs with an X, Y size of 1024 $\times$ 1024.

it could be that there might be strong batch effects across your samples. Check the distribution of transcripts in each FOV to make sure they are comparable, and maybe remove any that seem to be FOV specific

I"ll give this a try.

the second image looks like the layer_ratio is too high.

I'll try lowering the layer_ratio down.

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

No branches or pull requests

3 participants