# 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)

Introduction

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 2 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.

Create marker lists for individual placental datasets

For simplicity, we only consider 2 datasets here, but the analysis can easily be extended to include even more datasets. 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")

# 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

# Change the Idents of the Seurat Objects
Idents(object = vtdataset) <- "merged_annotation"
Idents(object = sdataset) <- "merged_annotation"


# Convert to SCE objects
vtSCE <- as.SingleCellExperiment(vtdataset)
sSCE <- as.SingleCellExperiment(sdataset)

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(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

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 <-  intersect(unique(vtSCE@colData$merged_annotation),
                            unique(sSCE@colData$merged_annotation))
common_labels
#> [1] "Cytotrophoblast"          "Macrophage"              
#> [3] "Fibroblast"               "Extravillous trophoblast"
#> [5] "Syncytiotrophoblast"      "Endothelial cell"        
#> [7] "Epithelial cell"

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.

vtSCE <- vtSCE[, vtSCE@colData$merged_annotation %in% common_labels]
sSCE <- sSCE[, sSCE@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(vtSCE, "cpm") <-  convert_to_cpm(assay(vtSCE))
assay(sSCE, "cpm") = convert_to_cpm(assay(sSCE))

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_vtSCE <- compute_markers(assay(vtSCE, "cpm"),
                                 vtSCE@colData$merged_annotation)
markers_sSCE <- compute_markers(assay(sSCE, "cpm"),
                                sSCE@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_vtSCE %>%
    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… ANXA1    5.03 0.936  -1091.    1023  0.0659   5878.   149. 
#> 2 all   Syncytiotro… S100P    4.92 0.918  -1001.    1023  0.0659   2007.    40.8
#> 3 all   Syncytiotro… SQST…    7.10 0.896   -900.    1023  0.0659   1390.    39.3
#> 4 all   Syncytiotro… KRT23    6.67 0.875   -804.    1023  0.0659   2495.    74.4
#> 5 all   Syncytiotro… TMEM…    7.06 0.875   -804.    1023  0.0659    492.    13.0
#> 6 all   Syncytiotro… GDF15   28.5  0.871   -789.    1023  0.0659   2539.   196. 
#> # … 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_vtSCE, "VT_markers.csv")
export_markers(markers_sSCE, "Suryawanshi_markers.csv")

Build list of meta-analytic markers

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(
    vtmarkers = read_markers("VT_markers.csv.gz"),
    smarkers = read_markers("Suryawanshi_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 × 15
#>    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       2 0.958   10.9     1.65  11553.   0.451
#>  2 all   Cytotrophobl…     2 PEG10       2 0.884    6.67    2.43   1562.   0.542
#>  3 all   Cytotrophobl…     3 SMAGP       2 0.868    8.65    2.63    918.   0.561
#>  4 all   Cytotrophobl…     4 EFEM…       2 0.864    6.51    1.83    985.   0.478
#>  5 all   Cytotrophobl…     5 DUSP9       2 0.861    7.97    3.47    916.   0.627
#>  6 all   Cytotrophobl…     6 ISYN…       2 0.842    5.78    1.99    794.   0.496
#>  7 all   Cytotrophobl…     7 SPIN…       2 0.832    5.80    2.61    809.   0.561
#>  8 all   Cytotrophobl…     8 FXYD3       2 0.829    5.23    2.59    636.   0.559
#>  9 all   Cytotrophobl…     9 BCAM        2 0.820    8.57    3.03    517.   0.585
#> 10 all   Cytotrophobl…    10 SLC2…       2 0.794    4.98    3.75    473.   0.633
#> # … with 5 more variables: recall <dbl>, population_size <dbl>,
#> #   n_datasets <int>, vtmarkers <lgl>, smarkers <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). For example insulin is extremely sensitive, but ADCYAP1 has a better binary-like behavior while keeping good sensitivity.

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(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.

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(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.

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(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.

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_(2_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_(2_datasets).csv.gz")

Build hierarchical marker lists

We can explicitly control how background expression affects marker selection by organizing cell types hierarchically. By grouping related cell types into classes: - markers will discriminate better against close cell types, which is particularly useful when there is no global marker that works. - cell types can still be recognized combinatorially (using class markers + within-class markers).

To create hierarchical marker lists, we need to define groups of cell types, but the rest of the procedure is almost identical to simple marker selection.

table(vtSCE@colData$merged_annotation)
#> 
#>          Cytotrophoblast         Endothelial cell          Epithelial cell 
#>                     8346                      143                       37 
#> Extravillous trophoblast               Fibroblast               Macrophage 
#>                     3037                     2118                      829 
#>      Syncytiotrophoblast 
#>                     1023

Here we create two classes: we will group all trophoblast cell types together and attribute all other cell types to a “non-trophoblast” class.

to_class = c("Cytotrophoblast"="trophoblast",
             "Endothelial cell"="non-trophoblast", 
             "Epithelial cell"="non-trophoblast",
             "Extravillous trophoblast"="trophoblast", 
             "Fibroblast"="non-trophoblast",
             "Macrophage"="non-trophoblast", 
             "Syncytiotrophoblast"="trophoblast")
vtSCE$class = to_class[vtSCE@colData$merged_annotation]
sSCE$class = to_class[sSCE@colData$merged_annotation]

Class-level markers

We start by computing class-level markers for each dataset, then compute meta-markers.

class_markers = list(
    vtmarkers = compute_markers(assay(vtSCE, "cpm"), vtSCE$class),
    smarkers = compute_markers(assay(sSCE, "cpm"), sSCE$class)
)
class_meta_markers = make_meta_markers(class_markers, detailed_stats = TRUE)

We look at Pareto markers for each class.

plot_pareto_summary(class_meta_markers, min_recurrence = 0)

Both classes have highly specific and sensitive markers. To better appreciate how background expression is distributed, we look at the expression of Pareto markers in our datasets.

plot_pareto_markers(class_meta_markers, "trophoblast", min_recurrence=0)

pareto_markers = get_pareto_markers(class_meta_markers, "trophoblast", min_recurrence=1)[1:10]
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.

We note that background expression is a concern particularly in the Muraro dataset. CHGB and PCSK1N are good examples of trade-off choices between specificity and sensitivity.

plot_pareto_markers(class_meta_markers, "non-trophoblast", min_recurrence=0)

pareto_markers = get_pareto_markers(class_meta_markers, "non-trophoblast", min_recurrence=1)
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.

On the non-trophoblast side, IFITM3 and CDC42PEP1 are strong marker genes, with the option to choose the latter to limit background expression in the Muraro dataset.

Within-class markers

Having establish good class markers, we can look within classes. The computation of markers within classes is obtained using the same procedure as before, but we set specific a “group” parameter to indicate which cell types need to be handled as separate classes.

markers = list(
    vtmarkers = compute_markers(assay(vtSCE, "cpm"), 
                                vtSCE@colData$merged_annotation,
                                vtSCE$class),
    smarkers = compute_markers(assay(sSCE, "cpm"), 
                               sSCE@colData$merged_annotation,
                               sSCE$class)
)
meta_markers = make_meta_markers(markers, detailed_stats = TRUE)

We look at Pareto markers for each cell type.

plot_pareto_summary(meta_markers, min_recurrence = 0)

Here, markers look roughly equivalent to the non-stratified analysis, which indicates that the best markers that distinguish say trophoblast cell types are naturally not expressed in non-trophoblast cell types, too. Let’s take a closer look at Extravillous trophoblast Pareto markers.

plot_pareto_markers(meta_markers, 
                    "Extravillous trophoblast", 
                    min_recurrence=0)

pareto_markers = get_pareto_markers(meta_markers,
                                    "Extravillous trophoblast",
                                    min_recurrence=0)
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.

We note that the last Pareto marker (HLA-G) is quite specific to EVT cells within trophoblast cell types (EVT, SCT, VCT).