text_plain_output_3.png text_plain_output_2.png application_vnd.jupyter.stderr_output_1.png
from sklearn.decomposition import PCA

import matplotlib.pyplot as plt

import numpy as np

import scanpy as sc

import scipy

import seaborn as sns

import time

import time

import time

adata = sc.datasets.krumsiek11()
adata.var.index

adata = sc.datasets.pbmc3k_processed()
adata.var.index

import time
for dataset in ['moignard15', 'pbmc3k', 'pbmc3k_processed', 'pbmc68k_reduced', 'paul15', 'krumsiek11']:
    t0 = time.time()
    adata = getattr(sc.datasets, dataset)()

dict_datasets_info = {'krumsiek11': 'Simulated myeloid progenitors [Krumsiek11].', 'moignard15': 'Hematopoiesis in early mouse embryos [Moignard15].', 'pbmc3k': '3k PBMCs from 10x Genomics', 'pbmc3k_processed': 'Processed 3k PBMCs from 10x Genomics.', 'pbmc68k_reduced': 'Subsampled and processed 68k PBMCs.', 'paul15': 'Development of Myeloid Progenitors [Paul15].'}

import time
from sklearn.decomposition import PCA
import scipy
for dataset in ['moignard15', 'pbmc3k', 'pbmc3k_processed', 'pbmc68k_reduced', 'paul15', 'krumsiek11']:
    t0 = time.time()
    adata = getattr(sc.datasets, dataset)()
    reducer = PCA(n_components=2)
    if not scipy.sparse.issparse(adata.X):
        r = reducer.fit_transform(adata.X)
    else:
        r = reducer.fit_transform(adata.X.toarray())

for accession in ['E-GEOD-98816', 'E-MTAB-9154']:
    t0 = time.time()
    adata = sc.datasets.ebi_expression_atlas(accession)
    print(np.round(time.time() - t0, 0), 'Seconds passed for loading')
    print(adata)
    print()
    reducer = PCA(n_components=2)
    if not scipy.sparse.issparse(adata.X):
        r = reducer.fit_transform(adata.X)
    else:
        r = reducer.fit_transform(adata.X.toarray())
    plt.figure(figsize=(20, 8))
    if not 'n_counts' in adata.obs.columns:
        sns.scatterplot(x=r[:, 0], y=r[:, 1])
    else:
        sns.scatterplot(x=r[:, 0], y=r[:, 1], hue=adata.obs['n_counts'])
    plt.title(accession + ' ' + str(len(adata)) + 'cells ', fontsize=20)
    plt.xlabel('PCA1', fontsize=20)
    plt.ylabel('PCA2', fontsize=20)
    plt.show()