fig_dir = '/home/jovyan/projects/P38_Adult-heart-RNA_celltype-annotation/notebooks/Revision/figures'
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
import numpy as np
import numpy.random as random
import pandas as pd
import scanpy as sc
import matplotlib.pyplot as plt
import sctk
import session_info
session_info.show()
----- matplotlib 3.5.2 numpy 1.21.5 pandas 1.3.5 scanpy 1.8.2 sctk NA session_info 1.0.0 -----
PIL 9.1.1 anndata 0.8.0 asciitree NA backcall 0.2.0 beta_ufunc NA binom_ufunc NA cached_property 1.5.1 cairo 1.20.0 cffi 1.14.4 cloudpickle 1.6.0 colorama 0.4.4 cycler 0.10.0 cython_runtime NA cytoolz 0.11.2 dask 2022.01.0 dateutil 2.8.1 decorator 4.4.2 defusedxml 0.6.0 fasteners 0.17.3 fsspec 2022.01.0 google NA h5py 3.1.0 igraph 0.10.2 importlib_metadata 1.7.0 ipykernel 5.4.2 ipython_genutils 0.2.0 ipywidgets 7.6.3 jedi 0.17.2 jinja2 3.1.2 joblib 1.0.0 kiwisolver 1.3.1 leidenalg 0.9.0 llvmlite 0.35.0 louvain 0.7.0 markupsafe 2.1.1 mpl_toolkits NA msgpack 1.0.3 natsort 7.1.0 nbinom_ufunc NA numba 0.52.0 numcodecs 0.9.1 numexpr 2.7.2 numpy_groupies 0.9.13 packaging 21.3 parso 0.7.1 pexpect 4.8.0 pickleshare 0.7.5 pkg_resources NA plotly 5.10.0 prompt_toolkit 3.0.10 psutil 5.9.0 ptyprocess 0.7.0 pyarrow 9.0.0 pygments 2.13.0 pyparsing 2.4.7 pytz 2020.5 scipy 1.7.3 scvelo 0.2.4 seaborn 0.11.1 setuptools_scm NA sinfo 0.3.1 six 1.14.0 sklearn 1.0.2 sphinxcontrib NA statsmodels 0.12.1 storemagic NA tables 3.6.1 tblib 1.7.0 texttable 1.6.3 threadpoolctl 2.1.0 tlz 0.11.2 toolz 0.11.2 tornado 6.1 traitlets 5.0.5 typing_extensions NA wcwidth 0.2.5 yaml 5.4.1 zarr 2.11.3 zipp NA zmq 21.0.1 zope NA
----- IPython 7.19.0 jupyter_client 6.1.11 jupyter_core 4.7.0 notebook 6.2.0 ----- Python 3.7.9 | packaged by conda-forge | (default, Dec 9 2020, 21:08:20) [GCC 9.3.0] Linux-4.15.0-189-generic-x86_64-with-debian-bullseye-sid ----- Session information updated at 2023-01-13 16:07
sc.settings.verbosity = 1 # verbosity: errors (0), warnings (1), info (2), hints (3)
sc.settings.set_figure_params(dpi=300, color_map = 'RdPu',)
adata = sc.read_h5ad('/nfs/team205/heart/anndata_objects/8regions/RNA_adult-8reg_full_raw_cellstate-annotated.h5ad',
backed='r')
adata
AnnData object with n_obs × n_vars = 704296 × 32732 backed at '/nfs/team205/heart/anndata_objects/8regions/RNA_adult-8reg_full_raw_cellstate-annotated.h5ad' obs: 'sangerID', 'combinedID', 'donor', 'donor_type', 'region', 'region_finest', 'age', 'gender', 'facility', 'cell_or_nuclei', 'modality', 'kit_10x', 'flushed', 'n_genes', 'n_genes_by_counts', 'total_counts', 'total_counts_mt', 'pct_counts_mt', 'total_counts_ribo', 'pct_counts_ribo', 'scrublet_score', 'scrublet_leiden', 'cluster_scrublet_score', 'doublet_pval', 'doublet_bh_pval', 'batch_key', 'leiden_scVI', 'cell_type', 'cell_state_HCAv1', 'cell_state_scNym', 'cell_state_scNym_confidence', 'cell_state', 'latent_RT_efficiency', 'latent_cell_probability', 'latent_scale', 'n_counts', '_scvi_batch', '_scvi_labels', 'clus20', 'doublet_cls', 'original_or_new', 'batch', 'scANVI_predictions', 'leiden_scArches' var: 'gene_name-new', 'gene_name_scRNA-0-original', 'gene_name_snRNA-1-original', 'gene_name_multiome-2-original' uns: 'age_colors', 'cell_or_nuclei_colors', 'cell_state_colors', 'cell_type_colors', 'donor_colors', 'donor_type_colors', 'facility_colors', 'flushed_colors', 'gender_colors', 'kit_10x_colors', 'leiden', 'modality_colors', 'neighbors', 'original_or_new_colors', 'region_colors', 'region_finest_colors', 'scANVI_predictions_colors', 'umap' obsm: 'X_scArches', 'X_umap' obsp: 'connectivities', 'distances'
# reorder the regions
adata.obs['region'].cat.reorder_categories([
'SAN','AVN','RA','LA','RV','LV','SP','AX',
], inplace=True)
cells = [
'SAN_P_cell',
]
plt.rcParams['figure.figsize'] = 1,3
obs = adata[adata.obs['cell_state'].isin(cells)].obs.copy()
tmp = pd.crosstab(obs['cell_state'], obs['donor'], normalize='index')
# tmp.plot.bar().legend(loc=1)
ax = tmp.plot.bar(stacked=True,width=0.7)
ax.grid(False)
ax.set_ylabel('proportion')
ax.legend(bbox_to_anchor=(1.0, 1.0))
ax.plot()
plt.show()
cells = [
'AVN_P_cell',
'AVN_bundle_cell',]
plt.rcParams['figure.figsize'] = 1.5,3
obs = adata[adata.obs['cell_state'].isin(cells)].obs.copy()
tmp = pd.crosstab(obs['cell_state'], obs['donor'], normalize='index')
# tmp.plot.bar().legend(loc=1)
ax = tmp.plot.bar(stacked=True,width=0.7)
ax.grid(False)
ax.set_ylabel('proportion')
ax.legend(bbox_to_anchor=(1.0, 1.0))
ax.plot()
plt.show()
cells = [
'Purkinje_cell',]
plt.rcParams['figure.figsize'] = 1,3
obs = adata[adata.obs['cell_state'].isin(cells)].obs.copy()
tmp = pd.crosstab(obs['cell_state'], obs['donor'], normalize='index')
# tmp.plot.bar().legend(loc=1)
ax = tmp.plot.bar(stacked=True,width=0.7)
ax.grid(False)
ax.set_ylabel('proportion')
ax.legend(bbox_to_anchor=(1.0, 1.0))
ax.plot()
plt.show()