How to use the scanpy.pl.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 / test_ctrVAE.py View on Github external
train_data.obs.loc[(train_data.obs['condition'] == target_key) & (
            train_data.obs['labels'].isin(train_digits)), 'type'] = 'training'
        train_data.obs.loc[
            (train_data.obs['condition'] == target_key) & (
                train_data.obs['labels'].isin(test_digits)), 'type'] = 'heldout'

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

    if train_digits is not None:
        sc.tl.umap(train_data)
        sc.pl.umap(train_data, color=['type', 'labels'],
                   save=f'_{data_name}_data_type.png',
                   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.png",
               wspace=0.5,
               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.png",
               wspace=0.5,
               show=False)
github theislab / trVAE / tests / test_trVAEMulti.py View on Github external
latent_with_true_labels = sc.AnnData(X=latent_with_true_labels)
        latent_with_true_labels.obs[condition_key] = data.obs[condition_key].values
        latent_with_true_labels.obs[cell_type_key] = data.obs[cell_type_key].values

        sc.pp.neighbors(train_data)
        sc.tl.umap(train_data)
        sc.pl.umap(train_data, color=color,
                   save=f'_{data_name}_{cell_type}_train_data',
                   show=False,
                   wspace=0.15,
                   frameon=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}_{cell_type}_mmd_latent_with_true_labels",
                   show=False,
                   wspace=0.15,
                   frameon=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}_{cell_type}_latent_with_true_labels",
                   show=False,
                   wspace=0.15,
                   frameon=False)

        # mmd_latent_with_true_labels.obs['mmd'] = 'others'
        # mmd_latent_with_true_labels.obs['mmd'] = mmd_latent_with_true_labels.obs.mmd.astype(str)
        # mmd_latent_with_true_labels.obs['mmd'].cat.add_categories([f'alpha-{target_keys[0]}'], inplace=True)
github theislab / trVAE / tests / test_trVAEATAC.py View on Github external
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 / scgen / tests / test_mmd_cvae.py View on Github external
network = scgen.MMDCVAE(x_dimension=train.X.shape[1], z_dimension=z_dim, alpha=alpha, beta=beta,
                            batch_mmd=True, kernel=kernel, train_with_fake_labels=False,
                            model_path="./")

    # network.train(train, n_epochs=n_epochs, batch_size=batch_size, verbose=2)
    print(f"network has been trained!")
    network.restore_model()
    true_labels= np.zeros(shape=(control_data.shape[0], 1))
    fake_labels = np.ones(shape=(control_data.shape[0], 1))
    pred = network.predict(data=control_data, encoder_labels=true_labels, decoder_labels=fake_labels)
    pred_adata = anndata.AnnData(pred, obs={condition_key: ["pred"] * len(pred), "cell_type":control_data.obs["cell_type"].tolist()},
                                 var={"var_names": control_data.var_names})
    all_adata = control_data.concatenate(pred_adata)
    sc.pp.neighbors(all_adata)
    sc.tl.umap(all_adata)
    sc.pl.umap(all_adata, color=[f"{condition_key}", "cell_type", "ISG15"],
               save="cross_pred")
    all_adata.write("cross_study_mmd.h5ad")
github theislab / trVAE / tests / test_rccvae_paired.py View on Github external
mmd_latent_with_fake_labels.obs['labels'] = pd.Categorical(train_data.obs['labels'].values)

        color = ['condition', 'labels']
    else:
        color = ['condition']

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

    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.png",
               wspace=0.5,
               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.png",
               wspace=0.5,
               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.png",
               wspace=0.5,
github theislab / trVAE / tests / test_vae.py View on Github external
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 colomemaria / epiScanpy / episcanpy / tools / _cell_id.py View on Github external
group = element.split(":")[1]
        group_contribution.append(group)

    most_prominent = max(set(group_contribution), key = group_contribution.count) 
    
    print("Differentially open peaks in promoters for known",cell_type,"marker genes are most prominently found in louvain group",most_prominent)
    
    # only take unique peaks (peaks can be among top markers in more than one group)
    unique_sig_peaks = []
    sig_gene_names = []
    for idx,name in enumerate(cell_type_peak):
        if name in sig_peak:
            sig_gene_names.append(cell_type_gene[idx])
            unique_sig_peaks.append(cell_type_peak[idx])
        
    return(sc.pl.umap(adata, color=unique_sig_peaks, title=sig_gene_names))   
github theislab / scgen / scgen / models / util.py View on Github external
plot_reg=True):
    plt.close("all")
    os.makedirs(path_to_save, exist_ok=True)
    sc.settings.figdir = os.path.abspath(path_to_save)
    if isinstance(network, scgen.VAEArithKeras):
        if sparse.issparse(train.X):
            latent = network.to_latent(train.X.A)
        else:
            latent = network.to_latent(train.X)
        latent = sc.AnnData(X=latent,
                            obs={condition_key: train.obs[condition_key].tolist(),
                                 cell_type_key: train.obs[cell_type_key].tolist()})
        if plot_umap:
            sc.pp.neighbors(latent)
            sc.tl.umap(latent)
            sc.pl.umap(latent, color=[condition_key, cell_type_key],
                       save=f"_latent",
                       show=False)

        cell_type_data = train[train.obs[cell_type_key] == cell_type]

        pred, delta = network.predict(adata=cell_type_data,
                                      conditions=conditions,
                                      cell_type_key=cell_type_key,
                                      condition_key=condition_key,
                                      celltype_to_predict=cell_type)

        pred_adata = anndata.AnnData(pred, obs={condition_key: ["pred"] * len(pred)},
                                     var={"var_names": cell_type_data.var_names})
        all_adata = cell_type_data.concatenate(pred_adata)
        sc.tl.rank_genes_groups(cell_type_data, groupby=condition_key, n_genes=100)
        diff_genes = cell_type_data.uns["rank_genes_groups"]["names"][conditions["stim"]]