# Load required libraries
library(SingleCellExperiment)
## Loading required package: SummarizedExperiment
## Loading required package: MatrixGenerics
## Loading required package: matrixStats
##
## Attaching package: 'MatrixGenerics'
## The following objects are masked from 'package:matrixStats':
##
## colAlls, colAnyNAs, colAnys, colAvgsPerRowSet, colCollapse,
## colCounts, colCummaxs, colCummins, colCumprods, colCumsums,
## colDiffs, colIQRDiffs, colIQRs, colLogSumExps, colMadDiffs,
## colMads, colMaxs, colMeans2, colMedians, colMins, colOrderStats,
## colProds, colQuantiles, colRanges, colRanks, colSdDiffs, colSds,
## colSums2, colTabulates, colVarDiffs, colVars, colWeightedMads,
## colWeightedMeans, colWeightedMedians, colWeightedSds,
## colWeightedVars, rowAlls, rowAnyNAs, rowAnys, rowAvgsPerColSet,
## rowCollapse, rowCounts, rowCummaxs, rowCummins, rowCumprods,
## rowCumsums, rowDiffs, rowIQRDiffs, rowIQRs, rowLogSumExps,
## rowMadDiffs, rowMads, rowMaxs, rowMeans2, rowMedians, rowMins,
## rowOrderStats, rowProds, rowQuantiles, rowRanges, rowRanks,
## rowSdDiffs, rowSds, rowSums2, rowTabulates, rowVarDiffs, rowVars,
## rowWeightedMads, rowWeightedMeans, rowWeightedMedians,
## rowWeightedSds, rowWeightedVars
## Loading required package: GenomicRanges
## Loading required package: stats4
## Loading required package: BiocGenerics
##
## Attaching package: 'BiocGenerics'
## The following objects are masked from 'package:stats':
##
## IQR, mad, sd, var, xtabs
## The following objects are masked from 'package:base':
##
## anyDuplicated, append, as.data.frame, basename, cbind, colnames,
## dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
## grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
## order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
## rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
## union, unique, unsplit, which.max, which.min
## Loading required package: S4Vectors
##
## Attaching package: 'S4Vectors'
## The following objects are masked from 'package:base':
##
## expand.grid, I, unname
## Loading required package: IRanges
## Loading required package: GenomeInfoDb
## Loading required package: Biobase
## Welcome to Bioconductor
##
## Vignettes contain introductory material; view with
## 'browseVignettes()'. To cite Bioconductor, see
## 'citation("Biobase")', and for packages 'citation("pkgname")'.
##
## Attaching package: 'Biobase'
## The following object is masked from 'package:MatrixGenerics':
##
## rowMedians
## The following objects are masked from 'package:matrixStats':
##
## anyMissing, rowMedians
library(Seurat)
## Attaching SeuratObject
## Attaching sp
##
## Attaching package: 'Seurat'
## The following object is masked from 'package:SummarizedExperiment':
##
## Assays
library(tidyverse)
## ── Attaching packages
## ───────────────────────────────────────
## tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6 ✔ purrr 0.3.4
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.4.1
## ✔ readr 2.1.3 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::collapse() masks IRanges::collapse()
## ✖ dplyr::combine() masks Biobase::combine(), BiocGenerics::combine()
## ✖ dplyr::count() masks matrixStats::count()
## ✖ dplyr::desc() masks IRanges::desc()
## ✖ tidyr::expand() masks S4Vectors::expand()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::first() masks S4Vectors::first()
## ✖ dplyr::lag() masks stats::lag()
## ✖ ggplot2::Position() masks BiocGenerics::Position(), base::Position()
## ✖ purrr::reduce() masks GenomicRanges::reduce(), IRanges::reduce()
## ✖ dplyr::rename() masks S4Vectors::rename()
## ✖ dplyr::slice() masks IRanges::slice()
library(MetaMarkers)
library(scRNAseq)
library(dplyr)
Single-cell RNA-sequencing technologies have enabled the discovery and characterization of an incredible number of novel cell types and batches. However, cell types are usually measured in only one biological condition and subject to technical variability, making it difficult to identify robust markers, particularly for rare populations. MetaMarkers proposed a simple methodology to pool marker information across datasets while keeping datasets independent, identifying robust marker signatures and
Here are some of the reasons why you may want to use MetaMarkers: - the pipeline is fast and easy to use, making it possible to aggregate a large number of datasets. - the more datasets you provide, the more technical and biological variability you sample, progressively increasing marker robustness. - MetaMarkers creates marker signatures that offer redundant information about cell types. For example, these robust signatures enable rapid cell type identification at the individual cell level, even if the main markers have not been measured in a particular cell due to dropout. - MetaMarkers offers the possibility to stratify marker selection by grouping cell types into broader classes, enabling combinatorial identification of cell types.
What is required from the user’s perspective are: - a list of annotated datasets. - matching cell type names across datasets.
To obtain matching annotation across datasets in an automated way, we suggest using Seurat to perform integrative clustering or MetaNeighbor to match highly replicable cell types.
We illustrate how to create meta-marker lists by using 4 placenta datasets. We show how to create meta-marker lists, visualize and pick the best meta-markers. We then show how to create hierarchical lists by grouping cell types into trophoblast and non-trophoblast classes.
Here, we will load the the datasets in the SingleCellExperiment format.
Then, we need to make sure that gene names are identical across datasets. Here, the two datasets share the same format of gene names. Note that MetaMarkers will automatically remove duplicate gene names, so we don’t need to worry.
vtdataset <- readRDS("vtSeurat2_annotated.rds")
sdataset <- readRDS("sSeurat2_annotated.rds")
ldataset <- readRDS("lSeurat_annotated.rds")
hdataset <- readRDS("hSeurat_annotated.rds")
# Collapse the cell types in Han dataset
lmeta_copy <- ldataset@meta.data %>%
select(Annotation)
dim(ldataset@meta.data)
#> [1] 1332 16
# read the cell types data frame
l_cell_types <- read.csv("Liu Cell Types.csv") %>%
rename(Annotation = Annotations)
# use inner_join() on hmeta_copy and h_cell_types
df <- inner_join(lmeta_copy, l_cell_types)
# Check if the order is maintained
summary(df$Annotation == lmeta_copy$Annotation)
#> Mode TRUE
#> logical 1332
# add to meta.data
ldataset$merged_annotation <- df$Merged
# Collapse the cell types in VT dataset
vtmeta_copy <- vtdataset@meta.data %>%
select(Annotation)
# Do the same thing for the vtSeurat
vt_cell_types <- read.csv("VT Cell Types.csv") %>%
rename(Annotation = Annotations)
# use inner_join() on vtmeta_copy and vt_cell_types
df_vt <- inner_join(vtmeta_copy, vt_cell_types)
# Check if the order is maintained
summary(df_vt$Annotation == vtmeta_copy$Annotation)
#> Mode TRUE
#> logical 16818
# add to meta.data
vtdataset$merged_annotation <- df_vt$Merged
# Collapse the cell types in Suryawanshi dataset
smeta_copy <- sdataset@meta.data %>%
select(CellType) %>%
mutate(Annotation = CellType)
sdataset@meta.data$CellType %>%
table()
#> .
#> Cytotrophoblast Epithelial (Neuroendocrine)
#> 1531 140
#> Extravillous trophoblast Hematopoietic (Erythroblast)
#> 48 775
#> Immune (Lymphocyte) Immune (Macrophage)
#> 993 627
#> Immune (Myeloid) Stromal (Endothelial)
#> 247 1154
#> Stromal (Fibroblast) Syncytiotrophoblast
#> 4591 758
# read the cell types data frame
s_cell_types <- read.csv("Suryawanshi Cell Types.csv") %>%
rename(Annotation = Annotations)
# use inner_join() on smeta_copy and s_cell_types
df_s <- inner_join(smeta_copy, s_cell_types)
# Check if the order is maintained
summary(df_s$Annotation == smeta_copy$Annotation)
#> Mode TRUE
#> logical 10864
# add to meta.data
sdataset$merged_annotation <- df_s$Merged
# Collapse the cell types in Han dataset
hmeta_copy <- hdataset@meta.data %>%
select(Annotation)
dim(hdataset@meta.data)
#> [1] 4383 17
# read the cell types data frame
h_cell_types <- read.csv("Han Cell Types.csv") %>%
rename(Annotation = Annotations)
# use inner_join() on hmeta_copy and h_cell_types
df <- inner_join(hmeta_copy, h_cell_types)
# Check if the order is maintained
summary(df$Annotation == hmeta_copy$Annotation)
#> Mode TRUE
#> logical 4383
# add to meta.data
hdataset$merged_annotation <- df$Merged
# Change the Idents of the Seurat Objects
Idents(object = ldataset) <- "merged_annotation"
Idents(object = vtdataset) <- "merged_annotation"
Idents(object = sdataset) <- "merged_annotation"
Idents(object = hdataset) <- "merged_annotation"
# Convert to SCE objects
lSCE <- as.SingleCellExperiment(ldataset)
vtSCE <- as.SingleCellExperiment(vtdataset)
sSCE <- as.SingleCellExperiment(sdataset)
hSCE <- as.SingleCellExperiment(hdataset)
Next we need to match cell type names across datasets. Cell types are contained in the “label” column of the datasets (part of the colData slot, but can be accessed directly as shown here).
table(lSCE@colData$merged_annotation)
#>
#> Cytotrophoblast Extravillous trophoblast Stromal cell
#> 245 437 587
#> Syncytiotrophoblast
#> 63
table(vtSCE@colData$merged_annotation)
#>
#> Cytotrophoblast Dendritic cell Endothelial cell
#> 8346 11 143
#> Epithelial cell Extravillous trophoblast Fibroblast
#> 37 3037 2118
#> Granulocyte Hofbauer cell ILC3
#> 37 1200 1
#> Macrophage Monocyte Natural killer cell
#> 829 16 9
#> Plasma Stromal cell Syncytiotrophoblast
#> 6 1 1023
#> T cells
#> 4
table(sSCE@colData$merged_annotation)
#>
#> Cytotrophoblast Endothelial cell Epithelial cell
#> 1531 1154 140
#> Erythroblast Extravillous trophoblast Fibroblast
#> 775 48 4591
#> Lymphocyte Macrophage Myeloid cell
#> 993 627 247
#> Syncytiotrophoblast
#> 758
table(hSCE@colData$merged_annotation)
#>
#> Cytotrophoblast Dendritic cell Endothelial cell
#> 31 526 8
#> Epithelial cell Erythroid cell Extravillous trophoblast
#> 12 507 584
#> Hofbauer cell Macrophage Neutrophil
#> 181 102 61
#> Proliferating cell Smooth muscle cell Stromal cell
#> 47 805 1500
#> Syncytiotrophoblast
#> 19
Some cell types are only present in one dataset, but there is a good overlap for the main cell types. We update names of cell types that overlap but have different names.
common_labels <- Reduce(intersect,
list(unique(lSCE@colData$merged_annotation),
unique(vtSCE@colData$merged_annotation),
unique(sSCE@colData$merged_annotation),
unique(hSCE@colData$merged_annotation)))
common_labels
#> [1] "Cytotrophoblast" "Extravillous trophoblast"
#> [3] "Syncytiotrophoblast"
We only keep cell types that are common to both datasets. Note that this step is not strictly necessary: if we kept cell types present in only one dataset, the pipeline would run normally but the “meta-markers” for these cell types would be based on a single dataset.
lSCE <- lSCE[, lSCE@colData$merged_annotation %in% common_labels]
vtSCE <- vtSCE[, vtSCE@colData$merged_annotation %in% common_labels]
sSCE <- sSCE[, sSCE@colData$merged_annotation %in% common_labels]
hSCE <- hSCE[, hSCE@colData$merged_annotation %in% common_labels]
The last step before computing markers is data normalization. The only requirement here is that the normalization is uniform across datasets for the meta-analytic stats to be meaningful. Any normalization procedure may be used, the MetaMarkers package offer a simple library size normalization procedure:
assay(lSCE, "cpm") <- convert_to_cpm(assay(lSCE))
assay(vtSCE, "cpm") <- convert_to_cpm(assay(vtSCE))
assay(sSCE, "cpm") = convert_to_cpm(assay(sSCE))
assay(hSCE, "cpm") = convert_to_cpm(assay(hSCE))
We can now proceed to marker selection (based on the ROC test). In our experience, it is best to not use logarithmic scaling as it will provide better fold change evaluation.
markers_lSCE <- compute_markers(assay(lSCE, "cpm"),
lSCE@colData$merged_annotation)
markers_vtSCE <- compute_markers(assay(vtSCE, "cpm"),
vtSCE@colData$merged_annotation)
markers_sSCE <- compute_markers(assay(sSCE, "cpm"),
sSCE@colData$merged_annotation)
markers_hSCE <- compute_markers(assay(hSCE, "cpm"),
hSCE@colData$merged_annotation)
These functions provide marker lists for all cell types in a given dataset (ranked by AUROC). For example, we can visualize the best markers for the Syncytiotrophoblast:
markers_hSCE %>%
filter(cell_type == "Syncytiotrophoblast") %>%
head
#> # A tibble: 6 × 14
#> group cell_type gene fold_…¹ auroc log_fdr popul…² popul…³ avera…⁴ se_ex…⁵
#> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 all Syncytiotro… PSG3 90.8 0.997 -22.4 19 0.0300 12757. 1436.
#> 2 all Syncytiotro… CGA 42.2 0.985 -21.2 19 0.0300 51158. 12398.
#> 3 all Syncytiotro… PSG1 970. 0.973 -20.0 19 0.0300 5754. 1004.
#> 4 all Syncytiotro… PSG9 147. 0.972 -19.9 19 0.0300 5505. 807.
#> 5 all Syncytiotro… PSG5 10.8 0.966 -19.3 19 0.0300 5981. 866.
#> 6 all Syncytiotro… CSH2 142. 0.965 -19.2 19 0.0300 31184. 7072.
#> # … with 4 more variables: detection_rate <dbl>, fold_change_detection <dbl>,
#> # precision <dbl>, recall <dbl>, and abbreviated variable names ¹fold_change,
#> # ²population_size, ³population_fraction, ⁴average_expression, ⁵se_expression
Individual dataset markers can be saved to file for later use, which is particularly useful to accumulate datasets over time and regenerate more comprehensive meta-marker lists.
export_markers(markers_lSCE, "Liu_markers.csv")
export_markers(markers_vtSCE, "VT_markers.csv")
export_markers(markers_sSCE, "Suryawanshi_markers.csv")
export_markers(markers_hSCE, "Han_markers.csv")
We now build meta-markers from individual dataset marker lists. First we load the markers we previously exported. Note that the export function compresses marker files by default, so the extension has changed.
markers = list(
lmarkers = read_markers("Liu_markers.csv.gz"),
vtmarkers = read_markers("VT_markers.csv.gz"),
smarkers = read_markers("Suryawanshi_markers.csv.gz"),
hmarkers = read_markers("Han_markers.csv.gz")
)
We create meta-markers by calling the following function. By default, the function only returns a ranked list of markers, but can also provide more detailed information about markers by setting “detailed_stats = TRUE”.
meta_markers <- make_meta_markers(markers, detailed_stats = TRUE)
We can look at meta-analytic markers for the Cytotrophoblast cell type again.
meta_markers %>%
filter(cell_type == "Cytotrophoblast") %>%
head(10)
#> # A tibble: 10 × 17
#> group cell_type rank gene recur…¹ auroc fold_…² fold_…³ expre…⁴ preci…⁵
#> <chr> <chr> <int> <chr> <int> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 all Cytotrophobl… 1 PAGE4 3 0.808 22.1 2.18 8811. 0.548
#> 2 all Cytotrophobl… 2 MEST 3 0.763 5.74 1.73 617. 0.497
#> 3 all Cytotrophobl… 3 ADRB1 3 0.636 6.03 3.33 0 NA
#> 4 all Cytotrophobl… 4 LDHB 2 0.786 4.19 1.55 1453. 0.472
#> 5 all Cytotrophobl… 5 SMAGP 2 0.744 8.33 2.01 719. 0.526
#> 6 all Cytotrophobl… 6 PEG10 2 0.738 7.59 2.03 1181. 0.530
#> 7 all Cytotrophobl… 7 FXYD3 2 0.731 4.51 1.66 753. 0.482
#> 8 all Cytotrophobl… 8 JUN 2 0.723 4.09 1.73 663. 0.520
#> 9 all Cytotrophobl… 9 ISYN… 2 0.723 6.54 1.81 597. 0.502
#> 10 all Cytotrophobl… 10 CYST… 2 0.720 6.71 1.92 417. 0.513
#> # … with 7 more variables: recall <dbl>, population_size <dbl>,
#> # n_datasets <int>, lmarkers <lgl>, vtmarkers <lgl>, smarkers <lgl>,
#> # hmarkers <lgl>, and abbreviated variable names ¹recurrence, ²fold_change,
#> # ³fold_change_detection, ⁴expression, ⁵precision
The PAGE4 gene is a member of the GAGE family. The GAGE genes are expressed in a variety of tumors and in some fetal and reproductive tissues.
The “recurrence” column shows how often (in how many datasets) a gene was detected as “strongly” differentially expressed (by default FC>4, FDR<0.05, these parameters can be changed when calling “make_meta_markers”).
To better appreciate the trade-off between AUROC and fold change of detection, we can look at genes that offer optimal AUROC performance vs genes that offer optimal detection performance by looking at the Pareto front of markers in the (AUROC, detection) plot.
plot_pareto_markers(meta_markers, "Cytotrophoblast", min_recurrence = 0)
In this plot, dotted lines indicate high AUROC performance (sensitive marker) and high detection performance (specific marker, binary-like behavior).
To better appreciate what the above explanation means, we can look at the expression of Pareto markers in one of the datasets.
pareto_markers = get_pareto_markers(meta_markers, "Cytotrophoblast", min_recurrence=1)
plot_marker_expression(assay(lSCE, "cpm"),
pareto_markers,
lSCE@colData$merged_annotation)
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.
plot_marker_expression(assay(vtSCE, "cpm"),
pareto_markers,
vtSCE@colData$merged_annotation)
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.
plot_marker_expression(assay(sSCE, "cpm"),
pareto_markers,
sSCE@colData$merged_annotation)
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.
plot_marker_expression(assay(hSCE, "cpm"),
pareto_markers,
hSCE@colData$merged_annotation)
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.
To obtain an overview of the strength of markers we can obtain for all cell types, we can make a summary plot that contains Pareto markers for all cell types.
plot_pareto_summary(meta_markers, min_recurrence=0)
We see that all cell types have highly sensitive markers, but the specificity (background expression) for these markers vary considerably. For example, cytotrophoblasts and syncytiotrophoblasts don’t have any marker that is both highly specific and sensitive.
plot_pareto_markers(meta_markers, "Syncytiotrophoblast", min_recurrence=0)
pareto_markers = get_pareto_markers(meta_markers, "Syncytiotrophoblast", min_recurrence=0)
plot_marker_expression(assay(lSCE, "cpm"),
pareto_markers,
lSCE@colData$merged_annotation)
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.
plot_marker_expression(assay(vtSCE, "cpm"),
pareto_markers,
vtSCE@colData$merged_annotation)
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.
plot_marker_expression(assay(sSCE, "cpm"),
pareto_markers,
sSCE@colData$merged_annotation)
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.
plot_marker_expression(assay(hSCE, "cpm"),
pareto_markers,
hSCE@colData$merged_annotation)
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.
On the opposite side of the spectrum, extravillous trophoblasts have 4 markers that are both highly specific and sensitive.
plot_pareto_markers(meta_markers,
"Extravillous trophoblast",
min_recurrence = 0)
pareto_markers = get_pareto_markers(meta_markers,
"Extravillous trophoblast",
min_recurrence=1)
plot_marker_expression(assay(lSCE, "cpm"),
pareto_markers,
lSCE@colData$merged_annotation)
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.
plot_marker_expression(assay(vtSCE, "cpm"),
pareto_markers,
vtSCE@colData$merged_annotation)
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.
plot_marker_expression(assay(sSCE, "cpm"),
pareto_markers,
sSCE@colData$merged_annotation)
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.
plot_marker_expression(assay(hSCE, "cpm"),
pareto_markers,
hSCE@colData$merged_annotation)
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.
The violin plot makes it clear how background expression is distributed across cell types.
We strongly recommend saving the meta-markers to a file for later use.
export_meta_markers(meta_markers, "meta_markers_(4_datasets).csv", names(markers))
The list can be retrieved later by loading the MetaMarkers package and running the following (again, note that the export function will compress the file by default, changing the file extension in the process).
meta_markers = read_meta_markers("meta_markers_(4_datasets).csv.gz")