<jupyter_start><jupyter_text>--- Mouse Quake_10x_Bladder<jupyter_code>quake_10x_bladder = cb.data.ExprDataSet.read_dataset("../../Datasets/data/Quake_10x_Bladder/data.h5")
utils.peek(quake_10x_bladder, "build/bladder/Quake_10x_Bladder")
quake_10x_bladder.obs.head()
quake_10x_bladder.obs["cluster"] = "cluster_" + quake_10x_bladder.obs["cluster"].astype(int).astype(str)
quake_10x_bladder.obs.dtypes
opt_model_kwargs = dict(batch_effect="donor")
quake_10x_bladder_model = cb.directi.fit_DIRECTi(
    quake_10x_bladder, quake_10x_bladder.uns["seurat_genes"],
    **fixed_model_kwargs, **opt_model_kwargs
)
quake_10x_bladder.latent = quake_10x_bladder_model.inference(quake_10x_bladder)
ax = quake_10x_bladder.visualize_latent("cell_ontology_class", scatter_kws=dict(rasterized=True))
ax.get_figure().savefig("build/bladder/Quake_10x_Bladder/cell_ontology_class.svg", dpi=utils.DPI, bbox_inches="tight")
ax = quake_10x_bladder.visualize_latent("cell_type1", scatter_kws=dict(rasterized=True))
ax.get_figure().savefig("build/bladder/Quake_10x_Bladder/cell_type1.svg", dpi=utils.DPI, bbox_inches="tight")
ax = quake_10x_bladder.visualize_latent("cluster", scatter_kws=dict(rasterized=True))
ax.get_figure().savefig("build/bladder/Quake_10x_Bladder/cluster.svg", dpi=utils.DPI, bbox_inches="tight")
ax = quake_10x_bladder.visualize_latent("free_annotation", scatter_kws=dict(rasterized=True))
ax.get_figure().savefig("build/bladder/Quake_10x_Bladder/free_annotation.svg", dpi=utils.DPI, bbox_inches="tight")
ax = quake_10x_bladder.visualize_latent("donor", scatter_kws=dict(rasterized=True))
ax.get_figure().savefig("build/bladder/Quake_10x_Bladder/donor.svg", dpi=utils.DPI, bbox_inches="tight")
ax = quake_10x_bladder.visualize_latent("gender", scatter_kws=dict(rasterized=True))
ax.get_figure().savefig("build/bladder/Quake_10x_Bladder/gender.svg", dpi=utils.DPI, bbox_inches="tight")
quake_10x_bladder.write_dataset("build/bladder/Quake_10x_Bladder/Quake_10x_Bladder.h5")
%%capture capio
quake_10x_bladder_models = [quake_10x_bladder_model]
opt_model_kwargs = dict(batch_effect="donor")
for i in range(1, cb.config.N_JOBS):
    print("==== Model %d ====" % i)
    quake_10x_bladder_models.append(cb.directi.fit_DIRECTi(
        quake_10x_bladder, quake_10x_bladder.uns["seurat_genes"],
        **fixed_model_kwargs, **opt_model_kwargs,
        random_seed=i
    ))
quake_10x_bladder_blast = cb.blast.BLAST(
    quake_10x_bladder_models, quake_10x_bladder, 
)
quake_10x_bladder_blast.save("build/bladder/Quake_10x_Bladder")
with open("build/bladder/Quake_10x_Bladder/stdout.txt", "w") as f:
    f.write(capio.stdout)
with open("build/bladder/Quake_10x_Bladder/stderr.txt", "w") as f:
    f.write(capio.stderr)
utils.self_projection(quake_10x_bladder_blast, "build/bladder/Quake_10x_Bladder")
%%writefile "build/bladder/Quake_10x_Bladder/predictable.txt"
cell_ontology_class
cell_type1
cluster
free_annotation<jupyter_output><empty_output><jupyter_text>Quake_Smart-seq2_Bladder<jupyter_code>quake_smart_seq2_bladder = cb.data.ExprDataSet.read_dataset("../../Datasets/data/Quake_Smart-seq2_Bladder/data.h5")
utils.peek(quake_smart_seq2_bladder, "build/bladder/Quake_Smart-seq2_Bladder")
quake_smart_seq2_bladder.obs.head()
quake_smart_seq2_bladder.obs["cluster"] = "cluster_" + quake_smart_seq2_bladder.obs["cluster"].astype(int).astype(str)
quake_smart_seq2_bladder.obs.dtypes
opt_model_kwargs = dict(batch_effect="donor")
quake_smart_seq2_bladder_model = cb.directi.fit_DIRECTi(
    quake_smart_seq2_bladder, quake_smart_seq2_bladder.uns["seurat_genes"],
    **fixed_model_kwargs, **opt_model_kwargs
)
quake_smart_seq2_bladder.latent = quake_smart_seq2_bladder_model.inference(quake_smart_seq2_bladder)
ax = quake_smart_seq2_bladder.visualize_latent("cell_ontology_class", scatter_kws=dict(rasterized=True))
ax.get_figure().savefig("build/bladder/Quake_Smart-seq2_Bladder/cell_ontology_class.svg", dpi=utils.DPI, bbox_inches="tight")
ax = quake_smart_seq2_bladder.visualize_latent("cell_type1", scatter_kws=dict(rasterized=True))
ax.get_figure().savefig("build/bladder/Quake_Smart-seq2_Bladder/cell_type1.svg", dpi=utils.DPI, bbox_inches="tight")
ax = quake_smart_seq2_bladder.visualize_latent("cluster", scatter_kws=dict(rasterized=True))
ax.get_figure().savefig("build/bladder/Quake_Smart-seq2_Bladder/cluster.svg", dpi=utils.DPI, bbox_inches="tight")
ax = quake_smart_seq2_bladder.visualize_latent("free_annotation", scatter_kws=dict(rasterized=True))
ax.get_figure().savefig("build/bladder/Quake_Smart-seq2_Bladder/free_annotation.svg", dpi=utils.DPI, bbox_inches="tight")
ax = quake_smart_seq2_bladder.visualize_latent("donor", scatter_kws=dict(rasterized=True))
ax.get_figure().savefig("build/bladder/Quake_Smart-seq2_Bladder/donor.svg", dpi=utils.DPI, bbox_inches="tight")
ax = quake_smart_seq2_bladder.visualize_latent("gender", scatter_kws=dict(rasterized=True))
ax.get_figure().savefig("build/bladder/Quake_Smart-seq2_Bladder/gender.svg", dpi=utils.DPI, bbox_inches="tight")
quake_smart_seq2_bladder.write_dataset("build/bladder/Quake_Smart-seq2_Bladder/Quake_Smart-seq2_Bladder.h5")
%%capture capio
quake_smart_seq2_bladder_models = [quake_smart_seq2_bladder_model]
opt_model_kwargs = dict(batch_effect="donor")
for i in range(1, cb.config.N_JOBS):
    print("==== Model %d ====" % i)
    quake_smart_seq2_bladder_models.append(cb.directi.fit_DIRECTi(
        quake_smart_seq2_bladder, quake_smart_seq2_bladder.uns["seurat_genes"],
        **fixed_model_kwargs, **opt_model_kwargs,
        random_seed=i
    ))
quake_smart_seq2_bladder_blast = cb.blast.BLAST(
    quake_smart_seq2_bladder_models, quake_smart_seq2_bladder, 
)
quake_smart_seq2_bladder_blast.save("build/bladder/Quake_Smart-seq2_Bladder")
with open("build/bladder/Quake_Smart-seq2_Bladder/stdout.txt", "w") as f:
    f.write(capio.stdout)
with open("build/bladder/Quake_Smart-seq2_Bladder/stderr.txt", "w") as f:
    f.write(capio.stderr)
utils.self_projection(quake_smart_seq2_bladder_blast, "build/bladder/Quake_Smart-seq2_Bladder")
%%writefile "build/bladder/Quake_Smart-seq2_Bladder/predictable.txt"
cell_ontology_class
cell_type1
cluster
free_annotation<jupyter_output><empty_output><jupyter_text>Mouse aligned<jupyter_code>os.makedirs("build/bladder/ALIGNED_Mus_musculus_Bladder", exist_ok=True)
#quake_smart_seq2_bladder.obs["quake_smart_seq2_bladder_donor"] = \
#    quake_smart_seq2_bladder.obs["donor"]
#quake_10x_bladder.obs["quake_10x_bladder_donor"] = \
#    quake_10x_bladder.obs["donor"]
mouse = cb.data.ExprDataSet.merge_datasets(dict(
    quake_10x_bladder=quake_10x_bladder,
    quake_smart_seq2_bladder=quake_smart_seq2_bladder
), merge_uns_slots=["seurat_genes"])
mouse.obs.head()
mouse.obs.dtypes
opt_model_kwargs = dict(
    batch_effect=["dataset_name", "donor"],
    #rmbatch_module=["MNNAdversarial", "Adversarial", "Adversarial", "Adversarial"],
    rmbatch_module_kwargs=dict(lambda_reg=0.01)
)
mouse_model = cb.directi.fit_DIRECTi(
    mouse, mouse.uns["seurat_genes"],
    **fixed_model_kwargs, **opt_model_kwargs
)
mouse.latent = mouse_model.inference(mouse)
ax = mouse.visualize_latent("cell_ontology_class", scatter_kws=dict(rasterized=True))
ax.get_figure().savefig("build/bladder/ALIGNED_Mus_musculus_Bladder/cell_ontology_class.svg", dpi=utils.DPI, bbox_inches="tight")
ax = mouse.visualize_latent("dataset_name", scatter_kws=dict(rasterized=True))
ax.get_figure().savefig("build/bladder/ALIGNED_Mus_musculus_Bladder/dataset_name.svg", dpi=utils.DPI, bbox_inches="tight")
ax = mouse.visualize_latent("donor", scatter_kws=dict(rasterized=True))
ax.get_figure().savefig("build/bladder/ALIGNED_Mus_musculus_Bladder/donor.svg", dpi=utils.DPI, bbox_inches="tight")
ax = mouse.visualize_latent("gender", scatter_kws=dict(rasterized=True))
ax.get_figure().savefig("build/bladder/ALIGNED_Mus_musculus_Bladder/gender.svg", dpi=utils.DPI, bbox_inches="tight")
mouse.write_dataset("build/bladder/ALIGNED_Mus_musculus_Bladder/ALIGNED_Mus_musculus_Bladder.h5")
%%capture capio
mouse_models = [mouse_model]
opt_model_kwargs = dict(
    batch_effect=["dataset_name", "donor"],
    #rmbatch_module=["MNNAdversarial", "Adversarial", "Adversarial", "Adversarial"],
    rmbatch_module_kwargs=dict(lambda_reg=0.01)
)
for i in range(1, cb.config.N_JOBS):
    print("==== Model %d ====" % i)
    mouse_models.append(cb.directi.fit_DIRECTi(
        mouse, mouse.uns["seurat_genes"],
        **fixed_model_kwargs, **opt_model_kwargs,
        random_seed=i
    ))
mouse_blast = cb.blast.BLAST(mouse_models, mouse)
mouse_blast.save("build/bladder/ALIGNED_Mus_musculus_Bladder")
with open("build/bladder/ALIGNED_Mus_musculus_Bladder/stdout.txt", "w") as f:
    f.write(capio.stdout)
with open("build/bladder/ALIGNED_Mus_musculus_Bladder/stderr.txt", "w") as f:
    f.write(capio.stderr)
utils.self_projection(mouse_blast, "build/bladder/ALIGNED_Mus_musculus_Bladder")
%%writefile "build/bladder/ALIGNED_Mus_musculus_Bladder/predictable.txt"
cell_ontology_class<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13319215336602763, 'fraction_numerical': 0.018947837717342843, 'mean_word_length': 8.860439560439561, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '484388', 'license': 'MIT', 'n_tokens_mistral': 3873, 'n_tokens_neox': 3585, 'n_words': 309, 'path': 'Notebooks/Database/bladder.ipynb', 'repo_name': 'gao-lab/Cell_BLAST', 'size': '8972'}