How to use the scanpy.tl.umap function in scanpy

To help you get started, we’ve selected a few scanpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github theislab / trVAE / tests / monitor_beta.py View on Github external
ari = trvae.mt.ari(mmd_latent, cell_type_key)
    nmi = trvae.mt.nmi(mmd_latent, cell_type_key)

    _, rec, mmd = network.get_reconstruction_error(net_valid_adata, condition_key)

    row = [alpha, eta, z_dim, mmd_dim, beta, asw, nmi, ari, ebm, rec, mmd]
    with open(f"./{filename}.csv", 'a') as file:
        writer = csv.writer(file)
        writer.writerow(row)
    file.close()

    os.makedirs(f"./results/Monitor/{filename}/", exist_ok=True)
    sc.settings.figdir = f"./results/Monitor/{filename}/"

    sc.pp.neighbors(mmd_latent)
    sc.tl.umap(mmd_latent)
    sc.pl.umap(mmd_latent, color=condition_key, frameon=False, title="", save=f"_trVAE_MMD_condition_{beta}.pdf")
    sc.pl.umap(mmd_latent, color=cell_type_key, frameon=False, title="", save=f"_trVAE_MMD_cell_type_{beta}.pdf")

    K.clear_session()
github theislab / trVAE / tests / test_trVAE.py View on Github external
color = ['condition']

    sc.pp.neighbors(data)
    sc.tl.umap(data)
    sc.pl.umap(data, color=color,
               save=f'_{data_name}_train_data',
               show=False)

    sc.pp.neighbors(latent_with_true_labels)
    sc.tl.umap(latent_with_true_labels)
    sc.pl.umap(latent_with_true_labels, color=color,
               save=f"_{data_name}_latent_with_true_labels",
               show=False)

    sc.pp.neighbors(latent_with_fake_labels)
    sc.tl.umap(latent_with_fake_labels)
    sc.pl.umap(latent_with_fake_labels, color=color,
               save=f"_{data_name}__latent_with_fake_labels",
               show=False)

    sc.pp.neighbors(mmd_latent_with_true_labels)
    sc.tl.umap(mmd_latent_with_true_labels)
    sc.pl.umap(mmd_latent_with_true_labels, color=color,
               save=f"_{data_name}_mmd_latent_with_true_labels",
               show=False)

    sc.pp.neighbors(mmd_latent_with_fake_labels)
    sc.tl.umap(mmd_latent_with_fake_labels)
    sc.pl.umap(mmd_latent_with_fake_labels, color=color,
               save=f"_{data_name}_mmd_latent_with_fake_labels",
               show=False)
    plt.close("all")
github theislab / trVAE / tests / test_vae.py View on Github external
network.restore_model()

    if sparse.issparse(data.X):
        data.X = data.X.A

    feed_data = data.X

    latent = network.to_latent(feed_data)

    latent = sc.AnnData(X=latent)
    latent.obs[cell_type_key] = data.obs[cell_type_key].values

    color = [cell_type_key]

    sc.pp.neighbors(train_data)
    sc.tl.umap(train_data)
    sc.pl.umap(train_data, color=color,
               save=f'_{data_name}_train_data.pdf',
               show=False)

    sc.pp.neighbors(latent)
    sc.tl.umap(latent)
    sc.pl.umap(latent, color=color,
               save=f"_{data_name}_latent.pdf",
               show=False)

    plt.close("all")
github theislab / scgen / tests / test_mmd_ccvae.py View on Github external
fake_labels = np.ones((len(unperturbed_data), 1))

            pred = network.predict(data=unperturbed_data, encoder_labels=true_labels, decoder_labels=fake_labels)
            pred_adata = anndata.AnnData(pred, obs={condition_key: ["pred"] * len(pred)},
                                         var={"var_names": cell_type_data.var_names})
            all_adata = cell_type_data.copy().concatenate(pred_adata.copy())

            scgen.plotting.reg_mean_plot(all_adata, condition_key=condition_key,
                                         axis_keys={"x": ctrl_key, "y": "pred", "y1": stim_key},
                                         path_to_save=f"./figures/reg_mean_{z_dim}.pdf")
            scgen.plotting.reg_var_plot(all_adata, condition_key=condition_key,
                                        axis_keys={"x": ctrl_key, "y": "pred", 'y1': stim_key},
                                        path_to_save=f"./figures/reg_var_{z_dim}.pdf")

            sc.pp.neighbors(all_adata)
            sc.tl.umap(all_adata)
            sc.pl.umap(all_adata, color=condition_key,
                       save="pred")

            # sc.pl.violin(all_adata, keys=diff_genes.tolist()[0], groupby=condition_key,
            #              save=f"_{z_dim}_{diff_genes.tolist()[0]}")

            os.chdir("../../../")
github theislab / trVAE / tests / test_trVAE.py View on Github external
show=False)

    sc.pp.neighbors(latent_with_fake_labels)
    sc.tl.umap(latent_with_fake_labels)
    sc.pl.umap(latent_with_fake_labels, color=color,
               save=f"_{data_name}__latent_with_fake_labels",
               show=False)

    sc.pp.neighbors(mmd_latent_with_true_labels)
    sc.tl.umap(mmd_latent_with_true_labels)
    sc.pl.umap(mmd_latent_with_true_labels, color=color,
               save=f"_{data_name}_mmd_latent_with_true_labels",
               show=False)

    sc.pp.neighbors(mmd_latent_with_fake_labels)
    sc.tl.umap(mmd_latent_with_fake_labels)
    sc.pl.umap(mmd_latent_with_fake_labels, color=color,
               save=f"_{data_name}_mmd_latent_with_fake_labels",
               show=False)
    plt.close("all")
github theislab / trVAE / tests / test_trVAEATAC.py View on Github external
# mmd_latent_with_true_labels.obs[cell_type_key] = data.obs[cell_type_key].values

    mmd_latent_with_fake_labels = sc.AnnData(X=mmd_latent_with_fake_labels)
    mmd_latent_with_fake_labels.obs['condition'] = data.obs['condition'].values
    # mmd_latent_with_fake_labels.obs[cell_type_key] = data.obs[cell_type_key].values

    color = ['condition']

    sc.pp.neighbors(data)
    sc.tl.umap(data)
    sc.pl.umap(data, color=color,
               save=f'_{data_name}_train_data',
               show=False)

    sc.pp.neighbors(latent_with_true_labels)
    sc.tl.umap(latent_with_true_labels)
    sc.pl.umap(latent_with_true_labels, color=color,
               save=f"_{data_name}_latent_with_true_labels",
               show=False)

    sc.pp.neighbors(latent_with_fake_labels)
    sc.tl.umap(latent_with_fake_labels)
    sc.pl.umap(latent_with_fake_labels, color=color,
               save=f"_{data_name}__latent_with_fake_labels",
               show=False)

    sc.pp.neighbors(mmd_latent_with_true_labels)
    sc.tl.umap(mmd_latent_with_true_labels)
    sc.pl.umap(mmd_latent_with_true_labels, color=color,
               save=f"_{data_name}_mmd_latent_with_true_labels",
               show=False)
github theislab / scgen / tests / test_mmd_cvae.py View on Github external
latent_with_true_labels = network.to_latent(net_train_data.X, labels=true_labels)
        latent_with_true_labels = sc.AnnData(X=latent_with_true_labels,
                                             obs={condition_key: net_train_data.obs[condition_key].tolist(),
                                                  cell_type_key: net_train_data.obs[cell_type_key].tolist()})
        sc.pp.neighbors(latent_with_true_labels)
        sc.tl.umap(latent_with_true_labels)
        sc.pl.umap(latent_with_true_labels, color=[condition_key, cell_type_key],
                   save=f"_latent_true_labels_{z_dim}",
                   show=False)

        latent_with_fake_labels = network.to_latent(net_train_data.X, fake_labels)
        latent_with_fake_labels = sc.AnnData(X=latent_with_fake_labels,
                                             obs={condition_key: net_train_data.obs[condition_key].tolist(),
                                                  cell_type_key: net_train_data.obs[cell_type_key].tolist()})
        sc.pp.neighbors(latent_with_fake_labels)
        sc.tl.umap(latent_with_fake_labels)
        sc.pl.umap(latent_with_fake_labels, color=[condition_key, cell_type_key],
                   save=f"_latent_fake_labels_{z_dim}",
                   show=False)

        mmd_with_true_labels = network.to_mmd_layer(network.cvae_model, net_train_data.X,
                                                    encoder_labels=true_labels, feed_fake=False)
        mmd_with_true_labels = sc.AnnData(X=mmd_with_true_labels,
                                          obs={condition_key: net_train_data.obs[condition_key].tolist(),
                                               cell_type_key: net_train_data.obs[cell_type_key].tolist()})
        sc.pp.neighbors(mmd_with_true_labels)
        sc.tl.umap(mmd_with_true_labels)
        sc.pl.umap(mmd_with_true_labels, color=[condition_key, cell_type_key],
                   save=f"_mmd_true_labels_{z_dim}",
                   show=False)

        mmd_with_fake_labels = network.to_mmd_layer(network.cvae_model, net_train_data.X,