Last updated: 2018-12-05
workflowr checks: (Click a bullet for more information) ✔ R Markdown file: up-to-date
Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.
✔ Environment: empty
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
✔ Seed:
set.seed(20180730)
The command set.seed(20180730)
was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.
✔ Session information: recorded
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
✔ Repository version: bd6173a
wflow_publish
or wflow_git_commit
). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:
Ignored files:
Ignored: .DS_Store
Ignored: .Rhistory
Ignored: .Rproj.user/
Ignored: analysis/cache.bak.20181031/
Ignored: analysis/cache.bak/
Ignored: analysis/cache.lind2.20181114/
Ignored: analysis/cache/
Ignored: data/Lindstrom2/
Ignored: data/processed.bak.20181031/
Ignored: data/processed.bak/
Ignored: data/processed.lind2.20181114/
Ignored: output/04B_Organoids_Nephron/cluster_de.csv.zip
Ignored: output/04B_Organoids_Nephron/conserved_markers.csv.zip
Ignored: output/04B_Organoids_Nephron/markers.csv.zip
Ignored: output/04_Organoids_Clustering/cluster_de.csv.zip
Ignored: output/04_Organoids_Clustering/conserved_markers.csv.zip
Ignored: output/04_Organoids_Clustering/markers.csv.zip
Ignored: output/07B_Combined_Nephron/cluster_de.csv.zip
Ignored: output/07B_Combined_Nephron/cluster_de_filtered.csv.zip
Ignored: output/07B_Combined_Nephron/conserved_markers.csv.zip
Ignored: output/07B_Combined_Nephron/markers.csv.zip
Ignored: output/07B_Combined_Nephron/podocyte_de.csv.zip
Ignored: output/07B_Combined_Nephron/podocyte_de_filtered.csv.zip
Ignored: output/07_Combined_Clustering/cluster_de.csv.zip
Ignored: output/07_Combined_Clustering/cluster_de_filtered.csv.zip
Ignored: output/07_Combined_Clustering/conserved_markers.csv.zip
Ignored: output/07_Combined_Clustering/group_de.csv.zip
Ignored: output/07_Combined_Clustering/markers.csv.zip
Ignored: packrat/lib-R/
Ignored: packrat/lib-ext/
Ignored: packrat/lib/
Ignored: packrat/src/
Ignored: test.csv.zip
Unstaged changes:
Deleted: output/04B_Organoids_Nephron/cluster_de.csv
Modified: output/04B_Organoids_Nephron/cluster_de.xlsx
Deleted: output/04B_Organoids_Nephron/conserved_markers.csv
Modified: output/04B_Organoids_Nephron/conserved_markers.xlsx
Deleted: output/04B_Organoids_Nephron/markers.csv
Modified: output/04B_Organoids_Nephron/markers.xlsx
Deleted: output/04_Organoids_Clustering/cluster_de.csv
Modified: output/04_Organoids_Clustering/cluster_de.xlsx
Deleted: output/04_Organoids_Clustering/conserved_markers.csv
Modified: output/04_Organoids_Clustering/conserved_markers.xlsx
Deleted: output/04_Organoids_Clustering/markers.csv
Modified: output/04_Organoids_Clustering/markers.xlsx
Deleted: output/07B_Combined_Nephron/cluster_de.csv
Modified: output/07B_Combined_Nephron/cluster_de.xlsx
Deleted: output/07B_Combined_Nephron/cluster_de_filtered.csv
Modified: output/07B_Combined_Nephron/cluster_de_filtered.xlsx
Deleted: output/07B_Combined_Nephron/conserved_markers.csv
Modified: output/07B_Combined_Nephron/conserved_markers.xlsx
Deleted: output/07B_Combined_Nephron/markers.csv
Modified: output/07B_Combined_Nephron/markers.xlsx
Deleted: output/07B_Combined_Nephron/podocyte_de.csv
Deleted: output/07B_Combined_Nephron/podocyte_de_filtered.csv
Deleted: output/07_Combined_Clustering/cluster_de.csv
Modified: output/07_Combined_Clustering/cluster_de.xlsx
Deleted: output/07_Combined_Clustering/cluster_de_filtered.csv
Modified: output/07_Combined_Clustering/cluster_de_filtered.xlsx
Deleted: output/07_Combined_Clustering/conserved_markers.csv
Modified: output/07_Combined_Clustering/conserved_markers.xlsx
Deleted: output/07_Combined_Clustering/group_de.csv
Deleted: output/07_Combined_Clustering/markers.csv
Modified: output/07_Combined_Clustering/markers.xlsx
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
File | Version | Author | Date | Message |
---|---|---|---|---|
Rmd | bd6173a | Luke Zappia | 2018-12-05 | Add gene ids to output files |
Rmd | 858cf44 | Luke Zappia | 2018-12-04 | Add hFK podocyte DE |
html | 858cf44 | Luke Zappia | 2018-12-04 | Add hFK podocyte DE |
html | 582acea | Luke Zappia | 2018-12-03 | Fix DE results summary plot cluster labels |
Rmd | 14f8c80 | Luke Zappia | 2018-11-21 | Fix filtered nephron DE output files |
html | 14f8c80 | Luke Zappia | 2018-11-21 | Fix filtered nephron DE output files |
Rmd | 12df6e3 | Luke Zappia | 2018-11-20 | Filter nephron cluster DE results |
html | 12df6e3 | Luke Zappia | 2018-11-20 | Filter nephron cluster DE results |
html | a61f9c9 | Luke Zappia | 2018-09-13 | Rebuild site |
html | ad10b21 | Luke Zappia | 2018-09-13 | Switch to GitHub |
Rmd | 7755ac7 | Luke Zappia | 2018-08-15 | Add methods document |
Rmd | bff4d5b | Luke Zappia | 2018-08-14 | Add crossover document |
Rmd | 30718d3 | Luke Zappia | 2018-08-14 | Add nephron reclustering |
# scRNA-seq
library("Seurat")
# Plotting
library("clustree")
library("viridis")
# Presentation
library("glue")
library("knitr")
# Parallel
library("BiocParallel")
# Paths
library("here")
# Output
library("writexl")
library("jsonlite")
# Tidyverse
library("tidyverse")
source(here("R/output.R"))
combined.path <- here("data/processed/Combined_clustered.Rds")
bpparam <- MulticoreParam(workers = 10)
In this document we are going to recluster the nephron clusters identified in the combined analysis.
if (file.exists(combined.path)) {
combined <- read_rds(combined.path)
} else {
stop("Clustered Combined dataset is missing. ",
"Please run '07_Combined_Clustering.Rmd' first.",
call. = FALSE)
}
de.sig <- read_csv(here("output/07_Combined_Clustering/de_signature.csv"),
col_types = cols(Gene = col_character()))$Gene
clusters <- c(6, 7, 10, 15)
comb.neph <- SubsetData(combined, ident.use = clusters)
comb.neph <- RunTSNE(comb.neph, reduction.use = "cca.aligned", dims.use = 1:20)
We are going to select only the cells in clusters 6, 7, 10 and 15. This leaves us with 1964 cells.
# Clear old clustering
not.res <- !grepl("res\\.", colnames(comb.neph@meta.data))
comb.neph@meta.data <- comb.neph@meta.data[, not.res]
n.dims <- 20
resolutions <- seq(0, 1, 0.1)
comb.neph <- FindClusters(comb.neph, reduction.type = "cca.aligned",
dims.use = 1:n.dims, resolution = resolutions,
force.recalc = TRUE)
Seurat
has a resolution parameter that indirectly controls the number of clusters it produces. We tried clustering at a range of resolutions from 0 to 1.
Here are t-SNE plots of the different clusterings.
src_list <- lapply(resolutions, function(res) {
src <- c("#### Res {{res}} {.unnumbered}",
"```{r cluster-tSNE-{{res}}}",
"TSNEPlot(comb.neph, group.by = 'res.{{res}}', do.return = TRUE)",
"```",
"")
knit_expand(text = src)
})
out <- knit_child(text = unlist(src_list), options = list(cache = FALSE))
TSNEPlot(comb.neph, group.by = 'res.0', do.return = TRUE)
Version | Author | Date |
---|---|---|
f31ab8a | Luke Zappia | 2018-08-14 |
TSNEPlot(comb.neph, group.by = 'res.0.1', do.return = TRUE)
Version | Author | Date |
---|---|---|
f31ab8a | Luke Zappia | 2018-08-14 |
TSNEPlot(comb.neph, group.by = 'res.0.2', do.return = TRUE)
Version | Author | Date |
---|---|---|
f31ab8a | Luke Zappia | 2018-08-14 |
TSNEPlot(comb.neph, group.by = 'res.0.3', do.return = TRUE)
Version | Author | Date |
---|---|---|
f31ab8a | Luke Zappia | 2018-08-14 |
TSNEPlot(comb.neph, group.by = 'res.0.4', do.return = TRUE)
Version | Author | Date |
---|---|---|
f31ab8a | Luke Zappia | 2018-08-14 |
TSNEPlot(comb.neph, group.by = 'res.0.5', do.return = TRUE)
Version | Author | Date |
---|---|---|
f31ab8a | Luke Zappia | 2018-08-14 |
TSNEPlot(comb.neph, group.by = 'res.0.6', do.return = TRUE)
Version | Author | Date |
---|---|---|
f31ab8a | Luke Zappia | 2018-08-14 |
TSNEPlot(comb.neph, group.by = 'res.0.7', do.return = TRUE)
Version | Author | Date |
---|---|---|
f31ab8a | Luke Zappia | 2018-08-14 |
TSNEPlot(comb.neph, group.by = 'res.0.8', do.return = TRUE)
Version | Author | Date |
---|---|---|
f31ab8a | Luke Zappia | 2018-08-14 |
TSNEPlot(comb.neph, group.by = 'res.0.9', do.return = TRUE)
Version | Author | Date |
---|---|---|
f31ab8a | Luke Zappia | 2018-08-14 |
TSNEPlot(comb.neph, group.by = 'res.1', do.return = TRUE)
Version | Author | Date |
---|---|---|
f31ab8a | Luke Zappia | 2018-08-14 |
Coloured by clustering resolution.
clustree(comb.neph)
Version | Author | Date |
---|---|---|
f31ab8a | Luke Zappia | 2018-08-14 |
Coloured by the SC3 stability metric.
clustree(comb.neph, node_colour = "sc3_stability")
Version | Author | Date |
---|---|---|
f31ab8a | Luke Zappia | 2018-08-14 |
Coloured by the expression of some well-known kidney marker genes.
genes <- c("PECAM1", "CDH5", "MEIS1", "PDGFRA", "HMGB2", "CENPA", "SIX1",
"DAPL1", "NPHS1", "PODXL", "S100A8", "TYROBP", "MAL", "EMX2",
"LRP2", "GATA3", "SLC12A1", "SPINT2", "TUBB2B", "STMN2", "TTYH1",
"HBA1", "HBG1")
is_present <- genes %in% rownames(comb.neph@data)
The following genes aren’t present in this dataset and will be skipped:
src_list <- lapply(genes[is_present], function(gene) {
src <- c("##### {{gene}} {.unnumbered}",
"```{r clustree-{{gene}}}",
"clustree(comb.neph, node_colour = '{{gene}}',",
"node_colour_aggr = 'mean',",
"exprs = 'scale.data') +",
"scale_colour_viridis_c(option = 'plasma', begin = 0.3)",
"```",
"")
knit_expand(text = src)
})
out <- knit_child(text = unlist(src_list), options = list(cache = FALSE))
clustree(comb.neph, node_colour = 'PECAM1',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'CDH5',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'MEIS1',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'PDGFRA',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'HMGB2',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'CENPA',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'SIX1',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'DAPL1',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'NPHS1',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'PODXL',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'S100A8',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'TYROBP',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'MAL',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'EMX2',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'LRP2',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'GATA3',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'SLC12A1',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'SPINT2',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'TUBB2B',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'STMN2',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'TTYH1',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
clustree(comb.neph, node_colour = 'HBA1',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
clustree(comb.neph, node_colour = 'HBG1',
node_colour_aggr = 'mean',
exprs = 'scale.data') +
scale_colour_viridis_c(option = 'plasma', begin = 0.3)
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
res <- 0.6
comb.neph <- SetIdent(comb.neph,
ident.use = comb.neph@meta.data[, paste0("res.", res)])
n.clusts <- length(unique(comb.neph@ident))
Based on these plots we will use a resolution of 0.6.
Let’s have a look at the clusters on a t-SNE plot.
p1 <- TSNEPlot(comb.neph, do.return = TRUE, pt.size = 0.5,
group.by = "DatasetSample")
p2 <- TSNEPlot(comb.neph, do.label = TRUE, do.return = TRUE, pt.size = 0.5)
plot_grid(p1, p2)
Version | Author | Date |
---|---|---|
f31ab8a | Luke Zappia | 2018-08-14 |
We can also look at the number of cells in each cluster.
plot.data <- comb.neph@meta.data %>%
select(Dataset, cluster = paste0("res.", res)) %>%
mutate(cluster = factor(as.numeric(cluster))) %>%
group_by(cluster, Dataset) %>%
summarise(count = n()) %>%
mutate(clust_total = sum(count)) %>%
mutate(clust_prop = count / clust_total) %>%
group_by(Dataset) %>%
mutate(dataset_total = sum(count)) %>%
ungroup() %>%
mutate(dataset_prop = count / dataset_total)
ggplot(plot.data, aes(x = cluster, y = count, fill = Dataset)) +
geom_col()
Version | Author | Date |
---|---|---|
f31ab8a | Luke Zappia | 2018-08-14 |
We are also interested in what proportions of the cells in each cluster come from each datasets (i.e. are there dataset specific clusters?).
ggplot(plot.data, aes(x = cluster, y = clust_prop, fill = Dataset)) +
geom_col()
Version | Author | Date |
---|---|---|
f31ab8a | Luke Zappia | 2018-08-14 |
Alternatively we can look at what proportion of the cells in each dataset are in each cluster. If each dataset has the same distribution of cell types the heights of the bars should be the same.
ggplot(plot.data, aes(x = cluster, y = dataset_prop, fill = Dataset)) +
geom_col(position = position_dodge(0.9))
Version | Author | Date |
---|---|---|
f31ab8a | Luke Zappia | 2018-08-14 |
Clustering is not very useful if we don’t know what cell types the clusters represent. One way to work that out is to look at marker genes, genes that are differentially expressed in one cluster compared to all other cells. Here we use the Wilcoxon rank sum test genes that are present in at least 10 percent of cells in at least one group (a cluster or all other cells).
markers <- bplapply(seq_len(n.clusts) - 1, function(cl) {
cl.markers <- FindMarkers(comb.neph, cl, logfc.threshold = 0, min.pct = 0.1,
print.bar = FALSE)
cl.markers$cluster <- cl
cl.markers$gene <- rownames(cl.markers)
return(cl.markers)
}, BPPARAM = bpparam)
markers <- bind_rows(markers) %>%
select(gene, cluster, everything())
Here we print out the top two markers for each cluster.
markers %>% group_by(cluster) %>% top_n(2, abs(avg_logFC)) %>% data.frame
A heatmap can give us a better view. We show the top five positive marker genes for each cluster.
top <- markers %>% group_by(cluster) %>% top_n(5, avg_logFC)
cols <- viridis(100)[c(1, 50, 100)]
DoHeatmap(comb.neph, genes.use = top$gene, slim.col.label = TRUE,
remove.key = TRUE, col.low = cols[1], col.mid = cols[2],
col.high = cols[3])
Version | Author | Date |
---|---|---|
f31ab8a | Luke Zappia | 2018-08-14 |
markers.list <- lapply(0:(n.clusts - 1), function(x) {
markers %>%
filter(cluster == x, p_val < 0.05) %>%
dplyr::arrange(-avg_logFC) %>%
select(Gene = gene, LogFC = avg_logFC, pVal = p_val)
})
names(markers.list) <- paste("Cluster", 0:(n.clusts - 1))
marker.summary <- markers.list %>%
map2_df(names(markers.list), ~ mutate(.x, Cluster = .y)) %>%
mutate(IsUp = LogFC > 0) %>%
group_by(Cluster) %>%
summarise(Up = sum(IsUp), Down = sum(!IsUp)) %>%
mutate(Down = -Down) %>%
gather(key = "Direction", value = "Count", -Cluster) %>%
mutate(Cluster = factor(Cluster, levels = names(markers.list)))
ggplot(marker.summary,
aes(x = fct_rev(Cluster), y = Count, fill = Direction)) +
geom_col() +
geom_text(aes(y = Count + sign(Count) * max(abs(Count)) * 0.07,
label = abs(Count)),
size = 6, colour = "grey25") +
coord_flip() +
scale_fill_manual(values = c("#377eb8", "#e41a1c")) +
ggtitle("Number of identified genes") +
theme(axis.title = element_blank(),
axis.line = element_blank(),
axis.ticks = element_blank(),
axis.text.x = element_blank(),
legend.position = "bottom")
Version | Author | Date |
---|---|---|
ad10b21 | Luke Zappia | 2018-09-13 |
We can also look at the full table of significant marker genes for each cluster.
src_list <- lapply(0:(n.clusts - 1), function(i) {
src <- c("### {{i}} {.unnumbered}",
"```{r marker-cluster-{{i}}}",
"markers.list[[{{i}} + 1]]",
"```",
"")
knit_expand(text = src)
})
out <- knit_child(text = unlist(src_list),
options = list(echo = FALSE, cache = FALSE))