sagar87 / spatialproteomics

Spatialproteomics is a light weight wrapper around xarray with the intention to facilitate the data exploration and analysis of highly multiplexed immunohistochemistry data. Docs available here: https://sagar87.github.io/spatialproteomics/ .
https://sagar87.github.io/spatialproteomics/
MIT License
14 stars 0 forks source link

Neighborhood analysis #87

Closed MeyerBender closed 1 week ago

MeyerBender commented 3 months ago

For visualizing neighborhoods, it would be cool to do a sort of Voronoi tessellation and then extract the edges from the tessellation and color in the corresponding neighborhoods while also plotting the borders in black or something like that.

MeyerBender commented 2 months ago

To generalize this a bit more, we could directly implement neighborhoods within spatialproteomics. A big advantage of this would be that we could subset cells by neighborhoods, and then look at the ct distribution within that. For example, assuming that one neighborhood encodes the germinal center, we could check if there are major differences in the composition of this environment between samples (given that they do not cluster completely separate).

This requires a couple of things to be implemented:

  1. Creation of neighborhoods on a sample level. Could implement both radius and kNN here. Example syntax: pp.compute_neighbors(method='radius'). This could add a new table of shape (cells, cell_types). We need to ensure that this is synchronizes with the obs column that holds the cell types.
  2. Clustering of neighborhoods using e. g. k-means. This is a bit trickier, since it needs to be performed on all samples simultaneously. Example syntax could be:
    sp_dict = {'1': sp_obj_1, '2': sp_obj_2}
    df = []
    for id, sp_obj in sp_dict.items():
    df.append(sp_obj.pp.get_layer_as_df('_neighborhoods'))
    df = pd.DataFrame(df)
    # clustering with k-means on the df
    ...
    # adding the neighborhoods back into the graph
    for id, sp_obj in sp_dict.items():
    sp_obj.pp.add_obs(df['id' == id])

    This is a bit cumbersome, however I think it makes sense to keep this apart from the package itself.

  3. Plotting: we should be able to plot the neighborhoods in a spatial context. This can be part of spatialproteomics again.
MeyerBender commented 2 months ago

Addressed in #97. Now also includes an ImageContainer, which allows you to do the entire analysis in one command. Next features should be: computation of distances and graph features, e. g. centrality, on specific neighborhoods.

MeyerBender commented 1 month ago

Node-level features are now implemented and have been merged to main in #102. Another nice add-on would be to have graph-level features such as homophily to compare different samples.

MeyerBender commented 1 month ago

Graph-level features implemented and merged in #104. Next up we need to look at distributions of node-level features to compare cores.

MeyerBender commented 1 week ago

These will be shown in the manuscript, closing issue.