Running SCALAR on human cortex snRNA-seq data for ligand-receptor interaction analysis
Running SCALAR on human cortex snRNA-seq data for ligand-receptor interaction analysis
import piasoimport numpy as npimport pandas as pdimport scanpy as scsc.set_figure_params(dpi=80,dpi_save=300, color_map='viridis',facecolor='white')from matplotlib import rcParams# To modify the default figure size, use rcParams.rcParams['figure.figsize'] = 4, 4rcParams['font.sans-serif'] = "Arial"rcParams['font.family'] = "Arial"sc.settings.verbosity = 3sc.logging.print_header()save_dir='.../Result/single-cell/Methods/PIASO'sc.settings.figdir = save_dirprefix='SEAAD_SCALAR_CCI_tutorial'import osif not os.path.exists(save_dir): os.makedirs(save_dir)
sc.set_figure_params(dpi=80,dpi_save=300, color_map='viridis',facecolor='white')rcParams['figure.figsize'] = 4, 4adata=sc.read('.../Result/single-cell/Enhancer/SEA-AD/SEA-AD_RNA_MTG_subsample_excludeReference_20k_piaso.h5ad')adatasc.pl.embedding(adata, basis='X_umap', color=['Subclass'], palette=piaso.pl.color.d_color3, legend_fontoutline=2, legend_fontweight=5, cmap='Spectral_r', ncols=3, size=10, frameon=False)sc.pl.embedding(adata, basis='X_umap', color=['Subclass'], palette=piaso.pl.color.d_color3, legend_fontoutline=2, legend_fontsize=7, legend_fontweight=5, legend_loc='on data', cmap='Spectral_r', ncols=3, size=10, frameon=False)import cosgadata.X.data%%timegroupby='Subclass'cosg.cosg(adata, key_added='cosg', # use_raw=False, layer='log1p', ## e.g., if you want to use the log1p layer in adata mu=100, expressed_pct=0.05, remove_lowly_expressed=True, n_genes_user=adata.n_vars, ### Use all the genes, to enable the calculation of transformed COSG scores # n_genes_user=100, groupby=groupby, return_by_group=True, verbosity=1)cosg_scores=cosg.indexByGene( adata.uns['cosg']['COSG'], # gene_key="names", score_key="scores", set_nan_to_zero=True, convert_negative_one_to_zero=True)cosg_scores=cosg.iqrLogNormalize(cosg_scores)cosg_scores### Load the mouse version# cellchatdb=pd.read_csv('.../')### Load the human versioncellchatdb=pd.read_csv('.../')cellchatdb.head()pd.Series(cellchatdb['annotation']).value_counts().head(30)pd.Series(cellchatdb['pathway_name']).value_counts().head(30)# # cellchatdb=cellchatdb.loc[:,['ligand', 'receptor', 'pathway_name']].copy()cellchatdb=cellchatdb.loc[:,['ligand', 'receptor', 'annotation']].copy()%%timespecific_interactions_cellchat = piaso.tl.runSCALAR( adata=adata, specificity_matrix=cosg_scores, lr_pairs=cellchatdb, ligand_col = 'ligand', receptor_col = 'receptor', annotation_col='annotation', sender_cell_types=list(adata.obs['Subclass'].cat.categories.values), receiver_cell_types=list(adata.obs['Subclass'].cat.categories.values), n_permutations=1000, n_nearest_neighbors=30, chunk_size=500000, random_seed=42)specific_interactions_cellchatpd.Series(specific_interactions_cellchat['nlog10_p_value_fdr']>-np.log10(0.2)).value_counts()pd.Series(specific_interactions_cellchat['nlog10_p_value_fdr']>-np.log10(0.05)).value_counts()specific_interactions_cellchat['CellTypeXCellType']=piaso.pp.getCrossCategories(specific_interactions_cellchat, 'sender', 'receiver')specific_interactions_cellchat['CellTypeXCellType']=specific_interactions_cellchat['CellTypeXCellType'].astype('str')specific_interactions_cellchat['ligandXreceptor']=piaso.pp.getCrossCategories(specific_interactions_cellchat, 'ligand', 'receptor', delimiter='-->')specific_interactions_cellchat['ligandXreceptor']=specific_interactions_cellchat['ligandXreceptor'].astype('str')specific_interactions_cellchat.head()len(specific_interactions_cellchat['CellTypeXCellType'].unique())adata.obs['Subclass'].cat.categoriessi_fdr=specific_interactions_cellchat[specific_interactions_cellchat['nlog10_p_value_fdr']>-np.log10(0.5)].copy()piaso.pl.plotLigandReceptorInteraction( interactions_df=si_fdr, specificity_df=cosg_scores, cell_type_pairs=['L5 ET@Sst', 'L5/6 NP@Sst', 'L5 ET@Pvalb', 'L5/6 NP@Pvalb',], ligand_receptor_sep='-->', top_n=50, y_max=10, heatmap_cmap='Purples', shared_legend=True)# specific_interactions_subset=specific_interactions.loc[# specific_interactions['annotation'].isin(['Secreted Signaling'])# ]
specific_interactions_cellchat_subset=specific_interactions_cellchat.loc[ specific_interactions_cellchat['annotation'].isin(['ECM-Receptor'])]
# specific_interactions_subset=specific_interactions.loc[# specific_interactions['annotation'].isin(['Cell-Cell Contact'])# ]
# specific_interactions_cellchat_subset=specific_interactions_cellchat.loc[# specific_interactions_cellchat['annotation'].isin(['Non-protein Signaling'])# ]piaso.pl.plotLigandReceptorInteraction( interactions_df=specific_interactions_cellchat_subset, specificity_df=cosg_scores, cell_type_pairs=['L5 ET@Sst', 'L5/6 NP@Sst', 'L5 ET@Pvalb', 'L5/6 NP@Pvalb',], ligand_receptor_sep='-->', top_n=50, y_max=10, heatmap_cmap='Purples', fig_height_per_pair=6, fig_width=20, shared_legend=True)piaso.pl.plotLigandReceptorInteraction( interactions_df=si_fdr, specificity_df=cosg_scores, cell_type_pairs=['L5 ET@Sst', 'L5/6 NP@Sst', 'L5 ET@Pvalb', 'L5/6 NP@Pvalb',], ligand_receptor_sep='-->', top_n=50, y_max=10, heatmap_cmap='Purples', heatmap_cmap_ligand='Blues', heatmap_cmap_receptor='Reds', shared_legend=True, vertical_layout=False, fig_height_per_pair=6, fig_width=20, color_labels_by_annotation=True,
)piaso.pl.plotLigandReceptorInteraction( interactions_df=si_fdr, specificity_df=cosg_scores, cell_type_pairs=['L5 ET@Sst', 'L5/6 NP@Sst', 'L5 ET@Pvalb', 'L5/6 NP@Pvalb',], # cell_type_pairs=['L5 NP@SST-Chrna2'], ligand_receptor_sep='-->', top_n=50, y_max=10, # heatmap_cmap='Purples', heatmap_cmap_ligand='Purples', heatmap_cmap_receptor='Reds', shared_legend=True, vertical_layout=True, fig_height_per_pair=6, fig_width=12, color_labels_by_annotation=True)piaso.pl.plotLigandReceptorInteraction( interactions_df=si_fdr, specificity_df=cosg_scores, cell_type_pairs=['L5 ET@Sst', 'L5/6 NP@Sst', 'L5 ET@Pvalb', 'L5/6 NP@Pvalb',], cell_type_sep='@', ligand_receptor_sep='-->', top_n=50, y_max=10, # heatmap_cmap='Purples', heatmap_cmap_ligand='Blues', heatmap_cmap_receptor='Reds', barplot_palette=piaso.pl.color.d_color10, shared_legend=True, vertical_layout=False, fig_height_per_pair=6, fig_width=20, color_labels_by_annotation=True, sort_by_category=True, category_agg_method='sum')piaso.pl.plotLigandReceptorInteraction( interactions_df=si_fdr, specificity_df=cosg_scores, cell_type_pairs=['L5 ET@Sst', 'L5/6 NP@Sst', 'L5 ET@Pvalb', 'L5/6 NP@Pvalb',], # col_cell_type_pair='Category', # col_annotation= 'ConfirmedCategories', cell_type_sep='@', ligand_receptor_sep='-->', top_n=50, y_max=10, # heatmap_cmap='Purples', heatmap_cmap_ligand='Blues', heatmap_cmap_receptor='Reds', barplot_palette=piaso.pl.color.d_color10, shared_legend=True, vertical_layout=True, fig_height_per_pair=6, fig_width=12, color_labels_by_annotation=True, sort_by_category=True, # category_agg_method='sum')si_fdr.head()adata.obs['Subclass'].cat.categoriespiaso.pl.plotLigandReceptorLollipop( si_fdr, specificity_df=cosg_scores, cell_type_pairs=[ 'Microglia-PVM@L6 CT' ], top_n=50, col_cell_type_pair='CellTypeXCellType', ## Specify the cell type conlumn # col_annotation= 'annotation', sort_by_category=True, fig_height_per_pair=4, fig_width=16, vertical_layout=False, background_colors=True, # show_grid=False, logfc_range=1, ### To control the log fold chaneg range base_circle_size=30, # size_dramatic_level=1, color_labels_by_annotation=True, # score_range_max=8, score_range_min=-8, ### To control the y-axis ranges
)piaso.pl.plotLigandReceptorLollipop( si_fdr, specificity_df=cosg_scores, cell_type_pairs=['L5 ET@Sst', 'L5/6 NP@Sst', 'L5 ET@Pvalb', 'L5/6 NP@Pvalb', ], top_n=50, col_cell_type_pair='CellTypeXCellType', ## Specify the cell type conlumn # col_annotation= 'annotation', sort_by_category=True, fig_height_per_pair=4, fig_width=16, vertical_layout=False, background_colors=True, # show_grid=False, logfc_range=1, ### To control the log fold chaneg range base_circle_size=30, # size_dramatic_level=1, color_labels_by_annotation=True, # score_range_max=8, score_range_min=-8, ### To control the y-axis ranges
)piaso.pl.plotLigandReceptorLollipop( si_fdr, specificity_df=cosg_scores, cell_type_pairs=['L5 ET@Sst', 'L5/6 NP@Sst', ], top_n=50, col_cell_type_pair='CellTypeXCellType', ## Specify the cell type conlumn # col_annotation= 'annotation', sort_by_category=True, fig_height_per_pair=10, fig_width=5, vertical_layout=True, background_colors=True, # show_grid=False, logfc_range=1, ### To control the log fold chaneg range base_circle_size=30, # size_dramatic_level=1, color_labels_by_annotation=True, # score_range_max=8, score_range_min=-8, ### To control the y-axis ranges
)