diff --git a/labs/scanpy/scanpy_03_integration.qmd b/labs/scanpy/scanpy_03_integration.qmd index 047fe76c..91f39509 100644 --- a/labs/scanpy/scanpy_03_integration.qmd +++ b/labs/scanpy/scanpy_03_integration.qmd @@ -68,6 +68,7 @@ As the stored AnnData object contains scaled data based on variable genes, we ne ```{python} adata2 = adata.raw.to_adata() +# in some versions of Anndata there is an issue with information on the logtransformation in the slot log1p.base so we set it to None to not get errors. adata2.uns['log1p']['base']=None # check that the matrix looks like normalized counts @@ -263,10 +264,10 @@ sc.tl.tsne(adata_sc, n_pcs = 30, use_rep = "Scanorama") ```{python} fig, axs = plt.subplots(2, 2, figsize=(10,8),constrained_layout=True) -sc.pl.umap(adata2, color="sample", title="BBKNN tsne", ax=axs[0,0], show=False) -sc.pl.umap(adata, color="sample", title="Scanorama tsne", ax=axs[0,1], show=False) +sc.pl.tsne(adata2, color="sample", title="BBKNN tsne", ax=axs[0,0], show=False) +sc.pl.tsne(adata_sc, color="sample", title="Scanorama tsne", ax=axs[0,1], show=False) sc.pl.umap(adata2, color="sample", title="BBKNN umap", ax=axs[1,0], show=False) -sc.pl.umap(adata, color="sample", title="Scanorama umap", ax=axs[1,1], show=False) +sc.pl.umap(adata_sc, color="sample", title="Scanorama umap", ax=axs[1,1], show=False) ``` {{< meta int_save >}} @@ -277,11 +278,10 @@ save_file = './data/covid/results/scanpy_covid_qc_dr_scanorama.h5ad' adata_sc.write_h5ad(save_file) ``` -## Compare all +## Overview all methods + +Now we will plot UMAPS with all three integration methods side by side. -:::{.callout-note title="Discuss"} -Plot umap of all the methods we tested here. Which do you think looks better and why? -::: ```{python} fig, axs = plt.subplots(2, 2, figsize=(10,8),constrained_layout=True) @@ -291,11 +291,16 @@ sc.pl.umap(adata_combat, color="sample", title="Combat", ax=axs[1,0], show=False sc.pl.umap(adata_sc, color="sample", title="Scanorama", ax=axs[1,1], show=False) ``` + :::{.callout-note title="Discuss"} +{{< meta int_conclusion >}} +::: + +## Extra task + Have a look at the documentation for [BBKNN](https://scanpy.readthedocs.io/en/latest/generated/scanpy.external.pp.bbknn.html#scanpy-external-pp-bbknn) Try changing some of the parameteres in BBKNN, such as distance metric, number of PCs and number of neighbors. How does the results change with different parameters? Can you explain why? -::: ## {{< meta session >}} diff --git a/labs/scanpy/scanpy_04_clustering.qmd b/labs/scanpy/scanpy_04_clustering.qmd index 93d01e8b..6c214181 100644 --- a/labs/scanpy/scanpy_04_clustering.qmd +++ b/labs/scanpy/scanpy_04_clustering.qmd @@ -79,12 +79,6 @@ genes = ["CD3E", "CD4", "CD8A", "GNLY","NKG7", "MS4A1","FCGR3A","CD14","LYZ","C sc.pl.dotplot(adata, genes, groupby='leiden_0.6', dendrogram=True) ``` -Plot proportion of cells from each condition per cluster. - -```{python} -tmp = pd.crosstab(adata.obs['leiden_0.6'],adata.obs['type'], normalize='index') -tmp.plot.bar(stacked=True).legend(loc='upper right') -``` ### Louvain @@ -165,6 +159,34 @@ sc.pl.umap(adata, color=['hclust_5', 'hclust_10', 'hclust_15']) adata.write_h5ad('./data/covid/results/scanpy_covid_qc_dr_scanorama_cl.h5ad') ``` + +## {{< meta clust_distribution >}} + +{{< meta clust_distribution_1 >}} + +Select the "leiden_0.6" and plot proportion of samples per cluster and also proportion covid vs ctrl. + +Plot proportion of cells from each condition per cluster. + +```{python} +tmp = pd.crosstab(adata.obs['leiden_0.6'],adata.obs['type'], normalize='index') +tmp.plot.bar(stacked=True).legend(bbox_to_anchor=(1.4, 1), loc='upper right') + +tmp = pd.crosstab(adata.obs['leiden_0.6'],adata.obs['sample'], normalize='index') +tmp.plot.bar(stacked=True).legend(bbox_to_anchor=(1.4, 1),loc='upper right') + +``` + +{{< meta clust_distribution_2 >}} + +{{< meta clust_distribution_3 >}} + +```{python} +tmp = pd.crosstab(adata.obs['sample'],adata.obs['leiden_0.6'], normalize='index') +tmp.plot.bar(stacked=True).legend(bbox_to_anchor=(1.4, 1), loc='upper right') + +``` + :::{.callout-note title="Discuss"} {{< meta clust_3 >}} ::: diff --git a/labs/seurat/seurat_04_clustering.qmd b/labs/seurat/seurat_04_clustering.qmd index 41ebe6d7..79532321 100644 --- a/labs/seurat/seurat_04_clustering.qmd +++ b/labs/seurat/seurat_04_clustering.qmd @@ -213,7 +213,7 @@ wrap_plots( saveRDS(alldata, "data/covid/results/seurat_covid_qc_dr_int_cl.rds") ``` -### {{< meta clust_distribution >}} +## {{< meta clust_distribution >}} {{< meta clust_distribution_1 >}}