planet

Installation

if(!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("planet")

Cell composition

To infer cell composition on placental villi DNAm samples, we can need to use placental reference cpgs (Yuan 2021). These are provided in this package as plCellCpGsThird and plCellCpGsFirst for third trimester (term) and first trimester samples, respectively.

In this example we are using term villi DNAm data, so we first load the reference cpgs plCellCpGsThird. This is a data frame of 600 cpgs, with mean methylation levels for each cell type.

# cell deconvolution packages
library(minfi)
library(EpiDISH)

# data wrangling and plotting
library(dplyr)
library(ggplot2)
library(tidyr)
library(planet)

# load example data
data("plBetas")
data("plCellCpGsThird")
head(plCellCpGsThird)
##            Trophoblasts   Stromal  Hofbauer Endothelial      nRBC
## cg10590657    0.1014098 0.9345796 0.8655285   0.8963641 0.8448382
## cg14923398    0.1282030 0.8902107 0.9036769   0.9383641 0.9508709
## cg05348366    0.1305697 0.9519820 0.8803082   0.9065136 0.9278057
## cg17907628    0.1215249 0.9278777 0.8727841   0.8914412 0.9143601
## cg26799656    0.1259953 0.9482014 0.8803863   0.8791004 0.9010419
## cg11862144    0.1561991 0.9430855 0.9114967   0.9341671 0.9647331
##            Syncytiotrophoblast
## cg10590657          0.05460441
## cg14923398          0.05383193
## cg05348366          0.06546727
## cg17907628          0.05325227
## cg26799656          0.06823985
## cg11862144          0.06044207

After our reference cpg data is loaded, we can estimate cell composition by applying either the Constrained Projection approach implemented by the R packages minfi or EpiDISH, or a non-constrained approach by EpiDish. I demonstrate how to do both.

Minfi

##            Trophoblasts    Stromal      Hofbauer Endothelial       nRBC
## GSM1944936    0.1091279 0.04891919  0.000000e+00  0.08983998 0.05294062
## GSM1944939    0.2299918 0.00000000 -1.806592e-19  0.07888007 0.03374149
## GSM1944942    0.1934287 0.03483540  0.000000e+00  0.09260353 0.02929310
## GSM1944944    0.2239896 0.06249135  1.608645e-03  0.11040693 0.04447951
## GSM1944946    0.1894152 0.07935955  0.000000e+00  0.10587439 0.05407587
## GSM1944948    0.2045124 0.07657717  0.000000e+00  0.09871149 0.02269798
##            Syncytiotrophoblast
## GSM1944936           0.6979477
## GSM1944939           0.6377822
## GSM1944942           0.6350506
## GSM1944944           0.5467642
## GSM1944946           0.6022329
## GSM1944948           0.6085825

EpiDISH

## 1
## 2
## 3
## 1
## 2
## 3
## 4
## 5
## 6
## 7
## 8
## 9
## 10
## 11
## 12
## 13
## 14
## 15
## 16
## 17
## 18
## 19
## 20
## 21
## 22
## 23
## 24

Compare

Below, I demonstrate how we can visually compare the different cell composition estimates.

Some notes:

Gestational age

Example Data

For demonstration, I use 24 samples from a placental DNAm dataset from GEO, (GSE7519), which contains samples collected in an Australian population. The DNA methylation data (in betas) can be accessed with data(plBetas) and corresponding sample information from data(plPhenoData). Note that for demonstration purposes, the cpgs have been filtered to a random ~10,000 CpGs, plus the CpGs used in all of the functions from this package.

## [1] 13918    24
sample_id sex disease gestation_wk ga_RPC ga_CPC ga_RRPC
GSM1944936 Male preeclampsia 36 38.46528 38.72867 38.65396
GSM1944939 Male preeclampsia 32 33.09680 34.21252 32.62763
GSM1944942 Female preeclampsia 32 34.32520 35.09565 33.32502
GSM1944944 Male preeclampsia 35 35.50937 36.71512 35.51295
GSM1944946 Female preeclampsia 38 37.63910 37.57931 36.61721
GSM1944948 Female preeclampsia 36 36.77051 38.42632 36.72150

There are 3 gestational age clocks for placental DNA methylation data from (Lee 2019):

  1. Robust Placental Clock (RPC)
  2. Control Placental Clock (CPC)
  3. Refined Robust Placental Clock (RRPC)

To predict gestational, we load the example data:

Predict Gestational Age

To select the type of clock, we can specify the type argument in predictAge.

We will apply all three clocks on this data, and add the predicted age to the sample information data.frame, plPhenoData.

## 558 of 558 predictors present.
## 546 of 546 predictors present.
## 395 of 395 predictors present.

Note that the number of predictors (CpGs) that were used in our data are printed. It’s important to take note if a significant number of predictive CpGs are missing in your data, as this can affect the predicted gestational age accuracy.

Next, I plot the difference between predicted and reported gestational age, for each of the 3 gestational age predictors.

## `geom_smooth()` using formula 'y ~ x'

Ethnicity

Before predicting ethnicity You can ensure that you have all features using the ethnicityCpGs vector:

data(ethnicityCpGs)
all(ethnicityCpGs %in% rownames(plBetas))
## [1] TRUE
results <- predictEthnicity(plBetas)
## 1860 of 1860 predictors present.
results %>%
    tail(8)
Sample_ID Predicted_ethnicity_nothresh Predicted_ethnicity Prob_African Prob_Asian Prob_Caucasian Highest_Prob
GSM1944959 Asian Asian 0.0123073 0.9523544 0.0353383 0.9523544
GSM1944960 Caucasian Caucasian 0.0156961 0.1595213 0.8247827 0.8247827
GSM1944961 Asian Asian 0.0208421 0.8954518 0.0837061 0.8954518
GSM1944962 Caucasian Caucasian 0.0009276 0.0008801 0.9981923 0.9981923
GSM1944963 Caucasian Caucasian 0.0022635 0.0028007 0.9949358 0.9949358
GSM1944964 Caucasian Caucasian 0.0065973 0.0112013 0.9822014 0.9822014
GSM1944965 Caucasian Caucasian 0.0021578 0.0024196 0.9954226 0.9954226
GSM1944966 Caucasian Caucasian 0.0011397 0.0017651 0.9970952 0.9970952

predictEthnicity returns probabilities corresponding to each ethnicity for each sample (e.g Prob_Caucasian, Prob_African, Prob_Asian). This applies a glmnet model described in (Yuan 2019). A final classification is determined in two ways:

  1. Predicted_ethnicity_nothresh - returns a classification corresponding to the highest class-specific probability.

  2. Predicted_ethnicity - if the highest class-specific probability is below 0.75, then the the sample is assigned an Amibiguous label. This threshold can be adjusted with the threshold argument. Samples with this label might require special attention in downstream analyses.

results %>%
    ggplot(aes(
        x = Prob_Caucasian, y = Prob_African,
        col = Predicted_ethnicity
    )) +
    geom_point(alpha = 0.7) +
    coord_cartesian(xlim = c(0, 1), ylim = c(0, 1)) +
    scale_x_continuous(labels = scales::percent) +
    scale_y_continuous(labels = scales::percent) +
    labs(x = "P(Caucasian)", y = "P(African)")

results %>%
    ggplot(aes(
        x = Prob_Caucasian, y = Prob_Asian,
        col = Predicted_ethnicity
    )) +
    geom_point(alpha = 0.7) +
    coord_cartesian(xlim = c(0, 1), ylim = c(0, 1)) +
    scale_x_continuous(labels = scales::percent) +
    scale_y_continuous(labels = scales::percent) +
    labs(x = "P(Caucasian)", y = "P(Asian)")

We can’t compare this to self-reported ethnicity as it is unavailable. But we know these samples were collected in Sydney, Australia, and are therefore likely mostly European with some East Asian participants.

table(results$Predicted_ethnicity)
## 
##     Asian Caucasian 
##         2        22

A note on adjustment in differential methylation analysis

Because ‘Ambiguous’ samples might have different mixtures of ancestries, it might be inadequate to adjust for them as one group in an analysis of admixed populations (e.g. 50/50 Asian/African should not be considered the same group as 50/50 Caucasian/African). One solution would be to simply remove these samples. Another would be to adjust for the raw probabilities-in this case, use only two of the three probabilities, since the third will be redundant (probabilities sum to 1). If sample numbers are large enough in each group, stratifying downstream analyses by ethnicity might also be a valid option.

References

Yuan V, Hui D, Yin Y, Peñaherrera MS, Beristain AG, Robinson WP. Cell-specific characterization of the placental methylome. BMC Genomics. 2021 Jan 6;22(1):6.

Yuan V, Price EM, Del Gobbo G, Mostafavi S, Cox B, Binder AM, et al. Accurate ethnicity prediction from placental DNA methylation data. Epigenetics & Chromatin. 2019 Aug 9;12(1):51.

Lee Y, Choufani S, Weksberg R, Wilson SL, Yuan V, Burt A, et al. Placental epigenetic clocks: estimating gestational age using placental DNA methylation levels. Aging (Albany NY). 2019 Jun 24;11(12):4238–53.

Session Info

sessionInfo()
## R version 4.2.1 (2022-06-23)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.5 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.16-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.16-bioc/R/lib/libRlapack.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_GB              LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] parallel  stats4    stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] planet_1.6.0                tidyr_1.2.1                
##  [3] ggplot2_3.3.6               dplyr_1.0.10               
##  [5] EpiDISH_2.14.0              minfi_1.44.0               
##  [7] bumphunter_1.40.0           locfit_1.5-9.6             
##  [9] iterators_1.0.14            foreach_1.5.2              
## [11] Biostrings_2.66.0           XVector_0.38.0             
## [13] SummarizedExperiment_1.28.0 Biobase_2.58.0             
## [15] MatrixGenerics_1.10.0       matrixStats_0.62.0         
## [17] GenomicRanges_1.50.0        GenomeInfoDb_1.34.0        
## [19] IRanges_2.32.0              S4Vectors_0.36.0           
## [21] BiocGenerics_0.44.0        
## 
## loaded via a namespace (and not attached):
##   [1] BiocFileCache_2.6.0       plyr_1.8.7               
##   [3] splines_4.2.1             BiocParallel_1.32.0      
##   [5] digest_0.6.30             htmltools_0.5.3          
##   [7] fansi_1.0.3               magrittr_2.0.3           
##   [9] memoise_2.0.1             tzdb_0.3.0               
##  [11] limma_3.54.0              readr_2.1.3              
##  [13] annotate_1.76.0           askpass_1.1              
##  [15] siggenes_1.72.0           prettyunits_1.1.1        
##  [17] colorspace_2.0-3          blob_1.2.3               
##  [19] rappdirs_0.3.3            xfun_0.34                
##  [21] crayon_1.5.2              RCurl_1.98-1.9           
##  [23] jsonlite_1.8.3            genefilter_1.80.0        
##  [25] GEOquery_2.66.0           survival_3.4-0           
##  [27] glue_1.6.2                gtable_0.3.1             
##  [29] zlibbioc_1.44.0           DelayedArray_0.24.0      
##  [31] Rhdf5lib_1.20.0           HDF5Array_1.26.0         
##  [33] scales_1.2.1              DBI_1.1.3                
##  [35] rngtools_1.5.2            Rcpp_1.0.9               
##  [37] xtable_1.8-4              progress_1.2.2           
##  [39] bit_4.0.4                 proxy_0.4-27             
##  [41] mclust_6.0.0              preprocessCore_1.60.0    
##  [43] httr_1.4.4                RColorBrewer_1.1-3       
##  [45] ellipsis_0.3.2            farver_2.1.1             
##  [47] pkgconfig_2.0.3           reshape_0.8.9            
##  [49] XML_3.99-0.12             sass_0.4.2               
##  [51] dbplyr_2.2.1              utf8_1.2.2               
##  [53] labeling_0.4.2            tidyselect_1.2.0         
##  [55] rlang_1.0.6               AnnotationDbi_1.60.0     
##  [57] munsell_0.5.0             tools_4.2.1              
##  [59] cachem_1.0.6              cli_3.4.1                
##  [61] generics_0.1.3            RSQLite_2.2.18           
##  [63] evaluate_0.17             stringr_1.4.1            
##  [65] fastmap_1.1.0             yaml_2.3.6               
##  [67] knitr_1.40                bit64_4.0.5              
##  [69] beanplot_1.3.1            scrime_1.3.5             
##  [71] purrr_0.3.5               KEGGREST_1.38.0          
##  [73] nlme_3.1-160              doRNG_1.8.2              
##  [75] sparseMatrixStats_1.10.0  nor1mix_1.3-0            
##  [77] xml2_1.3.3                biomaRt_2.54.0           
##  [79] compiler_4.2.1            filelock_1.0.2           
##  [81] curl_4.3.3                png_0.1-7                
##  [83] e1071_1.7-12              tibble_3.1.8             
##  [85] bslib_0.4.0               stringi_1.7.8            
##  [87] highr_0.9                 GenomicFeatures_1.50.0   
##  [89] lattice_0.20-45           Matrix_1.5-1             
##  [91] multtest_2.54.0           vctrs_0.5.0              
##  [93] pillar_1.8.1              lifecycle_1.0.3          
##  [95] rhdf5filters_1.10.0       jquerylib_0.1.4          
##  [97] data.table_1.14.4         bitops_1.0-7             
##  [99] rtracklayer_1.58.0        R6_2.5.1                 
## [101] BiocIO_1.8.0              codetools_0.2-18         
## [103] MASS_7.3-58.1             assertthat_0.2.1         
## [105] rhdf5_2.42.0              openssl_2.0.4            
## [107] rjson_0.2.21              withr_2.5.0              
## [109] GenomicAlignments_1.34.0  Rsamtools_2.14.0         
## [111] GenomeInfoDbData_1.2.9    locfdr_1.1-8             
## [113] mgcv_1.8-41               hms_1.1.2                
## [115] quadprog_1.5-8            grid_4.2.1               
## [117] base64_2.0.1              class_7.3-20             
## [119] rmarkdown_2.17            DelayedMatrixStats_1.20.0
## [121] illuminaio_0.40.0         restfulr_0.0.15