R/analyseDMRs.R
sliceDMRs.RdTake the top most DMRs per contrast, based on those with the largest value of the selected metric
sliceDMRs(
DMRs,
n = 1,
metric = deltaBeta,
makePositive = TRUE,
FDRthres = 0.05
)A data frame containing the output of calculateDMRs, potentially with multiple contrasts
How many DMRs to take of each contrast (if that many exists)
Which metric to use to select the top DMRs. Options are
deltaBeta, log2FC, adjPval, CpG_density, position (using seqnames and start
columns) or any other column in the data frame.
If adjPval or position are used, then the window with the smallest value
will be chosen, otherwise the largest value will be used.
Whether to reverse the contrast when the window is hypomethylated in the contrast.
Threshold on the adjusted p values
A data frame with the DMRs with the largest value of the selected metrics
# calculate some DMRs
DMRs <- exampleTumourNormal %>%
calculateDMRs(
variable = "type", contrasts = "all",
keepContrastMeans = FALSE
)
#> Calculating 10 possible contrasts on the type column.
#> Generating table of nrpm values for 819 regions across 10 samples.
#> Fitting initial GLM on 309 windows, without using parallelisation.
#> Performing contrast CRC_vs_LUAD
#> Performing contrast CRC_vs_LUSC
#> Performing contrast CRC_vs_NormalColon
#> Performing contrast CRC_vs_NormalLung
#> Performing contrast LUAD_vs_LUSC
#> Performing contrast LUAD_vs_NormalColon
#> Performing contrast LUAD_vs_NormalLung
#> Performing contrast LUSC_vs_NormalColon
#> Performing contrast LUSC_vs_NormalLung
#> Performing contrast NormalColon_vs_NormalLung
#> Contrasts Complete
#> selecting regions from contrast CRC_vs_LUAD
#> selected 33/309 windows
#> selecting regions from contrast CRC_vs_LUSC
#> selected 38/309 windows
#> selecting regions from contrast CRC_vs_NormalColon
#> selected 1/309 windows
#> selecting regions from contrast CRC_vs_NormalLung
#> selected 44/309 windows
#> selecting regions from contrast LUAD_vs_LUSC
#> selected 12/309 windows
#> selecting regions from contrast LUAD_vs_NormalColon
#> selected 13/309 windows
#> selecting regions from contrast LUAD_vs_NormalLung
#> selected 23/309 windows
#> selecting regions from contrast LUSC_vs_NormalColon
#> selected 38/309 windows
#> selecting regions from contrast LUSC_vs_NormalLung
#> selected 57/309 windows
#> selecting regions from contrast NormalColon_vs_NormalLung
#> selected 18/309 windows
#> adding test results from CRC_vs_LUAD
#> adding test results from CRC_vs_LUSC
#> adding test results from CRC_vs_NormalColon
#> adding test results from CRC_vs_NormalLung
#> adding test results from LUAD_vs_LUSC
#> adding test results from LUAD_vs_NormalColon
#> adding test results from LUAD_vs_NormalLung
#> adding test results from LUSC_vs_NormalColon
#> adding test results from LUSC_vs_NormalLung
#> adding test results from NormalColon_vs_NormalLung
# Find the DMRs with the largest deltaBeta between each comparison:
DMRs %>% sliceDMRs(n = 1)
#> # A tibble: 18 × 9
#> seqnames start end CpG_density log2FC adjPval deltaBeta group1 group2
#> <fct> <int> <int> <dbl> <dbl> <dbl> <dbl> <chr> <chr>
#> 1 7 25852801 25853100 18.4 2.50 4.10e-4 0.608 CRC LUAD
#> 2 7 27220801 27221100 6.98 3.74 1.26e-2 0.720 CRC LUSC
#> 3 7 27239401 27239700 21.1 4.19 5.24e-3 0.838 CRC Norma…
#> 4 7 27130201 27130500 28.2 1.88 6.19e-5 0.432 LUAD CRC
#> 5 7 27044401 27044700 14.7 1.85 1.78e-2 0.271 LUAD LUSC
#> 6 7 27130201 27130500 28.2 1.71 4.83e-3 0.414 LUAD Norma…
#> 7 7 27124201 27124500 18.1 1.11 2.37e-2 0.430 LUAD Norma…
#> 8 7 27166201 27166500 20.0 4.34 2.62e-5 0.839 LUSC CRC
#> 9 7 27151501 27151800 8.60 2.51 8.25e-3 0.657 LUSC LUAD
#> 10 7 27164401 27164700 15.0 4.39 4.71e-2 0.872 LUSC Norma…
#> 11 7 27166201 27166500 20.0 4.37 3.58e-7 0.839 LUSC Norma…
#> 12 7 27044401 27044700 14.7 1.11 4.92e-2 0.373 Norma… CRC
#> 13 7 27088201 27088500 19.7 1.76 1.12e-2 0.593 Norma… LUAD
#> 14 7 27044401 27044700 14.7 2.74 8.12e-7 0.593 Norma… LUSC
#> 15 7 27088201 27088500 19.7 2.12 4.63e-5 0.666 Norma… Norma…
#> 16 7 27159901 27160200 9.48 1.54 1.85e-2 0.465 Norma… CRC
#> 17 7 27507901 27508200 11.1 0.992 2.08e-2 0.395 Norma… LUAD
#> 18 7 25079401 25079700 7.87 3.20 4.03e-2 0.564 Norma… LUSC
# Or the windows with the largest log2FC:
DMRs %>% sliceDMRs(n = 1, metric = log2FC)
#> # A tibble: 18 × 9
#> seqnames start end CpG_density log2FC adjPval deltaBeta group1 group2
#> <fct> <int> <int> <dbl> <dbl> <dbl> <dbl> <chr> <chr>
#> 1 7 27220801 27221100 6.98 2.69 1.43e-2 0.599 CRC LUAD
#> 2 7 27220801 27221100 6.98 3.74 1.26e-2 0.720 CRC LUSC
#> 3 7 27251701 27252000 18.8 5.31 5.36e-3 0.762 CRC Norma…
#> 4 7 27096301 27096600 19.9 4.15 5.12e-6 0.222 LUAD CRC
#> 5 7 27096301 27096600 19.9 4.17 2.03e-3 0.222 LUAD LUSC
#> 6 7 27174001 27174300 25.1 3.63 1.56e-2 0.381 LUAD Norma…
#> 7 7 27199201 27199500 19.4 3.88 2.08e-2 0.316 LUAD Norma…
#> 8 7 27151201 27151500 16.5 5.40 1.53e-7 0.574 LUSC CRC
#> 9 7 25857001 25857300 17.1 3.28 1.16e-2 0.167 LUSC LUAD
#> 10 7 27205201 27205500 18.5 4.50 2.76e-2 0.489 LUSC Norma…
#> 11 7 27251701 27252000 18.8 4.39 4.03e-2 0.638 LUSC Norma…
#> 12 7 27044401 27044700 14.7 1.11 4.92e-2 0.373 Norma… CRC
#> 13 7 25860601 25860900 11.6 2.49 1.56e-2 0.464 Norma… LUAD
#> 14 7 25860601 25860900 11.6 3.82 4.67e-3 0.536 Norma… LUSC
#> 15 7 27251701 27252000 18.8 4.85 2.71e-2 0.499 Norma… Norma…
#> 16 7 27168601 27168900 8.79 2.23 3.31e-2 0.416 Norma… CRC
#> 17 7 27507901 27508200 11.1 0.992 2.08e-2 0.395 Norma… LUAD
#> 18 7 25079401 25079700 7.87 3.20 4.03e-2 0.564 Norma… LUSC
# Or the windows with the largest CpG_density:
DMRs %>% sliceDMRs(n = 1, metric = CpG_density)
#> # A tibble: 18 × 9
#> seqnames start end CpG_density log2FC adjPval deltaBeta group1 group2
#> <fct> <int> <int> <dbl> <dbl> <dbl> <dbl> <chr> <chr>
#> 1 7 27088201 27088500 19.7 2.01 5.75e-4 0.596 CRC LUAD
#> 2 7 27044401 27044700 14.7 1.63 1.74e-2 0.221 CRC LUSC
#> 3 7 27220501 27220800 22.8 4.23 1.60e-2 0.703 CRC Norma…
#> 4 7 27200101 27200400 30.3 2.97 3.09e-2 0.121 LUAD CRC
#> 5 7 27096301 27096600 19.9 4.17 2.03e-3 0.222 LUAD LUSC
#> 6 7 27130201 27130500 28.2 1.71 4.83e-3 0.414 LUAD Norma…
#> 7 7 27199501 27199800 34.8 3.72 2.38e-2 0.265 LUAD Norma…
#> 8 7 27156001 27156300 24.5 3.19 1.72e-3 0.316 LUSC CRC
#> 9 7 25852801 25853100 18.4 2.12 2.59e-2 0.441 LUSC LUAD
#> 10 7 27156001 27156300 24.5 3.02 8.30e-3 0.311 LUSC Norma…
#> 11 7 27156001 27156300 24.5 3.51 4.92e-5 0.322 LUSC Norma…
#> 12 7 27044401 27044700 14.7 1.11 4.92e-2 0.373 Norma… CRC
#> 13 7 27088201 27088500 19.7 1.76 1.12e-2 0.593 Norma… LUAD
#> 14 7 27044401 27044700 14.7 2.74 8.12e-7 0.593 Norma… LUSC
#> 15 7 27220501 27220800 22.8 3.93 4.98e-2 0.531 Norma… Norma…
#> 16 7 27175801 27176100 12.8 0.642 2.31e-2 0.255 Norma… CRC
#> 17 7 27507901 27508200 11.1 0.992 2.08e-2 0.395 Norma… LUAD
#> 18 7 27044401 27044700 14.7 1.96 5.59e-4 0.303 Norma… LUSC
# If adjPval is used, then the smallest value is chosen instead:
DMRs %>% sliceDMRs(n = 1, metric = CpG_density)
#> # A tibble: 18 × 9
#> seqnames start end CpG_density log2FC adjPval deltaBeta group1 group2
#> <fct> <int> <int> <dbl> <dbl> <dbl> <dbl> <chr> <chr>
#> 1 7 27088201 27088500 19.7 2.01 5.75e-4 0.596 CRC LUAD
#> 2 7 27044401 27044700 14.7 1.63 1.74e-2 0.221 CRC LUSC
#> 3 7 27220501 27220800 22.8 4.23 1.60e-2 0.703 CRC Norma…
#> 4 7 27200101 27200400 30.3 2.97 3.09e-2 0.121 LUAD CRC
#> 5 7 27096301 27096600 19.9 4.17 2.03e-3 0.222 LUAD LUSC
#> 6 7 27130201 27130500 28.2 1.71 4.83e-3 0.414 LUAD Norma…
#> 7 7 27199501 27199800 34.8 3.72 2.38e-2 0.265 LUAD Norma…
#> 8 7 27156001 27156300 24.5 3.19 1.72e-3 0.316 LUSC CRC
#> 9 7 25852801 25853100 18.4 2.12 2.59e-2 0.441 LUSC LUAD
#> 10 7 27156001 27156300 24.5 3.02 8.30e-3 0.311 LUSC Norma…
#> 11 7 27156001 27156300 24.5 3.51 4.92e-5 0.322 LUSC Norma…
#> 12 7 27044401 27044700 14.7 1.11 4.92e-2 0.373 Norma… CRC
#> 13 7 27088201 27088500 19.7 1.76 1.12e-2 0.593 Norma… LUAD
#> 14 7 27044401 27044700 14.7 2.74 8.12e-7 0.593 Norma… LUSC
#> 15 7 27220501 27220800 22.8 3.93 4.98e-2 0.531 Norma… Norma…
#> 16 7 27175801 27176100 12.8 0.642 2.31e-2 0.255 Norma… CRC
#> 17 7 27507901 27508200 11.1 0.992 2.08e-2 0.395 Norma… LUAD
#> 18 7 27044401 27044700 14.7 1.96 5.59e-4 0.303 Norma… LUSC
# If position is used, then the windows are sorted by genomic position:
DMRs %>% sliceDMRs(n = 1, metric = position)
#> # A tibble: 18 × 9
#> seqnames start end CpG_density log2FC adjPval deltaBeta group1 group2
#> <fct> <int> <int> <dbl> <dbl> <dbl> <dbl> <chr> <chr>
#> 1 7 25852801 25853100 18.4 2.50 4.10e-4 0.608 CRC LUAD
#> 2 7 25860601 25860900 11.6 3.68 4.24e-3 0.548 CRC LUSC
#> 3 7 25852801 25853100 18.4 2.07 1.38e-4 0.559 CRC Norma…
#> 4 7 25018801 25019100 15.3 1.99 4.96e-2 0.106 LUAD CRC
#> 5 7 27044401 27044700 14.7 1.85 1.78e-2 0.271 LUAD LUSC
#> 6 7 27096001 27096300 18.8 2.99 1.55e-2 0.145 LUAD Norma…
#> 7 7 27096001 27096300 18.8 3.72 3.94e-5 0.154 LUAD Norma…
#> 8 7 25857001 25857300 17.1 2.79 4.24e-3 0.161 LUSC CRC
#> 9 7 25852801 25853100 18.4 2.12 2.59e-2 0.441 LUSC LUAD
#> 10 7 25857001 25857300 17.1 3.03 1.46e-2 0.164 LUSC Norma…
#> 11 7 25852801 25853100 18.4 1.68 2.07e-2 0.392 LUSC Norma…
#> 12 7 27044401 27044700 14.7 1.11 4.92e-2 0.373 Norma… CRC
#> 13 7 25852801 25853100 18.4 2.19 1.12e-2 0.453 Norma… LUAD
#> 14 7 25860601 25860900 11.6 3.82 4.67e-3 0.536 Norma… LUSC
#> 15 7 25852801 25853100 18.4 1.75 1.16e-2 0.404 Norma… Norma…
#> 16 7 25107301 25107600 8.13 1.54 3.12e-2 0.438 Norma… CRC
#> 17 7 27507901 27508200 11.1 0.992 2.08e-2 0.395 Norma… LUAD
#> 18 7 25079401 25079700 7.87 3.20 4.03e-2 0.564 Norma… LUSC