Skip to content

Commit

Permalink
updates scanpy labs 03 and 04
Browse files Browse the repository at this point in the history
  • Loading branch information
asabjorklund committed Jan 19, 2024
1 parent 6e7f731 commit b673039
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 15 deletions.
21 changes: 13 additions & 8 deletions labs/scanpy/scanpy_03_integration.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 >}}
Expand All @@ -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)
Expand All @@ -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 >}}

Expand Down
34 changes: 28 additions & 6 deletions labs/scanpy/scanpy_04_clustering.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 >}}
:::
Expand Down
2 changes: 1 addition & 1 deletion labs/seurat/seurat_04_clustering.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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 >}}

Expand Down

0 comments on commit b673039

Please sign in to comment.