--- title: "MetaMarkers: Testing two placental datasets" output: html_document --- ```{r} # Load required libraries library(SingleCellExperiment) library(Seurat) library(tidyverse) library(MetaMarkers) library(scRNAseq) library(dplyr) ``` ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.align = "center", fig.width = 6, fig.height = 4.5 ) ``` ## 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. ```{r load_datasets, message=FALSE} 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) # 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() # 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) # 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). ```{r display_cell_types} table(vtSCE@colData$merged_annotation) table(sSCE@colData$merged_annotation) ``` 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. ```{r rename_cell_types} common_labels <- intersect(unique(vtSCE@colData$merged_annotation), unique(sSCE@colData$merged_annotation)) common_labels ``` 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. ```{r subset_datasets} 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: ```{r compute_cpm} 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. ```{r compute_markers} 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: ```{r show_syncytiotrophoblast_markers} markers_vtSCE %>% filter(cell_type == "Syncytiotrophoblast") %>% head ``` 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. ```{r export_markers} 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. ```{r read_markers} 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". ```{r compute_meta_markers} meta_markers <- make_meta_markers(markers, detailed_stats = TRUE) ``` We can look at meta-analytic markers for the Cytotrophoblast cell type again. ```{r show_cytotrophoblast_meta_markers} meta_markers %>% filter(cell_type == "Cytotrophoblast") %>% head(10) ``` 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. ```{r plot_cytotrophoblast_pareto_markers} 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. ```{r pareto_markers_detail} pareto_markers = get_pareto_markers(meta_markers, "Cytotrophoblast", min_recurrence=1) plot_marker_expression(assay(vtSCE, "cpm"), pareto_markers, vtSCE@colData$merged_annotation) plot_marker_expression(assay(sSCE, "cpm"), pareto_markers, sSCE@colData$merged_annotation) ``` 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. ```{r pareto_summary} 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. ```{r gamma_markers_detail} 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) plot_marker_expression(assay(sSCE, "cpm"), pareto_markers, sSCE@colData$merged_annotation) ``` On the opposite side of the spectrum, extravillous trophoblasts have 4 markers that are both highly specific and sensitive. ```{r mesenchymal_markers_detail} 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) plot_marker_expression(assay(sSCE, "cpm"), pareto_markers, sSCE@colData$merged_annotation) ``` 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. ```{r export_meta_markers} 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). ```{r read_meta_markers} 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. ```{r show_all_cell_types} table(vtSCE@colData$merged_annotation) ``` Here we create two classes: we will group all trophoblast cell types together and attribute all other cell types to a "non-trophoblast" class. ```{r group_cell_types} 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. ```{r class_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. ```{r class_pareto_summary} 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. ```{r trophoblast_pareto} 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) plot_marker_expression(assay(sSCE, "cpm"), pareto_markers, sSCE@colData$merged_annotation) ``` 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. ```{r non_trophoblast_pareto} 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) plot_marker_expression(assay(sSCE, "cpm"), pareto_markers, sSCE@colData$merged_annotation) ``` 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. ```{r} 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. ```{r pareto_within_class} 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. ```{r pareto_EVT_within} 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) plot_marker_expression(assay(sSCE, "cpm"), pareto_markers, sSCE@colData$merged_annotation) ``` We note that the last Pareto marker (HLA-G) is quite specific to EVT cells within trophoblast cell types (EVT, SCT, VCT).