# Developing-Heart-Local-Improved - Atac Analysis

**Pages:** 7

---

## Notebook

**URL:** http://127.0.0.1:9020/notebooks_html/Supplementary_materials/Epigenetic_stability/no1b_peakVI_per-midgrain.html

**Contents:**
- Import module¶
- Read in data¶
- Subset anndata¶
- Modify mid grain¶
- Run peakVI¶

**Examples:**

Example 1 (python):
```python
import scvi
import anndata
import scipy
import numpy as np
import pandas as pd
import scanpy as sc
import matplotlib.pyplot as plt

scvi.settings.seed = 420
```

Example 2 (python):
```python
Global seed set to 0
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/flax/core/frozen_dict.py:169: FutureWarning: jax.tree_util.register_keypaths is deprecated, and will be removed in a future release. Please use `register_pytree_with_keys()` instead.
  jax.tree_util.register_keypaths(
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/utilities/warnings.py:53: LightningDeprecationWarning: pytorch_lightning.utilities.warnings.rank_zero_deprecation has been deprecated in v1.6 and will be removed in v1.8. Use the equivalent function from the pytorch_lightning.utilities.rank_zero module instead.
  new_rank_zero_deprecation(
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/utilities/warnings.py:58: LightningDeprecationWarning: The `pytorch_lightning.loggers.base.rank_zero_experiment` is deprecated in v1.7 and will be removed in v1.9. Please use `pytorch_lightning.loggers.logger.rank_zero_experiment` instead.
  return new_rank_zero_deprecation(*args, **kwargs)
Global seed set to 420
```

Example 3 (python):
```python
import gc
import torch
```

Example 4 (python):
```python
import session_info
session_info.show()
```

Example 5 (python):
```python
-----
anndata             0.8.0
matplotlib          3.7.1
numpy               1.23.5
pandas              1.5.3
scanpy              1.9.3
scipy               1.10.1
scvi                0.19.0
session_info        1.0.0
torch               1.13.1+cu117
-----
```

Example 6 (python):
```python
PIL                 9.4.0
absl                NA
asttokens           NA
attr                22.2.0
backcall            0.2.0
certifi             2022.12.07
cffi                1.15.1
charset_normalizer  3.1.0
chex                0.1.6
comm                0.1.2
contextlib2         NA
cycler              0.10.0
cython_runtime      NA
dateutil            2.8.2
debugpy             1.6.6
decorator           5.1.1
defusedxml          0.7.1
deprecate           0.3.2
docrep              0.3.2
etils               1.1.0
executing           1.2.0
flax                0.6.7
fsspec              2023.3.0
google              NA
h5py                3.8.0
idna                3.4
igraph              0.10.4
importlib_metadata  NA
importlib_resources NA
ipykernel           6.21.3
ipython_genutils    0.2.0
ipywidgets          8.0.4
jax                 0.4.10
jaxlib              0.4.10
jedi                0.18.2
joblib              1.2.0
kiwisolver          1.4.4
leidenalg           0.9.1
llvmlite            0.39.1
ml_collections      NA
ml_dtypes           0.2.0
mpl_toolkits        NA
msgpack             1.0.5
mudata              0.2.1
multipledispatch    0.6.0
natsort             8.3.1
numba               0.56.4
numpyro             0.11.0
nvidia              NA
opt_einsum          v3.3.0
optax               0.1.4
packaging           23.0
parso               0.8.3
pexpect             4.8.0
pickleshare         0.7.5
pkg_resources       NA
platformdirs        3.1.1
prompt_toolkit      3.0.38
psutil              5.9.4
ptyprocess          0.7.0
pure_eval           0.2.2
pydev_ipython       NA
pydevconsole        NA
pydevd              2.9.5
pydevd_file_utils   NA
pydevd_plugins      NA
pydevd_tracing      NA
pygments            2.14.0
pyparsing           3.0.9
pyro                1.8.4
pytorch_lightning   1.7.7
pytz                2022.7.1
requests            2.28.2
rich                NA
setuptools          65.6.3
six                 1.16.0
sklearn             1.2.2
stack_data          0.6.2
tensorboard         2.12.0
texttable           1.6.7
threadpoolctl       3.1.0
toolz               0.12.0
torchmetrics        0.11.4
torchvision         0.14.1+cu117
tornado             6.2
tqdm                4.65.0
traitlets           5.9.0
tree                0.1.8
typing_extensions   NA
urllib3             1.26.15
wcwidth             0.2.6
yaml                6.0
zipp                NA
zmq                 25.0.1
zoneinfo            NA
```

Example 7 (unknown):
```unknown
-----
IPython             8.11.0
jupyter_client      8.0.3
jupyter_core        5.2.0
notebook            6.5.3
-----
Python 3.9.16 (main, Mar  8 2023, 14:00:05) [GCC 11.2.0]
Linux-4.15.0-214-generic-x86_64-with-glibc2.27
-----
Session information updated at 2023-12-29 23:02
```

Example 8 (python):
```python
adata = sc.read_h5ad('/nfs/team205/heart/anndata_objects/Foetal/multiome_ATAC/ArchR/project_output/PeakMatrix/Foetal_Peaks.h5ad')
adata
```

Example 9 (unknown):
```unknown
AnnData object with n_obs × n_vars = 167022 × 508040
    obs: 'sangerID', 'combinedID', 'donor', 'facility', 'cell_or_nuclei', 'modality', 'kit_10x', 'multiplexed', 'batch_key', 'region', 'FACSgate', 'sex', 'week', 'trimester', 'fine_grain', 'mid_grain', 'coarse_grain', 'heart_or_greatvessels'
    var: 'seqnames', 'start', 'end', 'width', 'strand', 'score', 'replicateScoreQuantile', 'groupScoreQuantile', 'Reproducibility', 'GroupReplicate', 'distToGeneStart', 'nearestGene', 'peakType', 'distToTSS', 'nearestTSS', 'GC', 'idx', 'N'
```

Example 10 (python):
```python
adata.X.data[:10]
```

Example 11 (unknown):
```unknown
array([2., 2., 2., 2., 1., 1., 2., 1., 2., 2.], dtype=float32)
```

Example 12 (python):
```python
set(adata.obs.batch_key)
```

Example 13 (unknown):
```unknown
{'C104_Nuclei_Multiome-v1',
 'C82_Nuclei_Multiome-v1',
 'C85_Nuclei_Multiome-v1',
 'C87_Nuclei_Multiome-v1',
 'C92_Nuclei_Multiome-v1',
 'C98_Nuclei_Multiome-v1',
 'Hst33_Nuclei_Multiome-v1',
 'Hst36_Nuclei_Multiome-v1',
 'Hst39_Nuclei_Multiome-v1',
 'Hst40_Nuclei_Multiome-v1',
 'Hst41_Nuclei_Multiome-v1'}
```

Example 14 (python):
```python
# read in selected nuclei id
df = pd.read_csv('/nfs/team205/heart/anndata_objects/Foetal/multiome_ATAC/ArchR/GEX_ATAC_comparison/subsampled_nuclei_n1000_29Dec2023.txt',
                 header=None)
nuclei_sel = pd.Index(df[0])
print(len(nuclei_sel))
nuclei_sel[:5]
```

Example 15 (unknown):
```unknown
Index(['7089STDY13216921_BHF_F_Hea13242528_TGGGCCTAGATGGACA-1',
       '7089STDY13216921_BHF_F_Hea13242528_AAAGGCTCAGCTACGT-1',
       '7089STDY13216921_BHF_F_Hea13242528_CATCATAAGCGATACT-1',
       '7089STDY13216921_BHF_F_Hea13242528_CAGGCTATCACCAATA-1',
       '7089STDY13216921_BHF_F_Hea13242528_CTAATGTCACTTCATC-1'],
      dtype='object', name=0)
```

Example 16 (python):
```python
# subset
adata = adata[nuclei_sel]
adata
```

Example 17 (unknown):
```unknown
View of AnnData object with n_obs × n_vars = 44136 × 508040
    obs: 'sangerID', 'combinedID', 'donor', 'facility', 'cell_or_nuclei', 'modality', 'kit_10x', 'multiplexed', 'batch_key', 'region', 'FACSgate', 'sex', 'week', 'trimester', 'fine_grain', 'mid_grain', 'coarse_grain', 'heart_or_greatvessels'
    var: 'seqnames', 'start', 'end', 'width', 'strand', 'score', 'replicateScoreQuantile', 'groupScoreQuantile', 'Reproducibility', 'GroupReplicate', 'distToGeneStart', 'nearestGene', 'peakType', 'distToTSS', 'nearestTSS', 'GC', 'idx', 'N'
```

Example 18 (python):
```python
# get indices of CCS cells
a_ccs_indices = adata.obs_names[adata.obs['fine_grain'].isin(['SinoatrialNodeCardiomyocytes','AtrioventricularNodeCardiomyocytes'])]
v_ccs_indices = adata.obs_names[adata.obs['fine_grain'].isin(['VentricularConductionSystemProximal','VentricularConductionSystemDistal'])]
# modify
adata.obs['mid_grain_mod'] = adata.obs['mid_grain'].astype('str').copy()
adata.obs.replace({'mid_grain_mod':{
    'AtrialCardiomyocytes':'AtrialCardiomyocytes_plusCCS',
    'VentricularCardiomyocytes':'VentricularCardiomyocytes_plusCCS'
}},inplace=True)
adata.obs.loc[a_ccs_indices,'mid_grain_mod'] = 'AtrialCardiomyocytes_plusCCS'
adata.obs.loc[v_ccs_indices,'mid_grain_mod'] = 'VentricularCardiomyocytes_plusCCS'
adata.obs['mid_grain_mod'].value_counts()
```

Example 19 (python):
```python
/tmp/ipykernel_4463/1930117738.py:5: ImplicitModificationWarning: Trying to modify attribute `.obs` of view, initializing view as actual.
  adata.obs['mid_grain_mod'] = adata.obs['mid_grain'].astype('str').copy()
```

Example 20 (unknown):
```unknown
LymphoidCells                        7006
Fibroblasts                          6969
VentricularCardiomyocytes_plusCCS    6531
AtrialCardiomyocytes_plusCCS         4381
MyeloidCells                         4321
MuralCells                           3103
BloodVesselEndothelialCells          3028
PericardialCells                     2187
Glia                                 1759
EndocardialCells                     1410
EpicardialCells                      1340
Neurons                              1101
LymphaticEndothelialCells            1000
Name: mid_grain_mod, dtype: int64
```

Example 21 (python):
```python
# adding 'region' as covariate
outdir = '/nfs/team205/heart/anndata_objects/Foetal/multiome_ATAC/ArchR/project_output/PeakMatrix/mid_grain_mod'

for celltype in set(adata.obs['mid_grain_mod']):
    print(f'###### {celltype} ######')
    
    # subset
    adata_sub = adata[adata.obs['mid_grain_mod']==celltype]
    print(adata_sub.shape)
    adata_sub = adata_sub.copy()
    
    # train
    scvi.model.PEAKVI.setup_anndata(adata_sub, 
                                    categorical_covariate_keys=['batch_key','region'] # added 'region'
                                   )
    pvi = scvi.model.PEAKVI(adata_sub)
    pvi.view_anndata_setup(adata_sub)
    pvi.train()
    
    # add to anndata
    latent = pvi.get_latent_representation()
    adata_sub.obsm["X_PeakVI"] = latent
    
    # save
    adata_sub.write(f'{outdir}/Foetal_{celltype}_Peaks_post-peakVI_added-cov-region_subsampled-n1000.h5ad')
    pvi.save(f'{outdir}/Foetal_{celltype}_added-cov-region_subsampled-n1000_peakVI-model', overwrite=True)
    
    # Convergency plot
    pvi.history['elbo_train']
    x = np.linspace(1, (len(pvi.history['elbo_train'])), (len(pvi.history['elbo_train'])))
    plt.plot(x, pvi.history['elbo_train'], label="train")
    plt.xlabel('epoch')
    plt.ylabel('elbo_train')
    plt.title(celltype)
    plt.show()
    
    # free up GPU
    del(pvi)
    gc.collect()
    torch.cuda.empty_cache()
```

Example 22 (unknown):
```unknown
###### AtrialCardiomyocytes_plusCCS ######
(4381, 508040)
```

Example 23 (unknown):
```unknown
No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
```

Example 24 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 25 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 26 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key', 'region'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 27 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  4381  │
│ n_extra_categorical_covs │   2    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 28 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 29 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 30 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 31 (python):
```python
extra_categorical_covs State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃          Categories           ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │    C82_Nuclei_Multiome-v1     │          0          │
│                        │    C85_Nuclei_Multiome-v1     │          1          │
│                        │    C87_Nuclei_Multiome-v1     │          2          │
│                        │    C92_Nuclei_Multiome-v1     │          3          │
│                        │    C98_Nuclei_Multiome-v1     │          4          │
│                        │    C104_Nuclei_Multiome-v1    │          5          │
│                        │   Hst33_Nuclei_Multiome-v1    │          6          │
│                        │   Hst36_Nuclei_Multiome-v1    │          7          │
│                        │   Hst39_Nuclei_Multiome-v1    │          8          │
│                        │   Hst40_Nuclei_Multiome-v1    │          9          │
│                        │   Hst41_Nuclei_Multiome-v1    │         10          │
│                        │                               │                     │
│  adata.obs['region']   │             aorta             │          0          │
│                        │             atria             │          1          │
│                        │         atrial septum         │          2          │
│                        │      heart without node       │          3          │
│                        │             node              │          4          │
│                        │         outflow tract         │          5          │
│                        │ pulmonary arches and branches │          6          │
│                        │         whole sample          │          7          │
│                        │                               │                     │
└────────────────────────┴───────────────────────────────┴─────────────────────┘
```

Example 32 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 33 (unknown):
```unknown
Epoch 85/500:  17%|███████████████████████▊                                                                                                                    | 85/500 [20:37<1:40:42, 14.56s/it, loss=4.09e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 33620.641. Signaling Trainer to stop.
```

Example 34 (unknown):
```unknown
###### BloodVesselEndothelialCells ######
(3028, 508040)
```

Example 35 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 36 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 37 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key', 'region'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 38 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  3028  │
│ n_extra_categorical_covs │   2    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 39 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 40 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 41 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 42 (python):
```python
extra_categorical_covs State Registry                       
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃           Categories            ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │     C82_Nuclei_Multiome-v1      │          0          │
│                        │     C85_Nuclei_Multiome-v1      │          1          │
│                        │     C87_Nuclei_Multiome-v1      │          2          │
│                        │     C92_Nuclei_Multiome-v1      │          3          │
│                        │     C98_Nuclei_Multiome-v1      │          4          │
│                        │     C104_Nuclei_Multiome-v1     │          5          │
│                        │    Hst33_Nuclei_Multiome-v1     │          6          │
│                        │    Hst36_Nuclei_Multiome-v1     │          7          │
│                        │    Hst39_Nuclei_Multiome-v1     │          8          │
│                        │    Hst40_Nuclei_Multiome-v1     │          9          │
│                        │    Hst41_Nuclei_Multiome-v1     │         10          │
│                        │                                 │                     │
│  adata.obs['region']   │              aorta              │          0          │
│                        │              apex               │          1          │
│                        │              atria              │          2          │
│                        │          atrial septum          │          3          │
│                        │        ductus arteriosus        │          4          │
│                        │       heart without node        │          5          │
│                        │         left ventricle          │          6          │
│                        │              node               │          7          │
│                        │          outflow tract          │          8          │
│                        │           pericardium           │          9          │
│                        │  pulmonary arches and branches  │         10          │
│                        │         right ventricle         │         11          │
│                        │ right ventricle and papillaries │         12          │
│                        │          whole sample           │         13          │
│                        │                                 │                     │
└────────────────────────┴─────────────────────────────────┴─────────────────────┘
```

Example 43 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 44 (unknown):
```unknown
Epoch 87/500:  17%|████████████████████████▎                                                                                                                   | 87/500 [14:18<1:07:56,  9.87s/it, loss=3.18e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 27406.602. Signaling Trainer to stop.
```

Example 45 (unknown):
```unknown
###### Glia ######
(1759, 508040)
```

Example 46 (python):
```python
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/scvi/data/_utils.py:168: UserWarning: Category 5 in adata.obs['batch_key'] has fewer than 3 cells. Models may not train properly.
  warnings.warn(
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/scvi/data/_utils.py:168: UserWarning: Category 7 in adata.obs['region'] has fewer than 3 cells. Models may not train properly.
  warnings.warn(
```

Example 47 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 48 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 49 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key', 'region'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 50 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  1759  │
│ n_extra_categorical_covs │   2    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 51 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 52 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 53 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 54 (python):
```python
extra_categorical_covs State Registry                       
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃           Categories            ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │     C82_Nuclei_Multiome-v1      │          0          │
│                        │     C85_Nuclei_Multiome-v1      │          1          │
│                        │     C87_Nuclei_Multiome-v1      │          2          │
│                        │     C92_Nuclei_Multiome-v1      │          3          │
│                        │     C98_Nuclei_Multiome-v1      │          4          │
│                        │     C104_Nuclei_Multiome-v1     │          5          │
│                        │    Hst33_Nuclei_Multiome-v1     │          6          │
│                        │    Hst36_Nuclei_Multiome-v1     │          7          │
│                        │    Hst39_Nuclei_Multiome-v1     │          8          │
│                        │    Hst40_Nuclei_Multiome-v1     │          9          │
│                        │    Hst41_Nuclei_Multiome-v1     │         10          │
│                        │                                 │                     │
│  adata.obs['region']   │              aorta              │          0          │
│                        │              atria              │          1          │
│                        │          atrial septum          │          2          │
│                        │        ductus arteriosus        │          3          │
│                        │       heart without node        │          4          │
│                        │         left ventricle          │          5          │
│                        │              node               │          6          │
│                        │          outflow tract          │          7          │
│                        │           pericardium           │          8          │
│                        │  pulmonary arches and branches  │          9          │
│                        │         right ventricle         │         10          │
│                        │ right ventricle and papillaries │         11          │
│                        │          whole sample           │         12          │
│                        │                                 │                     │
└────────────────────────┴─────────────────────────────────┴─────────────────────┘
```

Example 55 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 56 (unknown):
```unknown
Epoch 103/500:  21%|████████████████████████████▊                                                                                                               | 103/500 [10:00<38:33,  5.83s/it, loss=3.11e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 27903.340. Signaling Trainer to stop.
```

Example 57 (unknown):
```unknown
###### Neurons ######
(1101, 508040)
```

Example 58 (python):
```python
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/scvi/data/_utils.py:168: UserWarning: Category 5 in adata.obs['batch_key'] has fewer than 3 cells. Models may not train properly.
  warnings.warn(
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/scvi/data/_utils.py:168: UserWarning: Category 9 in adata.obs['region'] has fewer than 3 cells. Models may not train properly.
  warnings.warn(
```

Example 59 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 60 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 61 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key', 'region'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 62 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  1101  │
│ n_extra_categorical_covs │   2    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 63 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 64 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 65 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 66 (python):
```python
extra_categorical_covs State Registry                       
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃           Categories            ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │     C82_Nuclei_Multiome-v1      │          0          │
│                        │     C85_Nuclei_Multiome-v1      │          1          │
│                        │     C87_Nuclei_Multiome-v1      │          2          │
│                        │     C92_Nuclei_Multiome-v1      │          3          │
│                        │     C98_Nuclei_Multiome-v1      │          4          │
│                        │     C104_Nuclei_Multiome-v1     │          5          │
│                        │    Hst33_Nuclei_Multiome-v1     │          6          │
│                        │    Hst36_Nuclei_Multiome-v1     │          7          │
│                        │    Hst39_Nuclei_Multiome-v1     │          8          │
│                        │    Hst40_Nuclei_Multiome-v1     │          9          │
│                        │    Hst41_Nuclei_Multiome-v1     │         10          │
│                        │                                 │                     │
│  adata.obs['region']   │              aorta              │          0          │
│                        │              apex               │          1          │
│                        │              atria              │          2          │
│                        │          atrial septum          │          3          │
│                        │        ductus arteriosus        │          4          │
│                        │       heart without node        │          5          │
│                        │              node               │          6          │
│                        │           pericardium           │          7          │
│                        │  pulmonary arches and branches  │          8          │
│                        │ right ventricle and papillaries │          9          │
│                        │          whole sample           │         10          │
│                        │                                 │                     │
└────────────────────────┴─────────────────────────────────┴─────────────────────┘
```

Example 67 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/trainer.py:1892: PossibleUserWarning: The number of training batches (8) is smaller than the logging interval Trainer(log_every_n_steps=10). Set a lower value for log_every_n_steps if you want to see logs for the training epoch.
  rank_zero_warn(
```

Example 68 (unknown):
```unknown
Epoch 101/500:  20%|████████████████████████████▎                                                                                                               | 101/500 [06:13<24:34,  3.69s/it, loss=4.52e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 42978.691. Signaling Trainer to stop.
```

Example 69 (unknown):
```unknown
###### EndocardialCells ######
(1410, 508040)
```

Example 70 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 71 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 72 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key', 'region'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 73 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  1410  │
│ n_extra_categorical_covs │   2    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 74 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 75 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 76 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 77 (python):
```python
extra_categorical_covs State Registry                       
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃           Categories            ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │     C82_Nuclei_Multiome-v1      │          0          │
│                        │     C85_Nuclei_Multiome-v1      │          1          │
│                        │     C87_Nuclei_Multiome-v1      │          2          │
│                        │     C92_Nuclei_Multiome-v1      │          3          │
│                        │     C98_Nuclei_Multiome-v1      │          4          │
│                        │     C104_Nuclei_Multiome-v1     │          5          │
│                        │    Hst33_Nuclei_Multiome-v1     │          6          │
│                        │    Hst36_Nuclei_Multiome-v1     │          7          │
│                        │    Hst39_Nuclei_Multiome-v1     │          8          │
│                        │    Hst40_Nuclei_Multiome-v1     │          9          │
│                        │    Hst41_Nuclei_Multiome-v1     │         10          │
│                        │                                 │                     │
│  adata.obs['region']   │              aorta              │          0          │
│                        │              apex               │          1          │
│                        │              atria              │          2          │
│                        │          atrial septum          │          3          │
│                        │       heart without node        │          4          │
│                        │         left ventricle          │          5          │
│                        │              node               │          6          │
│                        │          outflow tract          │          7          │
│                        │         right ventricle         │          8          │
│                        │ right ventricle and papillaries │          9          │
│                        │          whole sample           │         10          │
│                        │                                 │                     │
└────────────────────────┴─────────────────────────────────┴─────────────────────┘
```

Example 78 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 79 (unknown):
```unknown
Epoch 106/500:  21%|█████████████████████████████▉                                                                                                               | 106/500 [08:17<30:49,  4.69s/it, loss=3.7e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 34130.070. Signaling Trainer to stop.
```

Example 80 (unknown):
```unknown
###### VentricularCardiomyocytes_plusCCS ######
(6531, 508040)
```

Example 81 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 82 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 83 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key', 'region'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 84 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  6531  │
│ n_extra_categorical_covs │   2    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 85 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 86 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 87 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 88 (python):
```python
extra_categorical_covs State Registry                       
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃           Categories            ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │     C82_Nuclei_Multiome-v1      │          0          │
│                        │     C85_Nuclei_Multiome-v1      │          1          │
│                        │     C87_Nuclei_Multiome-v1      │          2          │
│                        │     C92_Nuclei_Multiome-v1      │          3          │
│                        │     C98_Nuclei_Multiome-v1      │          4          │
│                        │     C104_Nuclei_Multiome-v1     │          5          │
│                        │    Hst33_Nuclei_Multiome-v1     │          6          │
│                        │    Hst36_Nuclei_Multiome-v1     │          7          │
│                        │    Hst39_Nuclei_Multiome-v1     │          8          │
│                        │    Hst40_Nuclei_Multiome-v1     │          9          │
│                        │    Hst41_Nuclei_Multiome-v1     │         10          │
│                        │                                 │                     │
│  adata.obs['region']   │              apex               │          0          │
│                        │              atria              │          1          │
│                        │          atrial septum          │          2          │
│                        │       heart without node        │          3          │
│                        │         left ventricle          │          4          │
│                        │              node               │          5          │
│                        │          outflow tract          │          6          │
│                        │         right ventricle         │          7          │
│                        │ right ventricle and papillaries │          8          │
│                        │          whole sample           │          9          │
│                        │                                 │                     │
└────────────────────────┴─────────────────────────────────┴─────────────────────┘
```

Example 89 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 90 (unknown):
```unknown
Epoch 88/500:  18%|████████████████████████▋                                                                                                                   | 88/500 [32:04<2:30:11, 21.87s/it, loss=4.62e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 34277.566. Signaling Trainer to stop.
```

Example 91 (unknown):
```unknown
###### PericardialCells ######
(2187, 508040)
```

Example 92 (python):
```python
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/scvi/data/_utils.py:168: UserWarning: Category 3 in adata.obs['batch_key'] has fewer than 3 cells. Models may not train properly.
  warnings.warn(
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/scvi/data/_utils.py:168: UserWarning: Category 0 in adata.obs['region'] has fewer than 3 cells. Models may not train properly.
  warnings.warn(
```

Example 93 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 94 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 95 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key', 'region'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 96 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  2187  │
│ n_extra_categorical_covs │   2    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 97 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 98 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 99 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 100 (python):
```python
extra_categorical_covs State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃          Categories           ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │    C87_Nuclei_Multiome-v1     │          0          │
│                        │    C92_Nuclei_Multiome-v1     │          1          │
│                        │    C98_Nuclei_Multiome-v1     │          2          │
│                        │    C104_Nuclei_Multiome-v1    │          3          │
│                        │   Hst39_Nuclei_Multiome-v1    │          4          │
│                        │   Hst40_Nuclei_Multiome-v1    │          5          │
│                        │   Hst41_Nuclei_Multiome-v1    │          6          │
│                        │                               │                     │
│  adata.obs['region']   │             aorta             │          0          │
│                        │         atrial septum         │          1          │
│                        │       ductus arteriosus       │          2          │
│                        │      heart without node       │          3          │
│                        │         outflow tract         │          4          │
│                        │          pericardium          │          5          │
│                        │ pulmonary arches and branches │          6          │
│                        │         whole sample          │          7          │
│                        │                               │                     │
└────────────────────────┴───────────────────────────────┴─────────────────────┘
```

Example 101 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 102 (unknown):
```unknown
Epoch 82/500:  16%|███████████████████████▎                                                                                                                      | 82/500 [09:55<50:37,  7.27s/it, loss=3.54e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 30433.793. Signaling Trainer to stop.
```

Example 103 (unknown):
```unknown
###### LymphoidCells ######
(7006, 508040)
```

Example 104 (python):
```python
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/scvi/data/_utils.py:168: UserWarning: Category 4 in adata.obs['batch_key'] has fewer than 3 cells. Models may not train properly.
  warnings.warn(
```

Example 105 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 106 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 107 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key', 'region'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 108 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  7006  │
│ n_extra_categorical_covs │   2    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 109 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 110 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 111 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 112 (python):
```python
extra_categorical_covs State Registry                       
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃           Categories            ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │     C82_Nuclei_Multiome-v1      │          0          │
│                        │     C85_Nuclei_Multiome-v1      │          1          │
│                        │     C87_Nuclei_Multiome-v1      │          2          │
│                        │     C92_Nuclei_Multiome-v1      │          3          │
│                        │     C98_Nuclei_Multiome-v1      │          4          │
│                        │    Hst33_Nuclei_Multiome-v1     │          5          │
│                        │    Hst36_Nuclei_Multiome-v1     │          6          │
│                        │    Hst39_Nuclei_Multiome-v1     │          7          │
│                        │    Hst40_Nuclei_Multiome-v1     │          8          │
│                        │    Hst41_Nuclei_Multiome-v1     │          9          │
│                        │                                 │                     │
│  adata.obs['region']   │              aorta              │          0          │
│                        │              atria              │          1          │
│                        │          atrial septum          │          2          │
│                        │        ductus arteriosus        │          3          │
│                        │       heart without node        │          4          │
│                        │         left ventricle          │          5          │
│                        │              node               │          6          │
│                        │           pericardium           │          7          │
│                        │  pulmonary arches and branches  │          8          │
│                        │         right ventricle         │          9          │
│                        │ right ventricle and papillaries │         10          │
│                        │          whole sample           │         11          │
│                        │                                 │                     │
└────────────────────────┴─────────────────────────────────┴─────────────────────┘
```

Example 113 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 114 (unknown):
```unknown
Epoch 81/500:  16%|██████████████████████▋                                                                                                                     | 81/500 [31:31<2:43:04, 23.35s/it, loss=2.75e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 21196.828. Signaling Trainer to stop.
```

Example 115 (unknown):
```unknown
###### EpicardialCells ######
(1340, 508040)
```

Example 116 (python):
```python
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/scvi/data/_utils.py:168: UserWarning: Category 12 in adata.obs['region'] has fewer than 3 cells. Models may not train properly.
  warnings.warn(
```

Example 117 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 118 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 119 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key', 'region'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 120 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  1340  │
│ n_extra_categorical_covs │   2    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 121 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 122 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 123 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 124 (python):
```python
extra_categorical_covs State Registry                       
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃           Categories            ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │     C82_Nuclei_Multiome-v1      │          0          │
│                        │     C85_Nuclei_Multiome-v1      │          1          │
│                        │     C87_Nuclei_Multiome-v1      │          2          │
│                        │     C92_Nuclei_Multiome-v1      │          3          │
│                        │     C98_Nuclei_Multiome-v1      │          4          │
│                        │     C104_Nuclei_Multiome-v1     │          5          │
│                        │    Hst33_Nuclei_Multiome-v1     │          6          │
│                        │    Hst36_Nuclei_Multiome-v1     │          7          │
│                        │    Hst39_Nuclei_Multiome-v1     │          8          │
│                        │    Hst40_Nuclei_Multiome-v1     │          9          │
│                        │    Hst41_Nuclei_Multiome-v1     │         10          │
│                        │                                 │                     │
│  adata.obs['region']   │              aorta              │          0          │
│                        │              apex               │          1          │
│                        │              atria              │          2          │
│                        │          atrial septum          │          3          │
│                        │        ductus arteriosus        │          4          │
│                        │       heart without node        │          5          │
│                        │         left ventricle          │          6          │
│                        │              node               │          7          │
│                        │          outflow tract          │          8          │
│                        │           pericardium           │          9          │
│                        │  pulmonary arches and branches  │         10          │
│                        │         right ventricle         │         11          │
│                        │ right ventricle and papillaries │         12          │
│                        │          whole sample           │         13          │
│                        │                                 │                     │
└────────────────────────┴─────────────────────────────────┴─────────────────────┘
```

Example 125 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 126 (unknown):
```unknown
Epoch 113/500:  23%|███████████████████████████████▋                                                                                                            | 113/500 [08:31<29:13,  4.53s/it, loss=4.23e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 37883.770. Signaling Trainer to stop.
```

Example 127 (unknown):
```unknown
###### MuralCells ######
(3103, 508040)
```

Example 128 (python):
```python
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/scvi/data/_utils.py:168: UserWarning: Category 1 in adata.obs['region'] has fewer than 3 cells. Models may not train properly.
  warnings.warn(
```

Example 129 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 130 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 131 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key', 'region'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 132 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  3103  │
│ n_extra_categorical_covs │   2    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 133 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 134 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 135 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 136 (python):
```python
extra_categorical_covs State Registry                       
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃           Categories            ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │     C82_Nuclei_Multiome-v1      │          0          │
│                        │     C85_Nuclei_Multiome-v1      │          1          │
│                        │     C87_Nuclei_Multiome-v1      │          2          │
│                        │     C92_Nuclei_Multiome-v1      │          3          │
│                        │     C98_Nuclei_Multiome-v1      │          4          │
│                        │     C104_Nuclei_Multiome-v1     │          5          │
│                        │    Hst33_Nuclei_Multiome-v1     │          6          │
│                        │    Hst36_Nuclei_Multiome-v1     │          7          │
│                        │    Hst39_Nuclei_Multiome-v1     │          8          │
│                        │    Hst40_Nuclei_Multiome-v1     │          9          │
│                        │    Hst41_Nuclei_Multiome-v1     │         10          │
│                        │                                 │                     │
│  adata.obs['region']   │              aorta              │          0          │
│                        │              apex               │          1          │
│                        │              atria              │          2          │
│                        │          atrial septum          │          3          │
│                        │        ductus arteriosus        │          4          │
│                        │       heart without node        │          5          │
│                        │         left ventricle          │          6          │
│                        │              node               │          7          │
│                        │          outflow tract          │          8          │
│                        │           pericardium           │          9          │
│                        │  pulmonary arches and branches  │         10          │
│                        │         right ventricle         │         11          │
│                        │ right ventricle and papillaries │         12          │
│                        │          whole sample           │         13          │
│                        │                                 │                     │
└────────────────────────┴─────────────────────────────────┴─────────────────────┘
```

Example 137 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 138 (unknown):
```unknown
Epoch 90/500:  18%|█████████████████████████▏                                                                                                                  | 90/500 [15:26<1:10:22, 10.30s/it, loss=3.15e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 27358.064. Signaling Trainer to stop.
```

Example 139 (unknown):
```unknown
###### Fibroblasts ######
(6969, 508040)
```

Example 140 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 141 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 142 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key', 'region'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 143 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  6969  │
│ n_extra_categorical_covs │   2    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 144 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 145 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 146 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 147 (python):
```python
extra_categorical_covs State Registry                       
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃           Categories            ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │     C82_Nuclei_Multiome-v1      │          0          │
│                        │     C85_Nuclei_Multiome-v1      │          1          │
│                        │     C87_Nuclei_Multiome-v1      │          2          │
│                        │     C92_Nuclei_Multiome-v1      │          3          │
│                        │     C98_Nuclei_Multiome-v1      │          4          │
│                        │     C104_Nuclei_Multiome-v1     │          5          │
│                        │    Hst33_Nuclei_Multiome-v1     │          6          │
│                        │    Hst36_Nuclei_Multiome-v1     │          7          │
│                        │    Hst39_Nuclei_Multiome-v1     │          8          │
│                        │    Hst40_Nuclei_Multiome-v1     │          9          │
│                        │    Hst41_Nuclei_Multiome-v1     │         10          │
│                        │                                 │                     │
│  adata.obs['region']   │              aorta              │          0          │
│                        │              apex               │          1          │
│                        │              atria              │          2          │
│                        │          atrial septum          │          3          │
│                        │        ductus arteriosus        │          4          │
│                        │       heart without node        │          5          │
│                        │         left ventricle          │          6          │
│                        │              node               │          7          │
│                        │          outflow tract          │          8          │
│                        │           pericardium           │          9          │
│                        │  pulmonary arches and branches  │         10          │
│                        │         right ventricle         │         11          │
│                        │ right ventricle and papillaries │         12          │
│                        │          whole sample           │         13          │
│                        │                                 │                     │
└────────────────────────┴─────────────────────────────────┴─────────────────────┘
```

Example 148 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 149 (unknown):
```unknown
Epoch 73/500:  15%|████████████████████▍                                                                                                                       | 73/500 [28:09<2:44:43, 23.15s/it, loss=4.02e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 29998.793. Signaling Trainer to stop.
```

Example 150 (unknown):
```unknown
###### MyeloidCells ######
(4321, 508040)
```

Example 151 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 152 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 153 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key', 'region'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 154 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  4321  │
│ n_extra_categorical_covs │   2    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 155 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 156 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 157 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 158 (python):
```python
extra_categorical_covs State Registry                       
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃           Categories            ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │     C82_Nuclei_Multiome-v1      │          0          │
│                        │     C85_Nuclei_Multiome-v1      │          1          │
│                        │     C87_Nuclei_Multiome-v1      │          2          │
│                        │     C92_Nuclei_Multiome-v1      │          3          │
│                        │     C98_Nuclei_Multiome-v1      │          4          │
│                        │     C104_Nuclei_Multiome-v1     │          5          │
│                        │    Hst33_Nuclei_Multiome-v1     │          6          │
│                        │    Hst36_Nuclei_Multiome-v1     │          7          │
│                        │    Hst39_Nuclei_Multiome-v1     │          8          │
│                        │    Hst40_Nuclei_Multiome-v1     │          9          │
│                        │    Hst41_Nuclei_Multiome-v1     │         10          │
│                        │                                 │                     │
│  adata.obs['region']   │              aorta              │          0          │
│                        │              apex               │          1          │
│                        │              atria              │          2          │
│                        │          atrial septum          │          3          │
│                        │        ductus arteriosus        │          4          │
│                        │       heart without node        │          5          │
│                        │         left ventricle          │          6          │
│                        │              node               │          7          │
│                        │          outflow tract          │          8          │
│                        │           pericardium           │          9          │
│                        │  pulmonary arches and branches  │         10          │
│                        │         right ventricle         │         11          │
│                        │ right ventricle and papillaries │         12          │
│                        │          whole sample           │         13          │
│                        │                                 │                     │
└────────────────────────┴─────────────────────────────────┴─────────────────────┘
```

Example 159 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 160 (unknown):
```unknown
Epoch 84/500:  17%|███████████████████████▌                                                                                                                    | 84/500 [20:24<1:41:05, 14.58s/it, loss=3.46e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 29149.953. Signaling Trainer to stop.
```

Example 161 (unknown):
```unknown
###### LymphaticEndothelialCells ######
(1000, 508040)
```

Example 162 (python):
```python
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/scvi/data/_utils.py:168: UserWarning: Category 5 in adata.obs['batch_key'] has fewer than 3 cells. Models may not train properly.
  warnings.warn(
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/scvi/data/_utils.py:168: UserWarning: Category 1 in adata.obs['region'] has fewer than 3 cells. Models may not train properly.
  warnings.warn(
```

Example 163 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 164 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 165 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key', 'region'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 166 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  1000  │
│ n_extra_categorical_covs │   2    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 167 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 168 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 169 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 170 (python):
```python
extra_categorical_covs State Registry                       
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃           Categories            ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │     C82_Nuclei_Multiome-v1      │          0          │
│                        │     C85_Nuclei_Multiome-v1      │          1          │
│                        │     C87_Nuclei_Multiome-v1      │          2          │
│                        │     C92_Nuclei_Multiome-v1      │          3          │
│                        │     C98_Nuclei_Multiome-v1      │          4          │
│                        │     C104_Nuclei_Multiome-v1     │          5          │
│                        │    Hst33_Nuclei_Multiome-v1     │          6          │
│                        │    Hst36_Nuclei_Multiome-v1     │          7          │
│                        │    Hst39_Nuclei_Multiome-v1     │          8          │
│                        │    Hst40_Nuclei_Multiome-v1     │          9          │
│                        │    Hst41_Nuclei_Multiome-v1     │         10          │
│                        │                                 │                     │
│  adata.obs['region']   │              aorta              │          0          │
│                        │              apex               │          1          │
│                        │              atria              │          2          │
│                        │          atrial septum          │          3          │
│                        │        ductus arteriosus        │          4          │
│                        │       heart without node        │          5          │
│                        │         left ventricle          │          6          │
│                        │              node               │          7          │
│                        │          outflow tract          │          8          │
│                        │           pericardium           │          9          │
│                        │  pulmonary arches and branches  │         10          │
│                        │         right ventricle         │         11          │
│                        │ right ventricle and papillaries │         12          │
│                        │          whole sample           │         13          │
│                        │                                 │                     │
└────────────────────────┴─────────────────────────────────┴─────────────────────┘
```

Example 171 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/trainer.py:1892: PossibleUserWarning: The number of training batches (8) is smaller than the logging interval Trainer(log_every_n_steps=10). Set a lower value for log_every_n_steps if you want to see logs for the training epoch.
  rank_zero_warn(
```

Example 172 (unknown):
```unknown
Epoch 105/500:  21%|█████████████████████████████▍                                                                                                              | 105/500 [06:14<23:29,  3.57s/it, loss=3.15e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 30158.045. Signaling Trainer to stop.
```

Example 173 (python):
```python
# NOT adding 'region' as covariate
outdir = '/nfs/team205/heart/anndata_objects/Foetal/multiome_ATAC/ArchR/project_output/PeakMatrix/mid_grain_mod'

for celltype in set(adata.obs['mid_grain_mod']):
    print(f'###### {celltype} ######')
    
    # subset
    adata_sub = adata[adata.obs['mid_grain_mod']==celltype]
    print(adata_sub.shape)
    adata_sub = adata_sub.copy()
    
    # train
    scvi.model.PEAKVI.setup_anndata(adata_sub, 
                                    categorical_covariate_keys=['batch_key']
                                   )
    pvi = scvi.model.PEAKVI(adata_sub)
    pvi.view_anndata_setup(adata_sub)
    pvi.train()
    
    # add to anndata
    latent = pvi.get_latent_representation()
    adata_sub.obsm["X_PeakVI"] = latent
    
    # save
    adata_sub.write(f'{outdir}/Foetal_{celltype}_Peaks_post-peakVI_subsampled-n1000.h5ad')
    pvi.save(f'{outdir}/Foetal_{celltype}_subsampled-n1000_peakVI-model', overwrite=True)
    
    # Convergency plot
    pvi.history['elbo_train']
    x = np.linspace(1, (len(pvi.history['elbo_train'])), (len(pvi.history['elbo_train'])))
    plt.plot(x, pvi.history['elbo_train'], label="train")
    plt.xlabel('epoch')
    plt.ylabel('elbo_train')
    plt.title(celltype)
    plt.show()
    
    # free up GPU
    del(pvi)
    gc.collect()
    torch.cuda.empty_cache()
```

Example 174 (unknown):
```unknown
###### AtrialCardiomyocytes_plusCCS ######
(4381, 508040)
```

Example 175 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 176 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 177 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 178 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  4381  │
│ n_extra_categorical_covs │   1    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 179 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 180 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 181 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 182 (python):
```python
extra_categorical_covs State Registry                   
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃        Categories        ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │  C82_Nuclei_Multiome-v1  │          0          │
│                        │  C85_Nuclei_Multiome-v1  │          1          │
│                        │  C87_Nuclei_Multiome-v1  │          2          │
│                        │  C92_Nuclei_Multiome-v1  │          3          │
│                        │  C98_Nuclei_Multiome-v1  │          4          │
│                        │ C104_Nuclei_Multiome-v1  │          5          │
│                        │ Hst33_Nuclei_Multiome-v1 │          6          │
│                        │ Hst36_Nuclei_Multiome-v1 │          7          │
│                        │ Hst39_Nuclei_Multiome-v1 │          8          │
│                        │ Hst40_Nuclei_Multiome-v1 │          9          │
│                        │ Hst41_Nuclei_Multiome-v1 │         10          │
│                        │                          │                     │
└────────────────────────┴──────────────────────────┴─────────────────────┘
```

Example 183 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 184 (unknown):
```unknown
Epoch 85/500:  17%|███████████████████████▉                                                                                                                     | 85/500 [20:32<1:40:16, 14.50s/it, loss=4.1e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 33508.570. Signaling Trainer to stop.
```

Example 185 (unknown):
```unknown
###### BloodVesselEndothelialCells ######
(3028, 508040)
```

Example 186 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 187 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 188 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 189 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  3028  │
│ n_extra_categorical_covs │   1    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 190 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 191 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 192 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 193 (python):
```python
extra_categorical_covs State Registry                   
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃        Categories        ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │  C82_Nuclei_Multiome-v1  │          0          │
│                        │  C85_Nuclei_Multiome-v1  │          1          │
│                        │  C87_Nuclei_Multiome-v1  │          2          │
│                        │  C92_Nuclei_Multiome-v1  │          3          │
│                        │  C98_Nuclei_Multiome-v1  │          4          │
│                        │ C104_Nuclei_Multiome-v1  │          5          │
│                        │ Hst33_Nuclei_Multiome-v1 │          6          │
│                        │ Hst36_Nuclei_Multiome-v1 │          7          │
│                        │ Hst39_Nuclei_Multiome-v1 │          8          │
│                        │ Hst40_Nuclei_Multiome-v1 │          9          │
│                        │ Hst41_Nuclei_Multiome-v1 │         10          │
│                        │                          │                     │
└────────────────────────┴──────────────────────────┴─────────────────────┘
```

Example 194 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 195 (unknown):
```unknown
Epoch 87/500:  17%|████████████████████████▎                                                                                                                   | 87/500 [14:41<1:09:46, 10.14s/it, loss=3.24e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 27426.242. Signaling Trainer to stop.
```

Example 196 (unknown):
```unknown
###### Glia ######
(1759, 508040)
```

Example 197 (python):
```python
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/scvi/data/_utils.py:168: UserWarning: Category 5 in adata.obs['batch_key'] has fewer than 3 cells. Models may not train properly.
  warnings.warn(
```

Example 198 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 199 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 200 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 201 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  1759  │
│ n_extra_categorical_covs │   1    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 202 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 203 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 204 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 205 (python):
```python
extra_categorical_covs State Registry                   
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃        Categories        ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │  C82_Nuclei_Multiome-v1  │          0          │
│                        │  C85_Nuclei_Multiome-v1  │          1          │
│                        │  C87_Nuclei_Multiome-v1  │          2          │
│                        │  C92_Nuclei_Multiome-v1  │          3          │
│                        │  C98_Nuclei_Multiome-v1  │          4          │
│                        │ C104_Nuclei_Multiome-v1  │          5          │
│                        │ Hst33_Nuclei_Multiome-v1 │          6          │
│                        │ Hst36_Nuclei_Multiome-v1 │          7          │
│                        │ Hst39_Nuclei_Multiome-v1 │          8          │
│                        │ Hst40_Nuclei_Multiome-v1 │          9          │
│                        │ Hst41_Nuclei_Multiome-v1 │         10          │
│                        │                          │                     │
└────────────────────────┴──────────────────────────┴─────────────────────┘
```

Example 206 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 207 (unknown):
```unknown
Epoch 100/500:  20%|████████████████████████████                                                                                                                | 100/500 [09:48<39:14,  5.89s/it, loss=3.08e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 27881.668. Signaling Trainer to stop.
```

Example 208 (unknown):
```unknown
###### Neurons ######
(1101, 508040)
```

Example 209 (python):
```python
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/scvi/data/_utils.py:168: UserWarning: Category 5 in adata.obs['batch_key'] has fewer than 3 cells. Models may not train properly.
  warnings.warn(
```

Example 210 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 211 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 212 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 213 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  1101  │
│ n_extra_categorical_covs │   1    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 214 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 215 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 216 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 217 (python):
```python
extra_categorical_covs State Registry                   
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃        Categories        ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │  C82_Nuclei_Multiome-v1  │          0          │
│                        │  C85_Nuclei_Multiome-v1  │          1          │
│                        │  C87_Nuclei_Multiome-v1  │          2          │
│                        │  C92_Nuclei_Multiome-v1  │          3          │
│                        │  C98_Nuclei_Multiome-v1  │          4          │
│                        │ C104_Nuclei_Multiome-v1  │          5          │
│                        │ Hst33_Nuclei_Multiome-v1 │          6          │
│                        │ Hst36_Nuclei_Multiome-v1 │          7          │
│                        │ Hst39_Nuclei_Multiome-v1 │          8          │
│                        │ Hst40_Nuclei_Multiome-v1 │          9          │
│                        │ Hst41_Nuclei_Multiome-v1 │         10          │
│                        │                          │                     │
└────────────────────────┴──────────────────────────┴─────────────────────┘
```

Example 218 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/trainer.py:1892: PossibleUserWarning: The number of training batches (8) is smaller than the logging interval Trainer(log_every_n_steps=10). Set a lower value for log_every_n_steps if you want to see logs for the training epoch.
  rank_zero_warn(
```

Example 219 (unknown):
```unknown
Epoch 110/500:  22%|██████████████████████████████▊                                                                                                             | 110/500 [06:52<24:23,  3.75s/it, loss=4.47e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 42944.938. Signaling Trainer to stop.
```

Example 220 (unknown):
```unknown
###### EndocardialCells ######
(1410, 508040)
```

Example 221 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 222 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 223 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 224 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  1410  │
│ n_extra_categorical_covs │   1    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 225 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 226 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 227 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 228 (python):
```python
extra_categorical_covs State Registry                   
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃        Categories        ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │  C82_Nuclei_Multiome-v1  │          0          │
│                        │  C85_Nuclei_Multiome-v1  │          1          │
│                        │  C87_Nuclei_Multiome-v1  │          2          │
│                        │  C92_Nuclei_Multiome-v1  │          3          │
│                        │  C98_Nuclei_Multiome-v1  │          4          │
│                        │ C104_Nuclei_Multiome-v1  │          5          │
│                        │ Hst33_Nuclei_Multiome-v1 │          6          │
│                        │ Hst36_Nuclei_Multiome-v1 │          7          │
│                        │ Hst39_Nuclei_Multiome-v1 │          8          │
│                        │ Hst40_Nuclei_Multiome-v1 │          9          │
│                        │ Hst41_Nuclei_Multiome-v1 │         10          │
│                        │                          │                     │
└────────────────────────┴──────────────────────────┴─────────────────────┘
```

Example 229 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 230 (unknown):
```unknown
Epoch 107/500:  21%|█████████████████████████████▉                                                                                                              | 107/500 [08:28<31:07,  4.75s/it, loss=3.81e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 34209.277. Signaling Trainer to stop.
```

Example 231 (unknown):
```unknown
###### VentricularCardiomyocytes_plusCCS ######
(6531, 508040)
```

Example 232 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 233 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 234 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 235 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  6531  │
│ n_extra_categorical_covs │   1    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 236 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 237 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 238 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 239 (python):
```python
extra_categorical_covs State Registry                   
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃        Categories        ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │  C82_Nuclei_Multiome-v1  │          0          │
│                        │  C85_Nuclei_Multiome-v1  │          1          │
│                        │  C87_Nuclei_Multiome-v1  │          2          │
│                        │  C92_Nuclei_Multiome-v1  │          3          │
│                        │  C98_Nuclei_Multiome-v1  │          4          │
│                        │ C104_Nuclei_Multiome-v1  │          5          │
│                        │ Hst33_Nuclei_Multiome-v1 │          6          │
│                        │ Hst36_Nuclei_Multiome-v1 │          7          │
│                        │ Hst39_Nuclei_Multiome-v1 │          8          │
│                        │ Hst40_Nuclei_Multiome-v1 │          9          │
│                        │ Hst41_Nuclei_Multiome-v1 │         10          │
│                        │                          │                     │
└────────────────────────┴──────────────────────────┴─────────────────────┘
```

Example 240 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 241 (unknown):
```unknown
Epoch 82/500:  16%|██████████████████████▉                                                                                                                     | 82/500 [30:02<2:33:06, 21.98s/it, loss=4.66e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 34396.367. Signaling Trainer to stop.
```

Example 242 (unknown):
```unknown
###### PericardialCells ######
(2187, 508040)
```

Example 243 (python):
```python
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/scvi/data/_utils.py:168: UserWarning: Category 3 in adata.obs['batch_key'] has fewer than 3 cells. Models may not train properly.
  warnings.warn(
```

Example 244 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 245 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 246 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 247 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  2187  │
│ n_extra_categorical_covs │   1    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 248 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 249 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 250 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 251 (python):
```python
extra_categorical_covs State Registry                   
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃        Categories        ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │  C87_Nuclei_Multiome-v1  │          0          │
│                        │  C92_Nuclei_Multiome-v1  │          1          │
│                        │  C98_Nuclei_Multiome-v1  │          2          │
│                        │ C104_Nuclei_Multiome-v1  │          3          │
│                        │ Hst39_Nuclei_Multiome-v1 │          4          │
│                        │ Hst40_Nuclei_Multiome-v1 │          5          │
│                        │ Hst41_Nuclei_Multiome-v1 │          6          │
│                        │                          │                     │
└────────────────────────┴──────────────────────────┴─────────────────────┘
```

Example 252 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 253 (unknown):
```unknown
Epoch 89/500:  18%|█████████████████████████▎                                                                                                                    | 89/500 [10:57<50:34,  7.38s/it, loss=3.53e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 30579.912. Signaling Trainer to stop.
```

Example 254 (unknown):
```unknown
###### LymphoidCells ######
(7006, 508040)
```

Example 255 (python):
```python
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/scvi/data/_utils.py:168: UserWarning: Category 4 in adata.obs['batch_key'] has fewer than 3 cells. Models may not train properly.
  warnings.warn(
```

Example 256 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 257 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 258 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 259 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  7006  │
│ n_extra_categorical_covs │   1    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 260 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 261 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 262 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 263 (python):
```python
extra_categorical_covs State Registry                   
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃        Categories        ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │  C82_Nuclei_Multiome-v1  │          0          │
│                        │  C85_Nuclei_Multiome-v1  │          1          │
│                        │  C87_Nuclei_Multiome-v1  │          2          │
│                        │  C92_Nuclei_Multiome-v1  │          3          │
│                        │  C98_Nuclei_Multiome-v1  │          4          │
│                        │ Hst33_Nuclei_Multiome-v1 │          5          │
│                        │ Hst36_Nuclei_Multiome-v1 │          6          │
│                        │ Hst39_Nuclei_Multiome-v1 │          7          │
│                        │ Hst40_Nuclei_Multiome-v1 │          8          │
│                        │ Hst41_Nuclei_Multiome-v1 │          9          │
│                        │                          │                     │
└────────────────────────┴──────────────────────────┴─────────────────────┘
```

Example 264 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 265 (unknown):
```unknown
Epoch 82/500:  16%|██████████████████████▉                                                                                                                     | 82/500 [32:31<2:45:47, 23.80s/it, loss=2.72e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 21162.615. Signaling Trainer to stop.
```

Example 266 (unknown):
```unknown
###### EpicardialCells ######
(1340, 508040)
```

Example 267 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 268 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 269 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 270 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  1340  │
│ n_extra_categorical_covs │   1    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 271 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 272 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 273 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 274 (python):
```python
extra_categorical_covs State Registry                   
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃        Categories        ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │  C82_Nuclei_Multiome-v1  │          0          │
│                        │  C85_Nuclei_Multiome-v1  │          1          │
│                        │  C87_Nuclei_Multiome-v1  │          2          │
│                        │  C92_Nuclei_Multiome-v1  │          3          │
│                        │  C98_Nuclei_Multiome-v1  │          4          │
│                        │ C104_Nuclei_Multiome-v1  │          5          │
│                        │ Hst33_Nuclei_Multiome-v1 │          6          │
│                        │ Hst36_Nuclei_Multiome-v1 │          7          │
│                        │ Hst39_Nuclei_Multiome-v1 │          8          │
│                        │ Hst40_Nuclei_Multiome-v1 │          9          │
│                        │ Hst41_Nuclei_Multiome-v1 │         10          │
│                        │                          │                     │
└────────────────────────┴──────────────────────────┴─────────────────────┘
```

Example 275 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 276 (unknown):
```unknown
Epoch 100/500:  20%|████████████████████████████                                                                                                                | 100/500 [07:39<30:37,  4.59s/it, loss=4.42e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 37964.527. Signaling Trainer to stop.
```

Example 277 (unknown):
```unknown
###### MuralCells ######
(3103, 508040)
```

Example 278 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 279 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 280 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 281 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  3103  │
│ n_extra_categorical_covs │   1    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 282 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 283 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 284 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 285 (python):
```python
extra_categorical_covs State Registry                   
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃        Categories        ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │  C82_Nuclei_Multiome-v1  │          0          │
│                        │  C85_Nuclei_Multiome-v1  │          1          │
│                        │  C87_Nuclei_Multiome-v1  │          2          │
│                        │  C92_Nuclei_Multiome-v1  │          3          │
│                        │  C98_Nuclei_Multiome-v1  │          4          │
│                        │ C104_Nuclei_Multiome-v1  │          5          │
│                        │ Hst33_Nuclei_Multiome-v1 │          6          │
│                        │ Hst36_Nuclei_Multiome-v1 │          7          │
│                        │ Hst39_Nuclei_Multiome-v1 │          8          │
│                        │ Hst40_Nuclei_Multiome-v1 │          9          │
│                        │ Hst41_Nuclei_Multiome-v1 │         10          │
│                        │                          │                     │
└────────────────────────┴──────────────────────────┴─────────────────────┘
```

Example 286 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 287 (unknown):
```unknown
Epoch 89/500:  18%|████████████████████████▉                                                                                                                   | 89/500 [15:13<1:10:20, 10.27s/it, loss=3.14e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 27392.287. Signaling Trainer to stop.
```

Example 288 (unknown):
```unknown
###### Fibroblasts ######
(6969, 508040)
```

Example 289 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 290 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 291 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 292 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  6969  │
│ n_extra_categorical_covs │   1    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 293 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 294 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 295 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 296 (python):
```python
extra_categorical_covs State Registry                   
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃        Categories        ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │  C82_Nuclei_Multiome-v1  │          0          │
│                        │  C85_Nuclei_Multiome-v1  │          1          │
│                        │  C87_Nuclei_Multiome-v1  │          2          │
│                        │  C92_Nuclei_Multiome-v1  │          3          │
│                        │  C98_Nuclei_Multiome-v1  │          4          │
│                        │ C104_Nuclei_Multiome-v1  │          5          │
│                        │ Hst33_Nuclei_Multiome-v1 │          6          │
│                        │ Hst36_Nuclei_Multiome-v1 │          7          │
│                        │ Hst39_Nuclei_Multiome-v1 │          8          │
│                        │ Hst40_Nuclei_Multiome-v1 │          9          │
│                        │ Hst41_Nuclei_Multiome-v1 │         10          │
│                        │                          │                     │
└────────────────────────┴──────────────────────────┴─────────────────────┘
```

Example 297 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 298 (unknown):
```unknown
Epoch 79/500:  16%|██████████████████████                                                                                                                      | 79/500 [30:43<2:43:41, 23.33s/it, loss=4.04e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 30068.029. Signaling Trainer to stop.
```

Example 299 (unknown):
```unknown
###### MyeloidCells ######
(4321, 508040)
```

Example 300 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 301 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 302 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 303 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  4321  │
│ n_extra_categorical_covs │   1    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 304 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 305 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 306 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 307 (python):
```python
extra_categorical_covs State Registry                   
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃        Categories        ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │  C82_Nuclei_Multiome-v1  │          0          │
│                        │  C85_Nuclei_Multiome-v1  │          1          │
│                        │  C87_Nuclei_Multiome-v1  │          2          │
│                        │  C92_Nuclei_Multiome-v1  │          3          │
│                        │  C98_Nuclei_Multiome-v1  │          4          │
│                        │ C104_Nuclei_Multiome-v1  │          5          │
│                        │ Hst33_Nuclei_Multiome-v1 │          6          │
│                        │ Hst36_Nuclei_Multiome-v1 │          7          │
│                        │ Hst39_Nuclei_Multiome-v1 │          8          │
│                        │ Hst40_Nuclei_Multiome-v1 │          9          │
│                        │ Hst41_Nuclei_Multiome-v1 │         10          │
│                        │                          │                     │
└────────────────────────┴──────────────────────────┴─────────────────────┘
```

Example 308 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 309 (unknown):
```unknown
Epoch 85/500:  17%|███████████████████████▊                                                                                                                    | 85/500 [20:33<1:40:20, 14.51s/it, loss=3.54e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 29083.998. Signaling Trainer to stop.
```

Example 310 (unknown):
```unknown
###### LymphaticEndothelialCells ######
(1000, 508040)
```

Example 311 (python):
```python
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/scvi/data/_utils.py:168: UserWarning: Category 5 in adata.obs['batch_key'] has fewer than 3 cells. Models may not train properly.
  warnings.warn(
```

Example 312 (unknown):
```unknown
Anndata setup with scvi-tools version 0.19.0.
```

Example 313 (unknown):
```unknown
Setup via `PEAKVI.setup_anndata` with arguments:
```

Example 314 (unknown):
```unknown
{
│   'batch_key': None,
│   'labels_key': None,
│   'categorical_covariate_keys': ['batch_key'],
│   'continuous_covariate_keys': None,
│   'layer': None
}
```

Example 315 (unknown):
```unknown
Summary Statistics          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃     Summary Stat Key     ┃ Value  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│         n_batch          │   1    │
│         n_cells          │  1000  │
│ n_extra_categorical_covs │   1    │
│ n_extra_continuous_covs  │   0    │
│         n_labels         │   1    │
│          n_vars          │ 508040 │
└──────────────────────────┴────────┘
```

Example 316 (python):
```python
Data Registry                             
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃      Registry Key      ┃            scvi-tools Location             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│           X            │                  adata.X                   │
│         batch          │          adata.obs['_scvi_batch']          │
│ extra_categorical_covs │ adata.obsm['_scvi_extra_categorical_covs'] │
│         labels         │         adata.obs['_scvi_labels']          │
└────────────────────────┴────────────────────────────────────────────┘
```

Example 317 (python):
```python
batch State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃     Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_batch'] │     0      │          0          │
└──────────────────────────┴────────────┴─────────────────────┘
```

Example 318 (python):
```python
labels State Registry                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃      Source Location      ┃ Categories ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['_scvi_labels'] │     0      │          0          │
└───────────────────────────┴────────────┴─────────────────────┘
```

Example 319 (python):
```python
extra_categorical_covs State Registry                   
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃    Source Location     ┃        Categories        ┃ scvi-tools Encoding ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ adata.obs['batch_key'] │  C82_Nuclei_Multiome-v1  │          0          │
│                        │  C85_Nuclei_Multiome-v1  │          1          │
│                        │  C87_Nuclei_Multiome-v1  │          2          │
│                        │  C92_Nuclei_Multiome-v1  │          3          │
│                        │  C98_Nuclei_Multiome-v1  │          4          │
│                        │ C104_Nuclei_Multiome-v1  │          5          │
│                        │ Hst33_Nuclei_Multiome-v1 │          6          │
│                        │ Hst36_Nuclei_Multiome-v1 │          7          │
│                        │ Hst39_Nuclei_Multiome-v1 │          8          │
│                        │ Hst40_Nuclei_Multiome-v1 │          9          │
│                        │ Hst41_Nuclei_Multiome-v1 │         10          │
│                        │                          │                     │
└────────────────────────┴──────────────────────────┴─────────────────────┘
```

Example 320 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/trainer.py:1892: PossibleUserWarning: The number of training batches (8) is smaller than the logging interval Trainer(log_every_n_steps=10). Set a lower value for log_every_n_steps if you want to see logs for the training epoch.
  rank_zero_warn(
```

Example 321 (unknown):
```unknown
Epoch 100/500:  20%|████████████████████████████                                                                                                                | 100/500 [05:55<23:41,  3.55s/it, loss=3.19e+08, v_num=1]
Monitored metric reconstruction_loss_validation did not improve in the last 50 records. Best score: 30174.766. Signaling Trainer to stop.
```

---

## Notebook

**URL:** http://127.0.0.1:9020/notebooks_html/Fig1_General_processing/RNA/QC/Demultiplex/No1_SOC_results_multiome-ATAC.html

**Contents:**
- Samples¶
- Read in and concatenate clusters.tsv¶
- Genotype matching¶
- 7089STDY13216920_BHF_F_Hea13242527¶
- 7089STDY13216921_BHF_F_Hea13242528¶
- 7089STDY13216922_BHF_F_Hea13242529¶
- 7089STDY13216923_BHF_F_Hea13242530¶
- Save clusters dataframe¶
- Proportions¶
- Doublets and scrublet score¶

74984 rows × 9 columns

will assign donors as below

**Examples:**

Example 1 (python):
```python
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import gaussian_kde

import scanpy as sc
```

Example 2 (unknown):
```unknown
# to use magic command %%R
%load_ext rpy2.ipython
```

Example 3 (unknown):
```unknown
%%R
library(GenotypeMixtures)
library(tidyverse)
```

Example 4 (unknown):
```unknown
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.4.0      ✔ purrr   0.3.4 
✔ tibble  3.1.8      ✔ dplyr   1.0.10
✔ tidyr   1.2.1      ✔ stringr 1.4.0 
✔ readr   2.1.3      ✔ forcats 0.5.1 
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
```

Example 5 (python):
```python
multiplexed_samples = pd.read_csv('/nfs/team205/heart/mapped/cellranger-arc200/csv/multiome-foetal_20221221.csv')
multiplexed_samples
```

Example 6 (python):
```python
# read in metadata
meta = pd.read_csv('/nfs/team205/heart/anndata_objects/Foetal/metadata/HeartTeamSamples_Mappeddata_20221223.csv', sep = ',', index_col = None)
meta = meta[meta['Publication']=='Foetal']
meta = meta[['sangerID', 'combinedID',
       'donor', 'donor_type', 'region', 'region_finest', 'age', 'gender',
       'facility', 'cell_or_nuclei', 'modality', 'kit_10x', 'flushed',
       'status']]

# select samples
meta = meta[meta['combinedID'].isin(multiplexed_samples['combinedID'])]

# select Multiome-ATAC
meta = meta[meta['modality']=='Multiome-ATAC']

# reindex
meta.index = range(len(meta))

meta
```

Example 7 (python):
```python
# min-ref/alt = 4
clusters_all = {}
multiplexed_IDs = ['7089STDY13216920_BHF_F_Hea13242527',
                   '7089STDY13216921_BHF_F_Hea13242528',
                   '7089STDY13216922_BHF_F_Hea13242529',
                   '7089STDY13216923_BHF_F_Hea13242530']

for i,ID in enumerate(multiplexed_IDs):
    df = pd.read_csv(f'/nfs/team205/heart/mapped/cellranger-arc200/SOC_out/{ID}/ATAC_SOC_common_variants/clusters.tsv', sep='\t')
    df['sample'] = ID
    if i==0:
        clusters_all = df.copy()
    else:
        clusters_all = pd.concat([clusters_all,df])
clusters_all = clusters_all[['sample', 'barcode', 'status', 'assignment', 'log_prob_singleton',
                           'log_prob_doublet', 'cluster0', 'cluster1', 'cluster2']]

# combine sample and barcode name: adata.obs_names
clusters_all['obsnames'] = clusters_all['sample'].astype('str')+'_'+clusters_all['barcode'].astype('str')
clusters_all.set_index('obsnames',inplace=True)

print(clusters_all['status'].value_counts())
clusters_all
```

Example 8 (javascript):
```javascript
singlet       63170
doublet        8383
unassigned     3431
Name: status, dtype: int64
```

Example 9 (unknown):
```unknown
set(clusters_all['sample'])
```

Example 10 (unknown):
```unknown
{'7089STDY13216920_BHF_F_Hea13242527',
 '7089STDY13216921_BHF_F_Hea13242528',
 '7089STDY13216922_BHF_F_Hea13242529',
 '7089STDY13216923_BHF_F_Hea13242530'}
```

Example 11 (python):
```python
# proportion of status in each genotype assignment
# most of them are singlet in single genotype assignment which is good
df = clusters_all.copy()

fig, axs = plt.subplots(nrows=1, ncols=len(multiplexed_IDs), figsize=(20,4)) 

for i,sam in enumerate(multiplexed_IDs):

    df = clusters_all[clusters_all['sample']==sam]
    tmp = pd.crosstab(df['assignment'], df['status'], normalize='index')
    # tmp.plot.bar().legend(loc=1)
    tmp.plot.bar(stacked=True,width=0.7,ax=axs[i])
    axs[i].grid(False)
    axs[i].set_ylabel('proportion')
    axs[i].set_title(sam)
    axs[i].legend(bbox_to_anchor=(1.0, 1.0))
    
plt.tight_layout()
```

Example 12 (python):
```python
# Proportion of status in each sample
# most are singlet
df = clusters_all.copy()
plt.rcParams['figure.figsize'] = 3,3
tmp = pd.crosstab(df['sample'], df['status'], 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()
```

Example 13 (unknown):
```unknown
# prepare the column for donor assignment
clusters_all['donor_assignment'] = 'donor_unassigned'
```

Example 14 (javascript):
```javascript
%%R -i meta
# prepare wrapper function
plot_result = function(ID, Donor){
    output_dir = '/nfs/team205/heart/mapped/cellranger-arc200/SOC_out/'
    
    if (Donor == 'Hst39'){
        ID_ref = '7089STDY13216926_BHF_F_Hea13242533'
    }else{
        ID_ref = meta %>% filter(donor==Donor) %>% pull(combinedID)
    }
    
    plot_cross_vaf(experiment_1_path = paste0(output_dir,ID,'/ATAC_SOC_common_variants/'), 
                   experiment_2_path = paste0(output_dir,ID_ref,'/ATAC_SOC_common_variants/'), 
                   experiment_1_name = strsplit(ID,'_')[[1]][1],
                   experiment_2_name = Donor)
}
```

Example 15 (unknown):
```unknown
targetID = '7089STDY13216920_BHF_F_Hea13242527'
```

Example 16 (unknown):
```unknown
%%R -i targetID
plot_result(ID=targetID, Donor='Hst39')
```

Example 17 (unknown):
```unknown
# assign donors
obsnames = clusters_all.index[(clusters_all['sample']==targetID)&\
                              (clusters_all['status']=='singlet')&\
                              (clusters_all['assignment']=='0')]
clusters_all.loc[obsnames,'donor_assignment'] = 'Hst39'
targetID
```

Example 18 (unknown):
```unknown
'7089STDY13216920_BHF_F_Hea13242527'
```

Example 19 (unknown):
```unknown
%%R -i targetID
plot_result(ID=targetID, Donor='Hst40')
```

Example 20 (unknown):
```unknown
# assign donors
obsnames = clusters_all.index[(clusters_all['sample']==targetID)&\
                              (clusters_all['status']=='singlet')&\
                              (clusters_all['assignment']=='1')]
clusters_all.loc[obsnames,'donor_assignment'] = 'Hst40'
targetID
```

Example 21 (unknown):
```unknown
'7089STDY13216920_BHF_F_Hea13242527'
```

Example 22 (unknown):
```unknown
targetID = '7089STDY13216921_BHF_F_Hea13242528'
```

Example 23 (unknown):
```unknown
%%R -i targetID
plot_result(ID=targetID, Donor='Hst39')
```

Example 24 (unknown):
```unknown
# assign donors
obsnames = clusters_all.index[(clusters_all['sample']==targetID)&\
                              (clusters_all['status']=='singlet')&\
                              (clusters_all['assignment']=='1')]
clusters_all.loc[obsnames,'donor_assignment'] = 'Hst39'
targetID
```

Example 25 (unknown):
```unknown
'7089STDY13216921_BHF_F_Hea13242528'
```

Example 26 (unknown):
```unknown
%%R -i targetID
plot_result(ID=targetID, Donor='Hst40')
```

Example 27 (unknown):
```unknown
# assign donors
obsnames = clusters_all.index[(clusters_all['sample']==targetID)&\
                              (clusters_all['status']=='singlet')&\
                              (clusters_all['assignment']=='0')]
clusters_all.loc[obsnames,'donor_assignment'] = 'Hst40'
targetID
```

Example 28 (unknown):
```unknown
'7089STDY13216921_BHF_F_Hea13242528'
```

Example 29 (unknown):
```unknown
%%R
output_dir = '/nfs/team205/heart/mapped/cellranger-arc200/SOC_out/'
plot_cross_vaf(experiment_1_path = paste0(output_dir,'7089STDY13216920_BHF_F_Hea13242527','/ATAC_SOC_common_variants/'), 
                   experiment_2_path = paste0(output_dir,'7089STDY13216921_BHF_F_Hea13242528','/ATAC_SOC_common_variants/'), 
                   experiment_1_name = '7089STDY13216920',
                   experiment_2_name = '7089STDY13216921')
```

Example 30 (unknown):
```unknown
targetID = '7089STDY13216922_BHF_F_Hea13242529'
```

Example 31 (unknown):
```unknown
%%R -i targetID
plot_result(ID=targetID, Donor='Hst36')
```

Example 32 (unknown):
```unknown
# assign donors
obsnames = clusters_all.index[(clusters_all['sample']==targetID)&\
                              (clusters_all['status']=='singlet')&\
                              (clusters_all['assignment']=='2')]
clusters_all.loc[obsnames,'donor_assignment'] = 'Hst36'
targetID
```

Example 33 (unknown):
```unknown
'7089STDY13216922_BHF_F_Hea13242529'
```

Example 34 (unknown):
```unknown
%%R -i targetID
plot_result(ID=targetID, Donor='Hst39')
```

Example 35 (unknown):
```unknown
# assign donors
obsnames = clusters_all.index[(clusters_all['sample']==targetID)&\
                              (clusters_all['status']=='singlet')&\
                              (clusters_all['assignment']=='0')]
clusters_all.loc[obsnames,'donor_assignment'] = 'Hst39'
targetID
```

Example 36 (unknown):
```unknown
'7089STDY13216922_BHF_F_Hea13242529'
```

Example 37 (unknown):
```unknown
%%R -i targetID
plot_result(ID=targetID, Donor='Hst40')
```

Example 38 (unknown):
```unknown
# assign donors
obsnames = clusters_all.index[(clusters_all['sample']==targetID)&\
                              (clusters_all['status']=='singlet')&\
                              (clusters_all['assignment']=='1')]
clusters_all.loc[obsnames,'donor_assignment'] = 'Hst40'
targetID
```

Example 39 (unknown):
```unknown
'7089STDY13216922_BHF_F_Hea13242529'
```

Example 40 (unknown):
```unknown
targetID = '7089STDY13216923_BHF_F_Hea13242530'
```

Example 41 (unknown):
```unknown
%%R -i targetID
plot_result(ID=targetID, Donor='Hst36')
```

Example 42 (unknown):
```unknown
'''
obsnames = clusters_all.index[(clusters_all['sample']==targetID)&(clusters_all['assignment']==    )]
clusters_all.loc[obsnames,'donor_assignment'] = 'Hst36'
targetID
'''
```

Example 43 (unknown):
```unknown
%%R -i targetID
plot_result(ID=targetID, Donor='Hst39')
```

Example 44 (unknown):
```unknown
'''
obsnames = clusters_all.index[(clusters_all['sample']==targetID)&(clusters_all['assignment']==    )]
clusters_all.loc[obsnames,'donor_assignment'] = 'Hst39'
targetID
'''
```

Example 45 (unknown):
```unknown
%%R -i targetID
plot_result(ID=targetID, Donor='Hst40')
```

Example 46 (unknown):
```unknown
'''
obsnames = clusters_all.index[(clusters_all['sample']==targetID)&(clusters_all['assignment']==    )]
clusters_all.loc[obsnames,'donor_assignment'] = 'Hst40'
targetID
'''
```

Example 47 (unknown):
```unknown
%%R
output_dir = '/nfs/team205/heart/mapped/cellranger-arc200/SOC_out/'
plot_cross_vaf(experiment_1_path = paste0(output_dir,'7089STDY13216922_BHF_F_Hea13242529','/ATAC_SOC_common_variants/'), 
                   experiment_2_path = paste0(output_dir,'7089STDY13216923_BHF_F_Hea13242530','/ATAC_SOC_common_variants/'), 
                   experiment_1_name = '7089STDY13216922',
                   experiment_2_name = '7089STDY13216923')
```

Example 48 (unknown):
```unknown
clusters_all.head()
```

Example 49 (unknown):
```unknown
clusters_all.to_csv('/nfs/team205/heart/mapped/cellranger-arc200/SOC_out/SOC-clusters_multiome-foetal_20221221.csv')
```

Example 50 (python):
```python
df = clusters_all.copy()
plt.rcParams['figure.figsize'] = 3,3
tmp = pd.crosstab(df['sample'], df['donor_assignment'], 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()

for sam in multiplexed_IDs:
    df_s = df[df['sample']==sam]
    print(f'##### {sam} #####')
    print(df_s['donor_assignment'].value_counts())
    print('')
```

Example 51 (unknown):
```unknown
##### 7089STDY13216920_BHF_F_Hea13242527 #####
Hst39               16670
Hst40                6894
donor_unassigned     3934
Name: donor_assignment, dtype: int64

##### 7089STDY13216921_BHF_F_Hea13242528 #####
Hst39               14867
Hst40                5944
donor_unassigned     3400
Name: donor_assignment, dtype: int64

##### 7089STDY13216922_BHF_F_Hea13242529 #####
Hst40               7408
Hst36               5093
Hst39               4786
donor_unassigned    4115
Name: donor_assignment, dtype: int64

##### 7089STDY13216923_BHF_F_Hea13242530 #####
donor_unassigned    1873
Name: donor_assignment, dtype: int64
```

Example 52 (python):
```python
# reason why donor was unassigned
df = clusters_all[clusters_all['donor_assignment']=='donor_unassigned']
plt.rcParams['figure.figsize'] = 3,3
tmp = pd.crosstab(df['sample'], df['status'], 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()

for sam in multiplexed_IDs:
    df_s = df[df['sample']==sam]
    print(f'##### {sam} #####')
    print(df_s['status'].value_counts())
    print('')
```

Example 53 (javascript):
```javascript
##### 7089STDY13216920_BHF_F_Hea13242527 #####
doublet       3086
unassigned     848
Name: status, dtype: int64

##### 7089STDY13216921_BHF_F_Hea13242528 #####
doublet       2655
unassigned     745
Name: status, dtype: int64

##### 7089STDY13216922_BHF_F_Hea13242529 #####
doublet       2362
unassigned    1753
Name: status, dtype: int64

##### 7089STDY13216923_BHF_F_Hea13242530 #####
singlet       1508
doublet        280
unassigned      85
Name: status, dtype: int64
```

Example 54 (python):
```python
# post-cellbender anndata
adata = sc.read_h5ad('/nfs/team205/heart/anndata_objects/Foetal/QC/multiome_RNA_foetal_prefilter.h5ad',
                     backed = 'r')
# only multiplexed data
adata = adata[adata.obs['combinedID'].isin(multiplexed_IDs)]

adata
```

Example 55 (unknown):
```unknown
View of AnnData object with n_obs × n_vars = 74984 × 36601 backed at '/nfs/team205/heart/anndata_objects/Foetal/QC/multiome_RNA_foetal_prefilter.h5ad'
    obs: 'latent_RT_efficiency', 'latent_cell_probability', 'latent_scale', 'sangerID', 'combinedID', 'donor', 'donor_type', 'region', 'region_finest', 'age', 'gender', 'facility', 'cell_or_nuclei', 'modality', 'kit_10x', 'flushed', 'scrublet_score', 'scrublet_leiden', 'cluster_scrublet_score', 'doublet_pval', 'doublet_bh_pval'
    var: 'gene_name', 'feature_type', 'ambient_expression-0', 'ambient_expression-1', 'ambient_expression-10', 'ambient_expression-11', 'ambient_expression-12', 'ambient_expression-13', 'ambient_expression-14', 'ambient_expression-15', 'ambient_expression-16', 'ambient_expression-17', 'ambient_expression-18', 'ambient_expression-19', 'ambient_expression-2', 'ambient_expression-20', 'ambient_expression-21', 'ambient_expression-22', 'ambient_expression-23', 'ambient_expression-24', 'ambient_expression-25', 'ambient_expression-26', 'ambient_expression-27', 'ambient_expression-28', 'ambient_expression-29', 'ambient_expression-3', 'ambient_expression-30', 'ambient_expression-31', 'ambient_expression-32', 'ambient_expression-33', 'ambient_expression-34', 'ambient_expression-35', 'ambient_expression-36', 'ambient_expression-37', 'ambient_expression-4', 'ambient_expression-5', 'ambient_expression-6', 'ambient_expression-7', 'ambient_expression-8', 'ambient_expression-9'
    obsm: 'latent_gene_encoding'
```

Example 56 (python):
```python
sc.settings.set_figure_params(dpi=120)
```

Example 57 (python):
```python
# add
col_to_add = ['status', 'assignment', 'log_prob_singleton',
               'log_prob_doublet', 'cluster0', 'cluster1', 'cluster2',
               'donor_assignment']
df = adata.obs.copy()
df[[f'SOC | {x}' for x in col_to_add]] = clusters_all[col_to_add].reindex(df.index)

sns.violinplot(data=df, x="scrublet_score", y="SOC | status")
plt.show()

df['SOC | status'].value_counts()
```

Example 58 (javascript):
```javascript
singlet       63170
doublet        8383
unassigned     3431
Name: SOC | status, dtype: int64
```

---

## Notebook

**URL:** http://127.0.0.1:9020/notebooks_html/Fig1_General_processing/ATAC/ATAC/post_peakVI_UMAPs.html

**Contents:**
- Import module¶
- Read in data¶
- Prepare color palette¶
- Plotting¶

**Examples:**

Example 1 (python):
```python
import numpy as np
import pandas as pd 
import scanpy as sc
import matplotlib.pyplot as plt
import matplotlib as mpl
# enables correct plotting of text
mpl.rcParams['pdf.fonttype'] = 42
mpl.rcParams['ps.fonttype'] = 42 
import seaborn as sns
# import sctk
```

Example 2 (python):
```python
import session_info
session_info.show()
```

Example 3 (python):
```python
-----
anndata             0.9.2
matplotlib          3.7.2
numpy               1.24.4
pandas              1.5.3
scanpy              1.9.3
seaborn             0.12.2
session_info        1.0.0
-----
```

Example 4 (python):
```python
PIL                         10.0.0
anyio                       NA
arrow                       1.2.3
asttokens                   NA
attr                        23.1.0
attrs                       23.1.0
babel                       2.12.1
backcall                    0.2.0
brotli                      1.0.9
certifi                     2023.11.17
cffi                        1.15.1
charset_normalizer          3.2.0
colorama                    0.4.6
comm                        0.1.4
cycler                      0.10.0
cython_runtime              NA
dateutil                    2.8.2
debugpy                     1.6.8
decorator                   5.1.1
defusedxml                  0.7.1
executing                   1.2.0
fastjsonschema              NA
fqdn                        NA
h5py                        3.9.0
idna                        3.4
igraph                      0.10.6
importlib_metadata          NA
importlib_resources         NA
ipykernel                   6.25.1
isoduration                 NA
jedi                        0.19.0
jinja2                      3.1.2
joblib                      1.3.2
json5                       NA
jsonpointer                 2.0
jsonschema                  4.19.0
jsonschema_specifications   NA
jupyter_events              0.7.0
jupyter_server              2.7.1
jupyterlab_server           2.24.0
kiwisolver                  1.4.5
leidenalg                   0.10.1
llvmlite                    0.40.1
markupsafe                  2.1.3
matplotlib_inline           0.1.6
mpl_toolkits                NA
natsort                     8.4.0
nbformat                    5.9.2
numba                       0.57.1
overrides                   NA
packaging                   23.1
parso                       0.8.3
patsy                       0.5.3
pexpect                     4.8.0
pickleshare                 0.7.5
pkg_resources               NA
plotly                      5.16.1
prometheus_client           NA
prompt_toolkit              3.0.39
psutil                      5.9.5
ptyprocess                  0.7.0
pure_eval                   0.2.2
pydev_ipython               NA
pydevconsole                NA
pydevd                      2.9.5
pydevd_file_utils           NA
pydevd_plugins              NA
pydevd_tracing              NA
pygments                    2.16.1
pyparsing                   3.0.9
pythonjsonlogger            NA
pytz                        2023.3
referencing                 NA
requests                    2.31.0
rfc3339_validator           0.1.4
rfc3986_validator           0.1.1
rpds                        NA
ruamel                      NA
scipy                       1.10.1
send2trash                  NA
six                         1.16.0
sklearn                     1.3.0
sniffio                     1.3.0
socks                       1.7.1
sphinxcontrib               NA
stack_data                  0.6.2
statsmodels                 0.14.0
texttable                   1.6.7
threadpoolctl               3.2.0
tornado                     6.3.3
traitlets                   5.9.0
typing_extensions           NA
uri_template                NA
urllib3                     2.0.4
wcwidth                     0.2.6
webcolors                   1.13
websocket                   1.6.2
yaml                        6.0.1
zipp                        NA
zmq                         25.1.1
zstandard                   0.19.0
```

Example 5 (unknown):
```unknown
-----
IPython             8.12.0
jupyter_client      8.3.0
jupyter_core        4.12.0
jupyterlab          4.0.5
notebook            7.0.2
-----
Python 3.8.17 (default, Jul  5 2023, 21:04:15) [GCC 11.2.0]
Linux-5.4.0-169-generic-x86_64-with-glibc2.17
-----
Session information updated at 2024-02-05 10:41
```

Example 6 (python):
```python
import importlib.util
import sys
spec = importlib.util.spec_from_file_location("module.name", "/nfs/team205/kk18/function/python/utils.py")
utils = importlib.util.module_from_spec(spec)
sys.modules["module.name"] = utils
spec.loader.exec_module(utils)
```

Example 7 (python):
```python
sc.settings.set_figure_params(dpi=120,dpi_save=300)
```

Example 8 (unknown):
```unknown
figdir = '/nfs/team205/heart/fetal_ms_figures/raw_plots_kk'
```

Example 9 (python):
```python
adata = sc.read_h5ad('/nfs/team205/heart/anndata_objects/Foetal/multiome_ATAC/ArchR/project_output/PeakMatrix/Foetal_Peaks_post-peakVI_umap.h5ad')
adata
```

Example 10 (unknown):
```unknown
AnnData object with n_obs × n_vars = 167022 × 508040
    obs: 'sangerID', 'combinedID', 'donor', 'facility', 'cell_or_nuclei', 'modality', 'kit_10x', 'scrublet_score', 'doublet_pval', 'doublet_bh_pval', 'n_genes', 'n_counts', 'n_genes_by_counts', 'log1p_n_genes_by_counts', 'total_counts', 'log1p_total_counts', 'total_counts_mt', 'log1p_total_counts_mt', 'pct_counts_mt', 'total_counts_ribo', 'log1p_total_counts_ribo', 'pct_counts_ribo', 'HB_score', 'multiplexed', 'batch_key', 'region', 'FACSgate', 'sex', 'week', 'trimester', 'fine_grain', 'mid_grain', 'coarse_grain', 'heart_or_greatvessels', 'cycling', 'S_score', 'G2M_score', 'phase', 'stress_score', 'hb1_score', '_scvi_batch', '_scvi_labels', 'cluster_pvi'
    uns: '_scvi_manager_uuid', '_scvi_uuid', 'leiden', 'neighbors', 'umap'
    obsm: 'X_PeakVI', 'X_umap'
    obsp: 'connectivities', 'distances'
```

Example 11 (python):
```python
adata.obs['fine_grain'].cat.categories
```

Example 12 (unknown):
```unknown
Index(['InnateLymphoidCells', 'AtrialCardiomyocytesLeft',
       'AtrialCardiomyocytesRight', 'AtrialCardiomyocytesCycling',
       'VentricularCardiomyocytesLeftCompact',
       'VentricularCardiomyocytesRightCompact',
       'VentricularCardiomyocytesLeftTrabeculated',
       'VentricularCardiomyocytesRightTrabeculated',
       'VentricularCardiomyocytesCycling', 'SinoatrialNodePacemakerCells',
       'AtrioventriclarNodePacemakerCells',
       'VentricularConductionSystemProximal',
       'VentricularConductionSystemDistal',
       'GreatVesselAdventitialFibroblasts',
       'CoronaryVesselAdventitialFibroblasts',
       'MyocardialInterstitialFibroblasts', 'SubEpicardialFibroblasts',
       'Myofibroblasts', 'LymphNodeFibroblasticReticularCells',
       'ValveInterstitialCells', 'GreatVesselSmoothMuscleCells',
       'CoronarySmoothMuscleCells', 'DuctusArteriosusSmoothMuscleCells',
       'CoronaryPericytes', 'PericardialCellsIntermediate',
       'PericardialCellsFibrous', 'PericardialCellsParietal',
       'GreatVesselArterialEndothelialCells',
       'GreatVesselVenousEndothelialCells', 'CoronaryArterialEndothelialCells',
       'CoronaryVenousEndothelialCells', 'CoronaryCapillaryEndothelialCells',
       'EndocardialCells', 'EndocardialCushionCells', 'ValveEndothelialCells',
       'LymphaticEndothelialCells', 'MesothelialEpicardialCells',
       'EpicardiumDerivedCells', 'NeuronPrecursors', 'ChromaffinCells',
       'SympatheticNeurons', 'ParasympatheticNeurons', 'SchwannCellPrecursors',
       'SchwannCells', 'MonocytesMPOpos', 'Monocytes', 'MonocyteDerivedCells',
       'MacrophagesCX3CR1pos', 'MacrophagesTIMD4pos', 'MacrophagesLYVE1pos',
       'MacrophagesATF3pos', 'DendriticCellsType1', 'DendriticCellsMature',
       'PlasmacytoidDendriticCells', 'MastCells', 'Megakaryocytes',
       'TCellsCD4pos', 'TCellsCD8pos', 'TregsCD4pos', 'ProBCells', 'BCells',
       'BCellsMS4A1pos', 'NaturalKillerCells'],
      dtype='object')
```

Example 13 (python):
```python
FineGrainPalette={
    'InnateLymphoidCells':'#72497f', # since want to start the numbering from 1
    
    'AtrialCardiomyocytesLeft':'#eac075',
    'AtrialCardiomyocytesRight':'#4c6b8a',
    'AtrialCardiomyocytesCycling':'#e94bc7',
    'VentricularCardiomyocytesLeftCompact':'#ab1c3c',
    'VentricularCardiomyocytesRightCompact':'#fdba45',
    'VentricularCardiomyocytesLeftTrabeculated':'#2b9200',
    'VentricularCardiomyocytesRightTrabeculated':'#0273a8',
    'VentricularCardiomyocytesCycling':'#e1acff',
    'SinoatrialNodeCardiomyocytes':'#854834',
    'AtrioventricularNodeCardiomyocytes':'#688500',
    'VentricularConductionSystemProximal':'#01ccc8',
    'VentricularConductionSystemDistal':'#b58fab',
    'GreatVesselAdventitialFibroblasts':'#ff7e97',
    'CoronaryVesselAdventitialFibroblasts':'#ff9b6e',
    'MyocardialInterstitialFibroblasts1':'#8a6800',
    'MyocardialInterstitialFibroblasts2':'#206601',
    'Myofibroblasts':'#1bdebf',
    'LymphNodeFibroblasticReticularCells':'#005aa0',
    'ValveInterstitialCells':'#e478ff',
    'GreatVesselSmoothMuscleCells':'#ff665f',
    'CoronarySmoothMuscleCells':'#d2cb18',
    'DuctusArteriosusSmoothMuscleCells':'#83d7b3',
    'CoronaryPericytes':'#9088ff',
    'PericardialCells1':'#c95e00',
    'PericardialCells2':'#01e077',
    'PericardialCells3':'#ff88e4',
    'GreatVesselArterialEndothelialCells':'#d4004b',
    'GreatVesselVenousEndothelialCells':'#8f4300',
    'CoronaryArterialEndothelialCells':'#89da5a',
    'CoronaryVenousEndothelialCells':'#006f86',
    'CoronaryCapillaryEndothelialCells':'#aa7dff',
    'EndocardialCells':'#ff8241',
    'EndocardialCushionCells':'#46603a',
    'ValveEndothelialCells':'#414eb6',
    'LymphaticEndothelialCells':'#8b3f60',
    'MesothelialEpicardialCells':'#0295fe',
    'EpicardiumDerivedCells':'#ff92c4',
    'NeuronPrecursors':'#d30038',
    'ChromaffinCells':'#726800',
    'SympatheticNeurons':'#01894b',
    'ParaympatheticNeurons':'#545191',
    'SchwannCellPrecursors':'#b0d276',
    'SchwannCells':'#b30079',
    'MonocytesMPOpos':'#c50066',
    'Monocytes':'#fab4b6',
    'MonocyteDerivedCells':'#d14008',
    'MacrophagesCX3CR1pos':'#eabe97',
    'MacrophagesTIMD4pos':'#b2a200',
    'MacrophagesLYVE1pos':'#4a6005',
    'MacrophagesATF3pos':'#3db833',
    'DendriticCellsType1':'#007859',
    'DendriticCellsMature':'#01a9db',
    'PlasmacytoidDendriticCells':'#2c54ab',
    'MastCells':'#d0bef2',
    'Megakaryocytes':'#94298f',
    'TCellsCD4pos':'#ff387c',
    'TCellsCD8pos':'#9e3429',
    'TregsCD4pos':'#b37700',
    'ProBCells':'#8dab00',
    'BCells':'#a8d1a1',
    'BCellsMS4A1pos':'#00d2f0',
    'NaturalKillerCells':'#abb4ff',
}

FineGrainPalette_mod = {}
for i,celltype in enumerate(FineGrainPalette.keys()):
    if i < 10:
        celltype_mod = f'  {i}   {celltype}'
    else:
        celltype_mod = f' {i}   {celltype}'
    FineGrainPalette_mod[celltype_mod] = FineGrainPalette[celltype]
```

Example 14 (python):
```python
sc.pl.umap(adata, color=['mid_grain'], frameon=False)
```

Example 15 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
```

Example 16 (python):
```python
sc.pl.umap(adata, color=['trimester'], frameon=False, show=False)
plt.savefig(f'{figdir}/Peaks_UMAP_trimesters.pdf', bbox_inches="tight",dpi=300)
```

Example 17 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
```

---

## Notebook

**URL:** http://127.0.0.1:9020/notebooks_html/Fig1_General_processing/ATAC/ATAC/DAR-genes-linkage_SANPC-specific.html

**Contents:**
- Read in adata and prepare¶
- Read in differential accessible result¶
  - Select celltypes to analyse¶
- Set celltypes to analyse¶

2756709 rows × 9 columns

**Examples:**

Example 1 (python):
```python
import scanpy as sc
import pandas as pd
import numpy as np
import anndata
import matplotlib.pyplot as plt
import matplotlib as mpl
# enables correct plotting of text
mpl.rcParams['pdf.fonttype'] = 42
mpl.rcParams['ps.fonttype'] = 42 
import seaborn as sns
import os
# import snapatac2 as snap
```

Example 2 (python):
```python
import session_info
session_info.show()
```

Example 3 (python):
```python
-----
anndata             0.9.2
matplotlib          3.7.2
numpy               1.24.4
pandas              1.5.3
scanpy              1.9.3
seaborn             0.12.2
session_info        1.0.0
-----
```

Example 4 (python):
```python
PIL                         10.0.0
anyio                       NA
arrow                       1.2.3
asttokens                   NA
attr                        23.1.0
attrs                       23.1.0
babel                       2.12.1
backcall                    0.2.0
brotli                      1.0.9
certifi                     2023.11.17
cffi                        1.15.1
charset_normalizer          3.2.0
colorama                    0.4.6
comm                        0.1.4
cycler                      0.10.0
cython_runtime              NA
dateutil                    2.8.2
debugpy                     1.6.8
decorator                   5.1.1
defusedxml                  0.7.1
executing                   1.2.0
fastjsonschema              NA
fqdn                        NA
h5py                        3.9.0
idna                        3.4
igraph                      0.10.6
importlib_metadata          NA
importlib_resources         NA
ipykernel                   6.25.1
isoduration                 NA
jedi                        0.19.0
jinja2                      3.1.2
joblib                      1.3.2
json5                       NA
jsonpointer                 2.0
jsonschema                  4.19.0
jsonschema_specifications   NA
jupyter_events              0.7.0
jupyter_server              2.7.1
jupyterlab_server           2.24.0
kiwisolver                  1.4.5
leidenalg                   0.10.1
llvmlite                    0.40.1
markupsafe                  2.1.3
mpl_toolkits                NA
natsort                     8.4.0
nbformat                    5.9.2
numba                       0.57.1
overrides                   NA
packaging                   23.1
parso                       0.8.3
patsy                       0.5.3
pexpect                     4.8.0
pickleshare                 0.7.5
pkg_resources               NA
plotly                      5.16.1
prometheus_client           NA
prompt_toolkit              3.0.39
psutil                      5.9.5
ptyprocess                  0.7.0
pure_eval                   0.2.2
pydev_ipython               NA
pydevconsole                NA
pydevd                      2.9.5
pydevd_file_utils           NA
pydevd_plugins              NA
pydevd_tracing              NA
pygments                    2.16.1
pyparsing                   3.0.9
pythonjsonlogger            NA
pytz                        2023.3
referencing                 NA
requests                    2.31.0
rfc3339_validator           0.1.4
rfc3986_validator           0.1.1
rpds                        NA
ruamel                      NA
scipy                       1.10.1
send2trash                  NA
six                         1.16.0
sklearn                     1.3.0
sniffio                     1.3.0
socks                       1.7.1
sphinxcontrib               NA
stack_data                  0.6.2
statsmodels                 0.14.0
texttable                   1.6.7
threadpoolctl               3.2.0
tornado                     6.3.3
traitlets                   5.9.0
typing_extensions           NA
uri_template                NA
urllib3                     2.0.4
wcwidth                     0.2.6
webcolors                   1.13
websocket                   1.6.2
yaml                        6.0.1
zipp                        NA
zmq                         25.1.1
zstandard                   0.19.0
```

Example 5 (unknown):
```unknown
-----
IPython             8.12.0
jupyter_client      8.3.0
jupyter_core        4.12.0
jupyterlab          4.0.5
notebook            7.0.2
-----
Python 3.8.17 (default, Jul  5 2023, 21:04:15) [GCC 11.2.0]
Linux-4.15.0-220-generic-x86_64-with-glibc2.17
-----
Session information updated at 2024-02-09 16:26
```

Example 6 (python):
```python
import importlib.util
import sys
spec = importlib.util.spec_from_file_location("module.name", "/nfs/team205/kk18/function/python/utils.py")
# spec = importlib.util.spec_from_file_location("module.name", "/home/jovyan/data_for_outage/function/python/utils.py")
utils = importlib.util.module_from_spec(spec)
sys.modules["module.name"] = utils
spec.loader.exec_module(utils)
```

Example 7 (python):
```python
sc.settings.set_figure_params(dpi=80,dpi_save=300)
```

Example 8 (unknown):
```unknown
figdir = '/nfs/team205/heart/fetal_ms_figures/raw_plots_kk'
```

Example 9 (python):
```python
# prepare expressing gene list
adata_gene = sc.read_h5ad('/nfs/team205/heart/anndata_objects/Foetal/Feb28ObjectRaw.h5ad')

# rename fine_grain cell types
celltype_rename = utils.read_pkl('/nfs/team205/heart/anndata_objects/Foetal/fine_grain_rename_dictionary.pkl')
adata_gene.obs['fine_grain'] = [celltype_rename[x] for x in adata_gene.obs['fine_grain']]

# log-normalise
sc.pp.normalize_total(adata_gene, target_sum=1e4)
sc.pp.log1p(adata_gene)

# calculate proportion of expressing cells per gene
exp_mat = utils.get_exp_proportion(adata_gene, groupby='fine_grain', use_rep='X')
print(exp_mat.shape)
exp_mat.head()
```

Example 10 (unknown):
```unknown
(36601, 63)
```

Example 11 (python):
```python
# read in adata peak with back mode
adata_peak = sc.read_h5ad('/nfs/team205/heart/anndata_objects/Foetal/multiome_ATAC/ArchR/project_output/PeakMatrix/Foetal_Peaks_tfidf.h5ad')

# modify peak names
adata_peak.var_names = [x.replace('_','-') for x in adata_peak.var_names]

# rename fine_grain cell types
adata_peak.obs['fine_grain'] = [celltype_rename[x] for x in adata_peak.obs['fine_grain']]

# accessible matrix
acc_mat = utils.get_exp_proportion(adata_peak, groupby='fine_grain', use_rep='X')

adata_peak
```

Example 12 (unknown):
```unknown
AnnData object with n_obs × n_vars = 167022 × 508040
    obs: 'sangerID', 'combinedID', 'donor', 'facility', 'cell_or_nuclei', 'modality', 'kit_10x', 'multiplexed', 'batch_key', 'region', 'FACSgate', 'sex', 'week', 'trimester', 'fine_grain', 'mid_grain', 'coarse_grain', 'heart_or_greatvessels'
    var: 'seqnames', 'start', 'end', 'width', 'strand', 'score', 'replicateScoreQuantile', 'groupScoreQuantile', 'Reproducibility', 'GroupReplicate', 'distToGeneStart', 'nearestGene', 'peakType', 'distToTSS', 'nearestTSS', 'GC', 'idx', 'N'
```

Example 13 (python):
```python
adata_peak.var_names[:10]
```

Example 14 (unknown):
```unknown
Index(['chr1:817093-817593', 'chr1:819818-820318', 'chr1:820542-821042',
       'chr1:825246-825746', 'chr1:826566-827066', 'chr1:827291-827791',
       'chr1:828703-829203', 'chr1:830674-831174', 'chr1:831213-831713',
       'chr1:832066-832566'],
      dtype='object')
```

Example 15 (unknown):
```unknown
dar_res_dir = '/nfs/team205/heart/anndata_objects/Foetal/multiome_ATAC/ArchR/project_output/MarkerPeaks'
os.listdir(dar_res_dir)
```

Example 16 (unknown):
```unknown
['SANP-vs-aCM.csv',
 'global_FDR001.csv',
 '.ipynb_checkpoints',
 'archive',
 'per-mid-grain.csv',
 'Mesenchymal_fine-grain_all.csv',
 'Cardiomyocytes_fine-grain_all.csv',
 'Leukocytes_fine-grain_all.csv',
 'Endothelium_fine-grain_all.csv',
 'Epicardium_fine-grain_all.csv',
 'Neural_fine-grain_all.csv',
 'global_coarse-grain_FDR005_logFC1.csv',
 'vCM_Left_Trab-vs-Compact.csv',
 'vCM_Left_Compact-vs-Trab.csv',
 'aCM-vs-SANP.csv']
```

Example 17 (python):
```python
DAR_res_dict={}
for file in os.listdir(dar_res_dir):
    if '_fine-grain_all.csv' in file:
        celltype = file.split('_fine-grain_all.csv')[0]
        # read in 
        df = pd.read_csv(f'{dar_res_dir}/{file}')
        # make peak names
        df['names'] = df['seqnames']+':'+df['start'].astype('str')+'-'+df['end'].astype('str')
        # rename fine_grain celltypes
        df['celltype'] = [celltype_rename[x] for x in df['celltype']]
        # add to the dictionary
        DAR_res_dict[celltype] = df.copy()
DAR_res_dict.keys()
```

Example 18 (unknown):
```unknown
dict_keys(['Mesenchymal', 'Cardiomyocytes', 'Leukocytes', 'Endothelium', 'Epicardium', 'Neural'])
```

Example 19 (unknown):
```unknown
DAR_res_dict[celltype]
```

Example 20 (unknown):
```unknown
DAR_res_dict.keys()
```

Example 21 (unknown):
```unknown
dict_keys(['Mesenchymal', 'Cardiomyocytes', 'Leukocytes', 'Endothelium', 'Epicardium', 'Neural'])
```

Example 22 (unknown):
```unknown
df = DAR_res_dict['Cardiomyocytes']

# select specific and accessible peaks
pval_thresh = 0.05
logFC_thresh_specific = 0.1

df = df[(df['FDR']<pval_thresh)&(df['Log2FC']>logFC_thresh_specific)]
df['celltype'].value_counts()
```

Example 23 (unknown):
```unknown
SinoatrialNodePacemakerCells                 3354
AtrialCardiomyocytesRight                    1213
AtrialCardiomyocytesLeft                      844
AtrialCardiomyocytesCycling                   579
AtrioventricularNodePacemakerCells            574
VentricularConductionSystemDistal             171
VentricularCardiomyocytesRightCompact          11
VentricularCardiomyocytesLeftCompact            2
VentricularCardiomyocytesLeftTrabeculated       2
VentricularConductionSystemProximal             2
VentricularCardiomyocytesCycling                1
Name: celltype, dtype: int64
```

Example 24 (python):
```python
import gseapy as gp
from gseapy import barplot, dotplot
```

Example 25 (python):
```python
celltype_reference = 'Cardiomyocytes'
celltype_of_interest = 'SinoatrialNodePacemakerCells'

# select specific and accessible peaks
accessible_proportion_thresh = 0.1
pval_thresh = 0.05
logFC_thresh_specific = 1


### Read in pyscenic region-gene metadata ###

# read in pyscenic outputs
eRegulon_metadata = pd.read_csv(f'/nfs/team205/heart/pyscenic/plus/eRegulon_metadata/{celltype_reference}_eRegulon_metadata_filtered.csv')
eRegulon_metadata['regulon_name_short'] = [x.split('_(')[0][:-2] for x in eRegulon_metadata['Region_signature_name']]
print(eRegulon_metadata.shape)

### Select accessible and specific peaks ###

# select peaks which is differentially accessible
DAR_res = DAR_res_dict[celltype_reference]
DAR_res = DAR_res[DAR_res['celltype']==celltype_of_interest]
DAR_res = DAR_res[(DAR_res['FDR']<pval_thresh)&(DAR_res['Log2FC']>logFC_thresh_specific)]

# select peaks which is accessible more than cetrain proportion of the cell type
acc_mat_bi = (acc_mat > accessible_proportion_thresh).astype('int')
acc_peaks = list(acc_mat_bi[acc_mat_bi[celltype_of_interest]==1].index)
DAR_res = DAR_res[DAR_res['names'].isin(acc_peaks)]

# add peaktype
DAR_res['peakType']=list(adata_peak.var.loc[list(DAR_res['names']),'peakType'])

# get the selected peaks
spec_peaks = list(DAR_res['names'])
print(len(spec_peaks))
print(len(acc_peaks))

### Get genes which linked to the peaks ###
# metadata of regions regulons which contain the selected peaks
eRegulon_metadata_sel = eRegulon_metadata[eRegulon_metadata['Region'].isin(spec_peaks)]
print(eRegulon_metadata_sel.shape)

# genes linked to the selected peaks
# and expressed in the cell type of interst 
expressed_proportion_thresh = 0.1
exp_genes = list(exp_mat.index[exp_mat[celltype_of_interest]>expressed_proportion_thresh])
print(f'n_genes expressed in {celltype_of_interest}: {len(exp_genes)}')

# get linked and expressed genes
df = eRegulon_metadata_sel[eRegulon_metadata_sel['Gene'].isin(exp_genes)]
df = df[['Region','Gene']]
df.drop_duplicates(inplace=True)
linked_genes = list(set(df['Gene']))
rank = df['Gene'].value_counts()
print(f'n_genes linked to specific peaks: {len(linked_genes)}')

# get genes which linked to enhancer peak
df['peakType'] = list(adata_peak.var['peakType'].loc[df['Region']])
linked_genes_enh = list(set(df[df['peakType'].isin(['Distal','Intronic'])]['Gene']))
print(f'n_genes linked to specific peaks (Distal, Intronic): {len(linked_genes_enh)}')

# plot
n_rank = 50
plt.rcParams['axes.grid'] = False
plt.rcParams['figure.figsize'] = 4.5,12
plt.barh(width=rank[:n_rank],y=rank[:n_rank].index,color='darkred')
plt.gca().invert_yaxis()
plt.title(f'Number of {celltype_of_interest} specific peaks')
plt.margins(y=0.01)
plt.show()

### Pathway enrichment analysis of the linked genes ###
# default: Human
geneset_list = ['MSigDB_Hallmark_2020','KEGG_2021_Human','GO_Biological_Process_2023','Reactome_2022']
enr = gp.enrichr(gene_list=linked_genes_enh, # or "./tests/data/gene_list.txt",
                 gene_sets=geneset_list,
                 organism='human', # don't forget to set organism to the one you desired! e.g. Yeast
                 outdir=None, # don't write to disk
                )

geneset = 'GO_Biological_Process_2023'
df = enr.results[enr.results['Gene_set'] == geneset]
df = df[df['Adjusted P-value'] < 0.1]
df = df.sort_values('Combined Score',ascending=False)

# plot
n_rank = 10
plt.rcParams['axes.grid'] = False
plt.rcParams['figure.figsize'] = 6,4
plt.barh(width=df[:n_rank]['Combined Score'],
         y=[x.split(' (')[0] for x in df[:n_rank]['Term']],
         color='darkred')
plt.gca().invert_yaxis()
plt.xlabel('Score')
plt.title(geneset)
plt.margins(y=0.05)
plt.savefig(f'{figdir}/Peak_linked-gene-pathways_{celltype_of_interest}.pdf', bbox_inches="tight",dpi=300)
plt.show()


for geneset in geneset_list:
    print(geneset)
    df = enr.results[enr.results['Gene_set'] == geneset]
    display(df.sort_values('Combined Score',ascending=False)[:20])
```

Example 26 (unknown):
```unknown
(260320, 18)
402
18427
(1621, 18)
n_genes expressed in SinoatrialNodePacemakerCells: 7427
n_genes linked to specific peaks: 211
n_genes linked to specific peaks (Distal, Intronic): 152
```

Example 27 (unknown):
```unknown
MSigDB_Hallmark_2020
```

Example 28 (unknown):
```unknown
KEGG_2021_Human
```

Example 29 (unknown):
```unknown
GO_Biological_Process_2023
```

Example 30 (unknown):
```unknown
Reactome_2022
```

Example 31 (python):
```python
# proportion of peaktypes
# specific&accessible peak and all peaks
df = pd.DataFrame({
    'type':list(np.repeat('All accessible peaks',len(acc_peaks)))+list(np.repeat('Specific peaks',len(spec_peaks))),
    'peakType':list(adata_peak.var.loc[acc_peaks,'peakType'])+list(adata_peak.var.loc[spec_peaks,'peakType'])
})
df['peakType'] = df['peakType'].astype('category')
df['peakType'].cat.reorder_categories(['Promoter','Exonic','Intronic','Distal'],
                                            inplace=True)

tmp = pd.crosstab(df['type'], df['peakType'], normalize='index')
# plot
plt.rcParams['figure.figsize'] = 2,3
tmp.plot.bar(stacked=True,width=0.7,legend=False)
plt.gca().grid(False)
plt.gca().set_title(celltype_of_interest)
plt.gca().set_xlabel('')
plt.gca().set_xticklabels(plt.gca().get_xticklabels(), rotation=45, 
                          ha='right',rotation_mode='anchor')
plt.gca().set_ylabel('proportion')
plt.gca().legend(bbox_to_anchor=(1.0, 1.0))
plt.show()
```

Example 32 (unknown):
```unknown
/tmp/ipykernel_30396/3341389757.py:8: FutureWarning: The `inplace` parameter in pandas.Categorical.reorder_categories is deprecated and will be removed in a future version. Reordering categories will always return a new Categorical object.
  df['peakType'].cat.reorder_categories(['Promoter','Exonic','Intronic','Distal'],
```

---

## Notebook

**URL:** http://127.0.0.1:9020/notebooks_html/Supplementary_materials/Epigenetic_stability/no2b_ATAC-nhoods_peakVI-embedding.html

**Contents:**
- Import module¶
- Parameters¶
- Differential acundance test (Milo)¶
- Define nhoods: Young, Old, Non-significant¶

**Examples:**

Example 1 (python):
```python
import numpy as np
import pandas as pd 
import scanpy as sc
import matplotlib.pyplot as plt
import seaborn as sns
# import sctk
```

Example 2 (python):
```python
# Configure rpy2 to Use the Correct R Installation:
import os
os.environ['R_HOME'] = '/nfs/team205/kk18/miniconda3/envs/vitro/lib/R'
# check
from rpy2.rinterface_lib import openrlib
print(openrlib.R_HOME)
```

Example 3 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/R
```

Example 4 (python):
```python
import milopy.core as milo
import milopy.plot as milopl
import milopy.utils
```

Example 5 (python):
```python
import session_info
session_info.show()
```

Example 6 (python):
```python
-----
matplotlib          3.7.2
milopy              0.1.1
numpy               1.24.4
pandas              1.5.3
rpy2                3.5.14
scanpy              1.9.3
seaborn             0.12.2
session_info        1.0.0
-----
```

Example 7 (python):
```python
PIL                         10.0.0
anndata                     0.9.2
anyio                       NA
arrow                       1.2.3
asttokens                   NA
attr                        23.1.0
attrs                       23.1.0
babel                       2.12.1
backcall                    0.2.0
backports                   NA
brotli                      1.0.9
certifi                     2023.11.17
cffi                        1.15.1
charset_normalizer          3.2.0
colorama                    0.4.6
comm                        0.1.4
cycler                      0.10.0
cython_runtime              NA
dateutil                    2.8.2
debugpy                     1.6.8
decorator                   5.1.1
defusedxml                  0.7.1
executing                   1.2.0
fastjsonschema              NA
fqdn                        NA
h5py                        3.9.0
idna                        3.4
igraph                      0.10.6
importlib_metadata          NA
importlib_resources         NA
ipykernel                   6.25.1
isoduration                 NA
jedi                        0.19.0
jinja2                      3.1.2
joblib                      1.3.2
json5                       NA
jsonpointer                 2.0
jsonschema                  4.19.0
jsonschema_specifications   NA
jupyter_events              0.7.0
jupyter_server              2.7.1
jupyterlab_server           2.24.0
kiwisolver                  1.4.5
leidenalg                   0.10.1
llvmlite                    0.40.1
markupsafe                  2.1.3
mpl_toolkits                NA
natsort                     8.4.0
nbformat                    5.9.2
numba                       0.57.1
overrides                   NA
packaging                   23.1
parso                       0.8.3
patsy                       0.5.3
pexpect                     4.8.0
pickleshare                 0.7.5
pkg_resources               NA
plotly                      5.16.1
prometheus_client           NA
prompt_toolkit              3.0.39
psutil                      5.9.5
ptyprocess                  0.7.0
pure_eval                   0.2.2
pydev_ipython               NA
pydevconsole                NA
pydevd                      2.9.5
pydevd_file_utils           NA
pydevd_plugins              NA
pydevd_tracing              NA
pygments                    2.16.1
pyparsing                   3.0.9
pythonjsonlogger            NA
pytz                        2023.3
referencing                 NA
requests                    2.31.0
rfc3339_validator           0.1.4
rfc3986_validator           0.1.1
rpds                        NA
ruamel                      NA
scipy                       1.10.1
send2trash                  NA
six                         1.16.0
sklearn                     1.3.0
sniffio                     1.3.0
socks                       1.7.1
sphinxcontrib               NA
stack_data                  0.6.2
statsmodels                 0.14.0
texttable                   1.6.7
threadpoolctl               3.2.0
tornado                     6.3.3
traitlets                   5.9.0
typing_extensions           NA
tzlocal                     NA
uri_template                NA
urllib3                     2.0.4
wcwidth                     0.2.6
webcolors                   1.13
websocket                   1.6.2
yaml                        6.0.1
zipp                        NA
zmq                         25.1.1
zstandard                   0.19.0
```

Example 8 (unknown):
```unknown
-----
IPython             8.12.0
jupyter_client      8.3.0
jupyter_core        4.12.0
jupyterlab          4.0.5
notebook            7.0.2
-----
Python 3.8.17 (default, Jul  5 2023, 21:04:15) [GCC 11.2.0]
Linux-4.15.0-220-generic-x86_64-with-glibc2.17
-----
Session information updated at 2023-12-31 21:01
```

Example 9 (python):
```python
import importlib.util
import sys
spec = importlib.util.spec_from_file_location("module.name", "/nfs/team205/kk18/function/python/utils.py")
utils = importlib.util.module_from_spec(spec)
sys.modules["module.name"] = utils
spec.loader.exec_module(utils)
```

Example 10 (python):
```python
sc.settings.set_figure_params(dpi=120)
```

Example 11 (unknown):
```unknown
outdir = '/nfs/team205/heart/anndata_objects/Foetal/multiome_ATAC/ArchR/project_output/Milo_nhoods/mid_grain_mod'
```

Example 12 (unknown):
```unknown
!ls /nfs/team205/heart/anndata_objects/Foetal/multiome_ATAC/ArchR/project_output/PeakMatrix/mid_grain_mod
```

Example 13 (unknown):
```unknown
Foetal_AtrialCardiomyocytes_plusCCS_added-cov-region_subsampled-n1000_peakVI-model
Foetal_AtrialCardiomyocytes_plusCCS_Peaks_post-peakVI_added-cov-region_subsampled-n1000.h5ad
Foetal_AtrialCardiomyocytes_plusCCS_Peaks_post-peakVI.h5ad
Foetal_AtrialCardiomyocytes_plusCCS_Peaks_post-peakVI_subsampled-n1000.h5ad
Foetal_AtrialCardiomyocytes_plusCCS_peakVI-model
Foetal_AtrialCardiomyocytes_plusCCS_subsampled-n1000_peakVI-model
Foetal_BloodVesselEndothelialCells_added-cov-region_subsampled-n1000_peakVI-model
Foetal_BloodVesselEndothelialCells_Peaks_post-peakVI_added-cov-region_subsampled-n1000.h5ad
Foetal_BloodVesselEndothelialCells_Peaks_post-peakVI.h5ad
Foetal_BloodVesselEndothelialCells_Peaks_post-peakVI_subsampled-n1000.h5ad
Foetal_BloodVesselEndothelialCells_peakVI-model
Foetal_BloodVesselEndothelialCells_subsampled-n1000_peakVI-model
Foetal_EndocardialCells_added-cov-region_subsampled-n1000_peakVI-model
Foetal_EndocardialCells_Peaks_post-peakVI_added-cov-region_subsampled-n1000.h5ad
Foetal_EndocardialCells_Peaks_post-peakVI.h5ad
Foetal_EndocardialCells_Peaks_post-peakVI_subsampled-n1000.h5ad
Foetal_EndocardialCells_peakVI-model
Foetal_EndocardialCells_subsampled-n1000_peakVI-model
Foetal_EpicardialCells_added-cov-region_subsampled-n1000_peakVI-model
Foetal_EpicardialCells_Peaks_post-peakVI_added-cov-region_subsampled-n1000.h5ad
Foetal_EpicardialCells_Peaks_post-peakVI.h5ad
Foetal_EpicardialCells_Peaks_post-peakVI_subsampled-n1000.h5ad
Foetal_EpicardialCells_peakVI-model
Foetal_EpicardialCells_subsampled-n1000_peakVI-model
Foetal_Fibroblasts_added-cov-region_subsampled-n1000_peakVI-model
Foetal_Fibroblasts_Peaks_post-peakVI_added-cov-region_subsampled-n1000.h5ad
Foetal_Fibroblasts_Peaks_post-peakVI.h5ad
Foetal_Fibroblasts_Peaks_post-peakVI_subsampled-n1000.h5ad
Foetal_Fibroblasts_peakVI-model
Foetal_Fibroblasts_subsampled-n1000_peakVI-model
Foetal_Glia_added-cov-region_subsampled-n1000_peakVI-model
Foetal_Glia_Peaks_post-peakVI_added-cov-region_subsampled-n1000.h5ad
Foetal_Glia_Peaks_post-peakVI.h5ad
Foetal_Glia_Peaks_post-peakVI_subsampled-n1000.h5ad
Foetal_Glia_peakVI-model
Foetal_Glia_subsampled-n1000_peakVI-model
Foetal_LymphaticEndothelialCells_added-cov-region_subsampled-n1000_peakVI-model
Foetal_LymphaticEndothelialCells_Peaks_post-peakVI_added-cov-region_subsampled-n1000.h5ad
Foetal_LymphaticEndothelialCells_Peaks_post-peakVI.h5ad
Foetal_LymphaticEndothelialCells_Peaks_post-peakVI_subsampled-n1000.h5ad
Foetal_LymphaticEndothelialCells_peakVI-model
Foetal_LymphaticEndothelialCells_subsampled-n1000_peakVI-model
Foetal_LymphoidCells_added-cov-region_subsampled-n1000_peakVI-model
Foetal_LymphoidCells_Peaks_post-peakVI_added-cov-region_subsampled-n1000.h5ad
Foetal_LymphoidCells_Peaks_post-peakVI.h5ad
Foetal_LymphoidCells_Peaks_post-peakVI_subsampled-n1000.h5ad
Foetal_LymphoidCells_peakVI-model
Foetal_LymphoidCells_subsampled-n1000_peakVI-model
Foetal_MuralCells_added-cov-region_subsampled-n1000_peakVI-model
Foetal_MuralCells_Peaks_post-peakVI_added-cov-region_subsampled-n1000.h5ad
Foetal_MuralCells_Peaks_post-peakVI.h5ad
Foetal_MuralCells_Peaks_post-peakVI_subsampled-n1000.h5ad
Foetal_MuralCells_peakVI-model
Foetal_MuralCells_subsampled-n1000_peakVI-model
Foetal_MyeloidCells_added-cov-region_subsampled-n1000_peakVI-model
Foetal_MyeloidCells_Peaks_post-peakVI_added-cov-region_subsampled-n1000.h5ad
Foetal_MyeloidCells_Peaks_post-peakVI.h5ad
Foetal_MyeloidCells_Peaks_post-peakVI_subsampled-n1000.h5ad
Foetal_MyeloidCells_peakVI-model
Foetal_MyeloidCells_subsampled-n1000_peakVI-model
Foetal_Neurons_added-cov-region_subsampled-n1000_peakVI-model
Foetal_Neurons_Peaks_post-peakVI_added-cov-region_subsampled-n1000.h5ad
Foetal_Neurons_Peaks_post-peakVI.h5ad
Foetal_Neurons_Peaks_post-peakVI_subsampled-n1000.h5ad
Foetal_Neurons_peakVI-model
Foetal_Neurons_subsampled-n1000_peakVI-model
Foetal_PericardialCells_added-cov-region_subsampled-n1000_peakVI-model
Foetal_PericardialCells_Peaks_post-peakVI_added-cov-region_subsampled-n1000.h5ad
Foetal_PericardialCells_Peaks_post-peakVI.h5ad
Foetal_PericardialCells_Peaks_post-peakVI_subsampled-n1000.h5ad
Foetal_PericardialCells_peakVI-model
Foetal_PericardialCells_subsampled-n1000_peakVI-model
Foetal_VentricularCardiomyocytes_plusCCS_added-cov-region_subsampled-n1000_peakVI-model
Foetal_VentricularCardiomyocytes_plusCCS_Peaks_post-peakVI_added-cov-region_subsampled-n1000.h5ad
Foetal_VentricularCardiomyocytes_plusCCS_Peaks_post-peakVI.h5ad
Foetal_VentricularCardiomyocytes_plusCCS_Peaks_post-peakVI_subsampled-n1000.h5ad
Foetal_VentricularCardiomyocytes_plusCCS_peakVI-model
Foetal_VentricularCardiomyocytes_plusCCS_subsampled-n1000_peakVI-model
```

Example 14 (python):
```python
%%time
adata_dict = {}
for i,celltype in enumerate(['AtrialCardiomyocytes_plusCCS',
                            'VentricularCardiomyocytes_plusCCS',
                             'BloodVesselEndothelialCells',
                             'EndocardialCells',
                            'LymphaticEndothelialCells',
                             'EpicardialCells',
                             'Fibroblasts',
                             'PericardialCells',
                             'MuralCells',
                             'Neurons',
                            'Glia',
                            'MyeloidCells',
                            'LymphoidCells']
                             ):
    print(f'####### {celltype} #######')
    
    adata_dict[celltype] = sc.read_h5ad(f'/nfs/team205/heart/anndata_objects/Foetal/multiome_ATAC/ArchR/project_output/PeakMatrix/mid_grain_mod/Foetal_{celltype}_Peaks_post-peakVI_added-cov-region_subsampled-n1000.h5ad')
    print(adata_dict[celltype].shape)
    
    # qc
    sc.pp.calculate_qc_metrics(adata_dict[celltype], log1p=True, inplace=True)
    # compute the k-nearest-neighbor graph that is used in both clustering and umap algorithms
    sc.pp.neighbors(adata_dict[celltype], use_rep="X_PeakVI", n_neighbors=100, key_added="peakvi")
    # compute the umap
    sc.tl.umap(adata_dict[celltype], min_dist=0.2, neighbors_key="peakvi")
    # cluster the space (we use a lower resolution to get fewer clusters than the default)
    # sc.tl.leiden(adata_dict[celltype], key_added="cluster_pvi", resolution=1, neighbors_key="peakvi")
    # plot
    sc.pl.umap(adata_dict[celltype], color=['week','donor','fine_grain'], size=20, legend_fontsize=12, wspace=0.3,
              cmap='RdPu')
    
    ## Construct neighbourhoods
    milo.make_nhoods(adata_dict[celltype], neighbors_key="peakvi", prop=0.05)
    ## Count cells in neighbourhoods
    ## Milo leverages the variation in cell numbers between replicates for the same experimental condition to test for differential abundance. 
    milo.count_nhoods(adata_dict[celltype], sample_col="donor")
    # differential abundance testing
    adata_dict[celltype].obs["week_continuous"] = [int(x.split('W')[0]) for x in adata_dict[celltype].obs["week"]] #rather than adata.obs["week"].cat.codes
    milo.DA_nhoods(adata_dict[celltype], design="~ week_continuous")
    milopy.utils.build_nhood_graph(adata_dict[celltype],basis='X_umap')
    # plot
    milopl.plot_nhood_graph(adata_dict[celltype], 
                        alpha=0.1, ## SpatialFDR level (1%) 
                        min_size=3, ## Size of smallest dot
                        title = 'DA log-Fold Change\n(FDR < 0.1)'
                       )
    # store logFC
    logfcs = abs(adata_dict[celltype].uns['nhood_adata'].obs['logFC'])
    df = pd.DataFrame({'Celltype':celltype,'logFC':logfcs})
    if i==0:
        logfc_df=df.copy()
    else:
        logfc_df=pd.concat([logfc_df,df])

# save adata dictionary
utils.save_pkl(adata_dict, f'{outdir}/added-cov-region_subsampled-n1000_post_milo_adata_dictionary.pkl')
```

Example 15 (unknown):
```unknown
####### AtrialCardiomyocytes_plusCCS #######
(4381, 508040)
```

Example 16 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
```

Example 17 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/anndata/_core/anndata.py:121: ImplicitModificationWarning: Transforming to str index.
  warnings.warn("Transforming to str index.", ImplicitModificationWarning)
```

Example 18 (unknown):
```unknown
####### VentricularCardiomyocytes_plusCCS #######
(6531, 508040)
```

Example 19 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
```

Example 20 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/anndata/_core/anndata.py:121: ImplicitModificationWarning: Transforming to str index.
  warnings.warn("Transforming to str index.", ImplicitModificationWarning)
```

Example 21 (unknown):
```unknown
####### BloodVesselEndothelialCells #######
(3028, 508040)
```

Example 22 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
```

Example 23 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/anndata/_core/anndata.py:121: ImplicitModificationWarning: Transforming to str index.
  warnings.warn("Transforming to str index.", ImplicitModificationWarning)
```

Example 24 (unknown):
```unknown
####### EndocardialCells #######
(1410, 508040)
```

Example 25 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
```

Example 26 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/anndata/_core/anndata.py:121: ImplicitModificationWarning: Transforming to str index.
  warnings.warn("Transforming to str index.", ImplicitModificationWarning)
```

Example 27 (unknown):
```unknown
####### LymphaticEndothelialCells #######
(1000, 508040)
```

Example 28 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
```

Example 29 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/anndata/_core/anndata.py:121: ImplicitModificationWarning: Transforming to str index.
  warnings.warn("Transforming to str index.", ImplicitModificationWarning)
```

Example 30 (unknown):
```unknown
####### EpicardialCells #######
(1340, 508040)
```

Example 31 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
```

Example 32 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/anndata/_core/anndata.py:121: ImplicitModificationWarning: Transforming to str index.
  warnings.warn("Transforming to str index.", ImplicitModificationWarning)
```

Example 33 (unknown):
```unknown
####### Fibroblasts #######
(6969, 508040)
```

Example 34 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
```

Example 35 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/anndata/_core/anndata.py:121: ImplicitModificationWarning: Transforming to str index.
  warnings.warn("Transforming to str index.", ImplicitModificationWarning)
```

Example 36 (unknown):
```unknown
####### PericardialCells #######
(2187, 508040)
```

Example 37 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
```

Example 38 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/anndata/_core/anndata.py:121: ImplicitModificationWarning: Transforming to str index.
  warnings.warn("Transforming to str index.", ImplicitModificationWarning)
```

Example 39 (unknown):
```unknown
####### MuralCells #######
(3103, 508040)
```

Example 40 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
```

Example 41 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/anndata/_core/anndata.py:121: ImplicitModificationWarning: Transforming to str index.
  warnings.warn("Transforming to str index.", ImplicitModificationWarning)
```

Example 42 (unknown):
```unknown
####### Neurons #######
(1101, 508040)
```

Example 43 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
```

Example 44 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/anndata/_core/anndata.py:121: ImplicitModificationWarning: Transforming to str index.
  warnings.warn("Transforming to str index.", ImplicitModificationWarning)
```

Example 45 (unknown):
```unknown
####### Glia #######
(1759, 508040)
```

Example 46 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
```

Example 47 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/anndata/_core/anndata.py:121: ImplicitModificationWarning: Transforming to str index.
  warnings.warn("Transforming to str index.", ImplicitModificationWarning)
```

Example 48 (unknown):
```unknown
####### MyeloidCells #######
(4321, 508040)
```

Example 49 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
```

Example 50 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/anndata/_core/anndata.py:121: ImplicitModificationWarning: Transforming to str index.
  warnings.warn("Transforming to str index.", ImplicitModificationWarning)
```

Example 51 (unknown):
```unknown
####### LymphoidCells #######
(7006, 508040)
```

Example 52 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:392: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  cax = scatter(
```

Example 53 (unknown):
```unknown
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/anndata/_core/anndata.py:121: ImplicitModificationWarning: Transforming to str index.
  warnings.warn("Transforming to str index.", ImplicitModificationWarning)
```

Example 54 (unknown):
```unknown
CPU times: user 4min 33s, sys: 11.4 s, total: 4min 45s
Wall time: 5min 8s
```

Example 55 (python):
```python
adata_dict.keys()
```

Example 56 (unknown):
```unknown
dict_keys(['AtrialCardiomyocytes_plusCCS', 'VentricularCardiomyocytes_plusCCS', 'BloodVesselEndothelialCells', 'EndocardialCells', 'LymphaticEndothelialCells', 'EpicardialCells', 'Fibroblasts', 'PericardialCells', 'MuralCells', 'Neurons', 'Glia', 'MyeloidCells', 'LymphoidCells'])
```

Example 57 (python):
```python
for celltype in adata_dict.keys():
    print(celltype)
    # get adata
    ad = adata_dict[celltype]
    # define nhoods based on the enrichment
    nhoods_res = ad.uns['nhood_adata'].obs.copy()
    nhoods_res['nhood'] = [f'nhood_{x+1}' for x in range(len(nhoods_res))]
    nhoods_res.set_index('nhood',inplace=True)
    nhoods_res['enrichment'] = 'nonsignificant'
    old_inds = nhoods_res.index[(nhoods_res['logFC']>0)&(nhoods_res['FDR']<0.1)]
    nhoods_res.loc[old_inds,'enrichment'] = 'old'
    young_inds = nhoods_res.index[(nhoods_res['logFC']<0)&(nhoods_res['FDR']<0.1)]
    nhoods_res.loc[young_inds,'enrichment'] = 'young'
    print(f'old nhoods: {len(old_inds)}')
    print(f'young nhoods: {len(young_inds)}')
    # get cells for each nhoods
    nhood_df = pd.DataFrame(ad.obsm['nhoods'].todense())
    nhood_df.index = ad.obs_names
    nhood_df.columns = nhoods_res.index
    nhoods_res['cells'] = [','.join(nhood_df.index[nhood_df[x]==1]) for x in nhood_df.columns]
    # save
    nhoods_res.to_csv(f'{outdir}/{celltype}_added-cov-region_subsampled-n1000_milo_nhoods_result.csv')
    
    nhoods_res['Nhood_size'].hist(bins=30)
    plt.title(celltype)
    plt.show()
```

Example 58 (unknown):
```unknown
AtrialCardiomyocytes_plusCCS
old nhoods: 79
young nhoods: 15
```

Example 59 (unknown):
```unknown
VentricularCardiomyocytes_plusCCS
old nhoods: 166
young nhoods: 26
```

Example 60 (unknown):
```unknown
BloodVesselEndothelialCells
old nhoods: 49
young nhoods: 0
```

Example 61 (unknown):
```unknown
EndocardialCells
old nhoods: 16
young nhoods: 8
```

Example 62 (unknown):
```unknown
LymphaticEndothelialCells
old nhoods: 17
young nhoods: 0
```

Example 63 (unknown):
```unknown
EpicardialCells
old nhoods: 24
young nhoods: 9
```

Example 64 (unknown):
```unknown
Fibroblasts
old nhoods: 197
young nhoods: 33
```

Example 65 (unknown):
```unknown
PericardialCells
old nhoods: 56
young nhoods: 3
```

Example 66 (unknown):
```unknown
MuralCells
old nhoods: 61
young nhoods: 5
```

Example 67 (unknown):
```unknown
Neurons
old nhoods: 6
young nhoods: 15
```

Example 68 (unknown):
```unknown
Glia
old nhoods: 22
young nhoods: 19
```

Example 69 (unknown):
```unknown
MyeloidCells
old nhoods: 70
young nhoods: 8
```

Example 70 (unknown):
```unknown
LymphoidCells
old nhoods: 256
young nhoods: 0
```

Example 71 (python):
```python
# adata_dict = utils.read_pkl(f'{outdir}/post_milo_adata_dictionary.pkl')
```

Example 72 (python):
```python
for celltype in adata_dict.keys():
    print(celltype)
    # get adata
    ad = adata_dict[celltype]
    # get nhoods
    nhoods_res = ad.uns['nhood_adata'].obs.copy()
    nhoods_no = [f'nhood_{x+1}' for x in range(len(nhoods_res))]
    # prepare dataframe: cell-by-nhoods, boolean
    df = pd.DataFrame(ad.obsm['nhoods'].todense(), columns=nhoods_no, index=ad.obs_names)
    # save
    df.to_csv(f'{outdir}/{celltype}_added-cov-region_subsampled-n1000_milo_cell-by-nhood.csv')
```

Example 73 (unknown):
```unknown
AtrialCardiomyocytes_plusCCS
VentricularCardiomyocytes_plusCCS
BloodVesselEndothelialCells
EndocardialCells
LymphaticEndothelialCells
EpicardialCells
Fibroblasts
PericardialCells
MuralCells
Neurons
Glia
MyeloidCells
LymphoidCells
```

Example 74 (python):
```python
midfix = '_added-cov-region_subsampled-n1000'
suffix = '_milo_nhoods_result.csv'

nhoods_res = {}
for file in os.listdir(outdir):
    if (midfix in file)&(suffix in file):
        celltype = file.replace(midfix,'').replace(suffix,'')
        print(celltype)
        nhoods_res[celltype] = pd.read_csv(f'{outdir}/{celltype}{midfix}{suffix}',
                                           index_col=0
                                          )
```

Example 75 (python):
```python
celltypes = [
    'AtrialCardiomyocytes_plusCCS',
    'VentricularCardiomyocytes_plusCCS',
    'Fibroblasts',
    'MuralCells',
    'PericardialCells', 
    'EpicardialCells',
    'BloodVesselEndothelialCells',
    'EndocardialCells', 
     'Neurons',
    'Glia', 
     'MyeloidCells',
    'LymphoidCells',   
             ]

for celltype in celltypes:
    nhoods_res[celltype]['Nhood_size'].hist(bins=30)
    plt.title(celltype)
    plt.show()
```

---

## Notebook

**URL:** http://127.0.0.1:9020/notebooks_html/Fig1_General_processing/ATAC/ATAC/run_peakVI.html

**Contents:**
- Import module¶
- Read in data¶
- Setup anndata for scVI¶

**Examples:**

Example 1 (python):
```python
import scvi
import anndata
import scipy
import numpy as np
import pandas as pd
import scanpy as sc
import matplotlib.pyplot as plt

scvi.settings.seed = 420
```

Example 2 (python):
```python
Global seed set to 0
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/flax/core/frozen_dict.py:169: FutureWarning: jax.tree_util.register_keypaths is deprecated, and will be removed in a future release. Please use `register_pytree_with_keys()` instead.
  jax.tree_util.register_keypaths(
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/utilities/warnings.py:53: LightningDeprecationWarning: pytorch_lightning.utilities.warnings.rank_zero_deprecation has been deprecated in v1.6 and will be removed in v1.8. Use the equivalent function from the pytorch_lightning.utilities.rank_zero module instead.
  new_rank_zero_deprecation(
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/utilities/warnings.py:58: LightningDeprecationWarning: The `pytorch_lightning.loggers.base.rank_zero_experiment` is deprecated in v1.7 and will be removed in v1.9. Please use `pytorch_lightning.loggers.logger.rank_zero_experiment` instead.
  return new_rank_zero_deprecation(*args, **kwargs)
Global seed set to 420
```

Example 3 (python):
```python
adata = sc.read_h5ad('/nfs/team205/heart/anndata_objects/Foetal/multiome_ATAC/ArchR/project_output/PeakMatrix/Foetal_Peaks.h5ad')
adata
```

Example 4 (unknown):
```unknown
AnnData object with n_obs × n_vars = 167022 × 508040
    obs: 'sangerID', 'combinedID', 'donor', 'facility', 'cell_or_nuclei', 'modality', 'kit_10x', 'scrublet_score', 'doublet_pval', 'doublet_bh_pval', 'n_genes', 'n_counts', 'n_genes_by_counts', 'log1p_n_genes_by_counts', 'total_counts', 'log1p_total_counts', 'total_counts_mt', 'log1p_total_counts_mt', 'pct_counts_mt', 'total_counts_ribo', 'log1p_total_counts_ribo', 'pct_counts_ribo', 'HB_score', 'multiplexed', 'batch_key', 'region', 'FACSgate', 'sex', 'week', 'trimester', 'fine_grain', 'mid_grain', 'coarse_grain', 'heart_or_greatvessels', 'cycling', 'S_score', 'G2M_score', 'phase', 'stress_score', 'hb1_score'
```

Example 5 (python):
```python
adata.X.data[:10]
```

Example 6 (unknown):
```unknown
array([2., 2., 2., 2., 1., 1., 2., 1., 2., 2.], dtype=float32)
```

Example 7 (python):
```python
scvi.model.PEAKVI.setup_anndata(adata, batch_key="donor")
```

Example 8 (unknown):
```unknown
No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
```

Example 9 (python):
```python
pvi = scvi.model.PEAKVI(adata)
pvi.train()
```

Example 10 (unknown):
```unknown
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
/nfs/team205/kk18/miniconda3/envs/scvi0190_env/lib/python3.9/site-packages/pytorch_lightning/trainer/configuration_validator.py:267: LightningDeprecationWarning: The `Callback.on_epoch_end` hook was deprecated in v1.6 and will be removed in v1.8. Please use `Callback.on_<train/validation/test>_epoch_end` instead.
  rank_zero_deprecation(
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
```

Example 11 (unknown):
```unknown
Epoch 18/500:   3%|█████▏                                                                                                                                                  | 17/500 [2:22:27<67:38:33, 504.17s/it, loss=4.17e+08, v_num=1]
```

Example 12 (python):
```python
latent = pvi.get_latent_representation()
adata.obsm["X_PeakVI"] = latent

print(latent.shape)
```

Example 13 (python):
```python
adata.write('/nfs/team205/heart/anndata_objects/Foetal/multiome_ATAC/ArchR/project_output/PeakMatrix/Foetal_Peaks_post-peakVI.h5ad')
```

Example 14 (unknown):
```unknown
pvi.save('/nfs/team205/heart/anndata_objects/Foetal/multiome_ATAC/ArchR/project_output/PeakMatrix/Foetal_peakVI-model', overwrite=True)
```

Example 15 (python):
```python
# Convergency plot
pvi.history['elbo_train']
x = np.linspace(1, (len(pvi.history['elbo_train'])), (len(pvi.history['elbo_train'])))
plt.plot(x, pvi.history['elbo_train'], label="train")
plt.xlabel('epoch')
plt.ylabel('elbo_train')
plt.show()
```

---

## Notebook

**URL:** http://127.0.0.1:9020/notebooks_html/Fig1_General_processing/ATAC/ATAC/DAR_plots_finegrain-specific.html

**Contents:**
- Read in cellname-change dictionary which also defines cell order¶
- Read in anndata (peak)¶
- Get accessible proportion matrix¶
- Read in DA results¶
- Defining peaks and plot cluster map¶
- Proportion of peak types¶

6539373 rows × 9 columns

**Examples:**

Example 1 (python):
```python
import scanpy as sc
import pandas as pd
import numpy as np
import anndata
import matplotlib.pyplot as plt
import matplotlib as mpl
# enables correct plotting of text
mpl.rcParams['pdf.fonttype'] = 42
mpl.rcParams['ps.fonttype'] = 42 
import seaborn as sns
import os
# import snapatac2 as snap
```

Example 2 (python):
```python
import session_info
session_info.show()
```

Example 3 (python):
```python
-----
anndata             0.9.2
matplotlib          3.7.2
numpy               1.24.4
pandas              1.5.3
scanpy              1.9.3
seaborn             0.12.2
session_info        1.0.0
-----
```

Example 4 (python):
```python
PIL                         10.0.0
anyio                       NA
arrow                       1.2.3
asttokens                   NA
attr                        23.1.0
attrs                       23.1.0
babel                       2.12.1
backcall                    0.2.0
brotli                      1.0.9
certifi                     2023.11.17
cffi                        1.15.1
charset_normalizer          3.2.0
colorama                    0.4.6
comm                        0.1.4
cycler                      0.10.0
cython_runtime              NA
dateutil                    2.8.2
debugpy                     1.6.8
decorator                   5.1.1
defusedxml                  0.7.1
executing                   1.2.0
fastjsonschema              NA
fqdn                        NA
h5py                        3.9.0
idna                        3.4
igraph                      0.10.6
importlib_metadata          NA
importlib_resources         NA
ipykernel                   6.25.1
isoduration                 NA
jedi                        0.19.0
jinja2                      3.1.2
joblib                      1.3.2
json5                       NA
jsonpointer                 2.0
jsonschema                  4.19.0
jsonschema_specifications   NA
jupyter_events              0.7.0
jupyter_server              2.7.1
jupyterlab_server           2.24.0
kiwisolver                  1.4.5
leidenalg                   0.10.1
llvmlite                    0.40.1
markupsafe                  2.1.3
mpl_toolkits                NA
natsort                     8.4.0
nbformat                    5.9.2
numba                       0.57.1
overrides                   NA
packaging                   23.1
parso                       0.8.3
patsy                       0.5.3
pexpect                     4.8.0
pickleshare                 0.7.5
pkg_resources               NA
plotly                      5.16.1
prometheus_client           NA
prompt_toolkit              3.0.39
psutil                      5.9.5
ptyprocess                  0.7.0
pure_eval                   0.2.2
pydev_ipython               NA
pydevconsole                NA
pydevd                      2.9.5
pydevd_file_utils           NA
pydevd_plugins              NA
pydevd_tracing              NA
pygments                    2.16.1
pyparsing                   3.0.9
pythonjsonlogger            NA
pytz                        2023.3
referencing                 NA
requests                    2.31.0
rfc3339_validator           0.1.4
rfc3986_validator           0.1.1
rpds                        NA
ruamel                      NA
scipy                       1.10.1
send2trash                  NA
six                         1.16.0
sklearn                     1.3.0
sniffio                     1.3.0
socks                       1.7.1
sphinxcontrib               NA
stack_data                  0.6.2
statsmodels                 0.14.0
texttable                   1.6.7
threadpoolctl               3.2.0
tornado                     6.3.3
traitlets                   5.9.0
typing_extensions           NA
uri_template                NA
urllib3                     2.0.4
wcwidth                     0.2.6
webcolors                   1.13
websocket                   1.6.2
yaml                        6.0.1
zipp                        NA
zmq                         25.1.1
zstandard                   0.19.0
```

Example 5 (unknown):
```unknown
-----
IPython             8.12.0
jupyter_client      8.3.0
jupyter_core        4.12.0
jupyterlab          4.0.5
notebook            7.0.2
-----
Python 3.8.17 (default, Jul  5 2023, 21:04:15) [GCC 11.2.0]
Linux-4.15.0-220-generic-x86_64-with-glibc2.17
-----
Session information updated at 2024-02-09 11:58
```

Example 6 (python):
```python
import importlib.util
import sys
spec = importlib.util.spec_from_file_location("module.name", "/nfs/team205/kk18/function/python/utils.py")
utils = importlib.util.module_from_spec(spec)
sys.modules["module.name"] = utils
spec.loader.exec_module(utils)
```

Example 7 (python):
```python
sc.settings.set_figure_params(dpi=80,dpi_save=300)
```

Example 8 (unknown):
```unknown
figdir = '/nfs/team205/heart/fetal_ms_figures/raw_plots_kk'
```

Example 9 (unknown):
```unknown
celltype_rename = utils.read_pkl('/nfs/team205/heart/anndata_objects/Foetal/fine_grain_rename_dictionary.pkl')
finegrain_order = list(celltype_rename.keys())
```

Example 10 (unknown):
```unknown
peakmatrix_dir = '/nfs/team205/heart/anndata_objects/Foetal/multiome_ATAC/ArchR/project_output/PeakMatrix'
```

Example 11 (python):
```python
# peak matrix, not-binarised
adata = sc.read_h5ad(f'{peakmatrix_dir}/Foetal_Peaks_tfidf.h5ad')
```

Example 12 (python):
```python
# rename fine_grain cell types
adata.obs['fine_grain'] = [celltype_rename[x] for x in adata.obs['fine_grain']]
```

Example 13 (unknown):
```unknown
AnnData object with n_obs × n_vars = 167022 × 508040
    obs: 'sangerID', 'combinedID', 'donor', 'facility', 'cell_or_nuclei', 'modality', 'kit_10x', 'multiplexed', 'batch_key', 'region', 'FACSgate', 'sex', 'week', 'trimester', 'fine_grain', 'mid_grain', 'coarse_grain', 'heart_or_greatvessels'
    var: 'seqnames', 'start', 'end', 'width', 'strand', 'score', 'replicateScoreQuantile', 'groupScoreQuantile', 'Reproducibility', 'GroupReplicate', 'distToGeneStart', 'nearestGene', 'peakType', 'distToTSS', 'nearestTSS', 'GC', 'idx', 'N'
```

Example 14 (python):
```python
adata.X.data[:10]
```

Example 15 (unknown):
```unknown
array([1.768611 , 1.9229858, 3.635446 , 1.3192275, 1.4049321, 1.8123279,
       1.6739427, 2.9703567, 3.3852873, 1.2617257], dtype=float32)
```

Example 16 (python):
```python
# accessible matrix
acc_mat = utils.get_exp_proportion(adata, groupby='fine_grain', use_rep='X')
```

Example 17 (unknown):
```unknown
dar_res_dir = '/nfs/team205/heart/anndata_objects/Foetal/multiome_ATAC/ArchR/project_output/MarkerPeaks'
os.listdir(dar_res_dir)
```

Example 18 (unknown):
```unknown
['SANP-vs-aCM.csv',
 'global_FDR001.csv',
 '.ipynb_checkpoints',
 'archive',
 'per-mid-grain.csv',
 'Mesenchymal_fine-grain_all.csv',
 'Cardiomyocytes_fine-grain_all.csv',
 'Leukocytes_fine-grain_all.csv',
 'Endothelium_fine-grain_all.csv',
 'Epicardium_fine-grain_all.csv',
 'Neural_fine-grain_all.csv',
 'global_coarse-grain_FDR005_logFC1.csv',
 'vCM_Left_Trab-vs-Compact.csv',
 'vCM_Left_Compact-vs-Trab.csv',
 'aCM-vs-SANP.csv']
```

Example 19 (python):
```python
DAR_res={}
for file in os.listdir(dar_res_dir):
    if '_fine-grain_all.csv' in file:
        celltype = file.split('_fine-grain_all.csv')[0]
        # read in 
        df = pd.read_csv(f'{dar_res_dir}/{file}')
        # make peak names
        df['names'] = df['seqnames']+':'+df['start'].astype('str')+'_'+df['end'].astype('str')
        # add to the dictionary
        DAR_res[celltype] = df.copy()
DAR_res.keys()
```

Example 20 (unknown):
```unknown
dict_keys(['Mesenchymal', 'Cardiomyocytes', 'Leukocytes', 'Endothelium', 'Epicardium', 'Neural'])
```

Example 21 (unknown):
```unknown
DAR_res['Cardiomyocytes'].head()
```

Example 22 (python):
```python
from scipy.stats import zscore
plt.rcParams['axes.grid'] = False

# set variables
accessible_proportion_thresh = 0.1
pval_thresh = 0.05
logFC_thresh_specific = 1
logFC_thresh_conserved = 0.3 # conserved: peaks which are not significant and the logFC is lower than this threshold 

# for storing results
specific_peaks = {}
conserved_peaks = {}

for celltype in DAR_res.keys():
    print(f'##### {celltype} #####')
    
    res = DAR_res[celltype].copy()
    # rename fine_grain cell types
    res['celltype'] = [celltype_rename[x] for x in res['celltype']]
    
    # select peaks accessible in at least one fine grain cell type
    df = acc_mat[list(set(res['celltype']))]
    peaks_open = list(df.index[df.max(axis=1)>accessible_proportion_thresh])
    res = res[res['names'].isin(peaks_open)]
    
    # select specific peaks    
    res_spec = res[(res['FDR']<pval_thresh)&(res['Log2FC']>logFC_thresh_specific)]
    peaks_spec = list(set(res_spec['names']))
    specific_peaks[celltype] = peaks_spec
    print(f'specific peaks: {len(peaks_spec)}')
    
    # select conserved peaks  
    ## prepare pivot dataframe
    res_pivot_logFC = res.pivot(index='names',columns='celltype',values='Log2FC')
    res_pivot_pval = res.pivot(index='names',columns='celltype',values='FDR')
    ## select
    peaks_cons = list(res_pivot_logFC.index[(res_pivot_logFC.max(axis=1)<logFC_thresh_conserved)&\
                                            (res_pivot_pval.min(axis=1)>pval_thresh)])
    conserved_peaks[celltype] = peaks_cons
    print(f'conserved peaks: {len(peaks_cons)}')
    
    # prepare mean count dataframe
    peak_count_df = adata[:,peaks_spec+peaks_cons].to_df()
    peak_count_df['fine_grain'] = adata.obs['fine_grain']
    peak_count_df = peak_count_df.groupby('fine_grain').mean().T
    peak_count_df = peak_count_df[list(set(res['celltype']))]
    ## scale
    peak_count_df = peak_count_df.apply(zscore,axis=1)
    ## separate
    df_spec = peak_count_df.loc[peaks_spec]
    df_cons = peak_count_df.loc[peaks_cons]
    
    # plot specific peaks
    if len(df_spec)>1:
        sns.clustermap(df_spec,yticklabels=False,figsize=(len(set(res['celltype']))/2.5, 10),
                       cmap='viridis')
        plt.title(f'{celltype} (specific peaks)')
        plt.savefig(f'{figdir}/Peak-heatmap_specific_{celltype}.pdf', bbox_inches="tight",dpi=300)
        plt.show()
    else:
        continue
    
    if len(df_cons)>1:
        # reoirder columns
        l = list(df_cons.columns)
        l.sort()
        df_cons = df_cons[l]
        # plot
        sns.clustermap(df_cons,col_cluster=False,yticklabels=False,figsize=(len(set(res['celltype']))/2.5, 10),
                      cmap='viridis')
        plt.title(f'{celltype} (conserved peaks)')
        plt.show()
    else:
        continue
    
    print('')
```

Example 23 (unknown):
```unknown
##### Mesenchymal #####
specific peaks: 2755
conserved peaks: 427
```

Example 24 (python):
```python
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/seaborn/matrix.py:560: UserWarning: Clustering large matrix with scipy. Installing `fastcluster` may give better performance.
  warnings.warn(msg)
```

Example 25 (unknown):
```unknown
##### Cardiomyocytes #####
specific peaks: 857
conserved peaks: 1492
```

Example 26 (python):
```python
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/seaborn/matrix.py:560: UserWarning: Clustering large matrix with scipy. Installing `fastcluster` may give better performance.
  warnings.warn(msg)
```

Example 27 (python):
```python
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/seaborn/matrix.py:560: UserWarning: Clustering large matrix with scipy. Installing `fastcluster` may give better performance.
  warnings.warn(msg)
```

Example 28 (unknown):
```unknown
##### Leukocytes #####
specific peaks: 9013
conserved peaks: 84
```

Example 29 (python):
```python
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/seaborn/matrix.py:560: UserWarning: Clustering large matrix with scipy. Installing `fastcluster` may give better performance.
  warnings.warn(msg)
```

Example 30 (unknown):
```unknown
##### Endothelium #####
specific peaks: 1535
conserved peaks: 941
```

Example 31 (python):
```python
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/seaborn/matrix.py:560: UserWarning: Clustering large matrix with scipy. Installing `fastcluster` may give better performance.
  warnings.warn(msg)
```

Example 32 (unknown):
```unknown
##### Epicardium #####
specific peaks: 1
conserved peaks: 8794
##### Neural #####
specific peaks: 2069
conserved peaks: 2361
```

Example 33 (python):
```python
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/seaborn/matrix.py:560: UserWarning: Clustering large matrix with scipy. Installing `fastcluster` may give better performance.
  warnings.warn(msg)
```

Example 34 (python):
```python
/nfs/team205/kk18/miniconda3/envs/vitro/lib/python3.8/site-packages/seaborn/matrix.py:560: UserWarning: Clustering large matrix with scipy. Installing `fastcluster` may give better performance.
  warnings.warn(msg)
```

Example 35 (python):
```python
plt.rcParams['figure.figsize'] = 10,3
fig, axs = plt.subplots(nrows=1,ncols=5)

celltypes_to_plot = ['Cardiomyocytes', 'Mesenchymal', 'Endothelium','Leukocytes', 'Neural']
for i,celltype in enumerate(celltypes_to_plot):
    # prepare dataframe
    peak_meta = adata.var.copy()
    peak_meta['type'] = np.nan
    peak_meta.loc[specific_peaks[celltype],'type'] = 'specific'
    peak_meta.loc[conserved_peaks[celltype],'type'] = 'conserved'
    peak_meta.dropna(inplace=True)
    
    peak_meta['peakType'] = peak_meta['peakType'].astype('category')
    peak_meta['peakType'].cat.reorder_categories(['Promoter','Exonic','Intronic','Distal'],
                                            inplace=True)
    
    # plot
    if len(set(peak_meta['type']))==2:
        tmp = pd.crosstab(peak_meta['type'], peak_meta['peakType'], normalize='index')
        # tmp.plot.bar().legend(loc=1)
        tmp.plot.bar(stacked=True,width=0.7,ax=axs[i],legend=False)
        axs[i].grid(False)
        axs[i].set_title(celltype)
        axs[i].set_xlabel('')
        axs[i].set_xticklabels(axs[i].get_xticklabels(), rotation=45, 
                                  ha='right',rotation_mode='anchor')
        if i==0:
            axs[i].set_ylabel('proportion')
        else:
            axs[i].set_ylabel('')
        
        if i==(len(celltypes_to_plot)-1):
            axs[i].legend(bbox_to_anchor=(1.0, 1.0))
fig.tight_layout()
fig.savefig(f'{figdir}/Peak-barplot_conserved-specific_per-celltype.pdf', bbox_inches="tight",dpi=300)
```

Example 36 (unknown):
```unknown
/tmp/ipykernel_26894/2711423203.py:14: FutureWarning: The `inplace` parameter in pandas.Categorical.reorder_categories is deprecated and will be removed in a future version. Reordering categories will always return a new Categorical object.
  peak_meta['peakType'].cat.reorder_categories(['Promoter','Exonic','Intronic','Distal'],
/tmp/ipykernel_26894/2711423203.py:14: FutureWarning: The `inplace` parameter in pandas.Categorical.reorder_categories is deprecated and will be removed in a future version. Reordering categories will always return a new Categorical object.
  peak_meta['peakType'].cat.reorder_categories(['Promoter','Exonic','Intronic','Distal'],
/tmp/ipykernel_26894/2711423203.py:14: FutureWarning: The `inplace` parameter in pandas.Categorical.reorder_categories is deprecated and will be removed in a future version. Reordering categories will always return a new Categorical object.
  peak_meta['peakType'].cat.reorder_categories(['Promoter','Exonic','Intronic','Distal'],
/tmp/ipykernel_26894/2711423203.py:14: FutureWarning: The `inplace` parameter in pandas.Categorical.reorder_categories is deprecated and will be removed in a future version. Reordering categories will always return a new Categorical object.
  peak_meta['peakType'].cat.reorder_categories(['Promoter','Exonic','Intronic','Distal'],
/tmp/ipykernel_26894/2711423203.py:14: FutureWarning: The `inplace` parameter in pandas.Categorical.reorder_categories is deprecated and will be removed in a future version. Reordering categories will always return a new Categorical object.
  peak_meta['peakType'].cat.reorder_categories(['Promoter','Exonic','Intronic','Distal'],
```

---
