06.1-differential-methylation-split
================
Kathleen Durkin
2025-05-14

- <a href="#1-download-methylation-calls-if-needed"
  id="toc-1-download-methylation-calls-if-needed">1 Download methylation
  calls if needed</a>
- <a href="#2-methylkit" id="toc-2-methylkit">2 methylKit</a>
- <a href="#3-combo" id="toc-3-combo">3 Combo</a>
  - <a href="#31-create-object" id="toc-31-create-object">3.1 Create
    object</a>
  - <a href="#32-descriptive-statistics"
    id="toc-32-descriptive-statistics">3.2 Descriptive statistics</a>
  - <a href="#33-filter" id="toc-33-filter">3.3 Filter</a>
  - <a href="#34-normalization" id="toc-34-normalization">3.4
    Normalization</a>
  - <a href="#35-merge" id="toc-35-merge">3.5 Merge</a>
  - <a href="#36-filter-2" id="toc-36-filter-2">3.6 Filter 2</a>
  - <a href="#37-data-structureoutlier-detection"
    id="toc-37-data-structureoutlier-detection">3.7 Data structure/Outlier
    detection</a>
  - <a href="#38-differential-methylation"
    id="toc-38-differential-methylation">3.8 Differential methylation</a>
    - <a href="#381-cpg-sites" id="toc-381-cpg-sites">3.8.1 CpG sites</a>
- <a href="#4-zygote" id="toc-4-zygote">4 Zygote</a>
  - <a href="#41-create-object" id="toc-41-create-object">4.1 Create
    object</a>
  - <a href="#42-filter" id="toc-42-filter">4.2 Filter</a>
  - <a href="#43-normalization" id="toc-43-normalization">4.3
    Normalization</a>
  - <a href="#44-merge" id="toc-44-merge">4.4 Merge</a>
  - <a href="#45-filter-2" id="toc-45-filter-2">4.5 Filter 2</a>
  - <a href="#46-data-structureoutlier-detection"
    id="toc-46-data-structureoutlier-detection">4.6 Data structure/Outlier
    detection</a>
  - <a href="#47-differential-methylation"
    id="toc-47-differential-methylation">4.7 Differential methylation</a>
    - <a href="#471-cpg-sites" id="toc-471-cpg-sites">4.7.1 CpG sites</a>
- <a href="#5-larvae" id="toc-5-larvae">5 Larvae</a>
  - <a href="#51-create-object" id="toc-51-create-object">5.1 Create
    object</a>
  - <a href="#52-filter" id="toc-52-filter">5.2 Filter</a>
  - <a href="#53-normalization" id="toc-53-normalization">5.3
    Normalization</a>
  - <a href="#54-merge" id="toc-54-merge">5.4 Merge</a>
  - <a href="#55-filter-2" id="toc-55-filter-2">5.5 Filter 2</a>
  - <a href="#56-data-structureoutlier-detection"
    id="toc-56-data-structureoutlier-detection">5.6 Data structure/Outlier
    detection</a>
  - <a href="#57-differential-methylation"
    id="toc-57-differential-methylation">5.7 Differential methylation</a>
    - <a href="#571-cpg-sites" id="toc-571-cpg-sites">5.7.1 CpG sites</a>
- <a href="#6-notes" id="toc-6-notes">6 Notes</a>

Performing differential methylation analysis using the `methylkit`
package. This time I’ll:

1)  change some of the parameters to match those used by Rondon et
    al. 2017 and Venkataraman et al. 2024

2)  split by life stage to look at differential methylation in the
    zygotes and in the larvae separately (parent conditions still the
    treatment factor)

Inputs:

- Methylation calls extracted from WGBS reads using `Bismark`:
  `[].fastp-trim_bismark_bt2_pe.deduplicated.bismark.cov.gz`, stored on
  [Gannet](https://gannet.fish.washington.edu/gitrepos/ceasmallr/output/02.20-bismark-methylation-extraction/)

# 1 Download methylation calls if needed

``` bash
# Run wget to retrieve FastQs and MD5 files
# Note: the --no-clobber command will skip re-downloading any files that are already present in the output directory
wget \
--directory-prefix ../data/bismark-methyl-extraction \
--recursive \
--no-check-certificate \
--continue \
--cut-dirs 4 \
--no-host-directories \
--no-parent \
--quiet \
--no-clobber \
--accept="*.deduplicated.bismark.cov.gz,checksums.md5" https://gannet.fish.washington.edu/gitrepos/ceasmallr/output/02.20-bismark-methylation-extraction/
```

``` bash
cd ../data/bismark-methyl-extraction/

echo "How many methylation calling files were downloaded?"
ls *.deduplicated.bismark.cov.gz | wc -l

echo ""

echo "Check file checksums:"
grep '.deduplicated.bismark.cov.gz' checksums.md5 | md5sum -c -
```

We should have N=32 (n=15 ControlxControl crosses, n=17 ExposedxExposed
crosses)

# 2 methylKit

Load packages

``` r
# Install packages if necessary
# if (!require("BiocManager", quietly = TRUE))
#     install.packages("BiocManager")
# BiocManager::install("methylKit")
# BiocManager::install("genomation")

# Load
library(tidyr)
library(dplyr)
```

    ## 
    ## Attaching package: 'dplyr'

    ## The following objects are masked from 'package:stats':
    ## 
    ##     filter, lag

    ## The following objects are masked from 'package:base':
    ## 
    ##     intersect, setdiff, setequal, union

``` r
library(methylKit)
```

    ## Loading required package: GenomicRanges

    ## Loading required package: stats4

    ## Loading required package: BiocGenerics

    ## 
    ## Attaching package: 'BiocGenerics'

    ## The following objects are masked from 'package:dplyr':
    ## 
    ##     combine, intersect, setdiff, union

    ## The following objects are masked from 'package:stats':
    ## 
    ##     IQR, mad, sd, var, xtabs

    ## The following objects are masked from 'package:base':
    ## 
    ##     anyDuplicated, aperm, 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:dplyr':
    ## 
    ##     first, rename

    ## The following object is masked from 'package:tidyr':
    ## 
    ##     expand

    ## The following objects are masked from 'package:base':
    ## 
    ##     expand.grid, I, unname

    ## Loading required package: IRanges

    ## 
    ## Attaching package: 'IRanges'

    ## The following objects are masked from 'package:dplyr':
    ## 
    ##     collapse, desc, slice

    ## Loading required package: GenomeInfoDb

    ## 
    ## Attaching package: 'methylKit'

    ## The following object is masked from 'package:dplyr':
    ## 
    ##     select

    ## The following object is masked from 'package:tidyr':
    ## 
    ##     unite

``` r
library(genomation)
```

    ## Loading required package: grid

    ## Warning: replacing previous import 'Biostrings::pattern' by 'grid::pattern'
    ## when loading 'genomation'

    ## 
    ## Attaching package: 'genomation'

    ## The following objects are masked from 'package:methylKit':
    ## 
    ##     getFeatsWithTargetsStats, getFlanks, getMembers,
    ##     getTargetAnnotationStats, plotTargetAnnotation

``` r
library(GenomicRanges)
library(gridExtra)
```

    ## 
    ## Attaching package: 'gridExtra'

    ## The following object is masked from 'package:BiocGenerics':
    ## 
    ##     combine

    ## The following object is masked from 'package:dplyr':
    ## 
    ##     combine

``` r
library(ggplot2)
```

Using tutorial:
<https://nbis-workshop-epigenomics.readthedocs.io/en/latest/content/tutorials/methylationSeq/Seq_Tutorial.html#introduction>

# 3 Combo

Rerun differential methylation analysis using both the lifestages, with
updated settings

## 3.1 Create object

``` r
# Define path to my samples directory
data_dir <- "../data/bismark-methyl-extraction"

# List all .bismark.cov.gz files in the samples directory
file.list <- list.files(path = data_dir, pattern = "\\.bismark.cov.gz$", full.names = TRUE)
# Exclude CF08-CM04-Larvae and CF08-CM05-Larvae (very low coverage and methylation)
file.list <- file.list[!grepl("CF08-CM04-Larvae|CF08-CM05-Larvae", file.list)]

# Extract just the filenames
file.names <- basename(file.list)

# Create sample IDs by stripping file extensions
sample.ids <- sub("_R1_001.fastp-trim_bismark_bt2_pe.deduplicated.bismark.cov.gz", "", file.names)
sample.ids <- sub("_R1_001.fastp-trim.REPAIRED_bismark_bt2_pe.deduplicated.bismark.cov.gz", ".REP", sample.ids)


# Assign treatment based on first letter of filename
# E = parents exposed to OA treatment
# C = parents held in control
treatment <- ifelse(startsWith(file.names, "E"), 1,
                    ifelse(startsWith(file.names, "C"), 0, NA))

# Read in methylation data
myobj <- methRead(as.list(file.list),
  sample.id = as.list(sample.ids),
  pipeline = "bismarkCoverage",
  assembly = "mm10",
  treatment = treatment,
  mincov = 10
)
```

    ## Received list of locations.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

``` r
# Inspect
str(myobj)
```

    ## Formal class 'methylRawList' [package "methylKit"] with 2 slots
    ##   ..@ .Data    :List of 30
    ##   .. ..$ :'data.frame':  6849 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:6849] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:6849] 51 88 89 147 148 193 194 246 257 264 ...
    ##   .. .. .. .. ..$ : int [1:6849] 51 88 89 147 148 193 194 246 257 264 ...
    ##   .. .. .. .. ..$ : chr [1:6849] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:6849] 52 104 33 116 57 51 39 61 114 150 ...
    ##   .. .. .. .. ..$ : int [1:6849] 1 0 0 0 1 0 0 2 5 0 ...
    ##   .. .. .. .. ..$ : int [1:6849] 51 104 33 116 56 51 39 59 109 150 ...
    ##   .. .. .. ..@ sample.id : chr "CF01-CM01-Zygote.REP"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:6849] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  2787371 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:2787371] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:2787371] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:2787371] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:2787371] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:2787371] 15 59 16 113 184 163 188 211 142 221 ...
    ##   .. .. .. .. ..$ : int [1:2787371] 0 1 0 4 3 0 3 1 0 3 ...
    ##   .. .. .. .. ..$ : int [1:2787371] 15 58 16 109 181 163 185 210 142 218 ...
    ##   .. .. .. ..@ sample.id : chr "CF01-CM02-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:2787371] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  274259 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:274259] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:274259] 49 50 51 52 88 89 147 148 193 194 ...
    ##   .. .. .. .. ..$ : int [1:274259] 49 50 51 52 88 89 147 148 193 194 ...
    ##   .. .. .. .. ..$ : chr [1:274259] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:274259] 80 19 82 19 206 173 235 257 63 145 ...
    ##   .. .. .. .. ..$ : int [1:274259] 3 2 2 0 10 9 6 12 1 5 ...
    ##   .. .. .. .. ..$ : int [1:274259] 77 17 80 19 196 164 229 245 62 140 ...
    ##   .. .. .. ..@ sample.id : chr "CF02-CM02-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:274259] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  596118 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:596118] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:596118] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:596118] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:596118] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:596118] 25 51 29 101 325 107 397 84 237 107 ...
    ##   .. .. .. .. ..$ : int [1:596118] 0 2 0 1 6 1 12 3 6 2 ...
    ##   .. .. .. .. ..$ : int [1:596118] 25 49 29 100 319 106 385 81 231 105 ...
    ##   .. .. .. ..@ sample.id : chr "CF03-CM03-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:596118] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  1960777 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:1960777] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:1960777] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : int [1:1960777] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : chr [1:1960777] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:1960777] 44 92 83 127 70 231 55 242 35 256 ...
    ##   .. .. .. .. ..$ : int [1:1960777] 4 2 0 3 1 8 1 8 1 4 ...
    ##   .. .. .. .. ..$ : int [1:1960777] 40 90 83 124 69 223 54 234 34 252 ...
    ##   .. .. .. ..@ sample.id : chr "CF03-CM04-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:1960777] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  2471065 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:2471065] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:2471065] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:2471065] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:2471065] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:2471065] 10 17 11 38 130 58 147 114 109 150 ...
    ##   .. .. .. .. ..$ : int [1:2471065] 0 1 0 1 1 2 4 6 4 5 ...
    ##   .. .. .. .. ..$ : int [1:2471065] 10 16 11 37 129 56 143 108 105 145 ...
    ##   .. .. .. ..@ sample.id : chr "CF03-CM05-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:2471065] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  745966 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:745966] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:745966] 50 51 52 88 89 147 148 149 193 194 ...
    ##   .. .. .. .. ..$ : int [1:745966] 50 51 52 88 89 147 148 149 193 194 ...
    ##   .. .. .. .. ..$ : chr [1:745966] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:745966] 85 116 99 252 669 323 731 13 263 496 ...
    ##   .. .. .. .. ..$ : int [1:745966] 1 1 1 8 9 8 21 0 8 9 ...
    ##   .. .. .. .. ..$ : int [1:745966] 84 115 98 244 660 315 710 13 255 487 ...
    ##   .. .. .. ..@ sample.id : chr "CF04-CM04-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:745966] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  3717313 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:3717313] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:3717313] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : int [1:3717313] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : chr [1:3717313] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:3717313] 24 50 77 85 80 110 61 124 11 139 ...
    ##   .. .. .. .. ..$ : int [1:3717313] 0 1 0 0 0 1 0 0 0 1 ...
    ##   .. .. .. .. ..$ : int [1:3717313] 24 49 77 85 80 109 61 124 11 138 ...
    ##   .. .. .. ..@ sample.id : chr "CF05-CM02-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:3717313] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  1295363 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:1295363] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:1295363] 50 51 52 88 89 147 148 149 193 194 ...
    ##   .. .. .. .. ..$ : int [1:1295363] 50 51 52 88 89 147 148 149 193 194 ...
    ##   .. .. .. .. ..$ : chr [1:1295363] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:1295363] 107 110 113 239 855 373 902 19 435 635 ...
    ##   .. .. .. .. ..$ : int [1:1295363] 4 2 2 7 19 8 18 1 12 14 ...
    ##   .. .. .. .. ..$ : int [1:1295363] 103 108 111 232 836 365 884 18 423 621 ...
    ##   .. .. .. ..@ sample.id : chr "CF05-CM05-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:1295363] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  716129 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:716129] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:716129] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:716129] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:716129] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:716129] 51 65 59 143 467 172 569 134 358 151 ...
    ##   .. .. .. .. ..$ : int [1:716129] 2 4 0 5 10 4 20 3 6 11 ...
    ##   .. .. .. .. ..$ : int [1:716129] 49 61 59 138 457 168 549 131 352 140 ...
    ##   .. .. .. ..@ sample.id : chr "CF06-CM01-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:716129] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  649349 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:649349] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:649349] 50 52 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : int [1:649349] 50 52 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : chr [1:649349] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:649349] 12 14 136 13 140 10 91 16 31 20 ...
    ##   .. .. .. .. ..$ : int [1:649349] 0 2 0 0 8 0 4 1 2 1 ...
    ##   .. .. .. .. ..$ : int [1:649349] 12 12 136 13 132 10 87 15 29 19 ...
    ##   .. .. .. ..@ sample.id : chr "CF06-CM02-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:649349] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  183710 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:183710] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:183710] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:183710] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:183710] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:183710] 86 205 102 483 586 587 611 514 385 571 ...
    ##   .. .. .. .. ..$ : int [1:183710] 2 1 0 6 5 4 9 10 2 10 ...
    ##   .. .. .. .. ..$ : int [1:183710] 84 204 102 477 581 583 602 504 383 561 ...
    ##   .. .. .. ..@ sample.id : chr "CF07-CM02-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:183710] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  313301 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:313301] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:313301] 49 50 51 52 88 89 147 148 193 194 ...
    ##   .. .. .. .. ..$ : int [1:313301] 49 50 51 52 88 89 147 148 193 194 ...
    ##   .. .. .. .. ..$ : chr [1:313301] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:313301] 106 36 110 37 241 357 266 453 79 254 ...
    ##   .. .. .. .. ..$ : int [1:313301] 2 0 4 1 11 4 7 6 3 5 ...
    ##   .. .. .. .. ..$ : int [1:313301] 104 36 106 36 230 353 259 447 76 249 ...
    ##   .. .. .. ..@ sample.id : chr "CF08-CM03-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:313301] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  689453 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:689453] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:689453] 50 51 52 88 89 147 148 149 193 194 ...
    ##   .. .. .. .. ..$ : int [1:689453] 50 51 52 88 89 147 148 149 193 194 ...
    ##   .. .. .. .. ..$ : chr [1:689453] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:689453] 105 44 112 81 1070 114 1217 21 127 869 ...
    ##   .. .. .. .. ..$ : int [1:689453] 8 0 7 3 26 4 42 2 5 28 ...
    ##   .. .. .. .. ..$ : int [1:689453] 97 44 105 78 1044 110 1175 19 122 841 ...
    ##   .. .. .. ..@ sample.id : chr "EF01-EM01-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:689453] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  1035967 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:1035967] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:1035967] 49 50 51 52 88 89 147 148 193 194 ...
    ##   .. .. .. .. ..$ : int [1:1035967] 49 50 51 52 88 89 147 148 193 194 ...
    ##   .. .. .. .. ..$ : chr [1:1035967] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:1035967] 257 39 269 44 534 436 804 567 604 385 ...
    ##   .. .. .. .. ..$ : int [1:1035967] 1 0 3 0 5 1 7 10 5 7 ...
    ##   .. .. .. .. ..$ : int [1:1035967] 256 39 266 44 529 435 797 557 599 378 ...
    ##   .. .. .. ..@ sample.id : chr "EF02-EM02-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:1035967] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  236386 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:236386] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:236386] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:236386] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:236386] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:236386] 27 68 29 105 262 108 302 46 170 69 ...
    ##   .. .. .. .. ..$ : int [1:236386] 0 0 0 1 10 2 4 4 9 2 ...
    ##   .. .. .. .. ..$ : int [1:236386] 27 68 29 104 252 106 298 42 161 67 ...
    ##   .. .. .. ..@ sample.id : chr "EF03-EM03-Zygote.REP"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:236386] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  1841161 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:1841161] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:1841161] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:1841161] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:1841161] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:1841161] 12 16 15 44 132 58 137 62 101 94 ...
    ##   .. .. .. .. ..$ : int [1:1841161] 1 1 0 3 7 7 1 2 0 5 ...
    ##   .. .. .. .. ..$ : int [1:1841161] 11 15 15 41 125 51 136 60 101 89 ...
    ##   .. .. .. ..@ sample.id : chr "EF03-EM04-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:1841161] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  2118011 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:2118011] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:2118011] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : int [1:2118011] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : chr [1:2118011] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:2118011] 15 23 126 33 156 46 112 53 25 56 ...
    ##   .. .. .. .. ..$ : int [1:2118011] 0 1 6 2 4 1 0 1 1 2 ...
    ##   .. .. .. .. ..$ : int [1:2118011] 15 22 120 31 152 45 112 52 24 54 ...
    ##   .. .. .. ..@ sample.id : chr "EF03-EM05-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:2118011] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  35872 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:35872] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:35872] 49 51 88 89 147 148 193 194 246 247 ...
    ##   .. .. .. .. ..$ : int [1:35872] 49 51 88 89 147 148 193 194 246 247 ...
    ##   .. .. .. .. ..$ : chr [1:35872] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:35872] 145 142 219 115 403 233 122 57 54 32 ...
    ##   .. .. .. .. ..$ : int [1:35872] 9 5 4 0 9 8 1 1 5 1 ...
    ##   .. .. .. .. ..$ : int [1:35872] 136 137 215 115 394 225 121 56 49 31 ...
    ##   .. .. .. ..@ sample.id : chr "EF04-EM04-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:35872] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  3388293 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:3388293] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:3388293] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:3388293] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:3388293] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:3388293] 10 34 11 69 91 117 101 172 89 193 ...
    ##   .. .. .. .. ..$ : int [1:3388293] 0 0 0 0 1 0 0 5 0 2 ...
    ##   .. .. .. .. ..$ : int [1:3388293] 10 34 11 69 90 117 101 167 89 191 ...
    ##   .. .. .. ..@ sample.id : chr "EF04-EM05-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:3388293] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  1712845 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:1712845] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:1712845] 51 52 88 89 147 148 193 194 246 247 ...
    ##   .. .. .. .. ..$ : int [1:1712845] 51 52 88 89 147 148 193 194 246 247 ...
    ##   .. .. .. .. ..$ : chr [1:1712845] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:1712845] 54 10 87 147 150 145 256 106 282 41 ...
    ##   .. .. .. .. ..$ : int [1:1712845] 0 1 2 2 3 2 1 1 2 2 ...
    ##   .. .. .. .. ..$ : int [1:1712845] 54 9 85 145 147 143 255 105 280 39 ...
    ##   .. .. .. ..@ sample.id : chr "EF05-EM01-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:1712845] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  7565 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:7565] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:7565] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : int [1:7565] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : chr [1:7565] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:7565] 81 118 61 318 151 60 35 38 13 59 ...
    ##   .. .. .. .. ..$ : int [1:7565] 1 2 2 1 2 3 0 1 0 3 ...
    ##   .. .. .. .. ..$ : int [1:7565] 80 116 59 317 149 57 35 37 13 56 ...
    ##   .. .. .. ..@ sample.id : chr "EF05-EM05-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:7565] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  3454081 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:3454081] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:3454081] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : int [1:3454081] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : chr [1:3454081] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:3454081] 35 58 58 82 73 144 58 152 43 161 ...
    ##   .. .. .. .. ..$ : int [1:3454081] 1 0 4 4 6 6 5 10 7 9 ...
    ##   .. .. .. .. ..$ : int [1:3454081] 34 58 54 78 67 138 53 142 36 152 ...
    ##   .. .. .. ..@ sample.id : chr "EF05-EM06-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:3454081] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  3306084 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:3306084] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:3306084] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : int [1:3306084] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : chr [1:3306084] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:3306084] 48 74 67 95 86 124 67 137 30 143 ...
    ##   .. .. .. .. ..$ : int [1:3306084] 0 0 0 0 1 2 1 1 1 1 ...
    ##   .. .. .. .. ..$ : int [1:3306084] 48 74 67 95 85 122 66 136 29 142 ...
    ##   .. .. .. ..@ sample.id : chr "EF06-EM01-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:3306084] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  2302918 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:2302918] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:2302918] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:2302918] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:2302918] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:2302918] 15 23 16 36 173 57 177 89 117 111 ...
    ##   .. .. .. .. ..$ : int [1:2302918] 0 0 0 0 3 1 4 1 2 8 ...
    ##   .. .. .. .. ..$ : int [1:2302918] 15 23 16 36 170 56 173 88 115 103 ...
    ##   .. .. .. ..@ sample.id : chr "EF06-EM02-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:2302918] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  50224 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:50224] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:50224] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:50224] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:50224] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:50224] 24 73 27 152 266 199 354 129 234 141 ...
    ##   .. .. .. .. ..$ : int [1:50224] 0 0 1 4 10 5 17 8 7 5 ...
    ##   .. .. .. .. ..$ : int [1:50224] 24 73 26 148 256 194 337 121 227 136 ...
    ##   .. .. .. ..@ sample.id : chr "EF06-EM06-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:50224] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  57069 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:57069] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:57069] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:57069] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:57069] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:57069] 19 112 18 236 168 330 238 141 125 173 ...
    ##   .. .. .. .. ..$ : int [1:57069] 0 0 0 0 1 2 6 0 1 4 ...
    ##   .. .. .. .. ..$ : int [1:57069] 19 112 18 236 167 328 232 141 124 169 ...
    ##   .. .. .. ..@ sample.id : chr "EF07-EM01-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:57069] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  2263969 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:2263969] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:2263969] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : int [1:2263969] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : chr [1:2263969] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:2263969] 30 54 59 84 78 110 55 121 17 128 ...
    ##   .. .. .. .. ..$ : int [1:2263969] 1 0 1 0 0 1 1 1 0 0 ...
    ##   .. .. .. .. ..$ : int [1:2263969] 29 54 58 84 78 109 54 120 17 128 ...
    ##   .. .. .. ..@ sample.id : chr "EF07-EM03-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:2263969] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  2822850 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:2822850] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:2822850] 51 88 89 147 148 193 194 246 257 264 ...
    ##   .. .. .. .. ..$ : int [1:2822850] 51 88 89 147 148 193 194 246 257 264 ...
    ##   .. .. .. .. ..$ : chr [1:2822850] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:2822850] 15 24 44 52 36 116 19 112 118 123 ...
    ##   .. .. .. .. ..$ : int [1:2822850] 0 0 1 0 1 1 0 0 1 0 ...
    ##   .. .. .. .. ..$ : int [1:2822850] 15 24 43 52 35 115 19 112 117 123 ...
    ##   .. .. .. ..@ sample.id : chr "EF08-EM03-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:2822850] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  2036693 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:2036693] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:2036693] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:2036693] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:2036693] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:2036693] 17 15 19 29 159 32 152 57 97 71 ...
    ##   .. .. .. .. ..$ : int [1:2036693] 0 1 0 0 4 1 3 2 1 0 ...
    ##   .. .. .. .. ..$ : int [1:2036693] 17 14 19 29 155 31 149 55 96 71 ...
    ##   .. .. .. ..@ sample.id : chr "EF08-EM04-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:2036693] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   ..@ treatment: num [1:30] 0 0 0 0 0 0 0 0 0 0 ...

``` r
head(myobj[[1]])
```

    ##           chr start end strand coverage numCs numTs
    ## 1 NC_007175.2    51  51      *       52     1    51
    ## 2 NC_007175.2    88  88      *      104     0   104
    ## 3 NC_007175.2    89  89      *       33     0    33
    ## 4 NC_007175.2   147 147      *      116     0   116
    ## 5 NC_007175.2   148 148      *       57     1    56
    ## 6 NC_007175.2   193 193      *       51     0    51

## 3.2 Descriptive statistics

``` r
# Get a histogram of the methylation percentage per sample
for (i in 1:length(myobj)){
  getMethylationStats(myobj[[i]], plot=TRUE, both.strands=FALSE)
}
```

![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-1.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-2.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-3.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-4.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-5.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-6.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-7.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-8.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-9.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-10.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-11.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-12.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-13.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-14.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-15.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-16.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-17.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-18.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-19.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-20.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-21.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-22.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-23.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-24.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-25.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-26.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-27.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-28.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-29.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-5-30.png)<!-- -->

CF08-CM04-Larvae.REP and CF08-CM05-Larvae have almost no methylated
sites and poor coverage. I think I’ll go back and exclude them from the
analysis for now.

``` r
for (i in 1:length(myobj)){
  getCoverageStats(myobj[[i]], plot=TRUE, both.strands=FALSE)
  # # Get percentile data by setting plot=FALSE
  # getCoverageStats(myobj[[i]], plot=FALSE, both.strands=FALSE)
}
```

![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-1.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-2.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-3.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-4.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-5.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-6.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-7.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-8.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-9.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-10.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-11.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-12.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-13.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-14.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-15.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-16.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-17.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-18.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-19.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-20.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-21.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-22.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-23.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-24.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-25.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-26.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-27.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-28.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-29.png)<!-- -->![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-6-30.png)<!-- -->

## 3.3 Filter

We want to filter out bases with low coverage (\<10 reads) because they
will reduce reliability in downstream analyses. We also want to discard
any bases with exceptionally high coverage (in the 99.9th percentile),
as this is an indication of PCR amplification bias.

``` r
myobj.filt <- filterByCoverage(myobj,
                      lo.count=10,
                      lo.perc=NULL,
                      hi.count=NULL,
                      hi.perc=99.9)
```

## 3.4 Normalization

Next, we normalize the coverage values among samples.

``` r
myobj.filt.norm <- normalizeCoverage(myobj.filt, method = "median")
```

## 3.5 Merge

Data doesn’t appear to be two-stranded, so will use `destrand=FALSE`

``` r
meth <- methylKit::unite(myobj.filt.norm, destrand=FALSE)
```

    ## uniting...

``` r
nrow(meth)
```

    ## [1] 114

We retain 114 CpG site that have coverage in all samples

## 3.6 Filter 2

This step was reccommended in the tutorial I was following, but doesn’t
seem to have been implemented in Rondon et al. 2017 or Venkataraman et
al. 2024, so I’ll skip for now

``` r
# # get percent methylation matrix
# pm=percMethylation(meth)
# 
# # calculate standard deviation of CpGs
# sds=matrixStats::rowSds(pm)
# 
# # Visualize the distribution of the per-CpG standard deviation
# # to determine a suitable cutoff
# hist(sds, breaks = 100)
# 
# # keep only CpG with standard deviations larger than 2%
# meth <- meth[sds > 2]
# 
# # This leaves us with this number of CpG sites
# nrow(meth)
```

Could also remove known C/T SNPs if we want (will exclude this step for
now)

``` r
# # give the locations of 2 example SNPs
# mut <- GRanges(seqnames=c("chr1","chr18"),
#          ranges=IRanges(start=c(3020690, 9853326),
#                         end=c(3020690,9853326)))
# 
# # select CpGs that do not overlap with mutations
# meth <- meth[!as(meth,"GRanges") %over% mut, ]
```

## 3.7 Data structure/Outlier detection

``` r
getCorrelation(meth,plot=FALSE)
```

    ##                      CF01-CM01-Zygote.REP CF01-CM02-Larvae CF02-CM02-Zygote
    ## CF01-CM01-Zygote.REP            1.0000000        0.9626511        0.9316613
    ## CF01-CM02-Larvae                0.9626511        1.0000000        0.9532052
    ## CF02-CM02-Zygote                0.9316613        0.9532052        1.0000000
    ## CF03-CM03-Zygote                0.9555180        0.9552805        0.9406687
    ## CF03-CM04-Larvae                0.8656347        0.9058621        0.8877305
    ## CF03-CM05-Larvae                0.9350585        0.9594298        0.9260410
    ## CF04-CM04-Zygote                0.9057510        0.9442308        0.9161675
    ## CF05-CM02-Larvae                0.9508214        0.9632465        0.9538973
    ## CF05-CM05-Zygote                0.9546738        0.9640608        0.9410297
    ## CF06-CM01-Zygote                0.9567806        0.9577119        0.9448012
    ## CF06-CM02-Larvae                0.9515306        0.9597489        0.9574223
    ## CF07-CM02-Zygote                0.9537859        0.9541258        0.9561738
    ## CF08-CM03-Zygote                0.9637628        0.9523555        0.9412068
    ## EF01-EM01-Zygote                0.9538268        0.9680478        0.9519960
    ## EF02-EM02-Zygote                0.9692511        0.9664779        0.9368289
    ## EF03-EM03-Zygote.REP            0.9600940        0.9640634        0.9448262
    ## EF03-EM04-Larvae                0.9460763        0.9490400        0.9361896
    ## EF03-EM05-Larvae                0.9476961        0.9559802        0.9388073
    ## EF04-EM04-Zygote                0.9431097        0.9478661        0.9025268
    ## EF04-EM05-Larvae                0.9480473        0.9690123        0.9490613
    ## EF05-EM01-Larvae                0.9565284        0.9746374        0.9486033
    ## EF05-EM05-Zygote                0.9292202        0.9488727        0.9317296
    ## EF05-EM06-Larvae                0.9140767        0.9231186        0.9356323
    ## EF06-EM01-Larvae                0.9549344        0.9737688        0.9578091
    ## EF06-EM02-Larvae                0.9640618        0.9608665        0.9354497
    ## EF06-EM06-Larvae                0.9496427        0.9492089        0.9215026
    ## EF07-EM01-Zygote                0.9377640        0.9662930        0.9447879
    ## EF07-EM03-Larvae                0.9571681        0.9780888        0.9401240
    ## EF08-EM03-Larvae                0.9388560        0.9702703        0.9524768
    ## EF08-EM04-Larvae                0.9400434        0.9598539        0.9480532
    ##                      CF03-CM03-Zygote CF03-CM04-Larvae CF03-CM05-Larvae
    ## CF01-CM01-Zygote.REP        0.9555180        0.8656347        0.9350585
    ## CF01-CM02-Larvae            0.9552805        0.9058621        0.9594298
    ## CF02-CM02-Zygote            0.9406687        0.8877305        0.9260410
    ## CF03-CM03-Zygote            1.0000000        0.9293518        0.9697806
    ## CF03-CM04-Larvae            0.9293518        1.0000000        0.9188522
    ## CF03-CM05-Larvae            0.9697806        0.9188522        1.0000000
    ## CF04-CM04-Zygote            0.9311525        0.9469995        0.9369194
    ## CF05-CM02-Larvae            0.9538984        0.8648770        0.9423824
    ## CF05-CM05-Zygote            0.9576515        0.8807627        0.9382063
    ## CF06-CM01-Zygote            0.9556619        0.8787214        0.9458919
    ## CF06-CM02-Larvae            0.9613048        0.8843242        0.9397957
    ## CF07-CM02-Zygote            0.9707544        0.9136855        0.9504747
    ## CF08-CM03-Zygote            0.9711610        0.8956200        0.9478400
    ## EF01-EM01-Zygote            0.9600771        0.9001363        0.9452423
    ## EF02-EM02-Zygote            0.9635805        0.8763964        0.9442778
    ## EF03-EM03-Zygote.REP        0.9530143        0.8783801        0.9472824
    ## EF03-EM04-Larvae            0.9586396        0.8868992        0.9458748
    ## EF03-EM05-Larvae            0.9531902        0.8893582        0.9378341
    ## EF04-EM04-Zygote            0.9322414        0.8559054        0.9307185
    ## EF04-EM05-Larvae            0.9712211        0.9153894        0.9628423
    ## EF05-EM01-Larvae            0.9609910        0.8878000        0.9495931
    ## EF05-EM05-Zygote            0.9315550        0.8531857        0.9296730
    ## EF05-EM06-Larvae            0.9498527        0.9033241        0.9275687
    ## EF06-EM01-Larvae            0.9714458        0.9354831        0.9612468
    ## EF06-EM02-Larvae            0.9444691        0.8491580        0.9318001
    ## EF06-EM06-Larvae            0.9410916        0.8654282        0.9169623
    ## EF07-EM01-Zygote            0.9394039        0.8704705        0.9387172
    ## EF07-EM03-Larvae            0.9536483        0.9004340        0.9534151
    ## EF08-EM03-Larvae            0.9619460        0.9363950        0.9596760
    ## EF08-EM04-Larvae            0.9708436        0.9264941        0.9534415
    ##                      CF04-CM04-Zygote CF05-CM02-Larvae CF05-CM05-Zygote
    ## CF01-CM01-Zygote.REP        0.9057510        0.9508214        0.9546738
    ## CF01-CM02-Larvae            0.9442308        0.9632465        0.9640608
    ## CF02-CM02-Zygote            0.9161675        0.9538973        0.9410297
    ## CF03-CM03-Zygote            0.9311525        0.9538984        0.9576515
    ## CF03-CM04-Larvae            0.9469995        0.8648770        0.8807627
    ## CF03-CM05-Larvae            0.9369194        0.9423824        0.9382063
    ## CF04-CM04-Zygote            1.0000000        0.8929078        0.9088475
    ## CF05-CM02-Larvae            0.8929078        1.0000000        0.9558520
    ## CF05-CM05-Zygote            0.9088475        0.9558520        1.0000000
    ## CF06-CM01-Zygote            0.9067974        0.9587019        0.9686948
    ## CF06-CM02-Larvae            0.9010594        0.9702427        0.9567078
    ## CF07-CM02-Zygote            0.9274267        0.9592687        0.9486604
    ## CF08-CM03-Zygote            0.9152037        0.9483886        0.9619727
    ## EF01-EM01-Zygote            0.9326932        0.9621586        0.9543913
    ## EF02-EM02-Zygote            0.9121142        0.9571078        0.9755040
    ## EF03-EM03-Zygote.REP        0.9147925        0.9521598        0.9656696
    ## EF03-EM04-Larvae            0.9228578        0.9371954        0.9463158
    ## EF03-EM05-Larvae            0.9056217        0.9549713        0.9666409
    ## EF04-EM04-Zygote            0.9134614        0.9102549        0.9351567
    ## EF04-EM05-Larvae            0.9355888        0.9684804        0.9641274
    ## EF05-EM01-Larvae            0.9177737        0.9662467        0.9560628
    ## EF05-EM05-Zygote            0.8935281        0.9369244        0.9582886
    ## EF05-EM06-Larvae            0.9129012        0.9412317        0.9130130
    ## EF06-EM01-Larvae            0.9499731        0.9672551        0.9561091
    ## EF06-EM02-Larvae            0.8906506        0.9570130        0.9692225
    ## EF06-EM06-Larvae            0.8947127        0.9448902        0.9420343
    ## EF07-EM01-Zygote            0.9191925        0.9654438        0.9622621
    ## EF07-EM03-Larvae            0.9312133        0.9737414        0.9750971
    ## EF08-EM03-Larvae            0.9467397        0.9553895        0.9440812
    ## EF08-EM04-Larvae            0.9406589        0.9606186        0.9547350
    ##                      CF06-CM01-Zygote CF06-CM02-Larvae CF07-CM02-Zygote
    ## CF01-CM01-Zygote.REP        0.9567806        0.9515306        0.9537859
    ## CF01-CM02-Larvae            0.9577119        0.9597489        0.9541258
    ## CF02-CM02-Zygote            0.9448012        0.9574223        0.9561738
    ## CF03-CM03-Zygote            0.9556619        0.9613048        0.9707544
    ## CF03-CM04-Larvae            0.8787214        0.8843242        0.9136855
    ## CF03-CM05-Larvae            0.9458919        0.9397957        0.9504747
    ## CF04-CM04-Zygote            0.9067974        0.9010594        0.9274267
    ## CF05-CM02-Larvae            0.9587019        0.9702427        0.9592687
    ## CF05-CM05-Zygote            0.9686948        0.9567078        0.9486604
    ## CF06-CM01-Zygote            1.0000000        0.9539412        0.9429074
    ## CF06-CM02-Larvae            0.9539412        1.0000000        0.9636773
    ## CF07-CM02-Zygote            0.9429074        0.9636773        1.0000000
    ## CF08-CM03-Zygote            0.9757561        0.9627075        0.9550373
    ## EF01-EM01-Zygote            0.9563292        0.9580561        0.9641658
    ## EF02-EM02-Zygote            0.9661661        0.9537790        0.9597284
    ## EF03-EM03-Zygote.REP        0.9764223        0.9483573        0.9386225
    ## EF03-EM04-Larvae            0.9584442        0.9395637        0.9396720
    ## EF03-EM05-Larvae            0.9697520        0.9469081        0.9446611
    ## EF04-EM04-Zygote            0.9429322        0.9129228        0.9180775
    ## EF04-EM05-Larvae            0.9643497        0.9645096        0.9616661
    ## EF05-EM01-Larvae            0.9557155        0.9641580        0.9527523
    ## EF05-EM05-Zygote            0.9633765        0.9346475        0.9244002
    ## EF05-EM06-Larvae            0.9276584        0.9353584        0.9460110
    ## EF06-EM01-Larvae            0.9467665        0.9655021        0.9761528
    ## EF06-EM02-Larvae            0.9606322        0.9475501        0.9519562
    ## EF06-EM06-Larvae            0.9538832        0.9402181        0.9335967
    ## EF07-EM01-Zygote            0.9477285        0.9506664        0.9498945
    ## EF07-EM03-Larvae            0.9672859        0.9551281        0.9496994
    ## EF08-EM03-Larvae            0.9432623        0.9551827        0.9599564
    ## EF08-EM04-Larvae            0.9503159        0.9588868        0.9660175
    ##                      CF08-CM03-Zygote EF01-EM01-Zygote EF02-EM02-Zygote
    ## CF01-CM01-Zygote.REP        0.9637628        0.9538268        0.9692511
    ## CF01-CM02-Larvae            0.9523555        0.9680478        0.9664779
    ## CF02-CM02-Zygote            0.9412068        0.9519960        0.9368289
    ## CF03-CM03-Zygote            0.9711610        0.9600771        0.9635805
    ## CF03-CM04-Larvae            0.8956200        0.9001363        0.8763964
    ## CF03-CM05-Larvae            0.9478400        0.9452423        0.9442778
    ## CF04-CM04-Zygote            0.9152037        0.9326932        0.9121142
    ## CF05-CM02-Larvae            0.9483886        0.9621586        0.9571078
    ## CF05-CM05-Zygote            0.9619727        0.9543913        0.9755040
    ## CF06-CM01-Zygote            0.9757561        0.9563292        0.9661661
    ## CF06-CM02-Larvae            0.9627075        0.9580561        0.9537790
    ## CF07-CM02-Zygote            0.9550373        0.9641658        0.9597284
    ## CF08-CM03-Zygote            1.0000000        0.9540359        0.9641956
    ## EF01-EM01-Zygote            0.9540359        1.0000000        0.9604826
    ## EF02-EM02-Zygote            0.9641956        0.9604826        1.0000000
    ## EF03-EM03-Zygote.REP        0.9658651        0.9553864        0.9649413
    ## EF03-EM04-Larvae            0.9586737        0.9476427        0.9607740
    ## EF03-EM05-Larvae            0.9613714        0.9559912        0.9705938
    ## EF04-EM04-Zygote            0.9396659        0.9233711        0.9626382
    ## EF04-EM05-Larvae            0.9648784        0.9697953        0.9618085
    ## EF05-EM01-Larvae            0.9550694        0.9562533        0.9673460
    ## EF05-EM05-Zygote            0.9356753        0.9353401        0.9609501
    ## EF05-EM06-Larvae            0.9452713        0.9345120        0.9227468
    ## EF06-EM01-Larvae            0.9572333        0.9686469        0.9565102
    ## EF06-EM02-Larvae            0.9575387        0.9530956        0.9801303
    ## EF06-EM06-Larvae            0.9526830        0.9469066        0.9480105
    ## EF07-EM01-Zygote            0.9317855        0.9589995        0.9613835
    ## EF07-EM03-Larvae            0.9515387        0.9629834        0.9642486
    ## EF08-EM03-Larvae            0.9451373        0.9637957        0.9497985
    ## EF08-EM04-Larvae            0.9583139        0.9646445        0.9624916
    ##                      EF03-EM03-Zygote.REP EF03-EM04-Larvae EF03-EM05-Larvae
    ## CF01-CM01-Zygote.REP            0.9600940        0.9460763        0.9476961
    ## CF01-CM02-Larvae                0.9640634        0.9490400        0.9559802
    ## CF02-CM02-Zygote                0.9448262        0.9361896        0.9388073
    ## CF03-CM03-Zygote                0.9530143        0.9586396        0.9531902
    ## CF03-CM04-Larvae                0.8783801        0.8868992        0.8893582
    ## CF03-CM05-Larvae                0.9472824        0.9458748        0.9378341
    ## CF04-CM04-Zygote                0.9147925        0.9228578        0.9056217
    ## CF05-CM02-Larvae                0.9521598        0.9371954        0.9549713
    ## CF05-CM05-Zygote                0.9656696        0.9463158        0.9666409
    ## CF06-CM01-Zygote                0.9764223        0.9584442        0.9697520
    ## CF06-CM02-Larvae                0.9483573        0.9395637        0.9469081
    ## CF07-CM02-Zygote                0.9386225        0.9396720        0.9446611
    ## CF08-CM03-Zygote                0.9658651        0.9586737        0.9613714
    ## EF01-EM01-Zygote                0.9553864        0.9476427        0.9559912
    ## EF02-EM02-Zygote                0.9649413        0.9607740        0.9705938
    ## EF03-EM03-Zygote.REP            1.0000000        0.9596010        0.9646166
    ## EF03-EM04-Larvae                0.9596010        1.0000000        0.9563151
    ## EF03-EM05-Larvae                0.9646166        0.9563151        1.0000000
    ## EF04-EM04-Zygote                0.9378878        0.9365996        0.9283406
    ## EF04-EM05-Larvae                0.9671515        0.9612710        0.9632555
    ## EF05-EM01-Larvae                0.9554064        0.9499246        0.9633164
    ## EF05-EM05-Zygote                0.9537982        0.9450968        0.9552633
    ## EF05-EM06-Larvae                0.9242489        0.9267709        0.9346481
    ## EF06-EM01-Larvae                0.9480649        0.9453809        0.9554529
    ## EF06-EM02-Larvae                0.9590997        0.9358465        0.9580085
    ## EF06-EM06-Larvae                0.9594998        0.9304215        0.9404032
    ## EF07-EM01-Zygote                0.9507760        0.9446826        0.9486437
    ## EF07-EM03-Larvae                0.9681611        0.9418165        0.9641482
    ## EF08-EM03-Larvae                0.9491194        0.9439979        0.9484201
    ## EF08-EM04-Larvae                0.9473871        0.9555077        0.9585412
    ##                      EF04-EM04-Zygote EF04-EM05-Larvae EF05-EM01-Larvae
    ## CF01-CM01-Zygote.REP        0.9431097        0.9480473        0.9565284
    ## CF01-CM02-Larvae            0.9478661        0.9690123        0.9746374
    ## CF02-CM02-Zygote            0.9025268        0.9490613        0.9486033
    ## CF03-CM03-Zygote            0.9322414        0.9712211        0.9609910
    ## CF03-CM04-Larvae            0.8559054        0.9153894        0.8878000
    ## CF03-CM05-Larvae            0.9307185        0.9628423        0.9495931
    ## CF04-CM04-Zygote            0.9134614        0.9355888        0.9177737
    ## CF05-CM02-Larvae            0.9102549        0.9684804        0.9662467
    ## CF05-CM05-Zygote            0.9351567        0.9641274        0.9560628
    ## CF06-CM01-Zygote            0.9429322        0.9643497        0.9557155
    ## CF06-CM02-Larvae            0.9129228        0.9645096        0.9641580
    ## CF07-CM02-Zygote            0.9180775        0.9616661        0.9527523
    ## CF08-CM03-Zygote            0.9396659        0.9648784        0.9550694
    ## EF01-EM01-Zygote            0.9233711        0.9697953        0.9562533
    ## EF02-EM02-Zygote            0.9626382        0.9618085        0.9673460
    ## EF03-EM03-Zygote.REP        0.9378878        0.9671515        0.9554064
    ## EF03-EM04-Larvae            0.9365996        0.9612710        0.9499246
    ## EF03-EM05-Larvae            0.9283406        0.9632555        0.9633164
    ## EF04-EM04-Zygote            1.0000000        0.9331271        0.9391637
    ## EF04-EM05-Larvae            0.9331271        1.0000000        0.9657220
    ## EF05-EM01-Larvae            0.9391637        0.9657220        1.0000000
    ## EF05-EM05-Zygote            0.9424886        0.9498497        0.9468673
    ## EF05-EM06-Larvae            0.8845544        0.9496727        0.9366013
    ## EF06-EM01-Larvae            0.9263536        0.9773204        0.9662919
    ## EF06-EM02-Larvae            0.9393852        0.9482400        0.9550263
    ## EF06-EM06-Larvae            0.9174542        0.9465277        0.9538974
    ## EF07-EM01-Zygote            0.9299775        0.9706231        0.9547007
    ## EF07-EM03-Larvae            0.9292640        0.9717730        0.9585685
    ## EF08-EM03-Larvae            0.9225617        0.9792362        0.9607221
    ## EF08-EM04-Larvae            0.9219147        0.9834614        0.9558676
    ##                      EF05-EM05-Zygote EF05-EM06-Larvae EF06-EM01-Larvae
    ## CF01-CM01-Zygote.REP        0.9292202        0.9140767        0.9549344
    ## CF01-CM02-Larvae            0.9488727        0.9231186        0.9737688
    ## CF02-CM02-Zygote            0.9317296        0.9356323        0.9578091
    ## CF03-CM03-Zygote            0.9315550        0.9498527        0.9714458
    ## CF03-CM04-Larvae            0.8531857        0.9033241        0.9354831
    ## CF03-CM05-Larvae            0.9296730        0.9275687        0.9612468
    ## CF04-CM04-Zygote            0.8935281        0.9129012        0.9499731
    ## CF05-CM02-Larvae            0.9369244        0.9412317        0.9672551
    ## CF05-CM05-Zygote            0.9582886        0.9130130        0.9561091
    ## CF06-CM01-Zygote            0.9633765        0.9276584        0.9467665
    ## CF06-CM02-Larvae            0.9346475        0.9353584        0.9655021
    ## CF07-CM02-Zygote            0.9244002        0.9460110        0.9761528
    ## CF08-CM03-Zygote            0.9356753        0.9452713        0.9572333
    ## EF01-EM01-Zygote            0.9353401        0.9345120        0.9686469
    ## EF02-EM02-Zygote            0.9609501        0.9227468        0.9565102
    ## EF03-EM03-Zygote.REP        0.9537982        0.9242489        0.9480649
    ## EF03-EM04-Larvae            0.9450968        0.9267709        0.9453809
    ## EF03-EM05-Larvae            0.9552633        0.9346481        0.9554529
    ## EF04-EM04-Zygote            0.9424886        0.8845544        0.9263536
    ## EF04-EM05-Larvae            0.9498497        0.9496727        0.9773204
    ## EF05-EM01-Larvae            0.9468673        0.9366013        0.9662919
    ## EF05-EM05-Zygote            1.0000000        0.8933449        0.9343133
    ## EF05-EM06-Larvae            0.8933449        1.0000000        0.9504584
    ## EF06-EM01-Larvae            0.9343133        0.9504584        1.0000000
    ## EF06-EM02-Larvae            0.9353164        0.9172799        0.9464214
    ## EF06-EM06-Larvae            0.9261120        0.9118994        0.9361377
    ## EF07-EM01-Zygote            0.9623968        0.9120374        0.9677222
    ## EF07-EM03-Larvae            0.9504448        0.9237209        0.9677326
    ## EF08-EM03-Larvae            0.9284377        0.9399898        0.9800648
    ## EF08-EM04-Larvae            0.9328340        0.9593568        0.9786286
    ##                      EF06-EM02-Larvae EF06-EM06-Larvae EF07-EM01-Zygote
    ## CF01-CM01-Zygote.REP        0.9640618        0.9496427        0.9377640
    ## CF01-CM02-Larvae            0.9608665        0.9492089        0.9662930
    ## CF02-CM02-Zygote            0.9354497        0.9215026        0.9447879
    ## CF03-CM03-Zygote            0.9444691        0.9410916        0.9394039
    ## CF03-CM04-Larvae            0.8491580        0.8654282        0.8704705
    ## CF03-CM05-Larvae            0.9318001        0.9169623        0.9387172
    ## CF04-CM04-Zygote            0.8906506        0.8947127        0.9191925
    ## CF05-CM02-Larvae            0.9570130        0.9448902        0.9654438
    ## CF05-CM05-Zygote            0.9692225        0.9420343        0.9622621
    ## CF06-CM01-Zygote            0.9606322        0.9538832        0.9477285
    ## CF06-CM02-Larvae            0.9475501        0.9402181        0.9506664
    ## CF07-CM02-Zygote            0.9519562        0.9335967        0.9498945
    ## CF08-CM03-Zygote            0.9575387        0.9526830        0.9317855
    ## EF01-EM01-Zygote            0.9530956        0.9469066        0.9589995
    ## EF02-EM02-Zygote            0.9801303        0.9480105        0.9613835
    ## EF03-EM03-Zygote.REP        0.9590997        0.9594998        0.9507760
    ## EF03-EM04-Larvae            0.9358465        0.9304215        0.9446826
    ## EF03-EM05-Larvae            0.9580085        0.9404032        0.9486437
    ## EF04-EM04-Zygote            0.9393852        0.9174542        0.9299775
    ## EF04-EM05-Larvae            0.9482400        0.9465277        0.9706231
    ## EF05-EM01-Larvae            0.9550263        0.9538974        0.9547007
    ## EF05-EM05-Zygote            0.9353164        0.9261120        0.9623968
    ## EF05-EM06-Larvae            0.9172799        0.9118994        0.9120374
    ## EF06-EM01-Larvae            0.9464214        0.9361377        0.9677222
    ## EF06-EM02-Larvae            1.0000000        0.9494972        0.9449160
    ## EF06-EM06-Larvae            0.9494972        1.0000000        0.9275602
    ## EF07-EM01-Zygote            0.9449160        0.9275602        1.0000000
    ## EF07-EM03-Larvae            0.9600972        0.9517634        0.9676288
    ## EF08-EM03-Larvae            0.9370603        0.9269298        0.9549604
    ## EF08-EM04-Larvae            0.9461791        0.9249370        0.9556649
    ##                      EF07-EM03-Larvae EF08-EM03-Larvae EF08-EM04-Larvae
    ## CF01-CM01-Zygote.REP        0.9571681        0.9388560        0.9400434
    ## CF01-CM02-Larvae            0.9780888        0.9702703        0.9598539
    ## CF02-CM02-Zygote            0.9401240        0.9524768        0.9480532
    ## CF03-CM03-Zygote            0.9536483        0.9619460        0.9708436
    ## CF03-CM04-Larvae            0.9004340        0.9363950        0.9264941
    ## CF03-CM05-Larvae            0.9534151        0.9596760        0.9534415
    ## CF04-CM04-Zygote            0.9312133        0.9467397        0.9406589
    ## CF05-CM02-Larvae            0.9737414        0.9553895        0.9606186
    ## CF05-CM05-Zygote            0.9750971        0.9440812        0.9547350
    ## CF06-CM01-Zygote            0.9672859        0.9432623        0.9503159
    ## CF06-CM02-Larvae            0.9551281        0.9551827        0.9588868
    ## CF07-CM02-Zygote            0.9496994        0.9599564        0.9660175
    ## CF08-CM03-Zygote            0.9515387        0.9451373        0.9583139
    ## EF01-EM01-Zygote            0.9629834        0.9637957        0.9646445
    ## EF02-EM02-Zygote            0.9642486        0.9497985        0.9624916
    ## EF03-EM03-Zygote.REP        0.9681611        0.9491194        0.9473871
    ## EF03-EM04-Larvae            0.9418165        0.9439979        0.9555077
    ## EF03-EM05-Larvae            0.9641482        0.9484201        0.9585412
    ## EF04-EM04-Zygote            0.9292640        0.9225617        0.9219147
    ## EF04-EM05-Larvae            0.9717730        0.9792362        0.9834614
    ## EF05-EM01-Larvae            0.9585685        0.9607221        0.9558676
    ## EF05-EM05-Zygote            0.9504448        0.9284377        0.9328340
    ## EF05-EM06-Larvae            0.9237209        0.9399898        0.9593568
    ## EF06-EM01-Larvae            0.9677326        0.9800648        0.9786286
    ## EF06-EM02-Larvae            0.9600972        0.9370603        0.9461791
    ## EF06-EM06-Larvae            0.9517634        0.9269298        0.9249370
    ## EF07-EM01-Zygote            0.9676288        0.9549604        0.9556649
    ## EF07-EM03-Larvae            1.0000000        0.9594550        0.9612765
    ## EF08-EM03-Larvae            0.9594550        1.0000000        0.9776941
    ## EF08-EM04-Larvae            0.9612765        0.9776941        1.0000000

``` r
clusterSamples(meth, dist="correlation", method="ward", plot=TRUE)
```

    ## The "ward" method has been renamed to "ward.D"; note new "ward.D2"

![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-13-1.png)<!-- -->

    ## 
    ## Call:
    ## hclust(d = d, method = HCLUST.METHODS[hclust.method])
    ## 
    ## Cluster method   : ward.D 
    ## Distance         : pearson 
    ## Number of objects: 30

``` r
PCASamples(meth)
```

![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-14-1.png)<!-- -->

## 3.8 Differential methylation

### 3.8.1 CpG sites

``` r
# Test for differential methylation
# Apply Benjamini-Hochberg adjustment for multiple testing (default)
myDiff <- calculateDiffMeth(meth, adjust="BH")
```

    ## two groups detected:
    ##  will calculate methylation difference as the difference of
    ## treatment (group: 1) - control (group: 0)

``` r
# Not sure what minimum difference is appropriate here. Rondon et al. 2017 used 25%, Venkataraman et al. 2024 used 50%
myDiff_sig_diff25 <- getMethylDiff(myDiff, difference = 25, qvalue = 0.01)
```

    ## Warning in max(i): no non-missing arguments to max; returning -Inf

``` r
myDiff_sig_diff50 <- getMethylDiff(myDiff, difference = 50, qvalue = 0.01)
```

    ## Warning in max(i): no non-missing arguments to max; returning -Inf

``` r
nrow(myDiff_sig_diff25)
```

    ## [1] 0

``` r
nrow(myDiff_sig_diff50)
```

    ## [1] 0

There are 0 CpG sites that are differentially methylated based on
parental exposure.

Last time I found 3, but I wasn’t filtering by methylation difference,
and I was basing significance off of the raw pvalue (`pvalue`), instead
of the FDR-adjusted pvalues (`qvalue`)

Now run differential methylation analysis separately on the zygote and
larvae groups

# 4 Zygote

## 4.1 Create object

``` r
# Define path to my samples directory
data_dir <- "../data/bismark-methyl-extraction"

# List all .bismark.cov.gz files in the samples directory
## Only list Zygote files
file.list_zygote <- list.files(path = data_dir, pattern = ".*Zygote.*\\.bismark.cov.gz$", full.names = TRUE)

# Extract just the filenames
file.names_zygote <- basename(file.list_zygote)

# Create sample IDs by stripping file extensions
sample.ids_zygote <- sub("_R1_001.fastp-trim_bismark_bt2_pe.deduplicated.bismark.cov.gz", "", file.names_zygote)
sample.ids_zygote <- sub("_R1_001.fastp-trim.REPAIRED_bismark_bt2_pe.deduplicated.bismark.cov.gz", ".REP", sample.ids_zygote)


# Assign treatment based on first letter of filename
# E = parents exposed to OA treatment
# C = parents held in control
treatment_zygote <- ifelse(startsWith(file.names_zygote, "E"), 1,
                      ifelse(startsWith(file.names_zygote, "C"), 0, NA))

# Read in methylation data
myobj_zygote <- methRead(as.list(file.list_zygote),
  sample.id = as.list(sample.ids_zygote),
  pipeline = "bismarkCoverage",
  assembly = "mm10",
  treatment = treatment_zygote,
  mincov = 10
)
```

    ## Received list of locations.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

``` r
# Inspect
str(myobj_zygote)
```

    ## Formal class 'methylRawList' [package "methylKit"] with 2 slots
    ##   ..@ .Data    :List of 14
    ##   .. ..$ :'data.frame':  6849 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:6849] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:6849] 51 88 89 147 148 193 194 246 257 264 ...
    ##   .. .. .. .. ..$ : int [1:6849] 51 88 89 147 148 193 194 246 257 264 ...
    ##   .. .. .. .. ..$ : chr [1:6849] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:6849] 52 104 33 116 57 51 39 61 114 150 ...
    ##   .. .. .. .. ..$ : int [1:6849] 1 0 0 0 1 0 0 2 5 0 ...
    ##   .. .. .. .. ..$ : int [1:6849] 51 104 33 116 56 51 39 59 109 150 ...
    ##   .. .. .. ..@ sample.id : chr "CF01-CM01-Zygote.REP"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:6849] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  274259 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:274259] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:274259] 49 50 51 52 88 89 147 148 193 194 ...
    ##   .. .. .. .. ..$ : int [1:274259] 49 50 51 52 88 89 147 148 193 194 ...
    ##   .. .. .. .. ..$ : chr [1:274259] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:274259] 80 19 82 19 206 173 235 257 63 145 ...
    ##   .. .. .. .. ..$ : int [1:274259] 3 2 2 0 10 9 6 12 1 5 ...
    ##   .. .. .. .. ..$ : int [1:274259] 77 17 80 19 196 164 229 245 62 140 ...
    ##   .. .. .. ..@ sample.id : chr "CF02-CM02-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:274259] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  596118 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:596118] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:596118] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:596118] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:596118] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:596118] 25 51 29 101 325 107 397 84 237 107 ...
    ##   .. .. .. .. ..$ : int [1:596118] 0 2 0 1 6 1 12 3 6 2 ...
    ##   .. .. .. .. ..$ : int [1:596118] 25 49 29 100 319 106 385 81 231 105 ...
    ##   .. .. .. ..@ sample.id : chr "CF03-CM03-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:596118] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  745966 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:745966] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:745966] 50 51 52 88 89 147 148 149 193 194 ...
    ##   .. .. .. .. ..$ : int [1:745966] 50 51 52 88 89 147 148 149 193 194 ...
    ##   .. .. .. .. ..$ : chr [1:745966] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:745966] 85 116 99 252 669 323 731 13 263 496 ...
    ##   .. .. .. .. ..$ : int [1:745966] 1 1 1 8 9 8 21 0 8 9 ...
    ##   .. .. .. .. ..$ : int [1:745966] 84 115 98 244 660 315 710 13 255 487 ...
    ##   .. .. .. ..@ sample.id : chr "CF04-CM04-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:745966] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  1295363 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:1295363] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:1295363] 50 51 52 88 89 147 148 149 193 194 ...
    ##   .. .. .. .. ..$ : int [1:1295363] 50 51 52 88 89 147 148 149 193 194 ...
    ##   .. .. .. .. ..$ : chr [1:1295363] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:1295363] 107 110 113 239 855 373 902 19 435 635 ...
    ##   .. .. .. .. ..$ : int [1:1295363] 4 2 2 7 19 8 18 1 12 14 ...
    ##   .. .. .. .. ..$ : int [1:1295363] 103 108 111 232 836 365 884 18 423 621 ...
    ##   .. .. .. ..@ sample.id : chr "CF05-CM05-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:1295363] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  716129 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:716129] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:716129] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:716129] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:716129] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:716129] 51 65 59 143 467 172 569 134 358 151 ...
    ##   .. .. .. .. ..$ : int [1:716129] 2 4 0 5 10 4 20 3 6 11 ...
    ##   .. .. .. .. ..$ : int [1:716129] 49 61 59 138 457 168 549 131 352 140 ...
    ##   .. .. .. ..@ sample.id : chr "CF06-CM01-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:716129] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  183710 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:183710] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:183710] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:183710] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:183710] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:183710] 86 205 102 483 586 587 611 514 385 571 ...
    ##   .. .. .. .. ..$ : int [1:183710] 2 1 0 6 5 4 9 10 2 10 ...
    ##   .. .. .. .. ..$ : int [1:183710] 84 204 102 477 581 583 602 504 383 561 ...
    ##   .. .. .. ..@ sample.id : chr "CF07-CM02-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:183710] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  313301 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:313301] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:313301] 49 50 51 52 88 89 147 148 193 194 ...
    ##   .. .. .. .. ..$ : int [1:313301] 49 50 51 52 88 89 147 148 193 194 ...
    ##   .. .. .. .. ..$ : chr [1:313301] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:313301] 106 36 110 37 241 357 266 453 79 254 ...
    ##   .. .. .. .. ..$ : int [1:313301] 2 0 4 1 11 4 7 6 3 5 ...
    ##   .. .. .. .. ..$ : int [1:313301] 104 36 106 36 230 353 259 447 76 249 ...
    ##   .. .. .. ..@ sample.id : chr "CF08-CM03-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:313301] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  689453 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:689453] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:689453] 50 51 52 88 89 147 148 149 193 194 ...
    ##   .. .. .. .. ..$ : int [1:689453] 50 51 52 88 89 147 148 149 193 194 ...
    ##   .. .. .. .. ..$ : chr [1:689453] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:689453] 105 44 112 81 1070 114 1217 21 127 869 ...
    ##   .. .. .. .. ..$ : int [1:689453] 8 0 7 3 26 4 42 2 5 28 ...
    ##   .. .. .. .. ..$ : int [1:689453] 97 44 105 78 1044 110 1175 19 122 841 ...
    ##   .. .. .. ..@ sample.id : chr "EF01-EM01-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:689453] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  1035967 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:1035967] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:1035967] 49 50 51 52 88 89 147 148 193 194 ...
    ##   .. .. .. .. ..$ : int [1:1035967] 49 50 51 52 88 89 147 148 193 194 ...
    ##   .. .. .. .. ..$ : chr [1:1035967] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:1035967] 257 39 269 44 534 436 804 567 604 385 ...
    ##   .. .. .. .. ..$ : int [1:1035967] 1 0 3 0 5 1 7 10 5 7 ...
    ##   .. .. .. .. ..$ : int [1:1035967] 256 39 266 44 529 435 797 557 599 378 ...
    ##   .. .. .. ..@ sample.id : chr "EF02-EM02-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:1035967] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  236386 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:236386] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:236386] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:236386] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:236386] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:236386] 27 68 29 105 262 108 302 46 170 69 ...
    ##   .. .. .. .. ..$ : int [1:236386] 0 0 0 1 10 2 4 4 9 2 ...
    ##   .. .. .. .. ..$ : int [1:236386] 27 68 29 104 252 106 298 42 161 67 ...
    ##   .. .. .. ..@ sample.id : chr "EF03-EM03-Zygote.REP"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:236386] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  35872 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:35872] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:35872] 49 51 88 89 147 148 193 194 246 247 ...
    ##   .. .. .. .. ..$ : int [1:35872] 49 51 88 89 147 148 193 194 246 247 ...
    ##   .. .. .. .. ..$ : chr [1:35872] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:35872] 145 142 219 115 403 233 122 57 54 32 ...
    ##   .. .. .. .. ..$ : int [1:35872] 9 5 4 0 9 8 1 1 5 1 ...
    ##   .. .. .. .. ..$ : int [1:35872] 136 137 215 115 394 225 121 56 49 31 ...
    ##   .. .. .. ..@ sample.id : chr "EF04-EM04-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:35872] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  7565 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:7565] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:7565] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : int [1:7565] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : chr [1:7565] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:7565] 81 118 61 318 151 60 35 38 13 59 ...
    ##   .. .. .. .. ..$ : int [1:7565] 1 2 2 1 2 3 0 1 0 3 ...
    ##   .. .. .. .. ..$ : int [1:7565] 80 116 59 317 149 57 35 37 13 56 ...
    ##   .. .. .. ..@ sample.id : chr "EF05-EM05-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:7565] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  57069 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:57069] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:57069] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:57069] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:57069] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:57069] 19 112 18 236 168 330 238 141 125 173 ...
    ##   .. .. .. .. ..$ : int [1:57069] 0 0 0 0 1 2 6 0 1 4 ...
    ##   .. .. .. .. ..$ : int [1:57069] 19 112 18 236 167 328 232 141 124 169 ...
    ##   .. .. .. ..@ sample.id : chr "EF07-EM01-Zygote"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:57069] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   ..@ treatment: num [1:14] 0 0 0 0 0 0 0 0 1 1 ...

``` r
head(myobj_zygote[[1]])
```

    ##           chr start end strand coverage numCs numTs
    ## 1 NC_007175.2    51  51      *       52     1    51
    ## 2 NC_007175.2    88  88      *      104     0   104
    ## 3 NC_007175.2    89  89      *       33     0    33
    ## 4 NC_007175.2   147 147      *      116     0   116
    ## 5 NC_007175.2   148 148      *       57     1    56
    ## 6 NC_007175.2   193 193      *       51     0    51

## 4.2 Filter

We want to filter out bases with low coverage (\<10 reads) because they
will reduce reliability in downstream analyses. We also want to discard
any bases with exceptionally high coverage (in the 99.9th percentile),
as this is an indication of PCR amplification bias.

``` r
myobj.filt_zygote <- filterByCoverage(myobj_zygote,
                      lo.count=10,
                      lo.perc=NULL,
                      hi.count=NULL,
                      hi.perc=99.9)
```

## 4.3 Normalization

Next, we normalize the coverage values among samples.

``` r
myobj.filt.norm_zygote <- normalizeCoverage(myobj.filt_zygote, method = "median")
```

## 4.4 Merge

Data doesn’t appear to be two-stranded, so will use `destrand=FALSE`

``` r
meth_zygote <- methylKit::unite(myobj.filt.norm_zygote, destrand=FALSE)
```

    ## uniting...

``` r
nrow(meth_zygote)
```

    ## [1] 398

We retain 398 CpG site that have coverage in all zygote samples

## 4.5 Filter 2

This step was reccommended in the tutorial I was following, but doesn’t
seem to have been implemented in Rondon et al. 2017 or Venkataraman et
al. 2024, so I’ll skip for now

``` r
# # get percent methylation matrix
# pm_zygote=percMethylation(meth_zygote)
# 
# # calculate standard deviation of CpGs
# sds_zygote=matrixStats::rowSds(pm_zygote)
# 
# # Visualize the distribution of the per-CpG standard deviation
# # to determine a suitable cutoff
# hist(sds_zygote, breaks = 100)
# 
# # keep only CpG with standard deviations larger than 2%
# meth_zygote <- meth_zygote[sds_zygote > 2]
# 
# # This leaves us with this number of CpG sites
# nrow(meth_zygote)
```

## 4.6 Data structure/Outlier detection

``` r
getCorrelation(meth_zygote,plot=FALSE)
```

    ##                      CF01-CM01-Zygote.REP CF02-CM02-Zygote CF03-CM03-Zygote
    ## CF01-CM01-Zygote.REP            1.0000000        0.9323562        0.9599413
    ## CF02-CM02-Zygote                0.9323562        1.0000000        0.9356480
    ## CF03-CM03-Zygote                0.9599413        0.9356480        1.0000000
    ## CF04-CM04-Zygote                0.9284685        0.9235988        0.9419427
    ## CF05-CM05-Zygote                0.9541221        0.9375269        0.9528019
    ## CF06-CM01-Zygote                0.9299398        0.9269346        0.9324440
    ## CF07-CM02-Zygote                0.9496101        0.9592584        0.9480036
    ## CF08-CM03-Zygote                0.9629409        0.9407843        0.9717178
    ## EF01-EM01-Zygote                0.9244500        0.9269811        0.9193060
    ## EF02-EM02-Zygote                0.9061858        0.9119118        0.9075036
    ## EF03-EM03-Zygote.REP            0.9433614        0.9394965        0.9425492
    ## EF04-EM04-Zygote                0.9311747        0.9121941        0.9144257
    ## EF05-EM05-Zygote                0.9087703        0.8951534        0.9138768
    ## EF07-EM01-Zygote                0.9471304        0.9373513        0.9568709
    ##                      CF04-CM04-Zygote CF05-CM05-Zygote CF06-CM01-Zygote
    ## CF01-CM01-Zygote.REP        0.9284685        0.9541221        0.9299398
    ## CF02-CM02-Zygote            0.9235988        0.9375269        0.9269346
    ## CF03-CM03-Zygote            0.9419427        0.9528019        0.9324440
    ## CF04-CM04-Zygote            1.0000000        0.9373912        0.9041195
    ## CF05-CM05-Zygote            0.9373912        1.0000000        0.9484146
    ## CF06-CM01-Zygote            0.9041195        0.9484146        1.0000000
    ## CF07-CM02-Zygote            0.9303227        0.9449444        0.9317900
    ## CF08-CM03-Zygote            0.9359335        0.9593220        0.9486228
    ## EF01-EM01-Zygote            0.9119032        0.9268380        0.9156479
    ## EF02-EM02-Zygote            0.9245526        0.9315790        0.9125142
    ## EF03-EM03-Zygote.REP        0.9381808        0.9539277        0.9440696
    ## EF04-EM04-Zygote            0.9164781        0.9261868        0.9056719
    ## EF05-EM05-Zygote            0.9144895        0.9301722        0.9058545
    ## EF07-EM01-Zygote            0.9367507        0.9482273        0.9213257
    ##                      CF07-CM02-Zygote CF08-CM03-Zygote EF01-EM01-Zygote
    ## CF01-CM01-Zygote.REP        0.9496101        0.9629409        0.9244500
    ## CF02-CM02-Zygote            0.9592584        0.9407843        0.9269811
    ## CF03-CM03-Zygote            0.9480036        0.9717178        0.9193060
    ## CF04-CM04-Zygote            0.9303227        0.9359335        0.9119032
    ## CF05-CM05-Zygote            0.9449444        0.9593220        0.9268380
    ## CF06-CM01-Zygote            0.9317900        0.9486228        0.9156479
    ## CF07-CM02-Zygote            1.0000000        0.9529296        0.9348709
    ## CF08-CM03-Zygote            0.9529296        1.0000000        0.9283968
    ## EF01-EM01-Zygote            0.9348709        0.9283968        1.0000000
    ## EF02-EM02-Zygote            0.9263326        0.9170928        0.8938457
    ## EF03-EM03-Zygote.REP        0.9413182        0.9521744        0.9262707
    ## EF04-EM04-Zygote            0.9247782        0.9266485        0.8949727
    ## EF05-EM05-Zygote            0.9000480        0.9114411        0.8740744
    ## EF07-EM01-Zygote            0.9418913        0.9519795        0.9212619
    ##                      EF02-EM02-Zygote EF03-EM03-Zygote.REP EF04-EM04-Zygote
    ## CF01-CM01-Zygote.REP        0.9061858            0.9433614        0.9311747
    ## CF02-CM02-Zygote            0.9119118            0.9394965        0.9121941
    ## CF03-CM03-Zygote            0.9075036            0.9425492        0.9144257
    ## CF04-CM04-Zygote            0.9245526            0.9381808        0.9164781
    ## CF05-CM05-Zygote            0.9315790            0.9539277        0.9261868
    ## CF06-CM01-Zygote            0.9125142            0.9440696        0.9056719
    ## CF07-CM02-Zygote            0.9263326            0.9413182        0.9247782
    ## CF08-CM03-Zygote            0.9170928            0.9521744        0.9266485
    ## EF01-EM01-Zygote            0.8938457            0.9262707        0.8949727
    ## EF02-EM02-Zygote            1.0000000            0.9463617        0.9204940
    ## EF03-EM03-Zygote.REP        0.9463617            1.0000000        0.9220849
    ## EF04-EM04-Zygote            0.9204940            0.9220849        1.0000000
    ## EF05-EM05-Zygote            0.9348046            0.9296697        0.8993353
    ## EF07-EM01-Zygote            0.9028974            0.9329473        0.9146117
    ##                      EF05-EM05-Zygote EF07-EM01-Zygote
    ## CF01-CM01-Zygote.REP        0.9087703        0.9471304
    ## CF02-CM02-Zygote            0.8951534        0.9373513
    ## CF03-CM03-Zygote            0.9138768        0.9568709
    ## CF04-CM04-Zygote            0.9144895        0.9367507
    ## CF05-CM05-Zygote            0.9301722        0.9482273
    ## CF06-CM01-Zygote            0.9058545        0.9213257
    ## CF07-CM02-Zygote            0.9000480        0.9418913
    ## CF08-CM03-Zygote            0.9114411        0.9519795
    ## EF01-EM01-Zygote            0.8740744        0.9212619
    ## EF02-EM02-Zygote            0.9348046        0.9028974
    ## EF03-EM03-Zygote.REP        0.9296697        0.9329473
    ## EF04-EM04-Zygote            0.8993353        0.9146117
    ## EF05-EM05-Zygote            1.0000000        0.9234435
    ## EF07-EM01-Zygote            0.9234435        1.0000000

``` r
clusterSamples(meth_zygote, dist="correlation", method="ward", plot=TRUE)
```

    ## The "ward" method has been renamed to "ward.D"; note new "ward.D2"

![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-22-1.png)<!-- -->

    ## 
    ## Call:
    ## hclust(d = d, method = HCLUST.METHODS[hclust.method])
    ## 
    ## Cluster method   : ward.D 
    ## Distance         : pearson 
    ## Number of objects: 14

``` r
PCASamples(meth_zygote)
```

![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-23-1.png)<!-- -->

## 4.7 Differential methylation

### 4.7.1 CpG sites

``` r
# Test for differential methylation
# Apply Benjamini-Hochberg adjustment for multiple testing (default)
myDiff_zygote <- calculateDiffMeth(meth_zygote, adjust="BH")
```

    ## two groups detected:
    ##  will calculate methylation difference as the difference of
    ## treatment (group: 1) - control (group: 0)

``` r
# Not sure what minimum difference is appropriate here. Rondon et al. 2017 used 25%, Venkataraman et al. 2024 used 50%
myDiff_zygote_sig_diff25 <- getMethylDiff(myDiff_zygote, difference = 25, qvalue = 0.01)
```

    ## Warning in max(i): no non-missing arguments to max; returning -Inf

``` r
myDiff_zygote_sig_diff50 <- getMethylDiff(myDiff_zygote, difference = 50, qvalue = 0.01)
```

    ## Warning in max(i): no non-missing arguments to max; returning -Inf

``` r
nrow(myDiff_zygote_sig_diff25)
```

    ## [1] 0

``` r
nrow(myDiff_zygote_sig_diff50)
```

    ## [1] 0

There are 0 CpG sites that are differentially methylated based on
parental exposure in zygotes

# 5 Larvae

## 5.1 Create object

``` r
# Define path to my samples directory
data_dir <- "../data/bismark-methyl-extraction"

# List all .bismark.cov.gz files in the samples directory
## Only list larvae files
file.list_larvae <- list.files(path = data_dir, pattern = ".*Larvae.*\\.bismark.cov.gz$", full.names = TRUE)
# Exclude CF08-CM04-Larvae and CF08-CM05-Larvae (very low coverage and methylation)
file.list_larvae <- file.list_larvae[!grepl("CF08-CM04-Larvae|CF08-CM05-Larvae", file.list_larvae)]

# Extract just the filenames
file.names_larvae <- basename(file.list_larvae)

# Create sample IDs by stripping file extensions
sample.ids_larvae <- sub("_R1_001.fastp-trim_bismark_bt2_pe.deduplicated.bismark.cov.gz", "", file.names_larvae)
sample.ids_larvae <- sub("_R1_001.fastp-trim.REPAIRED_bismark_bt2_pe.deduplicated.bismark.cov.gz", ".REP", sample.ids_larvae)


# Assign treatment based on first letter of filename
# E = parents exposed to OA treatment
# C = parents held in control
treatment_larvae <- ifelse(startsWith(file.names_larvae, "E"), 1,
                      ifelse(startsWith(file.names_larvae, "C"), 0, NA))

# Read in methylation data
myobj_larvae <- methRead(as.list(file.list_larvae),
  sample.id = as.list(sample.ids_larvae),
  pipeline = "bismarkCoverage",
  assembly = "mm10",
  treatment = treatment_larvae,
  mincov = 10
)
```

    ## Received list of locations.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

    ## Uncompressing file.

    ## Reading file.

``` r
# Inspect
str(myobj_larvae)
```

    ## Formal class 'methylRawList' [package "methylKit"] with 2 slots
    ##   ..@ .Data    :List of 16
    ##   .. ..$ :'data.frame':  2787371 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:2787371] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:2787371] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:2787371] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:2787371] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:2787371] 15 59 16 113 184 163 188 211 142 221 ...
    ##   .. .. .. .. ..$ : int [1:2787371] 0 1 0 4 3 0 3 1 0 3 ...
    ##   .. .. .. .. ..$ : int [1:2787371] 15 58 16 109 181 163 185 210 142 218 ...
    ##   .. .. .. ..@ sample.id : chr "CF01-CM02-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:2787371] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  1960777 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:1960777] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:1960777] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : int [1:1960777] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : chr [1:1960777] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:1960777] 44 92 83 127 70 231 55 242 35 256 ...
    ##   .. .. .. .. ..$ : int [1:1960777] 4 2 0 3 1 8 1 8 1 4 ...
    ##   .. .. .. .. ..$ : int [1:1960777] 40 90 83 124 69 223 54 234 34 252 ...
    ##   .. .. .. ..@ sample.id : chr "CF03-CM04-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:1960777] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  2471065 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:2471065] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:2471065] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:2471065] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:2471065] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:2471065] 10 17 11 38 130 58 147 114 109 150 ...
    ##   .. .. .. .. ..$ : int [1:2471065] 0 1 0 1 1 2 4 6 4 5 ...
    ##   .. .. .. .. ..$ : int [1:2471065] 10 16 11 37 129 56 143 108 105 145 ...
    ##   .. .. .. ..@ sample.id : chr "CF03-CM05-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:2471065] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  3717313 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:3717313] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:3717313] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : int [1:3717313] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : chr [1:3717313] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:3717313] 24 50 77 85 80 110 61 124 11 139 ...
    ##   .. .. .. .. ..$ : int [1:3717313] 0 1 0 0 0 1 0 0 0 1 ...
    ##   .. .. .. .. ..$ : int [1:3717313] 24 49 77 85 80 109 61 124 11 138 ...
    ##   .. .. .. ..@ sample.id : chr "CF05-CM02-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:3717313] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  649349 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:649349] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:649349] 50 52 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : int [1:649349] 50 52 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : chr [1:649349] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:649349] 12 14 136 13 140 10 91 16 31 20 ...
    ##   .. .. .. .. ..$ : int [1:649349] 0 2 0 0 8 0 4 1 2 1 ...
    ##   .. .. .. .. ..$ : int [1:649349] 12 12 136 13 132 10 87 15 29 19 ...
    ##   .. .. .. ..@ sample.id : chr "CF06-CM02-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:649349] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  1841161 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:1841161] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:1841161] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:1841161] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:1841161] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:1841161] 12 16 15 44 132 58 137 62 101 94 ...
    ##   .. .. .. .. ..$ : int [1:1841161] 1 1 0 3 7 7 1 2 0 5 ...
    ##   .. .. .. .. ..$ : int [1:1841161] 11 15 15 41 125 51 136 60 101 89 ...
    ##   .. .. .. ..@ sample.id : chr "EF03-EM04-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:1841161] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  2118011 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:2118011] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:2118011] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : int [1:2118011] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : chr [1:2118011] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:2118011] 15 23 126 33 156 46 112 53 25 56 ...
    ##   .. .. .. .. ..$ : int [1:2118011] 0 1 6 2 4 1 0 1 1 2 ...
    ##   .. .. .. .. ..$ : int [1:2118011] 15 22 120 31 152 45 112 52 24 54 ...
    ##   .. .. .. ..@ sample.id : chr "EF03-EM05-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:2118011] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  3388293 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:3388293] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:3388293] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:3388293] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:3388293] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:3388293] 10 34 11 69 91 117 101 172 89 193 ...
    ##   .. .. .. .. ..$ : int [1:3388293] 0 0 0 0 1 0 0 5 0 2 ...
    ##   .. .. .. .. ..$ : int [1:3388293] 10 34 11 69 90 117 101 167 89 191 ...
    ##   .. .. .. ..@ sample.id : chr "EF04-EM05-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:3388293] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  1712845 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:1712845] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:1712845] 51 52 88 89 147 148 193 194 246 247 ...
    ##   .. .. .. .. ..$ : int [1:1712845] 51 52 88 89 147 148 193 194 246 247 ...
    ##   .. .. .. .. ..$ : chr [1:1712845] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:1712845] 54 10 87 147 150 145 256 106 282 41 ...
    ##   .. .. .. .. ..$ : int [1:1712845] 0 1 2 2 3 2 1 1 2 2 ...
    ##   .. .. .. .. ..$ : int [1:1712845] 54 9 85 145 147 143 255 105 280 39 ...
    ##   .. .. .. ..@ sample.id : chr "EF05-EM01-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:1712845] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  3454081 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:3454081] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:3454081] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : int [1:3454081] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : chr [1:3454081] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:3454081] 35 58 58 82 73 144 58 152 43 161 ...
    ##   .. .. .. .. ..$ : int [1:3454081] 1 0 4 4 6 6 5 10 7 9 ...
    ##   .. .. .. .. ..$ : int [1:3454081] 34 58 54 78 67 138 53 142 36 152 ...
    ##   .. .. .. ..@ sample.id : chr "EF05-EM06-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:3454081] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  3306084 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:3306084] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:3306084] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : int [1:3306084] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : chr [1:3306084] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:3306084] 48 74 67 95 86 124 67 137 30 143 ...
    ##   .. .. .. .. ..$ : int [1:3306084] 0 0 0 0 1 2 1 1 1 1 ...
    ##   .. .. .. .. ..$ : int [1:3306084] 48 74 67 95 85 122 66 136 29 142 ...
    ##   .. .. .. ..@ sample.id : chr "EF06-EM01-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:3306084] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  2302918 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:2302918] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:2302918] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:2302918] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:2302918] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:2302918] 15 23 16 36 173 57 177 89 117 111 ...
    ##   .. .. .. .. ..$ : int [1:2302918] 0 0 0 0 3 1 4 1 2 8 ...
    ##   .. .. .. .. ..$ : int [1:2302918] 15 23 16 36 170 56 173 88 115 103 ...
    ##   .. .. .. ..@ sample.id : chr "EF06-EM02-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:2302918] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  50224 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:50224] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:50224] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:50224] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:50224] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:50224] 24 73 27 152 266 199 354 129 234 141 ...
    ##   .. .. .. .. ..$ : int [1:50224] 0 0 1 4 10 5 17 8 7 5 ...
    ##   .. .. .. .. ..$ : int [1:50224] 24 73 26 148 256 194 337 121 227 136 ...
    ##   .. .. .. ..@ sample.id : chr "EF06-EM06-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:50224] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  2263969 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:2263969] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:2263969] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : int [1:2263969] 51 88 89 147 148 193 194 246 247 257 ...
    ##   .. .. .. .. ..$ : chr [1:2263969] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:2263969] 30 54 59 84 78 110 55 121 17 128 ...
    ##   .. .. .. .. ..$ : int [1:2263969] 1 0 1 0 0 1 1 1 0 0 ...
    ##   .. .. .. .. ..$ : int [1:2263969] 29 54 58 84 78 109 54 120 17 128 ...
    ##   .. .. .. ..@ sample.id : chr "EF07-EM03-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:2263969] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  2822850 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:2822850] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:2822850] 51 88 89 147 148 193 194 246 257 264 ...
    ##   .. .. .. .. ..$ : int [1:2822850] 51 88 89 147 148 193 194 246 257 264 ...
    ##   .. .. .. .. ..$ : chr [1:2822850] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:2822850] 15 24 44 52 36 116 19 112 118 123 ...
    ##   .. .. .. .. ..$ : int [1:2822850] 0 0 1 0 1 1 0 0 1 0 ...
    ##   .. .. .. .. ..$ : int [1:2822850] 15 24 43 52 35 115 19 112 117 123 ...
    ##   .. .. .. ..@ sample.id : chr "EF08-EM03-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:2822850] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   .. ..$ :'data.frame':  2036693 obs. of  7 variables:
    ## Formal class 'methylRaw' [package "methylKit"] with 8 slots
    ##   .. .. .. ..@ .Data     :List of 7
    ##   .. .. .. .. ..$ : chr [1:2036693] "NC_007175.2" "NC_007175.2" "NC_007175.2" "NC_007175.2" ...
    ##   .. .. .. .. ..$ : int [1:2036693] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : int [1:2036693] 50 51 52 88 89 147 148 193 194 246 ...
    ##   .. .. .. .. ..$ : chr [1:2036693] "*" "*" "*" "*" ...
    ##   .. .. .. .. ..$ : int [1:2036693] 17 15 19 29 159 32 152 57 97 71 ...
    ##   .. .. .. .. ..$ : int [1:2036693] 0 1 0 0 4 1 3 2 1 0 ...
    ##   .. .. .. .. ..$ : int [1:2036693] 17 14 19 29 155 31 149 55 96 71 ...
    ##   .. .. .. ..@ sample.id : chr "EF08-EM04-Larvae"
    ##   .. .. .. ..@ assembly  : chr "mm10"
    ##   .. .. .. ..@ context   : chr "CpG"
    ##   .. .. .. ..@ resolution: chr "base"
    ##   .. .. .. ..@ names     : chr [1:7] "chr" "start" "end" "strand" ...
    ##   .. .. .. ..@ row.names : int [1:2036693] 1 2 3 4 5 6 7 8 9 10 ...
    ##   .. .. .. ..@ .S3Class  : chr "data.frame"
    ##   ..@ treatment: num [1:16] 0 0 0 0 0 1 1 1 1 1 ...

``` r
head(myobj_larvae[[1]])
```

    ##           chr start end strand coverage numCs numTs
    ## 1 NC_007175.2    50  50      *       15     0    15
    ## 2 NC_007175.2    51  51      *       59     1    58
    ## 3 NC_007175.2    52  52      *       16     0    16
    ## 4 NC_007175.2    88  88      *      113     4   109
    ## 5 NC_007175.2    89  89      *      184     3   181
    ## 6 NC_007175.2   147 147      *      163     0   163

## 5.2 Filter

We want to filter out bases with low coverage (\<10 reads) because they
will reduce reliability in downstream analyses. We also want to discard
any bases with exceptionally high coverage (in the 99.9th percentile),
as this is an indication of PCR amplification bias.

``` r
myobj.filt_larvae <- filterByCoverage(myobj_larvae,
                      lo.count=10,
                      lo.perc=NULL,
                      hi.count=NULL,
                      hi.perc=99.9)
```

## 5.3 Normalization

Next, we normalize the coverage values among samples.

``` r
myobj.filt.norm_larvae <- normalizeCoverage(myobj.filt_larvae, method = "median")
```

## 5.4 Merge

Data doesn’t appear to be two-stranded, so will use `destrand=FALSE`

``` r
meth_larvae <- methylKit::unite(myobj.filt.norm_larvae, destrand=FALSE)
```

    ## uniting...

``` r
nrow(meth_larvae)
```

    ## [1] 12128

We retain 12128 CpG site that have coverage in all larvae samples

## 5.5 Filter 2

This step was reccommended in the tutorial I was following, but doesn’t
seem to have been implemented in Rondon et al. 2017 or Venkataraman et
al. 2024, so I’ll skip for now

``` r
# # get percent methylation matrix
# pm_larvae=percMethylation(meth_larvae)
# 
# # calculate standard deviation of CpGs
# sds_larvae=matrixStats::rowSds(pm_larvae)
# 
# # Visualize the distribution of the per-CpG standard deviation
# # to determine a suitable cutoff
# hist(sds_larvae, breaks = 100)
# 
# # keep only CpG with standard deviations larger than 2%
# meth_larvae <- meth_larvae[sds_larvae > 2]
# 
# # This leaves us with this number of CpG sites
# nrow(meth_larvae)
```

## 5.6 Data structure/Outlier detection

``` r
getCorrelation(meth_larvae,plot=FALSE)
```

    ##                  CF01-CM02-Larvae CF03-CM04-Larvae CF03-CM05-Larvae
    ## CF01-CM02-Larvae        1.0000000        0.9401636        0.9465813
    ## CF03-CM04-Larvae        0.9401636        1.0000000        0.9577780
    ## CF03-CM05-Larvae        0.9465813        0.9577780        1.0000000
    ## CF05-CM02-Larvae        0.9639878        0.9399256        0.9459701
    ## CF06-CM02-Larvae        0.9577389        0.9375168        0.9388874
    ## EF03-EM04-Larvae        0.9423352        0.9395088        0.9452719
    ## EF03-EM05-Larvae        0.9416143        0.9359887        0.9458775
    ## EF04-EM05-Larvae        0.9517367        0.9494320        0.9498409
    ## EF05-EM01-Larvae        0.9487475        0.9434134        0.9468373
    ## EF05-EM06-Larvae        0.9423567        0.9386104        0.9404489
    ## EF06-EM01-Larvae        0.9461047        0.9456231        0.9488625
    ## EF06-EM02-Larvae        0.9434972        0.9417313        0.9446152
    ## EF06-EM06-Larvae        0.9248424        0.9199882        0.9238649
    ## EF07-EM03-Larvae        0.9404891        0.9378818        0.9421539
    ## EF08-EM03-Larvae        0.9443700        0.9413943        0.9453010
    ## EF08-EM04-Larvae        0.9458618        0.9432334        0.9464337
    ##                  CF05-CM02-Larvae CF06-CM02-Larvae EF03-EM04-Larvae
    ## CF01-CM02-Larvae        0.9639878        0.9577389        0.9423352
    ## CF03-CM04-Larvae        0.9399256        0.9375168        0.9395088
    ## CF03-CM05-Larvae        0.9459701        0.9388874        0.9452719
    ## CF05-CM02-Larvae        1.0000000        0.9559375        0.9431348
    ## CF06-CM02-Larvae        0.9559375        1.0000000        0.9406640
    ## EF03-EM04-Larvae        0.9431348        0.9406640        1.0000000
    ## EF03-EM05-Larvae        0.9481010        0.9392215        0.9586549
    ## EF04-EM05-Larvae        0.9496684        0.9474838        0.9456729
    ## EF05-EM01-Larvae        0.9462235        0.9424754        0.9444477
    ## EF05-EM06-Larvae        0.9443576        0.9397616        0.9419881
    ## EF06-EM01-Larvae        0.9457958        0.9379987        0.9451717
    ## EF06-EM02-Larvae        0.9452161        0.9386242        0.9435984
    ## EF06-EM06-Larvae        0.9252334        0.9250958        0.9266740
    ## EF07-EM03-Larvae        0.9659969        0.9360776        0.9395308
    ## EF08-EM03-Larvae        0.9422204        0.9400620        0.9436720
    ## EF08-EM04-Larvae        0.9440452        0.9410234        0.9610943
    ##                  EF03-EM05-Larvae EF04-EM05-Larvae EF05-EM01-Larvae
    ## CF01-CM02-Larvae        0.9416143        0.9517367        0.9487475
    ## CF03-CM04-Larvae        0.9359887        0.9494320        0.9434134
    ## CF03-CM05-Larvae        0.9458775        0.9498409        0.9468373
    ## CF05-CM02-Larvae        0.9481010        0.9496684        0.9462235
    ## CF06-CM02-Larvae        0.9392215        0.9474838        0.9424754
    ## EF03-EM04-Larvae        0.9586549        0.9456729        0.9444477
    ## EF03-EM05-Larvae        1.0000000        0.9433572        0.9412870
    ## EF04-EM05-Larvae        0.9433572        1.0000000        0.9550512
    ## EF05-EM01-Larvae        0.9412870        0.9550512        1.0000000
    ## EF05-EM06-Larvae        0.9408228        0.9497681        0.9578537
    ## EF06-EM01-Larvae        0.9433647        0.9514033        0.9614268
    ## EF06-EM02-Larvae        0.9449060        0.9485549        0.9463506
    ## EF06-EM06-Larvae        0.9251367        0.9280759        0.9260623
    ## EF07-EM03-Larvae        0.9446467        0.9434768        0.9381528
    ## EF08-EM03-Larvae        0.9415999        0.9668396        0.9471291
    ## EF08-EM04-Larvae        0.9426395        0.9525594        0.9483793
    ##                  EF05-EM06-Larvae EF06-EM01-Larvae EF06-EM02-Larvae
    ## CF01-CM02-Larvae        0.9423567        0.9461047        0.9434972
    ## CF03-CM04-Larvae        0.9386104        0.9456231        0.9417313
    ## CF03-CM05-Larvae        0.9404489        0.9488625        0.9446152
    ## CF05-CM02-Larvae        0.9443576        0.9457958        0.9452161
    ## CF06-CM02-Larvae        0.9397616        0.9379987        0.9386242
    ## EF03-EM04-Larvae        0.9419881        0.9451717        0.9435984
    ## EF03-EM05-Larvae        0.9408228        0.9433647        0.9449060
    ## EF04-EM05-Larvae        0.9497681        0.9514033        0.9485549
    ## EF05-EM01-Larvae        0.9578537        0.9614268        0.9463506
    ## EF05-EM06-Larvae        1.0000000        0.9438364        0.9442058
    ## EF06-EM01-Larvae        0.9438364        1.0000000        0.9690705
    ## EF06-EM02-Larvae        0.9442058        0.9690705        1.0000000
    ## EF06-EM06-Larvae        0.9415975        0.9487659        0.9499590
    ## EF07-EM03-Larvae        0.9385506        0.9397812        0.9397303
    ## EF08-EM03-Larvae        0.9402237        0.9453591        0.9427734
    ## EF08-EM04-Larvae        0.9427585        0.9499926        0.9454418
    ##                  EF06-EM06-Larvae EF07-EM03-Larvae EF08-EM03-Larvae
    ## CF01-CM02-Larvae        0.9248424        0.9404891        0.9443700
    ## CF03-CM04-Larvae        0.9199882        0.9378818        0.9413943
    ## CF03-CM05-Larvae        0.9238649        0.9421539        0.9453010
    ## CF05-CM02-Larvae        0.9252334        0.9659969        0.9422204
    ## CF06-CM02-Larvae        0.9250958        0.9360776        0.9400620
    ## EF03-EM04-Larvae        0.9266740        0.9395308        0.9436720
    ## EF03-EM05-Larvae        0.9251367        0.9446467        0.9415999
    ## EF04-EM05-Larvae        0.9280759        0.9434768        0.9668396
    ## EF05-EM01-Larvae        0.9260623        0.9381528        0.9471291
    ## EF05-EM06-Larvae        0.9415975        0.9385506        0.9402237
    ## EF06-EM01-Larvae        0.9487659        0.9397812        0.9453591
    ## EF06-EM02-Larvae        0.9499590        0.9397303        0.9427734
    ## EF06-EM06-Larvae        1.0000000        0.9196545        0.9209967
    ## EF07-EM03-Larvae        0.9196545        1.0000000        0.9405300
    ## EF08-EM03-Larvae        0.9209967        0.9405300        1.0000000
    ## EF08-EM04-Larvae        0.9265074        0.9424217        0.9626033
    ##                  EF08-EM04-Larvae
    ## CF01-CM02-Larvae        0.9458618
    ## CF03-CM04-Larvae        0.9432334
    ## CF03-CM05-Larvae        0.9464337
    ## CF05-CM02-Larvae        0.9440452
    ## CF06-CM02-Larvae        0.9410234
    ## EF03-EM04-Larvae        0.9610943
    ## EF03-EM05-Larvae        0.9426395
    ## EF04-EM05-Larvae        0.9525594
    ## EF05-EM01-Larvae        0.9483793
    ## EF05-EM06-Larvae        0.9427585
    ## EF06-EM01-Larvae        0.9499926
    ## EF06-EM02-Larvae        0.9454418
    ## EF06-EM06-Larvae        0.9265074
    ## EF07-EM03-Larvae        0.9424217
    ## EF08-EM03-Larvae        0.9626033
    ## EF08-EM04-Larvae        1.0000000

``` r
clusterSamples(meth_larvae, dist="correlation", method="ward", plot=TRUE)
```

    ## The "ward" method has been renamed to "ward.D"; note new "ward.D2"

![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-31-1.png)<!-- -->

    ## 
    ## Call:
    ## hclust(d = d, method = HCLUST.METHODS[hclust.method])
    ## 
    ## Cluster method   : ward.D 
    ## Distance         : pearson 
    ## Number of objects: 16

``` r
PCASamples(meth_larvae)
```

![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-32-1.png)<!-- -->

## 5.7 Differential methylation

### 5.7.1 CpG sites

``` r
# Test for differential methylation
# Apply Benjamini-Hochberg adjustment for multiple testing (default)
myDiff_larvae <- calculateDiffMeth(meth_larvae, adjust="BH")
```

    ## two groups detected:
    ##  will calculate methylation difference as the difference of
    ## treatment (group: 1) - control (group: 0)

``` r
# Not sure what minimum difference is appropriate here. Rondon et al. 2017 used 25%, Venkataraman et al. 2024 used 50%
myDiff_larvae_sig_diff25 <- getMethylDiff(myDiff_larvae, difference = 25, qvalue = 0.01)
myDiff_larvae_sig_diff50 <- getMethylDiff(myDiff_larvae, difference = 50, qvalue = 0.01)


nrow(myDiff_larvae_sig_diff25)
```

    ## [1] 100

``` r
nrow(myDiff_larvae_sig_diff50)
```

    ## [1] 1

Based on a minimum difference of 25%, there are 100 CpG sites that are
differentially methylated based on parental exposure in larvae (1 DML
based on 50% minimum difference). Frankly, this seems super weird. I’d
expect any “inherited methylation” signatures present in the larval
stage (3 days post-fertilization) to also be retained in the preceding
zygote stage (9 hours post-fertilization)

``` r
# volcano plot to get an overview of differential methylation
myDiff_larvae$significant <- abs(myDiff_larvae$meth.diff) > 25 & myDiff_larvae$qvalue < 0.01

# Plot
ggplot(myDiff_larvae, aes(x = -log10(qvalue), y = meth.diff, color = significant)) +
  geom_point(size = 1) +
  scale_color_manual(values = c("gray" = "gray", "TRUE" = "red", "FALSE" = "gray")) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "black") +
  theme_minimal() +
  labs(
    x = expression(-log[10](qvalue)),
    y = "Methylation Difference",
    color = "Significant (|meth.diff| > 25, q < 0.01)",
    title = "CpGs Differentially Methylated by Parental Treatment"
  )
```

![](06.1-differential-methylation-split-lifestage_files/figure-gfm/unnamed-chunk-34-1.png)<!-- -->

Save Larvae DMLs. Note that methylKit output is 1-based start. To save
as a BED file, with 0-based start, I need to adjust the start postions
before saving

``` r
myDiff_larvae_sig_diff25$chromStart <- myDiff_larvae_sig_diff25$start - 1  # BED is 0-based start
myDiff_larvae_sig_diff25$chromEnd <- myDiff_larvae_sig_diff25$end          # End is exclusive in BED, but same here because it's a point

# Arrange in BED column order
myDiff_larvae_sig_diff25_BED <- getData(myDiff_larvae_sig_diff25)[, c("chr", "chromStart", "chromEnd", "strand", "meth.diff")]

# Save as BED file
write.table(
  myDiff_larvae_sig_diff25_BED,
  file = "../output/06.1-differential-methylation-split-lifestage/larvae_diff25_DML.bed",
  quote = FALSE,
  sep = "\t",
  row.names = FALSE,
  col.names = FALSE
)
```

# 6 Notes

Very weird results:

- No DMLs based on parent exposure when looking at all data together

- No DMLs based on parent exposure when looking only at zygote samples

- 100 DMLs based on parent exposure when looking only at larval samples

However, looking through the data filtering steps an obvious discrepancy
pops out. The zygote samples had *far* fewer CpG sites retained
post-filtering than the larval samples (398 in zygote vs. 12,128 in
larval). This also then affected the number of sites retained in the
un-split run (114), because we only kept CpG sites with sufficient
coverage in *all* included samples.

It seems likely, then that the abundance of DMLs in larvae and dearth of
DMLs in zygotes is due to low data quality or poor statistical
resolution. I should look into the data quantity/quality for these
samples and see if any major differences pop out.

I also need to check whether any of the larval DMLs were also identified
in the parents (in Venkataraman et al. 2024)
