Skip to content

Commit 876e161

Browse files
authored
Merge pull request #39 from CostaLab/doc
Doc Improved network functions and coloc module completely documented
2 parents 0ae6784 + 79e07a0 commit 876e161

12 files changed

Lines changed: 1515 additions & 183 deletions

File tree

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# Nichesphere
1+
<img align="right" src="nichesphere/nichesphere/source/_static/logo.png" alt="Nichesphere Logo" width="200">
22

3-
Nichesphere is an sc-verse compatible Python library which allows the user to find differential co-localization domains / niches based on cell type pair co-localization probabilities in different conditions. Cell type pair co-localization probabilities can be obtained in different ways, for example, through deconvolution of spatial transcriptomics / PIC-seq data (getting the probabilities of finding each cell type in each spot / multiplet) ; or counting cell boundaries overlaps for each cell type pair in single cell spatial data (MERFISH , CODEX …).
3+
# NicheSphere
4+
5+
NicheSphere is an sc-verse compatible Python library which allows the user to find differential co-localization domains / niches based on cell type pair co-localization probabilities in different conditions. Cell type pair co-localization probabilities can be obtained in different ways, for example, through deconvolution of spatial transcriptomics / PIC-seq data (getting the probabilities of finding each cell type in each spot / multiplet) ; or counting cell boundaries overlaps for each cell type pair in single cell spatial data (MERFISH , CODEX …).
46

57
It also offers the possibility to look at biological process based differential communication among differential co-localization domains based on Ligand-Receptor pairs expression data, such as results from CrossTalkeR [ref.].
68

nichesphere/nichesphere/coloc.py

Lines changed: 212 additions & 87 deletions
Large diffs are not rendered by default.

nichesphere/nichesphere/comm.py

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,43 @@
33
import numpy as np
44
import scipy
55
import seaborn as sns
6-
#import random
76
import matplotlib.pyplot as plt
87
import matplotlib.colors as mcolors
9-
#import ot
108
import networkx as nx
11-
#import itertools
129
import sklearn
13-
#import scanpy as sc
14-
#import sys
15-
#sys.path.append(".")
16-
#from tl import *
17-
#from . import tl
1810
from matplotlib.colors import ListedColormap
1911

2012
def unique(array):
13+
"""get unique elements in array without re-sorting
14+
15+
Parameters
16+
----------
17+
array : np.array
18+
19+
Returns
20+
-------
21+
uniq[index.argsort()] : np.array of unique elements of the original array in original order
22+
"""
2123
uniq, index = np.unique(array, return_index=True)
2224
return uniq[index.argsort()]
2325

2426
#%%
2527

2628
def cellCatContained(pair, cellCat):
29+
"""Check if a cell group (niche/type/category) is contained in a cell type pair
30+
31+
Parameters
32+
----------
33+
pair : list
34+
cell type list (usually cell type pairs in the form [cellTypeA,cellTypeB])
35+
36+
cellCat : list
37+
list of cell types in a cell group (niche/type/category)
38+
39+
Returns
40+
-------
41+
True or False
42+
"""
2743

2844
contained=[cellType in pair for cellType in cellCat]
2945
return True in contained
@@ -138,7 +154,7 @@ def getDiffComm(diffCommTbl, pairCatDF, ncells, cat):
138154

139155
#%%
140156

141-
def catNW(x_chem,colocNW, cell_group, group_cmap='tab20', ncols=20, color_group=None, plot_title='',
157+
def catNW(x_chem,colocNW, cell_group, group=None, group_cmap='tab20', ncols=20, color_group=None, plot_title='',
142158
clist=None, nodeSize=None, legend_ax=[0.7, 0.05, 0.15, 0.2], layout='neato', thr=0, fsize=(8,8), alpha=1, lab_spacing=7, edge_scale=1, pos=None):
143159

144160
# Choose colormap
@@ -163,7 +179,16 @@ def catNW(x_chem,colocNW, cell_group, group_cmap='tab20', ncols=20, color_group=
163179

164180
colors = np.vstack((np.flip(c1[128:256], axis=0), c2[128:256]))
165181
mymap = mcolors.LinearSegmentedColormap.from_list('my_colormap', colors)
166-
182+
183+
cmap=mcolors.LinearSegmentedColormap.from_list("WhiteGray",['white','lightgrey'])
184+
# Get the colormap colors
185+
graycmp = cmap(np.arange(cmap.N))
186+
# Set alpha (transparency)
187+
graycmp[:,-1] = np.linspace(0, alpha-0.2, cmap.N)
188+
c3=graycmp.copy()
189+
# Create new colormap
190+
graycmp = ListedColormap(graycmp)
191+
167192
#cell group cmap
168193
cmap = plt.cm.get_cmap(group_cmap, ncols)
169194
if clist == None:
@@ -249,6 +274,16 @@ def catNW(x_chem,colocNW, cell_group, group_cmap='tab20', ncols=20, color_group=
249274

250275
inter=pd.Series(np.abs(pd.Series(list(weights))))
251276
inter.index=edgeCols.index
277+
278+
####### NEW #######
279+
if group!=None:
280+
edgeCols[[cellCatContained(pair=[x.split('->')[0], x.split('->')[0]],
281+
cellCat=group)==False for x in edgeCols.index]]='lightgray'
282+
orange_edges = [(u,v) for u,v in G.edges if edgeCols[u+'->'+v] == 'orange']
283+
blue_edges = [(u,v) for u,v in G.edges if edgeCols[u+'->'+v] == 'lightblue']
284+
gray_edges = [(u,v) for u,v in G.edges if edgeCols[u+'->'+v] == 'lightgray']
285+
###################
286+
252287
###
253288

254289
if nodeSize == 'betweeness':
@@ -278,7 +313,13 @@ def catNW(x_chem,colocNW, cell_group, group_cmap='tab20', ncols=20, color_group=
278313

279314

280315
nx.draw_networkx_nodes(G,pos,node_color=color_group,ax=ax1)
281-
316+
317+
##########################################
318+
if group!=None:
319+
nx.draw_networkx_edges(G,pos=pos,edge_color=inter[edgeCols=='lightgray'],
320+
connectionstyle="arc3,rad=0.15", arrowstyle='<->',
321+
width=inter[edgeCols=='lightgray']*edge_scale,ax=ax1, edgelist=gray_edges, edge_cmap=graycmp, edge_vmin=-1*np.max(inter), edge_vmax=np.max(inter))
322+
##########################################
282323
nx.draw_networkx_edges(G,pos=pos_edges,edge_color=inter[edgeCols=='lightblue'],
283324
connectionstyle="arc3,rad=0.15",
284325
width=inter[edgeCols=='lightblue']*edge_scale,ax=ax1, edgelist=blue_edges, edge_cmap=cmap3,edge_vmin=-1*np.max(inter),
@@ -287,7 +328,6 @@ def catNW(x_chem,colocNW, cell_group, group_cmap='tab20', ncols=20, color_group=
287328
connectionstyle="arc3,rad=0.15",
288329
width=inter[edgeCols=='orange']*edge_scale,ax=ax1, edgelist=orange_edges, edge_cmap=cmap4,edge_vmin=-1*np.max(inter),
289330
edge_vmax=np.max(inter), arrowsize=20)
290-
291331
nx.draw_networkx_labels(G,pos_attrs,verticalalignment='bottom',
292332
font_size=12,clip_on=False,ax=ax1, font_weight='bold')
293333
f.suptitle(plot_title)
-10.7 KB
Loading
41 KB
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
About NicheSphere
2+
=================
3+
4+
**NicheSphere** is an sc-verse compatible Python library which allows the user to find differential co-localization domains / niches based on cell type pair co-localization probabilities in different conditions. Cell type pair co-localization probabilities can be obtained in different ways, for example, through deconvolution of spatial transcriptomics / PIC-seq data (getting the probabilities of finding each cell type in each spot / multiplet) ; or counting cell boundaries overlaps for each cell type pair in single cell spatial data (MERFISH , CODEX ...).
5+
6+
It also offers the possibility to look at biological process based differential communication among differential co-localization domains based on Ligand-Receptor pairs expression data, such as results from CrossTalkeR https://github.com/CostaLab/CrossTalkeR .
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
fake module
2-
=======================
1+
API
2+
===
33

4-
.. automodule:: fake
5-
:members:
6-
:undoc-members:
7-
:show-inheritance:
4+
:doc:`coloc`
5+
6+
:doc:`comm`
7+
8+
:doc:`tl`

nichesphere/nichesphere/source/index.rst

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,44 @@
33
You can adapt this file completely to your liking, but it should at least
44
contain the root `toctree` directive.
55
6-
Welcome to Nichesphere's documentation!
6+
Welcome to NicheSphere's documentation!
77
=======================================
88

9+
**NicheSphere** is an sc-verse compatible Python library which allows the user to find differential co-localization domains / niches and associated biological processes based on cell type pair co-localization probabilities in different conditions.
910

10-
Introduction
11-
============
1211

13-
**Nichesphere** is an sc-verse compatible Python library which allows the user to find differential co-localization domains / niches based on cell type pair co-localization probabilities in different conditions. Cell type pair co-localization probabilities can be obtained in different ways, for example, through deconvolution of spatial transcriptomics / PIC-seq data (getting the probabilities of finding each cell type in each spot / multiplet) ; or counting cell boundaries overlaps for each cell type pair in single cell spatial data (MERFISH , CODEX ...).
12+
.. toctree::
13+
:maxdepth: 2
14+
:caption: About NicheSphere
1415

15-
It also offers the possibility to look at biological process based differential communication among differential co-localization domains based on Ligand-Receptor pairs expression data, such as results from CrossTalkeR [ref.].
16+
about
1617

1718

18-
Installation
19-
============
19+
.. toctree::
20+
:maxdepth: 2
21+
:caption: Installation
2022

21-
In your terminal window run::
23+
installation
2224

23-
conda create --name test python=3.10
24-
conda activate test
25-
conda install pip
26-
pip install jupyterlab
27-
conda install --channel conda-forge pygraphviz
28-
conda install conda-forge::git
29-
pip install git+https://github.com/CostaLab/Nichesphere#subdirectory=nichesphere
3025

26+
.. toctree::
27+
:maxdepth: 2
28+
:caption: Tutorials
3129

32-
Tutorials
33-
=========
34-
35-
In our first example we will use data from the Myocardial Infarction atlas from Kuppe, C. et. Al., 2022 to find differential co-localization domains related to ischemia. The data you'll need to run the tutorials can be found here: https://doi.org/10.5281/zenodo.15790389
36-
37-
.. nbgallery::
38-
:caption: Notebooks:
39-
:glob:
40-
41-
notebooks/Nichesphere_tutorial_MIvisium_coloc.ipynb
42-
notebooks/Nichesphere_tutorial_MIvisium_comm.ipynb
43-
notebooks/Nichesphere_tutorial_MIvisium_preprocessing.ipynb
44-
30+
tutorials
4531

4632
Docker image and summarized analysis tutorial
4733
=============================================
4834

4935
We provide access to a Docker image, available at: https://gitlab.com/sysbiobig/ismb-eccb-2025-tutorial-vt3/container_registry. The Docker image comes preconfigured with all necessary libraries, tools, and software required to follow the hands-on exercises. Additionally, the repository at https://gitlab.com/sysbiobig/ismb-eccb-2025-tutorial-vt3 contains a summarized Nichesphere co-localization + communication analysis tutorial.
5036

5137

52-
API
53-
===
38+
.. toctree::
39+
:maxdepth: 2
40+
:caption: API
5441

55-
:doc:`coloc`
42+
api
5643

57-
:doc:`comm`
5844

59-
:doc:`tl`
6045

6146

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Installation
2+
============
3+
4+
Prerequisites
5+
-------------
6+
Before installing, ensure you have the following:
7+
8+
* Python > = 3.10 < = 3.12
9+
* pip (Python package manager)
10+
* pygraphviz . You can install it running this command in your terminal:
11+
12+
13+
.. code-block:: bash
14+
15+
conda install --channel conda-forge pygraphviz
16+
17+
18+
From GitHub
19+
-----------
20+
To install NicheSphere, run this command in your terminal:
21+
22+
.. code-block:: bash
23+
24+
pip install git+https://github.com/CostaLab/Nichesphere#subdirectory=nichesphere

0 commit comments

Comments
 (0)