<jupyter_start><jupyter_text>Load and preprocess data<jupyter_code># preprocessed Kang18 dataset (log transformed, highly variable genes) 
# with reactome annotations in adata.varm['I']
# download dataset - https://drive.google.com/file/d/1BWdDg4mW0wSvZxDFMh0EcG-gLGQ5PllN/view?usp=sharing
adata = sc.read('kang_count_proc.h5ad')
select_genes = adata.varm['I'].sum(1)>0
adata._inplace_subset_var(select_genes)
adata.X-=adata.X.mean(0)<jupyter_output><empty_output><jupyter_text>Get intercode latent representation<jupyter_code>LR = 0.001
BATCH_SIZE = 62
N_EPOCHS = 80

# regularization hyperparameters
# lambda0 - page 19 of presentation
# lambdas 1-3 - last term on page 20

LAMBDA0 = 0.1

LAMBDA1 = 0.93
LAMBDA3 = 0.57
intercode = Intercode(adata)
# n_sparse - number of sparse terms, corresponding l1 regularization hyperparameter - lambda2
# n_dense - number of dense terms
intercode.train(LR, BATCH_SIZE, N_EPOCHS, l2_reg_lambda0=LAMBDA0, lambda1=LAMBDA1, lambda3=LAMBDA3)
terms = ('INTERFERON_SIGNALING', 'SIGNALING_BY_THE_B_CELL_RECEPT')
encoded = intercode.encode(adata.X, term_names=terms)
adata.obs['INTERFERON_SIGNALING'] = encoded[:, 0]
adata.obs['SIGNALING_BY_THE_B_CELL_RECEPT'] = encoded[:, 1]
sc.pl.scatter(adata, x='INTERFERON_SIGNALING', y='SIGNALING_BY_THE_B_CELL_RECEPT', color='condition', size=22)
sc.pl.scatter(adata, x='INTERFERON_SIGNALING', y='SIGNALING_BY_THE_B_CELL_RECEPT', color='cell_type', size=22)
intercode.save('kang_last')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12163978494623656, 'fraction_numerical': 0.03494623655913978, 'mean_word_length': 7.758823529411765, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '67773', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 628, 'n_tokens_neox': 587, 'n_words': 100, 'path': 'notebooks/intercode-api-Kang18.ipynb', 'repo_name': 'theislab/intercode', 'size': '1488'}