R/calculateEnrichment.R
calculateCGEnrichmentGRanges.RdCompute CpG enrichment metrics (relH and GoGe) from a GenomicRanges::GRanges of read spans, using the specified BSgenome. Useful when reads are already represented as genomic ranges rather than extracted directly from a BAM file.
calculateCGEnrichmentGRanges(
readGRanges = NULL,
BSgenome = NULL,
chr.select = NULL
)GRanges
Genomic ranges representing fragments (each range = one fragment).
Default: NULL (must be supplied).
character(1)
Name of a BSgenome package, e.g. "BSgenome.Hsapiens.NCBI.GRCh38". The
package must be installed and loadable.
Default: NULL.
character() or NULL
Vector of chromosomes to restrict motif calculation.
Default: NULL (use all chromosomes).
A tibble with one row and the following columns:
relH — sample relH normalised by genome relH.
GoGe — sample GoGe normalised by genome GoGe.
nReads — total reads (fragments).
nReadsWithoutPattern — reads lacking "CG" motif.
n100bpReads — reads with length >= 100 bp.
n100bpReadsWithoutPattern — reads >= 100 bp lacking "CG".
relH and GoGe are computed by counting "CG" dinucleotides in the provided
fragments and normalising by genome-wide expectations (from
calculateGenomicCGDistribution()). Unlike calculateCGEnrichment(), this
function assumes reads are already summarised as genomic ranges.
calculateCGEnrichment(), calculateGenomicCGDistribution(),
GenomicRanges, BSgenome
# Runnable toy example with synthetic reads over chr1 (requires a BSgenome)
if (requireNamespace("BSgenome.Hsapiens.NCBI.GRCh38", quietly = TRUE)) {
n <- 200
gr <- GenomicRanges::GRanges(
seqnames = rep(1, n),
ranges = IRanges::IRanges(
start = sample(1e6:2e6, n),
width = sample(80:180, n, replace = TRUE)
),
strand = "*"
)
calculateCGEnrichmentGRanges(
readGRanges = gr,
BSgenome = "BSgenome.Hsapiens.NCBI.GRCh38",
chr.select = 1
)
}
#>
#> Attaching package: ‘BSgenome.Hsapiens.NCBI.GRCh38’
#> The following object is masked from ‘package:BSgenome.Hsapiens.UCSC.hg19’:
#>
#> Hsapiens
#> # A tibble: 1 × 6
#> relH GoGe nReads nReadsWithoutPattern n100bpReads n100bpReadsWithoutPattern
#> <dbl> <dbl> <int> <int> <int> <int>
#> 1 3.94 1.88 200 12 161 9