<jupyter_start><jupyter_text>Diagonal integration with label annotationA integration task is called [diagonal integration](https://www.nature.com/articles/s41587-021-00895-7) if different modalities share no correspondence information, either among cells or features, e.g., scATAC peaks and scRNA genes, we can use label annotations as prior information to improve the performance.<jupyter_code>import uniport as up
import scanpy as sc
import episcanpy as epi
up.__version__
adata_rna = sc.read('mouse_spleen/rna.h5ad', backup_url='ftp://ngs.sanger.ac.uk/production/teichmann/MultiMAP/rna.h5ad')
adata_atac = sc.read('mouse_spleen/atac-peaks.h5ad', backup_url='ftp://ngs.sanger.ac.uk/production/teichmann/MultiMAP/atac-peaks.h5ad')
print(adata_rna)
print(adata_atac)
adata_atac.obs['domain_id'] = 0
adata_atac.obs['domain_id'] = adata_atac.obs['domain_id'].astype('category')

adata_rna.obs['domain_id'] = 1
adata_rna.obs['domain_id'] = adata_rna.obs['domain_id'].astype('category')<jupyter_output><empty_output><jupyter_text>Preprocess scATAC peaks using `up.TFIDF_LSI`.<jupyter_code>adata_atac.X[adata_atac.X>1] = 1
up.TFIDF_LSI(adata_atac)
print(adata_atac)
# epi.pp.select_var_feature(adata_atac, nb_features=2000, show=False, copy=False)
up.batch_scale(adata_atac, use_rep='X_lsi')

adata_atac_copy = adata_atac.copy()
sc.pp.neighbors(adata_atac_copy, use_rep="X_lsi")
sc.tl.umap(adata_atac_copy, min_dist=0.1)
sc.pl.umap(adata_atac_copy, color=['source', 'cell_type'])
sc.pp.normalize_total(adata_rna)
sc.pp.log1p(adata_rna)
sc.pp.highly_variable_genes(adata_rna, n_top_genes=2000, inplace=False, subset=True)
sc.pp.pca(adata_rna)
up.batch_scale(adata_rna)
print(adata_rna)

adata_rna_copy = adata_rna.copy()
sc.pp.neighbors(adata_rna_copy)
sc.tl.umap(adata_rna_copy, min_dist=0.1)
sc.pl.umap(adata_rna_copy, color=['source', 'cell_type'])<jupyter_output>WARNING: adata.X seems to be already log-transformed.
AnnData object with n_obs × n_vars = 4382 × 2000
    obs: 'cell_type', 'source', 'domain_id'
    var: 'highly_variable', 'means', 'dispersions', 'dispersions_norm'
    uns: 'log1p', 'hvg', 'pca'
    obsm: 'X_pca'
    varm: 'PCs'<jupyter_text>Diagonal integration without prior information.<jupyter_code>adata = up.Run(adatas=[adata_atac, adata_rna], use_rep=['X_lsi','X'], mode='d', iteration=20000)
sc.pp.neighbors(adata, use_rep='latent')
sc.tl.umap(adata, min_dist=0.1)
sc.pl.umap(adata, color=['source', 'cell_type'])<jupyter_output>... storing 'cell_type' as categorical
... storing 'source' as categorical<jupyter_text>Construct prior correspondence information with label annotation.<jupyter_code>alpha=3
prior = up.get_prior(adata_atac.obs['cell_type'].values, adata_rna.obs['cell_type'].values, alpha=alpha)<jupyter_output><empty_output><jupyter_text>Diagonal integration with correspondence information.<jupyter_code>adata = up.Run(adatas=[adata_atac, adata_rna], use_rep=['X_lsi','X'], prior=[prior], mode='d', iteration=20000, lambda_ot=5)
sc.pp.neighbors(adata, use_rep='latent')
sc.tl.umap(adata, min_dist=0.1)
sc.pl.umap(adata, color=['source', 'cell_type'])<jupyter_output>... storing 'cell_type' as categorical
... storing 'source' as categorical
{'fraction_non_alphanumeric': 0.1472624292007552, 'fraction_numerical': 0.018879798615481436, 'mean_word_length': 7.830555555555556, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 19, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '519161', 'license': 'MIT', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1242, 'n_words': 200, 'path': 'docs/source/examples/diagonal_mouse_spleen.ipynb', 'repo_name': 'caokai1073/uniPort', 'size': '3178'}