comm module
Focused on differential communication
- nichesphere.comm.calculate_LR_CT_pair_scores_dir(ccommTable, LRscoresCol)
Get cell communication scores per cell type pair per LR pair by summing that LR pair scores for that cell type pair.
- Parameters:
ccommTable (pd.DataFrame) – Condition specific cell - cell communication table (output from CrossTalkeR)
LRscoresCol (str) – name of the ccommTable column where the LR scores are (usually ‘MeanLR’ for CrossTalkeR)
- Returns:
scores – cell communication scores per cell type / LR pair (allpair in CrossTalkeR)
- Return type:
pd.Series
- nichesphere.comm.catNW(x_chem, colocNW, cell_group, group=None, group_cmap='tab20', ncols=20, color_group=None, plot_title='', 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)
(Differential) communication network
- Parameters:
xchem (pd.DataFrame) – cell types x cell types data frame of significant scores for each cell cell interaction (for a specific LR category)
colocNW (nx.Graph) – Graph object with (differential) co-localization scores as weights
cell_group (dict) – dictionary with niche names as keys and lists of their corresponding cell types as values
group (list (default: None)) – list of nodes whose interaction will be highlighted
group_cmap (str (default: 'tab20')) – name of the color map from which the niche colors will be taken
ncols (int (default: 20)) – number of colors for the group_cmap
color_group (list) – list of colors (one color per node)
plot_title (str (default: '')) – plot title to be shown at the top of the network plot
clist (list (default: None)) – alternatively , one can input a list of niche colors
nodeSize (str (default: None)) – value that will define the size of the nodes. Options are ‘betweeness’, ‘pagerank’ (network statistics)
legend_ax (list (default: [0.7, 0.05, 0.15, 0.2])) – legend position in the form [x0, y0, width, height]
layout (str (default: 'neato')) – name of the layout to be used. Options are ‘neato’, ‘dot’, ‘kamada_kawai’, ‘spring’, ‘spectral’, ‘circular’, ‘force_atlas2’, ‘fruchterman_reingold’ and ‘random’)
lab_spacing (int (default: 9)) – spacing between labels and nodes
thr (float (default: 0)) – edge weights absolute value must be above this value for the edge to be shown
alpha (float (default: 1)) – edge transparency (from 0 to 1)
fsize (tuple) – figure size in the form (x,y)
pos (dict) – dictionary containing the calculated 2D positions (x, y coordinates) for every node
edge_scale (float) – factor to scale the edge width
- Returns:
G (nx.Graph) – Graph object with (differential) cell communication scores as weights
Network plot
- nichesphere.comm.cellCatContained(pair, cellCat)
Check if a cell group (niche/type/category) is contained in a cell type pair
- Parameters:
pair (list) – cell type list (usually cell type pairs in the form [cellTypeA,cellTypeB])
cellCat (list) – list of cell types in a cell group (niche/type/category)
- Return type:
True or False
- nichesphere.comm.diffCcommStats(c1CTpairScores_byCat, c2CTpairScores_byCat, cellCatCol)
Differential cell communication per LR category (eg: biological process)
- Parameters:
c1CTpairScores_byCat (pd.DataFrame) – exp cell communication table with all interactions
c2CTpairScores_byCat (pd.DataFrame) – control cell communication table with all interactions
cellCatCol (str) – name of the column in the communication tables containing the cell pair grouping we would like to compare (eg: ‘niche_pairs’, ‘cell_pairs’)
- Returns:
diffCommTable – dataframe of Wilcoxon statictics and p-values for each cell pair grouping in each LR category (eg: biological process) columns are named ‘wilcoxStat’, ‘wilcoxPval’, ‘cellCat’ and ‘LRcat’
- Return type:
pd.DataFrame
- nichesphere.comm.equalizeScoresTables(ctrlTbl, expTbl, ctrlCondition, expCondition)
Makes communication score tables contain the same interactions through adding 0s to be compared
- Parameters:
ctrlTbl (pd.DataFrame) – Condition specific (control) processed cell - cell communication table
expTbl (pd.DataFrame) – Condition specific (exp) processed cell - cell communication table
ctrlCondition (str) – name of the control condition (a column with this string will be added to the resulting table)
expCondition (str) – name of the exp condition (a column with this string will be added to the resulting table)
- Returns:
ctrlTbl,expTbl
ctrlTbl (pd.DataFrame) – control cell communication table with all interactions
expTbl (pd.DataFrame) – exp cell communication table with all interactions
- nichesphere.comm.getDiffComm(diffCommTbl, pairCatDF, ncells, cat)
get the differential communication scores for a specific LR category
- Parameters:
diffCommTbl (pd.DataFrame) – differential communication scores dataframe of cell pairs (or groupings) x LR categories (obtained with plotDiffCcommStatsHM function)
pairCatDF (pd.DataFrame)
ncells (int) – number of cells or groups
cat (str) – LR category to be tested
- Returns:
x_chem – cells x cells or groups x groups dataframe of differential communication scores for a specific LR category
- Return type:
pd.DataFrame
- nichesphere.comm.lr_ctPairScores_perCat_dir(ccommTable, db, dbCatCol, dbMatchCol, ccommMatchCol, ccommLRscoresCol, oneCTinteractions, condition, pairCatDF)
Calculate cell communication scores per ligand category from a database
- Parameters:
ccommTable (pd.DataFrame) – Condition specific cell - cell communication table (output from CrossTalkeR)
db (pd.DataFrame) – database table with information about element (ligand or receptor or both) category (eg: biological processes)
dbCatCol (str) – column in the database table containing the category (eg: biological process) with which the ligands/receptors/LR pairs are associated
dbMatchCol (str) – column in the database table containing the elements (ligands/receptors/LR pairs) associated to the categories
ccommMatchCol (str) – column in the ccommTable table containing the elements (ligands/receptors/LR pairs) associated to the categories
ccommLRscoresCol (str) – name of the ccommTable column where the LR scores are (usually ‘MeanLR’ for CrossTalkeR)
oneCTinteractions (list) – list of single cell interactions (celltype@celltype)
condition (str) – name of the analyzed condition (a column with this string will be added to the resulting table)
pairCatDF (pd.DataFrame) – dataframe of cell pairs and corresponding co-localization niche pairs
- Returns:
CTpairScores_byCat – cell communication table with new columns ‘cell_pairs’, ‘niche_pairs’, ‘LRcat’ and ‘condition’
- Return type:
pd.DataFrame
- nichesphere.comm.plotDiffCcommStatsHM(diffCommTable, min_pval, vmin=None, vmax=None)
Plot heatmap of differential cell communication statistics
- Parameters:
diffCommTable (pd.DataFrame) – dataframe of Wilcoxon statictics and p-values for each cell pair grouping in each LR category (obtained with diffCcommStats function)
min_pval (float) – scores with p-values higher than this won’t be shown
vmin (float (default: None)) – minimum value for the color map
vmax (float (default: None)) – maximum value for the color map
- Returns:
x_hm (pd.DataFrame) – differential communication scores dataframe of cell pair groupings x LR categories
plot (sns.matrix.ClusterGrid) – seaborn clustermap as an object
- nichesphere.comm.unique(array)
get unique elements in array without re-sorting
- Parameters:
array (np.array)
- Returns:
uniq[index.argsort()]
- Return type:
np.array of unique elements of the original array in original order