| Title: | Methylation Enrichment Sequencing Analysis |
|---|---|
| Description: | A package for the analysis of methylation enrichment sequencing data (e.g. MBD-seq or MEDIP-seq). This allows for the window-based evaluation of methylation levels (using the 'qsea' package), including functions for determining differentially methylated regions. Many functions are provided for tidyverse style modification of the qseaSet objects originally defined in 'qsea'. |
| Authors: | Simon Pearce [aut] (ORCID: <https://orcid.org/0000-0002-1680-5538>), Steven Hill [aut, cre] (ORCID: <https://orcid.org/0000-0002-5909-692X>), Paddy Harker [ctb] (ORCID: <https://orcid.org/0000-0002-2531-8774>), Kevin Brennan [ctb] (ORCID: <https://orcid.org/0000-0001-9018-9852>), Katarzyna Kamieniecka [ctb], Felipe Perez Martinez [ctb] (ORCID: <https://orcid.org/0009-0007-9138-3674>), Cancer Research UK National Biomarker Centre [cph, fnd] |
| Maintainer: | Steven Hill <[email protected]> |
| License: | GPL (>=2) |
| Version: | 0.99.5 |
| Built: | 2026-07-23 15:54:17 UTC |
| Source: | https://github.com/BiocStaging/mesa |
Scan BAM files listed in a qseaSet and add per-region counts and library
summaries using proper pairs (with MAPQ and insert-size filters) and,
optionally, high-quality unpaired R1 reads extended to a fragment length.
Parallelisation via BiocParallel is supported.
addBamCoveragePairedAndUnpaired( qs, fragmentLength = NULL, minMapQual = 30, maxInsertSize = 1000, minInsertSize = 100, minReferenceLength = 30, parallel = getMesaParallel(), properPairsOnly = FALSE )addBamCoveragePairedAndUnpaired( qs, fragmentLength = NULL, minMapQual = 30, maxInsertSize = 1000, minInsertSize = 100, minReferenceLength = 30, parallel = getMesaParallel(), properPairsOnly = FALSE )
qs |
|
fragmentLength |
|
minMapQual |
|
maxInsertSize |
|
minInsertSize |
|
minReferenceLength |
|
parallel |
|
properPairsOnly |
|
Per-region counts are computed from fragment midpoints to align with qsea’s
counting scheme. When properPairsOnly = FALSE, unpaired R1 reads are
extended from the 5' end by fragmentLength. If fragmentLength is not
supplied, it is estimated from proper pairs in the same BAM.
A qseaSet with updated slots:
Counts: updated count matrix.
Library: updated library table with summary metrics.
Parameters: appended record of MAPQ/size thresholds.
Parallel execution uses BiocParallel::bplapply() with the currently
registered backend (see BiocParallel::register()). Pass parallel = TRUE
and set a multi-core/cluster backend for speed.
getBamCoveragePairedAndUnpairedR1() (internal low-level worker),
qsea::getRegions(),
qsea::getSampleTable(),
BiocParallel::register()
Runs a CNV pipeline on each sample: counts fragments in fixed-size genomic
windows, normalises for GC and mappability (HMMcopy), segments, and stores
per-window copy-number in the qseaSet. Supports parallel execution.
Only GRCh38/hg38 is currently supported.
addHMMcopyCNV( qs, inputColumn = "input_file", windowSize = 1e+06, fragmentLength = NULL, plotDir = NULL, parallel = getMesaParallel(), maxInsertSize = 1000, minInsertSize = 50, minReferenceLength = 30, minMapQual = 30, properPairsOnly = FALSE, hmmCopyGC = NULL, hmmCopyMap = NULL )addHMMcopyCNV( qs, inputColumn = "input_file", windowSize = 1e+06, fragmentLength = NULL, plotDir = NULL, parallel = getMesaParallel(), maxInsertSize = 1000, minInsertSize = 50, minReferenceLength = 30, minMapQual = 30, properPairsOnly = FALSE, hmmCopyGC = NULL, hmmCopyMap = NULL )
qs |
|
inputColumn |
|
windowSize |
|
fragmentLength |
|
plotDir |
|
parallel |
|
maxInsertSize |
|
minInsertSize |
|
minReferenceLength |
|
minMapQual |
|
properPairsOnly |
|
hmmCopyGC |
|
hmmCopyMap |
|
Coverage is obtained (pairs + optional R1) over tiled windows, corrected with
HMMcopy (HMMcopy::correctReadcount() followed by HMMcopy::HMMsegment()),
and
merged back into the qseaSet. You must supply GC/mappability tracks binned
at
the same windowSize (or use package-provided defaults where applicable).
When parallel = TRUE, computation uses the currently registered backend
(see BiocParallel::register()).
The input qseaSet with CNV information attached, including:
per-window CNV tracks accessible via downstream CNV accessors,
library/sample tables updated with relevant CNV/coverage summaries,
(optionally) per-sample diagnostic PDFs if plotDir is provided.
runHMMcopy(),
plotCNVheatmap(),
getBamCoveragePairedAndUnpairedR1() (internal low-level worker),
HMMcopy::correctReadcount(),
HMMcopy::HMMsegment(),
BiocParallel::register()
Other CNV:
plotCNVheatmap(),
removeCNV(),
runHMMCopy()
## Not run: data(exampleTumourNormal, package = "mesa") exampleTumourNormal %>% addHMMcopyCNV( inputColumn = "input_file", windowSize = 1e6, hmmCopyGC = gc_hg38_1000kb, # GRanges with 'gc' column hmmCopyMap = map_hg38_1000kb, # GRanges with 'map' column properPairsOnly = TRUE, parallel = FALSE, plotDir = tempdir() ) ## End(Not run)## Not run: data(exampleTumourNormal, package = "mesa") exampleTumourNormal %>% addHMMcopyCNV( inputColumn = "input_file", windowSize = 1e6, hmmCopyGC = gc_hg38_1000kb, # GRanges with 'gc' column hmmCopyMap = map_hg38_1000kb, # GRanges with 'map' column properPairsOnly = TRUE, parallel = FALSE, plotDir = tempdir() ) ## End(Not run)
For each sample, compute the proportion of Edgar et al. “ultra-stable”
windows that are clearly methylated (beta >= minBeta) after filtering by
CpG density (>= minDensity). The result is added to the sample table as
hyperStableEdgar (overwriting any existing column of that name).
addHyperStableFraction(qseaSet, minDensity = 5, minBeta = 0.8)addHyperStableFraction(qseaSet, minDensity = 5, minBeta = 0.8)
qseaSet |
|
minDensity |
|
minBeta |
|
Genome restriction. Only supported for
"BSgenome.Hsapiens.NCBI.GRCh38"; the function stops otherwise (checked via
qsea::getParameters()).
Regions used. Uses mesa::hg38UltraStableProbes, a GRCh38 set derived
from array data (Edgar et al., 2014).
Computation. Windows overlapping the ultra-stable set are extracted,
beta values are computed via qsea::makeTable(norm_methods = "beta"),
windows with CpG_density < minDensity are dropped, NA beta
are treated as 0 for thresholding, and the per-sample
fraction with beta >= minBeta is returned.
The input qseaSet with its sampleTable augmented by a numeric column
hyperStableEdgar (range 0–1) giving, per sample, the fraction of
ultra-stable
windows called methylated.
Edgar R, Tan PPC, Portales-Casamar E, Pavlidis P (2014). Meta-analysis of human methylomes reveals stably methylated sequences surrounding CpG islands associated with high gene expression. https://pubmed.ncbi.nlm.nih.gov/25493099/
qsea::makeTable(), qsea::getSampleTable(), qsea::getSampleNames(),
hg38UltraStableProbes, getSampleQCSummary()
data(exampleTumourNormal, package = "mesa") # Run only if the example windows overlap the ultra-stable probes exampleTumourNormal %>% { has_ov <- sum( GenomicRanges::countOverlaps( qsea::getRegions(.), mesa::hg38UltraStableProbes ) ) > 0 if (has_ov) addHyperStableFraction(.) else { message( "No overlap with hg38UltraStableProbes in this toy dataset;", " skipping." ) . } } %>% qsea::getSampleTable() %>% dplyr::select(sample_name, dplyr::any_of("hyperStableEdgar")) %>% head()data(exampleTumourNormal, package = "mesa") # Run only if the example windows overlap the ultra-stable probes exampleTumourNormal %>% { has_ov <- sum( GenomicRanges::countOverlaps( qsea::getRegions(.), mesa::hg38UltraStableProbes ) ) > 0 if (has_ov) addHyperStableFraction(.) else { message( "No overlap with hg38UltraStableProbes in this toy dataset;", " skipping." ) . } } %>% qsea::getSampleTable() %>% dplyr::select(sample_name, dplyr::any_of("hyperStableEdgar")) %>% head()
Append library information to the sampleTable of a qseaSet. Columns are
taken from qseaSet@libraries$file_name, and when available, from
qseaSet@libraries$input_file (prefixed with "input_"). Existing columns
are not duplicated.
addLibraryInformation(qseaSet)addLibraryInformation(qseaSet)
qseaSet |
|
A qseaSet object:
addLibraryInformation(): returns the same qseaSet with its
sampleTable augmented by library-level columns.
data(exampleTumourNormal, package = "mesa") qs <- addLibraryInformation(exampleTumourNormal) head(qsea::getSampleTable(qs))data(exampleTumourNormal, package = "mesa") qs <- addLibraryInformation(exampleTumourNormal) head(qsea::getSampleTable(qs))
For each sample, compute MEDIPS-style CpG enrichment metrics (relH,
GoGe, and read counts) from its BAM and append the results to the
qseaSet sample metadata. Supports both pulldown (default) and input
libraries.
addMedipsEnrichmentFactors( qseaSet, exportPath = NULL, nonEnrich = FALSE, extend = 0, shift = 0, uniq = 0, chr.select = NULL, paired = TRUE, file_name = "file_name", nCores = 1 )addMedipsEnrichmentFactors( qseaSet, exportPath = NULL, nonEnrich = FALSE, extend = 0, shift = 0, uniq = 0, chr.select = NULL, paired = TRUE, file_name = "file_name", nCores = 1 )
qseaSet |
|
exportPath |
|
nonEnrich |
|
extend |
|
shift |
|
uniq |
|
chr.select |
|
paired |
|
file_name |
|
nCores |
|
Internally calls calculateCGEnrichment() per sample to derive relH/GoGe and
counts, then merges the results into the @libraries slot ($file_name for
pulldown, $input_file for input when nonEnrich = TRUE). Parallelisation
uses parallel::mclapply(); on non-Unix systems, nCores > 1 is ignored.
A qseaSet with new MEDIPS-style metrics appended:
Sample/library metrics (added under the appropriate library frame):
relH, GoGe, nReads, nReadsWithoutPattern, n100bpReads,
n100bpReadsWithoutPattern.
Provenance: any export artefacts (PDF/RDS) written to exportPath if
provided.
calculateCGEnrichment(), calculateCGEnrichmentGRanges()
# Requires BAM files and the MEDIPS package; see \dontrun{} for a full # usage example. ## Not run: if (requireNamespace("MEDIPS", quietly = TRUE) && requireNamespace("BSgenome.Hsapiens.UCSC.hg19", quietly = TRUE)) { bam <- system.file( "extdata", "hESCs.Input.chr22.bam", package = "MEDIPSData" ) data.frame( sample_name = "hESC_Input_chr22", file_name = bam, group = "Input", input_file = bam, stringsAsFactors = FALSE ) %>% qsea::createQseaSet("BSgenome.Hsapiens.UCSC.hg19") %>% addMedipsEnrichmentFactors( exportPath = tempdir(), chr.select = paste0("chr22"), paired = FALSE # If your qsea returns a BSgenome object and as.character() # doesn't help, uncomment: # , BSgenome_pkg = "BSgenome.Hsapiens.UCSC.hg19" ) %>% qsea::getSampleTable() %>% print() } ## End(Not run)# Requires BAM files and the MEDIPS package; see \dontrun{} for a full # usage example. ## Not run: if (requireNamespace("MEDIPS", quietly = TRUE) && requireNamespace("BSgenome.Hsapiens.UCSC.hg19", quietly = TRUE)) { bam <- system.file( "extdata", "hESCs.Input.chr22.bam", package = "MEDIPSData" ) data.frame( sample_name = "hESC_Input_chr22", file_name = bam, group = "Input", input_file = bam, stringsAsFactors = FALSE ) %>% qsea::createQseaSet("BSgenome.Hsapiens.UCSC.hg19") %>% addMedipsEnrichmentFactors( exportPath = tempdir(), chr.select = paste0("chr22"), paired = FALSE # If your qsea returns a BSgenome object and as.character() # doesn't help, uncomment: # , BSgenome_pkg = "BSgenome.Hsapiens.UCSC.hg19" ) %>% qsea::getSampleTable() %>% print() } ## End(Not run)
Apply a set of qsea normalisation steps to a qseaSet, including:
setting library factors to 1 (disabling TMM),
adding offsets based on an enrichment pattern, and
configuring enrichment parameters across a CpG-density window range.
addNormalisation( qseaSet, enrichmentMethod = "blind1-15", maxPatternDensity = 0.05 )addNormalisation( qseaSet, enrichmentMethod = "blind1-15", maxPatternDensity = 0.05 )
qseaSet |
|
enrichmentMethod |
|
maxPatternDensity |
|
This function encapsulates a recommended default pipeline for qsea normalisation. It ensures consistency across runs and simplifies code by bundling commonly applied steps.
#' Methods available for enrichmentMethod:
"blind1-15": the blind calibration method detailed in the qsea paper, fitting a straight line of decreasing expected average methylation levels from ~76% at CpG density = 1 to ~25% at CpG density = 15.
"none": no enrichment normalisation is performed.
A qseaSet with updates to:
Library factors — set to 1 via qsea::addLibraryFactors().
Offsets — added via qsea::addOffset() using getPattern() and
maxPatternDensity.
Enrichment parameters — configured over windows with CpG density in
[1, 15] using a linear signal schedule and
bins = seq(0.5, 40.5, 0.5).
Parameters slot — enrichmentMethod recorded in
qseaSet@parameters$enrichmentMethod.
qsea::addLibraryFactors(),
qsea::addOffset(),
qsea::addEnrichmentParameters(),
getPattern()
# addNormalisation requires windows spanning a range of CpG densities for # background estimation; the pre-filtered example datasets lack these, so # a synthetic qseaSet is used here. # Run normalisation on a toy qseaSet with ~100k reads qsea::getExampleQseaSet(expSamplingDepth = 100000) %>% addNormalisation(maxPatternDensity = 0.5) # Run with no enrichment normalisation qsea::getExampleQseaSet(expSamplingDepth = 1e5) %>% addNormalisation(enrichmentMethod = "none", maxPatternDensity = 0.5) # Access the recorded enrichment method qsea::getExampleQseaSet(expSamplingDepth = 1e5) %>% addNormalisation(maxPatternDensity = 0.5) %>% getParameters() %>% purrr::pluck("enrichmentMethod")# addNormalisation requires windows spanning a range of CpG densities for # background estimation; the pre-filtered example datasets lack these, so # a synthetic qseaSet is used here. # Run normalisation on a toy qseaSet with ~100k reads qsea::getExampleQseaSet(expSamplingDepth = 100000) %>% addNormalisation(maxPatternDensity = 0.5) # Run with no enrichment normalisation qsea::getExampleQseaSet(expSamplingDepth = 1e5) %>% addNormalisation(enrichmentMethod = "none", maxPatternDensity = 0.5) # Access the recorded enrichment method qsea::getExampleQseaSet(expSamplingDepth = 1e5) %>% addNormalisation(maxPatternDensity = 0.5) %>% getParameters() %>% purrr::pluck("enrichmentMethod")
Compute per-sample summaries across windows and left-join them to the
qseaSet sample table.
addSummaryAcrossWindows( qseaSet, regionsToOverlap = NULL, fn = mean, suffix = "", normMethod = c("nrpm", "beta"), naMethod = "impute", minEnrichment = 3 )addSummaryAcrossWindows( qseaSet, regionsToOverlap = NULL, fn = mean, suffix = "", normMethod = c("nrpm", "beta"), naMethod = "impute", minEnrichment = 3 )
qseaSet |
|
regionsToOverlap |
|
fn |
|
suffix |
|
normMethod |
|
naMethod |
|
minEnrichment |
|
Internally, this calls summariseAcrossWindows() to compute per-sample
summaries for the requested normMethod(s), then left-joins those summaries
to the sampleTable. Output column names typically encode the method and the
summary function (and include suffix when provided).
A qseaSet with new summary columns appended to its sampleTable.
summariseAcrossWindows(), getDataTable()
Other window-summaries:
countWindowsAboveCutoff(),
summariseAcrossWindows()
data(exampleTumourNormal, package = "mesa") # Add mean NRPM and beta across all windows exampleTumourNormal %>% addSummaryAcrossWindows( fn = mean, normMethod = c("nrpm","beta") ) %>% getSampleTable() # Maximum NRPM across a small genomic slice exampleTumourNormal %>% addSummaryAcrossWindows( regionsToOverlap = data.frame( seqnames = 7, start = 25002001, end = 25017900 ), fn = max, normMethod = "nrpm" ) %>% getSampleTable() # Add summaries repeatedly with different regions using a suffix exampleTumourNormal %>% addSummaryAcrossWindows( regionsToOverlap = data.frame( seqnames = 7, start = 25002001, end = 25017900 ), fn = median, normMethod = "nrpm", suffix = "subset" ) %>% addSummaryAcrossWindows( fn = median, normMethod = "nrpm", suffix = "all" ) %>% getSampleTable()data(exampleTumourNormal, package = "mesa") # Add mean NRPM and beta across all windows exampleTumourNormal %>% addSummaryAcrossWindows( fn = mean, normMethod = c("nrpm","beta") ) %>% getSampleTable() # Maximum NRPM across a small genomic slice exampleTumourNormal %>% addSummaryAcrossWindows( regionsToOverlap = data.frame( seqnames = 7, start = 25002001, end = 25017900 ), fn = max, normMethod = "nrpm" ) %>% getSampleTable() # Add summaries repeatedly with different regions using a suffix exampleTumourNormal %>% addSummaryAcrossWindows( regionsToOverlap = data.frame( seqnames = 7, start = 25002001, end = 25017900 ), fn = median, normMethod = "nrpm", suffix = "subset" ) %>% addSummaryAcrossWindows( fn = median, normMethod = "nrpm", suffix = "all" ) %>% getSampleTable()
Uses ChIPseeker::annotatePeak() to assign transcript-relative annotations
(promoter, exon, intron, intergenic, etc.) to genomic windows in dataTable.
If a genome is specified or globally set via setMesaGenome(), defaults and
convenience datasets are applied for GRCh38. CpG island context and FANTOM
enhancer overlaps can be added if the corresponding ranges are provided (or
left NULL to use mesa defaults for GRCh38).
annotateWindows( dataTable, genome = .getMesaGenome(), TxDb = .getMesaTxDb(), annoDb = .getMesaAnnoDb(), CpGislandsGR = NULL, FantomRegionsGR = NULL )annotateWindows( dataTable, genome = .getMesaGenome(), TxDb = .getMesaTxDb(), annoDb = .getMesaAnnoDb(), CpGislandsGR = NULL, FantomRegionsGR = NULL )
dataTable |
|
genome |
|
TxDb |
TxDb object or |
annoDb |
|
CpGislandsGR |
|
FantomRegionsGR |
|
Conversion: Non-GRanges inputs are converted via
qseaTableToChrGRanges().
Genome-aware defaults (GRCh38/hg38): Missing TxDb/annoDb/contexts
are
filled using the packages noted above when installed.
Seqlevels style: Output seqnames have the "chr" prefix removed
(e.g., "chr1" → "1").
ChIPseeker call: Uses tssRegion = c(-2000, 500), level = "transcript",
overlap = "all", verbose = FALSE.
Output columns: Includes annotation (full label), shortAnno
(without the
trailing parenthetical), and—when contexts are provided—landscape
(Island/Shore/Shelf/Open Sea) and inFantom (overlap count with FANTOM).
A tibble with the input windows augmented by ChIPseeker annotations and, when available, CpG island landscape and Fantom overlap.
ChIPseeker::annotatePeak(), setMesaGenome(), setMesaTxDb(),
setMesaAnnoDb(),
qseaTableToChrGRanges(), liftOverHg19()
data(exampleTumourNormal, package = "mesa") # Derive some regions (e.g., DMRs) then annotate using GRCh38 defaults exampleTumourNormal %>% calculateDMRs(variable = "tumour", contrasts = "first") %>% annotateWindows(genome = "hg38") # Or specify TxDb/annoDb explicitly exampleTumourNormal %>% calculateDMRs(variable = "tumour", contrasts = "first") %>% annotateWindows( TxDb = "TxDb.Hsapiens.UCSC.hg38.knownGene", annoDb = "org.Hs.eg.db" ) # Mouse example (mm10): supply mouse TxDb and OrgDb data(exampleMouse, package = "mesa") exampleMouse %>% getRegions() %>% annotateWindows( TxDb = "TxDb.Mmusculus.UCSC.mm10.knownGene", annoDb = "org.Mm.eg.db" ) # You can also set defaults globally using setMesaTxDb and setMesaAnnoDb: setMesaGenome("hg38"); setMesaTxDb("TxDb.Hsapiens.UCSC.hg38.knownGene"); setMesaAnnoDb("org.Hs.eg.db")data(exampleTumourNormal, package = "mesa") # Derive some regions (e.g., DMRs) then annotate using GRCh38 defaults exampleTumourNormal %>% calculateDMRs(variable = "tumour", contrasts = "first") %>% annotateWindows(genome = "hg38") # Or specify TxDb/annoDb explicitly exampleTumourNormal %>% calculateDMRs(variable = "tumour", contrasts = "first") %>% annotateWindows( TxDb = "TxDb.Hsapiens.UCSC.hg38.knownGene", annoDb = "org.Hs.eg.db" ) # Mouse example (mm10): supply mouse TxDb and OrgDb data(exampleMouse, package = "mesa") exampleMouse %>% getRegions() %>% annotateWindows( TxDb = "TxDb.Mmusculus.UCSC.mm10.knownGene", annoDb = "org.Mm.eg.db" ) # You can also set defaults globally using setMesaTxDb and setMesaAnnoDb: setMesaGenome("hg38"); setMesaTxDb("TxDb.Hsapiens.UCSC.hg38.knownGene"); setMesaAnnoDb("org.Hs.eg.db")
Extends dplyr::arrange() to reorder samples of a qseaSet based on
columns
in its sampleTable.
## S3 method for class 'qseaSet' arrange(.data, ..., .by_group = FALSE)## S3 method for class 'qseaSet' arrange(.data, ..., .by_group = FALSE)
.data |
|
... |
Expressions.
Variables or helper functions passed to |
.by_group |
|
A qseaSet object with samples reordered.
Both the count_matrix and the sampleTable are updated consistently.
qsea::getSampleTable(),
subsetQset(),
sort.qseaSet() (for natural sorting of sample names).
data(exampleTumourNormal, package = "mesa") # Reorder samples by age exampleTumourNormal %>% arrange(age) # Reorder by tissue exampleTumourNormal %>% arrange(tissue) # Reorder by tissue (descending), then tumour type exampleTumourNormal %>% arrange(desc(tissue), tumour)data(exampleTumourNormal, package = "mesa") # Reorder samples by age exampleTumourNormal %>% arrange(age) # Reorder by tissue exampleTumourNormal %>% arrange(tissue) # Reorder by tissue (descending), then tumour type exampleTumourNormal %>% arrange(desc(tissue), tumour)
Accept a GRanges or a data frame containing window coordinates and
return a valid GenomicRanges::GRanges. Supported data-frame schemas:
seqnames, start, end
chr, start, end (renamed to seqnames)
chr, window_start, window_end (renamed to seqnames/start/end)
asValidGranges(object)asValidGranges(object)
object |
|
A GenomicRanges::GRanges built from object.
Errors if no supported schema is found.
as_granges, qseaTableToChrGRanges
# From GRanges (passes through) GenomicRanges::GRanges("chr1", IRanges::IRanges(100, 200)) %>% asValidGranges() # From data.frame (seqnames/start/end) data.frame(seqnames = "chr2", start = 10, end = 20) %>% asValidGranges() # From data.frame (chr/window_start/window_end) data.frame(chr = "1", window_start = 1000, window_end = 1100) %>% asValidGranges()# From GRanges (passes through) GenomicRanges::GRanges("chr1", IRanges::IRanges(100, 200)) %>% asValidGranges() # From data.frame (seqnames/start/end) data.frame(seqnames = "chr2", start = 10, end = 20) %>% asValidGranges() # From data.frame (chr/window_start/window_end) data.frame(chr = "1", window_start = 1000, window_end = 1100) %>% asValidGranges()
A data frame containing cached relH and GoGe values for different BSgenomes, generated with calculateGenomicCGDistribution
BSgenome.Hsapiens.UCSC.hg19.CpG.distribution BSgenome.Hsapiens.NCBI.GRCh38.CpG.distribution BSgenome.Mmusculus.UCSC.mm10.CpG.distributionBSgenome.Hsapiens.UCSC.hg19.CpG.distribution BSgenome.Hsapiens.NCBI.GRCh38.CpG.distribution BSgenome.Mmusculus.UCSC.mm10.CpG.distribution
A data frame with 1 row and 2 columns
A data frame with 1 row and 2 columns
A data frame with 1 row and 2 columns
Compute CpG enrichment metrics (relH and GoGe) from aligned reads in a BAM file. Uses MEDIPS to obtain fragment ranges and Biostrings to interrogate the reference genome. Optionally exports a fragment-length density plot (PDF) and a serialized RDS with the GRanges of reads.
calculateCGEnrichment( file = NULL, BSgenome = NULL, exportPath = NULL, extend = 0, shift = 0, uniq = 0, chr.select = NULL, paired = TRUE )calculateCGEnrichment( file = NULL, BSgenome = NULL, exportPath = NULL, extend = 0, shift = 0, uniq = 0, chr.select = NULL, paired = TRUE )
file |
|
BSgenome |
|
exportPath |
|
extend |
|
shift |
|
uniq |
|
chr.select |
|
paired |
|
Reads are scanned for "CG" dinucleotides. Counts are normalised against
genome-wide expectations (relH, GoGe).
For GRCh38 and hg19, cached genomic distributions are bundled with mesa for efficiency.
For other genomes, calculateGenomicCGDistribution() is invoked.
A data.frame with columns:
file — input BAM path.
relH — sample relH normalised by genome relH.
GoGe — sample GoGe normalised by genome GoGe.
nReads — total reads considered.
nReadsWithoutPattern — reads lacking "CG" motif.
n100bpReads — reads with length >= 100 bp.
n100bpReadsWithoutPattern — reads >= 100 bp lacking "CG".
calculateCGEnrichmentGRanges(), calculateGenomicCGDistribution(),
MEDIPS, BSgenome
if (requireNamespace("MEDIPS", quietly = TRUE) && requireNamespace("MEDIPSData", quietly = TRUE) && requireNamespace("BSgenome.Hsapiens.UCSC.hg19", quietly = TRUE) && require("GenomicRanges", quietly = TRUE)) { calculateCGEnrichment( file = system.file( "extdata", "hESCs.Input.chr22.bam", package = "MEDIPSData" ), BSgenome = "BSgenome.Hsapiens.UCSC.hg19", exportPath = tempdir(), paired = FALSE ) }if (requireNamespace("MEDIPS", quietly = TRUE) && requireNamespace("MEDIPSData", quietly = TRUE) && requireNamespace("BSgenome.Hsapiens.UCSC.hg19", quietly = TRUE) && require("GenomicRanges", quietly = TRUE)) { calculateCGEnrichment( file = system.file( "extdata", "hESCs.Input.chr22.bam", package = "MEDIPSData" ), BSgenome = "BSgenome.Hsapiens.UCSC.hg19", exportPath = tempdir(), paired = FALSE ) }
Compute 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 )calculateCGEnrichmentGRanges( readGRanges = NULL, BSgenome = NULL, chr.select = NULL )
readGRanges |
|
BSgenome |
|
chr.select |
|
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.
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".
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 ) }# 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 ) }
Calculate one or more contrasts to find Differentially Methylated Regions (DMRs).
calculateDMRs( qseaSet, variable = NULL, covariates = NULL, contrasts = NULL, minReadCount = 0, minNRPM = 1, checkPVals = TRUE, FDRthres = 0.05, keepPvals = FALSE, formula = NULL, keepContrastMeans = TRUE, keepData = FALSE, keepGroupMeans = FALSE, direction = "both", calcDispersionAll = FALSE )calculateDMRs( qseaSet, variable = NULL, covariates = NULL, contrasts = NULL, minReadCount = 0, minNRPM = 1, checkPVals = TRUE, FDRthres = 0.05, keepPvals = FALSE, formula = NULL, keepContrastMeans = TRUE, keepData = FALSE, keepGroupMeans = FALSE, direction = "both", calcDispersionAll = FALSE )
qseaSet |
|
variable |
|
covariates |
|
contrasts |
|
minReadCount |
|
minNRPM |
|
checkPVals |
|
FDRthres |
|
keepPvals |
|
formula |
|
keepContrastMeans |
|
keepData |
|
keepGroupMeans |
|
direction |
|
calcDispersionAll |
|
Contrast strings are parsed as follows:
"A_vs_B" creates a single contrast A vs B;
"All"/"all" expands to all pairwise contrasts among levels of
variable
(via makeAllContrasts());
"All_vs_X" creates each level vs X;
"X_vs_All" creates X vs each other level;
"first" constructs only the first possible pair (based on factor order).
Internally, this function:
filters windows by minReadCount/minNRPM, 2) fits a Negative Binomial
Generalised Linear Model including dispersion estimates, 3) adds contrasts
as requested, calculating adjusted p-values (adjPval), log2 fold changes
(log2FC) and differences in beta values (deltaBeta), 4) creates an
output table showing any window which is differentially methylated (with
adjusted p-value below FDRthres) in at least one contrast.
Additional columns will be added containing data values if keepData and
keepGroupMeans are true.
A tibble with one row per significant region/window containing:
per-contrast statistics (e.g., log2FC, deltaBeta, test statistic),
multiple-testing results (FDR; optionally raw p-values if keepPvals),
optional group means (if keepGroupMeans = TRUE),
optional per-sample columns (if keepData = TRUE),
metadata columns for genomic coordinates and window attributes.
Other DMR-detection:
fitQseaGLM(),
getDMRsData(),
makeAllContrasts()
data(exampleTumourNormal, package = "mesa") # A single explicit contrast exampleTumourNormal %>% calculateDMRs(variable = "type", contrasts = "LUAD_vs_NormalLung") # All pairwise contrasts among levels of 'type' exampleTumourNormal %>% calculateDMRs(variable = "type", contrasts = "all") # Tighter FDR threshold exampleTumourNormal %>% calculateDMRs(variable = "type", contrasts = "all", FDRthres = 1e-4) # Return all per-sample columns for the first available contrast on 'tumour' exampleTumourNormal %>% calculateDMRs(variable = "tumour", contrasts = "first", keepData = TRUE)data(exampleTumourNormal, package = "mesa") # A single explicit contrast exampleTumourNormal %>% calculateDMRs(variable = "type", contrasts = "LUAD_vs_NormalLung") # All pairwise contrasts among levels of 'type' exampleTumourNormal %>% calculateDMRs(variable = "type", contrasts = "all") # Tighter FDR threshold exampleTumourNormal %>% calculateDMRs(variable = "type", contrasts = "all", FDRthres = 1e-4) # Return all per-sample columns for the first available contrast on 'tumour' exampleTumourNormal %>% calculateDMRs(variable = "tumour", contrasts = "first", keepData = TRUE)
For each sample, compute the proportion of windows with counts
>= numCountsNeeded that overlap regionsToOverlap, relative to all
windows with counts >= numCountsNeeded in that sample.
calculateFractionReadsInGRanges(qseaSet, regionsToOverlap, numCountsNeeded)calculateFractionReadsInGRanges(qseaSet, regionsToOverlap, numCountsNeeded)
qseaSet |
|
regionsToOverlap |
|
numCountsNeeded |
|
Operates on the window × sample count matrix from qsea::getCounts().
Counts are converted to a logical indicator (count >= numCountsNeeded)
and summed per sample:
initialOverBackNum: windows meeting the threshold genome-wide.
afterOverBackNum: windows meeting the threshold within
regionsToOverlap (via filterByOverlaps()).
The reported fraction is afterOverBackNum / initialOverBackNum.
Note: despite the function name, this computes a window-based fraction using a count threshold, not a direct fraction of raw reads.
A tibble with one row per sample containing:
sample_name
initialOverBackNum — windows >= threshold genome-wide
afterOverBackNum — windows >= threshold within regionsToOverlap
fraction — afterOverBackNum / initialOverBackNum
followed by columns from the sample table (left-joined by sample_name).
qsea::getCounts(), qsea::getSampleTable(), filterByOverlaps(),
hg38CpGIslands, subsetWindowsBySignal()
Other window-helpers:
convertToArrayBetaTable(),
downSample(),
subsetWindowsBySignal(),
subsetWindowsOverBackground()
data(exampleTumourNormal, package = "mesa") # Using the shipped ultra-stable probes (GRCh38) as the region set exampleTumourNormal %>% calculateFractionReadsInGRanges( regionsToOverlap = mesa::hg38CpGIslands, numCountsNeeded = 5 ) %>% dplyr::select(sample_name, initialOverBackNum, afterOverBackNum, fraction) # Define a small GRanges subset from the object's own windows gr <- exampleTumourNormal %>% qsea::getRegions() %>% head(n = 100) calculateFractionReadsInGRanges( qseaSet = exampleTumourNormal, regionsToOverlap = gr, numCountsNeeded = 3) %>% dplyr::select(sample_name, initialOverBackNum, afterOverBackNum, fraction)data(exampleTumourNormal, package = "mesa") # Using the shipped ultra-stable probes (GRCh38) as the region set exampleTumourNormal %>% calculateFractionReadsInGRanges( regionsToOverlap = mesa::hg38CpGIslands, numCountsNeeded = 5 ) %>% dplyr::select(sample_name, initialOverBackNum, afterOverBackNum, fraction) # Define a small GRanges subset from the object's own windows gr <- exampleTumourNormal %>% qsea::getRegions() %>% head(n = 100) calculateFractionReadsInGRanges( qseaSet = exampleTumourNormal, regionsToOverlap = gr, numCountsNeeded = 3) %>% dplyr::select(sample_name, initialOverBackNum, afterOverBackNum, fraction)
Compute genome-wide CpG metrics for a given BSgenome:
relH: relative CpG frequency (% of dinucleotides that are "CG").
GoGe: enrichment statistic .
calculateGenomicCGDistribution(BSgenome)calculateGenomicCGDistribution(BSgenome)
BSgenome |
|
These values are used as denominators to normalise sample-level CpG enrichment.
Chromosomes with names containing "rand" or "chrUn" are excluded.
The BSgenome indicated by BSgenome is loaded dynamically.
Uses Biostrings and BSgenome utilities to count CpG, C, and G occurrences across the genome.
A data.frame with two numeric columns:
genome.relH — percent of "CG" dinucleotides genome-wide.
genome.GoGe — GoGe enrichment statistic.
calculateCGEnrichment(), calculateCGEnrichmentGRanges(), BSgenome,
Biostrings
# Example: compute genome-wide CpG metrics for a S. cerevisae genome. # It could be done for GRCh38 genome instead, but it will take more time to # run (package must be installed) if (requireNamespace("BSgenome.Scerevisiae.UCSC.sacCer3", quietly = TRUE)) { calculateGenomicCGDistribution("BSgenome.Scerevisiae.UCSC.sacCer3") }# Example: compute genome-wide CpG metrics for a S. cerevisae genome. # It could be done for GRCh38 genome instead, but it will take more time to # run (package must be installed) if (requireNamespace("BSgenome.Scerevisiae.UCSC.sacCer3", quietly = TRUE)) { calculateGenomicCGDistribution("BSgenome.Scerevisiae.UCSC.sacCer3") }
S4 method for colnames that returns the column
names of a
qseaSet's sample metadata table (i.e., qsea::getSampleTable()).
## S4 method for signature 'qseaSet' colnames(x)## S4 method for signature 'qseaSet' colnames(x)
x |
|
character().
A character vector containing the column names of the sample table.
qsea::getSampleTable(),
qsea::getSampleNames()
data(exampleTumourNormal, package = "mesa") # Retrieve the column names of the sample metadata colnames(exampleTumourNormal)data(exampleTumourNormal, package = "mesa") # Retrieve the column names of the sample metadata colnames(exampleTumourNormal)
Merge two qseaSet objects (or .rds files containing them) into a single
qseaSet. This is the pairwise worker used internally by
combineQsetsList().
combineQsets( qseaSet1, qseaSet2, checkParams = FALSE, regionsToKeep = NULL, dropDuplicates = FALSE )combineQsets( qseaSet1, qseaSet2, checkParams = FALSE, regionsToKeep = NULL, dropDuplicates = FALSE )
qseaSet1 |
|
qseaSet2 |
|
checkParams |
|
regionsToKeep |
|
dropDuplicates |
|
A qseaSet object containing:
Samples from both inputs.
Regions restricted by regionsToKeep if supplied.
Duplicates handled according to dropDuplicates.
Global parameters optionally checked for consistency.
combineQsetsList() for merging more than two inputs.
data(exampleTumourNormal, package = "mesa") # Split a cohort into Tumour and Normal, then combine back tumours <- exampleTumourNormal %>% filter(tumour == "Tumour") normals <- exampleTumourNormal %>% filter(tumour == "Normal") combineQsets(tumours, normals)data(exampleTumourNormal, package = "mesa") # Split a cohort into Tumour and Normal, then combine back tumours <- exampleTumourNormal %>% filter(tumour == "Tumour") normals <- exampleTumourNormal %>% filter(tumour == "Normal") combineQsets(tumours, normals)
Merge a list of qseaSet objects (or .rds files containing them) into a
single qseaSet. Useful when cohorts were processed separately (e.g.,
tumour/normal, multiple runs) and need to be combined into one container.
combineQsetsList( qseaSets, firstQset = NULL, dropDuplicates = TRUE, checkParams = TRUE, regionsToKeep = NULL )combineQsetsList( qseaSets, firstQset = NULL, dropDuplicates = TRUE, checkParams = TRUE, regionsToKeep = NULL )
qseaSets |
|
firstQset |
|
dropDuplicates |
|
checkParams |
|
regionsToKeep |
|
A qseaSet object:
Combined samples from all inputs (or from firstQset plus inputs).
Duplicates handled according to dropDuplicates.
Regions optionally prefiltered by regionsToKeep prior to merge.
combineQsets() for pairwise merging.
data(exampleTumourNormal, package = "mesa") # Split a cohort into Tumour and Normal, create a list, then combine back tumours <- exampleTumourNormal %>% filter(tumour == "Tumour") normals <- exampleTumourNormal %>% filter(tumour == "Normal") qsetList <- list(tumours, normals) combineQsetsList(qsetList)data(exampleTumourNormal, package = "mesa") # Split a cohort into Tumour and Normal, create a list, then combine back tumours <- exampleTumourNormal %>% filter(tumour == "Tumour") normals <- exampleTumourNormal %>% filter(tumour == "Normal") qsetList <- list(tumours, normals) combineQsetsList(qsetList)
Build a probe × sample beta table by mapping qseaSet windows to array
probe coordinates. Currently supports Illumina Infinium 450k probes on
GRCh38; a custom GRanges of probes can also be supplied.
convertToArrayBetaTable(qseaSet, arrayDetails = "Infinium450k")convertToArrayBetaTable(qseaSet, arrayDetails = "Infinium450k")
qseaSet |
|
arrayDetails |
|
Probe coordinates are matched to qseaSet windows (e.g., via overlap). When
multiple windows are relevant for a probe, the package's implementation is
used to derive a single beta value per probe. Ensure the probe genome build
matches the qseaSet (e.g., GRCh38) to avoid mismatches.
A data.frame with one row per probe (including an ID column) and one
column per sample containing the corresponding beta values. Probes with no
matching/overlapping window receive NA.
getDataTable(), dataset mesa::hg38_450kArrayGR
Other window-helpers:
calculateFractionReadsInGRanges(),
downSample(),
subsetWindowsBySignal(),
subsetWindowsOverBackground()
data(exampleTumourNormal, package = "mesa") # Use the built-in keyword for 450k probes (GRCh38) exampleTumourNormal %>% convertToArrayBetaTable(arrayDetails = "Infinium450k") %>% head() # Supply an explicit GRanges of 450k probes (must have metadata column 'ID') exampleTumourNormal %>% convertToArrayBetaTable(arrayDetails = mesa::hg38_450kArrayGR) %>% head()data(exampleTumourNormal, package = "mesa") # Use the built-in keyword for 450k probes (GRCh38) exampleTumourNormal %>% convertToArrayBetaTable(arrayDetails = "Infinium450k") %>% head() # Supply an explicit GRanges of 450k probes (must have metadata column 'ID') exampleTumourNormal %>% convertToArrayBetaTable(arrayDetails = mesa::hg38_450kArrayGR) %>% head()
For a given set of genomic windows, count (per sample) how many windows exceed a chosen threshold using the selected normalisation/measure.
countWindowsAboveCutoff( qseaSet, GRanges, samples = NULL, cutoff = 0, normMethod = "nrpm" )countWindowsAboveCutoff( qseaSet, GRanges, samples = NULL, cutoff = 0, normMethod = "nrpm" )
qseaSet |
|
GRanges |
|
samples |
|
cutoff |
|
normMethod |
|
The function builds a window × sample matrix over GRanges for the chosen
normMethod, optionally restricts to samples, and counts, per sample, the
number of windows with value >= cutoff. It also reports how many windows
were evaluated (totalWindowsUsed). Results are joined with the sample
table.
A tibble with one row per sample containing:
sample_name
numOverCutoff — number of windows >= cutoff
totalWindowsUsed — number of windows evaluated
followed by columns from the sample table (left-joined).
getDataTable(), summariseAcrossWindows()
Other window-summaries:
addSummaryAcrossWindows(),
summariseAcrossWindows()
data(exampleTumourNormal, package = "mesa") #' # Count windows with NRPM >= 1 over the first 100 regions countWindowsAboveCutoff(exampleTumourNormal, qsea::getRegions(exampleTumourNormal)[1:100], cutoff = 1, normMethod = "nrpm")data(exampleTumourNormal, package = "mesa") #' # Count windows with NRPM >= 1 over the first 100 regions countWindowsAboveCutoff(exampleTumourNormal, qsea::getRegions(exampleTumourNormal)[1:100], cutoff = 1, normMethod = "nrpm")
Randomly subsample reads to a fixed depth across all samples in a qseaSet.
Useful for equalising library sizes prior to comparison.
downSample(qseaSet, nReads)downSample(qseaSet, nReads)
qseaSet |
|
nReads |
|
Downsampling is performed independently per sample. To obtain reproducible
results across runs, call set.seed() before invoking downSample().
Samples with total reads < nReads are not upsampled.
A qseaSet with downsampled counts. Library metadata
(valid_fragments, offset, library_factor) are updated accordingly.
getDataTable(), subsetWindowsBySignal(), mixSamples()
Other window-helpers:
calculateFractionReadsInGRanges(),
convertToArrayBetaTable(),
subsetWindowsBySignal(),
subsetWindowsOverBackground()
data(exampleTumourNormal, package = "mesa") set.seed(1) # Downsample to 100 fragments per sample, then check per-sample totals exampleTumourNormal %>% downSample(100) %>% getCountTable() %>% dplyr::select(tidyselect::matches("_[NT]")) %>% colSums() %>% range() # should be ~ c(100, 100) if all samples had >= 100 reads # Also inspect the updated library sizes recorded in the sample table exampleTumourNormal %>% downSample(100) %>% qsea::getSampleTable() %>% dplyr::select(patient, type, gender)data(exampleTumourNormal, package = "mesa") set.seed(1) # Downsample to 100 fragments per sample, then check per-sample totals exampleTumourNormal %>% downSample(100) %>% getCountTable() %>% dplyr::select(tidyselect::matches("_[NT]")) %>% colSums() %>% range() # should be ~ c(100, 100) if all samples had >= 100 reads # Also inspect the updated library sizes recorded in the sample table exampleTumourNormal %>% downSample(100) %>% qsea::getSampleTable() %>% dplyr::select(patient, type, gender)
The 2019 ENCODE list of regions that are poorly mapped (2019 https://doi.org/10.1038/s41598-019-45839-z). List downloaded from https://github.com/Boyle-Lab/Blacklist/blob/master/lists/ hg38-blacklist.v2.bed.gz and edited to remove "chr".
ENCODEbadRegionsENCODEbadRegions
A Granges object with 636 ranges:
chromosome
position on the chromosome
https://github.com/Boyle-Lab/Blacklist/blob/master/lists/ hg38-blacklist.v2.bed.gz
A qseaSet object containing a small region of chromosome 5 for a mouse cell line, 2 replicates of 2 conditions (processed within CRUK-MI CBC).
exampleMouseexampleMouse
A qseaSet object with 153 regions and 4 samples:
A qseaSet object containing a small region of chromosome 7 for 5 paired tumour/normal samples (commercially bought from Origene and processed within CRUK-MI CBC).
exampleTumourNormalexampleTumourNormal
A qseaSet object with 819 regions and 10 samples:
A data frame containing FANTOM5 enhancer regions, hg38
FantomRegionsFantomRegions
A data frame with 63285 rows and 3 variables:
Extends dplyr::filter() to subset samples in a qseaSet based on
predicates applied to its sampleTable.
## S3 method for class 'qseaSet' filter(.data, ..., .preserve = FALSE)## S3 method for class 'qseaSet' filter(.data, ..., .preserve = FALSE)
.data |
|
... |
Predicate expressions passed to |
.preserve |
|
Filtering is performed on the result of qsea::getSampleTable(.data).
Matching rows determine the sample_names retained in the qseaSet.
Grouped filtering (group_by) is not supported for qseaSet.
A qseaSet object containing only the samples whose
sampleTable rows satisfied the filter expressions. If no samples
remain, an empty qseaSet is returned (with a message but not an error).
qsea::getSampleTable() to inspect metadata,
subsetQset() for explicit sample subsetting,
selectQset() for column selection in the sampleTable.
data(exampleTumourNormal, package = "mesa") # Keep only older patients exampleTumourNormal %>% filter(age >= 70) # Restrict to colon tissue exampleTumourNormal %>% filter(tissue == "Colon") # Select only tumour samples exampleTumourNormal %>% filter(tumour != "Normal") # Combine predicates: lung tumours only exampleTumourNormal %>% filter(stringr::str_detect(sample_name, "Lung"), tumour != "Normal") # If no rows match, returns empty qseaSet (with a message) exampleTumourNormal %>% filter(tissue == "Liver")data(exampleTumourNormal, package = "mesa") # Keep only older patients exampleTumourNormal %>% filter(age >= 70) # Restrict to colon tissue exampleTumourNormal %>% filter(tissue == "Colon") # Select only tumour samples exampleTumourNormal %>% filter(tumour != "Normal") # Combine predicates: lung tumours only exampleTumourNormal %>% filter(stringr::str_detect(sample_name, "Lung"), tumour != "Normal") # If no rows match, returns empty qseaSet (with a message) exampleTumourNormal %>% filter(tissue == "Liver")
filterByOverlaps() retains windows that overlap, while
filterByNonOverlaps() retains windows that do not overlap a set of
genomic regions. Inputs may use different chromosome styles (with or without
the "chr" prefix); styles are harmonized automatically before overlap
computation.
filterByOverlaps(qseaSet, regionsToOverlap) filterByNonOverlaps(qseaSet, regionsToOverlap)filterByOverlaps(qseaSet, regionsToOverlap) filterByNonOverlaps(qseaSet, regionsToOverlap)
qseaSet |
|
regionsToOverlap |
|
Chromosome naming is aligned using GenomeInfoDb::seqlevelsStyle() so that
overlap computation is consistent even when one input uses "chr1" and the
other uses "1". Only the window set is filtered; sample metadata and
counts are subset accordingly.
A qseaSet object:
filterByOverlaps(): returns the input qseaSet restricted to
windows that overlap regionsToOverlap.
filterByNonOverlaps(): returns the input qseaSet restricted to
windows that do not overlap regionsToOverlap.
filter_by_overlaps,
filter_by_non_overlaps,
GRanges-class
data(exampleTumourNormal, package = "mesa") # Data frame input rgns <- data.frame(seqnames = 7L, start = 25002001L, end = 25017900L) filterByOverlaps(exampleTumourNormal, regionsToOverlap = rgns) filterByNonOverlaps(exampleTumourNormal, regionsToOverlap = rgns) # GRanges input gr <- GenomicRanges::GRanges("chr7", IRanges::IRanges(25002001L, 25017900L)) filterByOverlaps(exampleTumourNormal, regionsToOverlap = gr) filterByNonOverlaps(exampleTumourNormal, regionsToOverlap = gr)data(exampleTumourNormal, package = "mesa") # Data frame input rgns <- data.frame(seqnames = 7L, start = 25002001L, end = 25017900L) filterByOverlaps(exampleTumourNormal, regionsToOverlap = rgns) filterByNonOverlaps(exampleTumourNormal, regionsToOverlap = rgns) # GRanges input gr <- GenomicRanges::GRanges("chr7", IRanges::IRanges(25002001L, 25017900L)) filterByOverlaps(exampleTumourNormal, regionsToOverlap = gr) filterByNonOverlaps(exampleTumourNormal, regionsToOverlap = gr)
Filters the regions of a qseaSet using dplyr::filter() predicates
applied to its regions (as a data frame), then subsets the object
accordingly.
filterWindows(qseaSet, ...)filterWindows(qseaSet, ...)
qseaSet |
|
... |
Expressions.
Predicates passed to |
A qseaSet object with only regions matching the filter conditions.
Both the count_matrix and @regions slot are updated consistently.
qsea::getRegions(),
filter.qseaSet() (for filtering samples instead of regions),
dplyr::filter()
data(exampleTumourNormal, package = "mesa") # Keep regions starting before position 25,020,000 exampleTumourNormal %>% filterWindows(start <= 25020000) # Keep regions with CpG density > 10 exampleTumourNormal %>% filterWindows(CpG_density > 10) # Combine multiple conditions exampleTumourNormal %>% filterWindows(seqnames == "chr7", CpG_density > 5)data(exampleTumourNormal, package = "mesa") # Keep regions starting before position 25,020,000 exampleTumourNormal %>% filterWindows(start <= 25020000) # Keep regions with CpG density > 10 exampleTumourNormal %>% filterWindows(CpG_density > 10) # Combine multiple conditions exampleTumourNormal %>% filterWindows(seqnames == "chr7", CpG_density > 5)
Fit a negative-binomial GLM using qsea::fitNBglm() on counts from a
qsea::qseaSet, and add one or more contrasts.
This is the low-level worker used by calculateDMRs().
fitQseaGLM( qseaSet, variable = NULL, covariates = NULL, contrasts = NULL, keepIndex = NULL, minReadCount = 0, minNRPM = 1, checkPVals = TRUE, formula = NULL, calcDispersionAll = FALSE )fitQseaGLM( qseaSet, variable = NULL, covariates = NULL, contrasts = NULL, keepIndex = NULL, minReadCount = 0, minNRPM = 1, checkPVals = TRUE, formula = NULL, calcDispersionAll = FALSE )
qseaSet |
|
variable |
|
covariates |
|
contrasts |
|
keepIndex |
|
minReadCount |
|
minNRPM |
|
checkPVals |
|
formula |
|
calcDispersionAll |
|
Dispersion is estimated across the windows retained after filtering.
When calcDispersionAll = TRUE, all samples contribute to dispersion
estimation even if not part of any contrast.
Contrasts are added sequentially with qsea::addContrast().
By default, beta-normalised counts are used as the outcome (as in qsea).
A qseaGLM object containing:
the fitted negative-binomial GLM;
(optionally) one or more added contrasts (group1 vs group2);
filtering metadata (based on keepIndex, minReadCount, minNRPM);
model specification (variable, covariates, or formula).
Other DMR-detection:
calculateDMRs(),
getDMRsData(),
makeAllContrasts()
data(exampleTumourNormal, package = "mesa") qs <- exampleTumourNormal contr <- tibble::tibble(group1 = "LUAD", group2 = "NormalLung") fitQseaGLM(qs, variable = "type", contrasts = contr)data(exampleTumourNormal, package = "mesa") qs <- exampleTumourNormal contr <- tibble::tibble(group1 = "LUAD", group2 = "NormalLung") fitQseaGLM(qs, variable = "type", contrasts = contr)
Fixed-size bins with average GC content per bin. Bins are ordered by chromosome size (not strictly numeric).
data(gc_hg38_1000kb); data(gc_hg38_500kb); data(gc_hg38_50kb) gc_hg38_50kb gc_hg38_500kbdata(gc_hg38_1000kb); data(gc_hg38_500kb); data(gc_hg38_50kb) gc_hg38_50kb gc_hg38_500kb
One of:
A data.table/data.frame with columns:
Chromosome (e.g., "chr1", ..., "chrX", "chrY").
0-based start of the bin.
1-based end of the bin.
Average GC fraction in the bin (0–1).
A GRanges with genomic bins and mcols(.)$gc storing
the average GC fraction (0–1) per bin.
An object of class data.table (inherits from data.frame) with 61775 rows and 4 columns.
An object of class data.table (inherits from data.frame) with 6188 rows and 4 columns.
gc_hg38_1000kb, gc_hg38_500kb, and gc_hg38_50kb
return objects as described in @format with bin sizes of 1000 kb,
500 kb, and 50 kb, respectively.
https://github.com/broadinstitute/ichorCNA
Convenience wrapper around getDataTable() to extract beta values
(fraction methylated). Returns a window × sample (or group) table for
downstream summaries/plots.
getBetaTable( qseaSet, useGroupMeans = FALSE, minEnrichment = 3, addMethodSuffix = FALSE, verbose = TRUE )getBetaTable( qseaSet, useGroupMeans = FALSE, minEnrichment = 3, addMethodSuffix = FALSE, verbose = TRUE )
qseaSet |
|
useGroupMeans |
|
minEnrichment |
|
addMethodSuffix |
|
verbose |
|
A tibble/data.frame with one row per genomic window and columns for each
sample (or group), plus any window metadata included by getDataTable().
getDataTable(), getCountTable(), getNRPMTable()
Other table-helpers:
getCountTable(),
getDataTable(),
getNRPMTable(),
getSampleGroups2(),
makeTransposedTable(),
removeLibraryFactors(),
removeNormMethodSuffix()
data(exampleTumourNormal, package = "mesa") # Per-sample beta (first rows/columns), with a minimum read threshold exampleTumourNormal %>% getBetaTable(minEnrichment = 3) %>% dplyr::select(1:6) %>% head() # Group means instead of individual samples exampleTumourNormal %>% getBetaTable(useGroupMeans = TRUE, minEnrichment = 3) %>% dplyr::select(1:6) %>% head() # Keep the method suffix in column names exampleTumourNormal %>% getBetaTable(addMethodSuffix = TRUE) %>% names() %>% head() # Inspect how many NAs arise from the minEnrichment filter exampleTumourNormal %>% getBetaTable(minEnrichment = 5) %>% dplyr::select(dplyr::where(is.numeric)) %>% is.na() %>% colSums() %>% head()data(exampleTumourNormal, package = "mesa") # Per-sample beta (first rows/columns), with a minimum read threshold exampleTumourNormal %>% getBetaTable(minEnrichment = 3) %>% dplyr::select(1:6) %>% head() # Group means instead of individual samples exampleTumourNormal %>% getBetaTable(useGroupMeans = TRUE, minEnrichment = 3) %>% dplyr::select(1:6) %>% head() # Keep the method suffix in column names exampleTumourNormal %>% getBetaTable(addMethodSuffix = TRUE) %>% names() %>% head() # Inspect how many NAs arise from the minEnrichment filter exampleTumourNormal %>% getBetaTable(minEnrichment = 5) %>% dplyr::select(dplyr::where(is.numeric)) %>% is.na() %>% colSums() %>% head()
Convenience wrapper that returns genomic positions of the "CG" motif
for the specified BSgenome and chromosomes, via
MEDIPS::MEDIPS.getPositions().
getCGPositions(BSgenome, chr.select)getCGPositions(BSgenome, chr.select)
BSgenome |
Character(1). BSgenome package name. |
chr.select |
Character vector of chromosome names to include (e.g.,
|
A GRanges-class of motif positions.
calculateCGEnrichment,
calculateCGEnrichmentGRanges, MEDIPS
# Requires MEDIPS and a BSgenome package # if (requireNamespace("BSgenome.Hsapiens.NCBI.GRCh38", quietly = TRUE)) { # getCGPositions("BSgenome.Hsapiens.NCBI.GRCh38", chr.select = 22) # }# Requires MEDIPS and a BSgenome package # if (requireNamespace("BSgenome.Hsapiens.NCBI.GRCh38", quietly = TRUE)) { # getCGPositions("BSgenome.Hsapiens.NCBI.GRCh38", chr.select = 22) # }
Convenience wrapper around getDataTable() to extract raw counts.
Returns a window × sample (or group) table for downstream summaries/plots.
getCountTable( qseaSet, useGroupMeans = FALSE, addMethodSuffix = FALSE, verbose = TRUE )getCountTable( qseaSet, useGroupMeans = FALSE, addMethodSuffix = FALSE, verbose = TRUE )
qseaSet |
|
useGroupMeans |
|
addMethodSuffix |
|
verbose |
|
A tibble/data.frame with one row per genomic window and columns for each
sample (or group), plus any window metadata included by getDataTable().
getDataTable(), getNRPMTable(), getBetaTable()
Other table-helpers:
getBetaTable(),
getDataTable(),
getNRPMTable(),
getSampleGroups2(),
makeTransposedTable(),
removeLibraryFactors(),
removeNormMethodSuffix()
data(exampleTumourNormal, package = "mesa") # Per-sample counts (first rows/columns) exampleTumourNormal %>% getCountTable() %>% dplyr::select(1:6) %>% head() # Group means instead of individual samples exampleTumourNormal %>% getCountTable(useGroupMeans = TRUE) %>% dplyr::select(1:6) %>% head() # Keep the method suffix in column names exampleTumourNormal %>% getCountTable(addMethodSuffix = TRUE) %>% names() %>% head()data(exampleTumourNormal, package = "mesa") # Per-sample counts (first rows/columns) exampleTumourNormal %>% getCountTable() %>% dplyr::select(1:6) %>% head() # Group means instead of individual samples exampleTumourNormal %>% getCountTable(useGroupMeans = TRUE) %>% dplyr::select(1:6) %>% head() # Keep the method suffix in column names exampleTumourNormal %>% getCountTable(addMethodSuffix = TRUE) %>% names() %>% head()
Build a per-window table for one or more normalisation methods, returning values per sample or group means.
getDataTable( qseaSet, normMethod = "nrpm", useGroupMeans = FALSE, minEnrichment = 3, addMethodSuffix = FALSE, verbose = TRUE )getDataTable( qseaSet, normMethod = "nrpm", useGroupMeans = FALSE, minEnrichment = 3, addMethodSuffix = FALSE, verbose = TRUE )
qseaSet |
|
normMethod |
|
useGroupMeans |
|
minEnrichment |
|
addMethodSuffix |
|
verbose |
|
The result is a window × sample (or group) table. Window coordinates and
any available region metadata (e.g., seqnames, start, end, densities)
are kept alongside the requested measures. Column naming: when a single
method is requested and addMethodSuffix = FALSE, columns are bare sample /
group names; otherwise a _{method} (and for group means _{method}_means)
suffix is appended.
For "beta", windows with reads < minEnrichment are set to NA before
aggregation. Use removeNormMethodSuffix() afterwards if you want to strip
method tags in wide tables.
A tibble/data.frame with one row per genomic window and one column per sample (or group), plus window metadata columns.
getCountTable(), getNRPMTable(), getBetaTable(),
removeNormMethodSuffix()
Other table-helpers:
getBetaTable(),
getCountTable(),
getNRPMTable(),
getSampleGroups2(),
makeTransposedTable(),
removeLibraryFactors(),
removeNormMethodSuffix()
data(exampleTumourNormal, package = "mesa") # Default: NRPM per window (first few columns) exampleTumourNormal %>% getDataTable() %>% dplyr::select(1:6) %>% head() # Multiple methods together (suffixes retained automatically) exampleTumourNormal %>% getDataTable(normMethod = c("nrpm","beta"), minEnrichment = 3) %>% dplyr::select(1:8) %>% head() # Group means instead of individual samples exampleTumourNormal %>% getDataTable(useGroupMeans = TRUE, normMethod = "nrpm") %>% dplyr::select(1:6) %>% head() # Keep (or later remove) the method suffix exampleTumourNormal %>% getDataTable(normMethod = "nrpm", addMethodSuffix = TRUE) %>% names() %>% head()data(exampleTumourNormal, package = "mesa") # Default: NRPM per window (first few columns) exampleTumourNormal %>% getDataTable() %>% dplyr::select(1:6) %>% head() # Multiple methods together (suffixes retained automatically) exampleTumourNormal %>% getDataTable(normMethod = c("nrpm","beta"), minEnrichment = 3) %>% dplyr::select(1:8) %>% head() # Group means instead of individual samples exampleTumourNormal %>% getDataTable(useGroupMeans = TRUE, normMethod = "nrpm") %>% dplyr::select(1:6) %>% head() # Keep (or later remove) the method suffix exampleTumourNormal %>% getDataTable(normMethod = "nrpm", addMethodSuffix = TRUE) %>% names() %>% head()
Given a qsea::qseaGLM object with one or more contrasts, extract a wide
results table of statistics, adjusted p-values, and (optionally) group means
and per-sample values.
getDMRsData( qseaSet, qseaGLM, sampleNames = NULL, variable = NULL, keepData = FALSE, keepGroupMeans = FALSE, FDRthres = 0.05, keepPvals = FALSE, keepFragmentInfo = FALSE, direction = "both" )getDMRsData( qseaSet, qseaGLM, sampleNames = NULL, variable = NULL, keepData = FALSE, keepGroupMeans = FALSE, FDRthres = 0.05, keepPvals = FALSE, keepFragmentInfo = FALSE, direction = "both" )
qseaSet |
|
qseaGLM |
|
sampleNames |
|
variable |
|
keepData |
|
keepGroupMeans |
|
FDRthres |
|
keepPvals |
|
keepFragmentInfo |
|
direction |
|
Significant rows are determined using FDRthres and direction via
qsea::isSignificant(). When keepData = TRUE and sampleNames = NULL,
per-sample columns are included for all samples in the fitted model (or the
subset relevant to each contrast, depending on the internal representation).
Group means require variable to identify the groupings used in contrasts.
A tibble with one row per DMR (window) containing:
Per-contrast statistics (e.g., log2FC, deltaBeta, test statistic).
Multiple-testing output (FDR; optionally raw p-values if keepPvals).
Optional group summaries if keepGroupMeans = TRUE.
Optional per-sample columns if keepData = TRUE (for sampleNames).
Optional fragment/MAPQ metrics if keepFragmentInfo = TRUE.
Other DMR-detection:
calculateDMRs(),
fitQseaGLM(),
makeAllContrasts()
data(exampleTumourNormal, package = "mesa") qs <- exampleTumourNormal contr <- tibble::tibble(group1 = "LUAD", group2 = "NormalLung") glmfit <- fitQseaGLM(qs, variable = "type", contrasts = contr) getDMRsData(qs, glmfit, variable = "type", FDRthres = 0.1)data(exampleTumourNormal, package = "mesa") qs <- exampleTumourNormal contr <- tibble::tibble(group1 = "LUAD", group2 = "NormalLung") glmfit <- fitQseaGLM(qs, variable = "type", contrasts = contr) getDMRsData(qs, glmfit, variable = "type", FDRthres = 0.1)
Annotate windows, then summarise signal and counts by CpG landscape (Island/Shore/Shelf/Open Sea) and short genomic annotation (e.g., Promoter/Exon/Intron/Intergenic).
getGenomicFeatureDistribution( qseaSet, cutoff = 1, normMethod = "nrpm", minEnrichment = 3 )getGenomicFeatureDistribution( qseaSet, cutoff = 1, normMethod = "nrpm", minEnrichment = 3 )
qseaSet |
|
cutoff |
|
normMethod |
|
minEnrichment |
|
Windows are annotated via annotateWindows() (which can add CpG landscape
and a concise shortAnno label). The function then groups by sample_name,
landscape, and shortAnno to compute:
nWindows: number of windows in the group,
sum: sum of the selected measure across those windows,
nOverCutoff: number of windows with value >= cutoff.
When using beta, windows failing minEnrichment are treated as NA before
summarisation.
This function requires a transcript database and OrgDb to annotate windows
(via
annotateWindows()). Either:
set them globally with setMesaGenome() (recommended for GRCh38/hg38), or
provide compatible TxDb/annoDb packages yourself.
A tibble with columns:
sample_name, landscape, shortAnno, nWindows, sum, nOverCutoff,
followed by sample-table metadata joined from qseaSet.
annotateWindows(), summariseAcrossWindows(), getDataTable()
Other annotation-summaries:
plotGenomicFeatureDistribution()
# Ensure annotation defaults are available (GRCh38/hg38) setMesaGenome("hg38") data(exampleTumourNormal, package = "mesa") # NRPM-based context summary exampleTumourNormal %>% getGenomicFeatureDistribution(cutoff = 1, normMethod = "nrpm") %>% head() # Beta-based summary (apply a minimum enrichment for non-NA betas) exampleTumourNormal %>% getGenomicFeatureDistribution( cutoff = 0.7, normMethod = "beta", minEnrichment = 3 ) %>% head()# Ensure annotation defaults are available (GRCh38/hg38) setMesaGenome("hg38") data(exampleTumourNormal, package = "mesa") # NRPM-based context summary exampleTumourNormal %>% getGenomicFeatureDistribution(cutoff = 1, normMethod = "nrpm") %>% head() # Beta-based summary (apply a minimum enrichment for non-NA betas) exampleTumourNormal %>% getGenomicFeatureDistribution( cutoff = 0.7, normMethod = "beta", minEnrichment = 3 ) %>% head()
Get annotation DB for current or specified genome
getMesaAnnoDb(genome = NULL)getMesaAnnoDb(genome = NULL)
genome |
Genome build, defaults to current setting |
Character string of annotation database name (e.g., "org.Hs.eg.db", "org.Mm.eg.db")
Get current mesa genome setting
getMesaGenome()getMesaGenome()
Character string of current genome setting (e.g., "hg38", "hg19", "mm10")
Get TxDb for current or specified genome
getMesaTxDb(genome = NULL)getMesaTxDb(genome = NULL)
genome |
Genome build, defaults to current setting |
A TxDb object for the specified genome
Convenience wrapper around getDataTable() to extract NRPM values
(normalised reads per million). Returns a window × sample (or group) table
for downstream summaries/plots.
getNRPMTable( qseaSet, useGroupMeans = FALSE, addMethodSuffix = FALSE, verbose = TRUE )getNRPMTable( qseaSet, useGroupMeans = FALSE, addMethodSuffix = FALSE, verbose = TRUE )
qseaSet |
|
useGroupMeans |
|
addMethodSuffix |
|
verbose |
|
A tibble/data.frame with one row per genomic window and columns for each
sample (or group), plus any window metadata included by getDataTable().
getDataTable(), getCountTable(), getBetaTable()
Other table-helpers:
getBetaTable(),
getCountTable(),
getDataTable(),
getSampleGroups2(),
makeTransposedTable(),
removeLibraryFactors(),
removeNormMethodSuffix()
data(exampleTumourNormal, package = "mesa") # Per-sample NRPM (first rows/columns) exampleTumourNormal %>% getNRPMTable() %>% dplyr::select(1:6) %>% head() # Group means instead of individual samples exampleTumourNormal %>% getNRPMTable(useGroupMeans = TRUE) %>% dplyr::select(1:6) %>% head() # Keep the method suffix in column names exampleTumourNormal %>% getNRPMTable(addMethodSuffix = TRUE) %>% names() %>% head()data(exampleTumourNormal, package = "mesa") # Per-sample NRPM (first rows/columns) exampleTumourNormal %>% getNRPMTable() %>% dplyr::select(1:6) %>% head() # Group means instead of individual samples exampleTumourNormal %>% getNRPMTable(useGroupMeans = TRUE) %>% dplyr::select(1:6) %>% head() # Keep the method suffix in column names exampleTumourNormal %>% getNRPMTable(addMethodSuffix = TRUE) %>% names() %>% head()
Scan the region metadata of a qseaSet for columns ending in "_density"
(e.g., "CpG_density") and return the base pattern names (e.g., "CpG").
getPattern(qseaSet)getPattern(qseaSet)
qseaSet |
|
This function inspects mcols(qsea::getRegions(qseaSet)), selects column
names matching the regex "_density$", and strips that suffix. It does not
compute densities or modify the object. If no matching columns exist, a
zero-length character vector is returned.
character() vector of pattern names discovered (length 0 if none).
qsea::addPatternDensity(), qsea::getRegions(), S4Vectors::mcols()
data(exampleTumourNormal, package = "mesa") # Returns character(0) if no *_density columns are present exampleTumourNormal %>% getPattern()data(exampleTumourNormal, package = "mesa") # Returns character(0) if no *_density columns are present exampleTumourNormal %>% getPattern()
Convenience wrapper around getDimRed() with method = "PCA".
Convenience wrapper around getDimRed() with method = "UMAP".
Run PCA or UMAP on methylation signal matrices extracted from a
qsea::qseaSet. This is the core workhorse for dimensionality reduction;
wrappers such as getPCA() and getUMAP() provide simplified access.
getPCA( qseaSet, dataTable = NULL, regionsToOverlap = NULL, normMethod = "beta", minEnrichment = 3, useGroupMeans = FALSE, minDensity = 0, topVarNum = 1000, topVarSamples = NULL, center = TRUE, scale = FALSE, nPC = 5, returnDataTable = FALSE, verbose = TRUE ) getUMAP( qseaSet, dataTable = NULL, regionsToOverlap = NULL, normMethod = "beta", minEnrichment = 3, useGroupMeans = FALSE, minDensity = 0, topVarNum = 1000, topVarSamples = NULL, returnDataTable = FALSE, verbose = TRUE, ... ) getDimRed( qseaSet, dataTable = NULL, method = "PCA", regionsToOverlap = NULL, normMethod = "beta", minEnrichment = 3, useGroupMeans = FALSE, minDensity = 0, topVarNum = 1000, topVarSamples = NULL, center = TRUE, scale = FALSE, nPC = 5, returnDataTable = FALSE, verbose = TRUE, ... )getPCA( qseaSet, dataTable = NULL, regionsToOverlap = NULL, normMethod = "beta", minEnrichment = 3, useGroupMeans = FALSE, minDensity = 0, topVarNum = 1000, topVarSamples = NULL, center = TRUE, scale = FALSE, nPC = 5, returnDataTable = FALSE, verbose = TRUE ) getUMAP( qseaSet, dataTable = NULL, regionsToOverlap = NULL, normMethod = "beta", minEnrichment = 3, useGroupMeans = FALSE, minDensity = 0, topVarNum = 1000, topVarSamples = NULL, returnDataTable = FALSE, verbose = TRUE, ... ) getDimRed( qseaSet, dataTable = NULL, method = "PCA", regionsToOverlap = NULL, normMethod = "beta", minEnrichment = 3, useGroupMeans = FALSE, minDensity = 0, topVarNum = 1000, topVarSamples = NULL, center = TRUE, scale = FALSE, nPC = 5, returnDataTable = FALSE, verbose = TRUE, ... )
qseaSet |
|
dataTable |
|
regionsToOverlap |
|
normMethod |
|
minEnrichment |
|
useGroupMeans |
|
minDensity |
|
topVarNum |
|
topVarSamples |
|
center |
|
scale |
|
nPC |
|
returnDataTable |
|
verbose |
|
... |
Additional arguments passed to |
method |
|
:
For method = "PCA", DR is performed via stats::prcomp() with center
and scale controls.
For method = "UMAP", DR is performed via uwot::umap().
Prior to DR, optional filtering is applied: enrichment cut-off
(minEnrichment), CpG density (minDensity), region restriction
(regionsToOverlap), and most-variable windows (topVarNum).
When topVarNum or topVarSamples are vectorised/lists, multiple DR runs
are performed and collected in res.
A mesaDimRed object with:
res: Named list of DR results; each element is a mesaPCA (for PCA)
or mesaUMAP (for UMAP). Names correspond to entries in params$topVar.
samples: Character vector of sample IDs used.
dataTable (optional): The numeric matrix used for DR when
returnDataTable = TRUE. It reflects filtering by regionsToOverlap and
minDensity, removal of rows with missing values, and may include columns of
window SDs when applicable (named per params$topVar).
params: List of parameters used (method, selection/filter settings, etc.).
sampleTable: Copy of qsea::getSampleTable(qseaSet).
getPCA(): Principal component analysis of a qseaSet.
getUMAP(): Uniform manifold approximation and projection of a
qseaSet.
getPCA(), getUMAP(), mesaDimRed, mesaPCA,
mesaUMAP, qsea::normMethod(), uwot::umap(), stats::prcomp()
Other dimred-helpers:
plotDimRed(),
plotUMAP()
Other dimred-helpers:
plotDimRed(),
plotUMAP()
Other dimred-helpers:
plotDimRed(),
plotUMAP()
data(exampleTumourNormal, package = "mesa") # Default PCA (beta-normalised, top 1000 most variable windows, 5 PCs) exampleTumourNormal %>% getPCA() # Request only the top 3 PCs exampleTumourNormal %>% getPCA(nPC = 3) # Use multiple cutoffs for most-variable windows # (returns list of PCA results) exampleTumourNormal %>% getPCA(topVarNum = c(10, 100, 500, NA)) %>% slot("res") %>% names() # Default UMAP exampleTumourNormal %>% getUMAP(n_neighbors = 5) # Alter UMAP hyperparameters exampleTumourNormal %>% getUMAP(n_neighbors = 5, min_dist = 1) # Use top 500 most variable windows only exampleTumourNormal %>% getUMAP(n_neighbors = 5, topVarNum = 500) data(exampleTumourNormal, package = "mesa") # PCA on default beta-normalised matrix, keep 3 PCs exampleTumourNormal %>% getDimRed(method = "PCA", nPC = 3) # UMAP on the top 500 most variable windows exampleTumourNormal %>% getDimRed(method = "UMAP", topVarNum = 500, n_neighbors = 5) # Restrict DR to a set of regions (coerced from data.frame) regs <- data.frame(seqnames = "chr7", start = 25002001, end = 25027900) exampleTumourNormal %>% getDimRed(method = "PCA", regionsToOverlap = regs) # Vectorised topVarNum runs (returns a list of results) exampleTumourNormal %>% getDimRed(method = "UMAP", topVarNum = c(500, 2000), n_neighbors = 5) %>% slot("res") %>% names()data(exampleTumourNormal, package = "mesa") # Default PCA (beta-normalised, top 1000 most variable windows, 5 PCs) exampleTumourNormal %>% getPCA() # Request only the top 3 PCs exampleTumourNormal %>% getPCA(nPC = 3) # Use multiple cutoffs for most-variable windows # (returns list of PCA results) exampleTumourNormal %>% getPCA(topVarNum = c(10, 100, 500, NA)) %>% slot("res") %>% names() # Default UMAP exampleTumourNormal %>% getUMAP(n_neighbors = 5) # Alter UMAP hyperparameters exampleTumourNormal %>% getUMAP(n_neighbors = 5, min_dist = 1) # Use top 500 most variable windows only exampleTumourNormal %>% getUMAP(n_neighbors = 5, topVarNum = 500) data(exampleTumourNormal, package = "mesa") # PCA on default beta-normalised matrix, keep 3 PCs exampleTumourNormal %>% getDimRed(method = "PCA", nPC = 3) # UMAP on the top 500 most variable windows exampleTumourNormal %>% getDimRed(method = "UMAP", topVarNum = 500, n_neighbors = 5) # Restrict DR to a set of regions (coerced from data.frame) regs <- data.frame(seqnames = "chr7", start = 25002001, end = 25027900) exampleTumourNormal %>% getDimRed(method = "PCA", regionsToOverlap = regs) # Vectorised topVarNum runs (returns a list of results) exampleTumourNormal %>% getDimRed(method = "UMAP", topVarNum = c(500, 2000), n_neighbors = 5) %>% slot("res") %>% names()
Return a tidy summary of the most relevant QC fields from a qseaSet
sampleTable. If core library metrics are missing, they are first added via
addLibraryInformation().
getSampleQCSummary(qseaSet)getSampleQCSummary(qseaSet)
qseaSet |
|
If the sampleTable lacks library metrics (e.g., valid_fragments), the
function calls addLibraryInformation() to populate them. The output keeps
sample_name and any columns whose names match the regex
"valid_fragment|relH|hyperStable|ichorTumo" (if present), then orders rows
by sample_name.
A tibble with one row per sample containing:
sample_name
any available QC columns matching valid_fragment, relH, hyperStable,
or ichorTumo.
Columns not present in the sampleTable are silently omitted.
qsea::getSampleTable(), addLibraryInformation(),
addHyperStableFraction()
data("exampleTumourNormal", package = "mesa") # QC summary (adds library info if missing), ordered by sample_name exampleTumourNormal %>% getSampleQCSummary() %>% head()data("exampleTumourNormal", package = "mesa") # QC summary (adds library info if missing), ordered by sample_name exampleTumourNormal %>% getSampleQCSummary() %>% head()
Return character labels of the form "seqnames:start-end" for each genomic
window/region.
getWindowNames(x)getWindowNames(x)
x |
|
If x is a qseaSet, regions are taken from qsea::getRegions(x).
Otherwise
the input is coerced to GRanges (see asValidGranges()) and labels are
constructed as "seqnames:start-end".
character() vector of window labels, one per region.
qsea::getRegions(), asValidGranges()
# From a GRanges (no intermediate objects) GenomicRanges::GRanges(c("chr1", "chr2"), IRanges::IRanges(c(10, 20), c(15, 30))) %>% getWindowNames() # From a data.frame (no intermediate objects) data.frame(seqnames = c("chr1", "chr2"), start = c(100, 200), end = c(120, 220)) %>% getWindowNames() # From a qseaSet shipped with mesa (if available) data(exampleTumourNormal, package = "mesa") exampleTumourNormal %>% getWindowNames() %>% head()# From a GRanges (no intermediate objects) GenomicRanges::GRanges(c("chr1", "chr2"), IRanges::IRanges(c(10, 20), c(15, 30))) %>% getWindowNames() # From a data.frame (no intermediate objects) data.frame(seqnames = c("chr1", "chr2"), start = c(100, 200), end = c(120, 220)) %>% getWindowNames() # From a qseaSet shipped with mesa (if available) data(exampleTumourNormal, package = "mesa") exampleTumourNormal %>% getWindowNames() %>% head()
Convenience wrapper for qsea::getRegions(), returning the genomic windows.
getWindows(qseaSet)getWindows(qseaSet)
qseaSet |
|
A GenomicRanges::GRanges of windows.
qsea::getRegions(), getWindowNames()
data(exampleTumourNormal, package = "mesa") exampleTumourNormal %>% getWindows() %>% head()data(exampleTumourNormal, package = "mesa") exampleTumourNormal %>% getWindows() %>% head()
A chain object to liftOver hg19 to hg38
hg19ToHg38.over.chainhg19ToHg38.over.chain
A chain object to liftOver hg19 to hg38
A GRanges object containing the Illumina Infinium 450k array probe locations for hg38
hg38_450kArrayGRhg38_450kArrayGR
A GRanges object with 485541 ranges and 2 metadata columns:
Array probe ID
A field suggesting whether the probe could be unreliable (if TRUE) due to some kind of technical issue
A GRanges object containing CpG islands in hg38 coordinates. Generated from http://hgdownload.cse.ucsc.edu/goldenpath/hg38/database/cpgIslandExt.txt.gz
hg38CpGIslandshg38CpGIslands
A GRanges object with 31144 ranges and 7 metadata columns:
Number of bases in each island
Number of CGs in each island
Number of Cs or Gs in the island
Percent CGs in the island
Percent of Cs or Gs in the island
Unclear what this column means
Genomic loci that are consistently methylated (“ultra-stable”)
across many human tissues and diseases, mapped to GRCh38.
Regions correspond to Illumina array probe loci (cg identifiers)
derived as in Edgar et al.
(2014), and are intended for QC and summary metrics (e.g.,
addHyperStableFraction()).
hg38UltraStableProbeshg38UltraStableProbes
A GRanges object with 974 ranges and 1 metadata column:
Character cg identifier for the probe/locus (e.g.,
"cg11733071").
Seqnames: numeric chromosomes "1"–"22" (no "chr" prefix; UCSC
style
can be set if needed).
Strand: "*" for all ranges.
Widths: 3 bp windows (probe CpG ±1 bp).
Genome metadata: currently unset; set to "hg38" if you need an
explicit
tag.
When combining with other GRanges, harmonise styles/metadata as needed,
e.g.
use GenomeInfoDb::seqlevelsStyle() to convert to "UCSC" ("chr1", …)
and GenomeInfoDb::genome() to set "hg38".
Processed from public array resources following Edgar et al. (2014).
Edgar R, Tan PPC, Portales-Casamar E, Pavlidis P (2014). Meta-analysis of human methylomes reveals stably methylated sequences surrounding CpG islands associated with high gene expression. https://pubmed.ncbi.nlm.nih.gov/25493099/
data(hg38UltraStableProbes) # Basic overview hg38UltraStableProbes length(hg38UltraStableProbes) # 974 all(GenomicRanges::width(hg38UltraStableProbes) == 3) # TRUE (3-bp windows) # The object uses numeric chromosomes and an unset genome tag GenomeInfoDb::seqlevels(hg38UltraStableProbes)[1:5] GenomeInfoDb::genome(hg38UltraStableProbes) # empty # Harmonise style/metadata if needed gr <- hg38UltraStableProbes GenomeInfoDb::seqlevelsStyle(gr) <- "UCSC" # or "NCBI" / "Ensembl" #' # (for 1,2... instead of chr1, chr2...) GenomeInfoDb::genome(gr) <- "hg38" # or "GRCh38" # Count overlaps with a toy region toy <- GenomicRanges::GRanges("1", IRanges::IRanges(951160, 951170)) GenomicRanges::countOverlaps(toy, hg38UltraStableProbes) # With UCSC-style example toy_ucsc <- GenomicRanges::GRanges("chr1", IRanges::IRanges(951160, 951170)) GenomicRanges::countOverlaps(toy_ucsc, gr) # after style harmonisation abovedata(hg38UltraStableProbes) # Basic overview hg38UltraStableProbes length(hg38UltraStableProbes) # 974 all(GenomicRanges::width(hg38UltraStableProbes) == 3) # TRUE (3-bp windows) # The object uses numeric chromosomes and an unset genome tag GenomeInfoDb::seqlevels(hg38UltraStableProbes)[1:5] GenomeInfoDb::genome(hg38UltraStableProbes) # empty # Harmonise style/metadata if needed gr <- hg38UltraStableProbes GenomeInfoDb::seqlevelsStyle(gr) <- "UCSC" # or "NCBI" / "Ensembl" #' # (for 1,2... instead of chr1, chr2...) GenomeInfoDb::genome(gr) <- "hg38" # or "GRCh38" # Count overlaps with a toy region toy <- GenomicRanges::GRanges("1", IRanges::IRanges(951160, 951170)) GenomicRanges::countOverlaps(toy, hg38UltraStableProbes) # With UCSC-style example toy_ucsc <- GenomicRanges::GRanges("chr1", IRanges::IRanges(951160, 951170)) GenomicRanges::countOverlaps(toy_ucsc, gr) # after style harmonisation above
Predicate helper used in input validation and branching logic.
is.qseaSet(x)is.qseaSet(x)
x |
|
logical(1): TRUE if x inherits from class "qseaSet",
otherwise FALSE.
qsea::createQseaSet(), qsea::getSampleTable(), base::inherits()
data(exampleTumourNormal, package = "mesa") # TRUE for qseaSet objects exampleTumourNormal %>% is.qseaSet() # FALSE for non-qseaSet objects iris %>% is.qseaSet()data(exampleTumourNormal, package = "mesa") # TRUE for qseaSet objects exampleTumourNormal %>% is.qseaSet() # FALSE for non-qseaSet objects iris %>% is.qseaSet()
Extend dplyr::left_join() to operate on the sampleTable slot of a
mesaDimRed object.
## S3 method for class 'mesaDimRed' left_join( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), keep = NULL, ... )## S3 method for class 'mesaDimRed' left_join( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), keep = NULL, ... )
x |
|
y |
|
by |
|
copy |
|
suffix |
|
keep |
|
... |
Additional arguments to |
A mesaDimRed object:
sampleTable updated with y via a left join.
new <- data.frame(sample_name = c("Colon1_N", "Colon2_N"), foo = c(1, 2)) exampleTumourNormal %>% getPCA() %>% left_join(new, by = join_by(sample_name)) %>% getSampleTable()new <- data.frame(sample_name = c("Colon1_N", "Colon2_N"), foo = c(1, 2)) exampleTumourNormal %>% getPCA() %>% left_join(new, by = join_by(sample_name)) %>% getSampleTable()
Extends dplyr::left_join() to merge a data frame into a qseaSet's
sampleTable. Useful for adding annotations or metadata to samples.
## S3 method for class 'qseaSet' left_join( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), keep = NULL, ... )## S3 method for class 'qseaSet' left_join( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), keep = NULL, ... )
x |
|
y |
|
by |
|
copy |
|
suffix |
|
keep |
|
... |
Additional arguments passed to |
A qseaSet object with its sampleTable updated:
existing rows preserved,
additional columns from y merged by sample name or other keys,
duplicate column names disambiguated with suffix.
qsea::getSampleTable() to view metadata,
mutate.qseaSet(), filter.qseaSet() for other dplyr verbs,
dplyr::left_join() for join semantics.
data(exampleTumourNormal, package = "mesa") # Join 'patient' (y) to 'sample_name' (x) newData <- tibble::tibble( patient = c("Colon1", "Colon2", "Lung1", "Lung3"), new = 1:4 ) exampleTumourNormal %>% left_join(newData, by = c("sample_name" = "patient")) %>% qsea::getSampleTable()data(exampleTumourNormal, package = "mesa") # Join 'patient' (y) to 'sample_name' (x) newData <- tibble::tibble( patient = c("Colon1", "Colon2", "Lung1", "Lung3"), new = 1:4 ) exampleTumourNormal %>% left_join(newData, by = c("sample_name" = "patient")) %>% qsea::getSampleTable()
Convert genomic intervals from UCSC hg19 to hg38/GRCh38 using a preloaded chain object.
liftOverHg19(grOrDf)liftOverHg19(grOrDf)
grOrDf |
|
Internally, the input is coerced to a GRanges (adding "chr" if needed),
then lifted over via rtracklayer with the chain stored in
mesa::hg19ToHg38.over.chain. Unmappable or split mappings are handled by
rtracklayer::liftOver(), and unmapped intervals are discarded when the
result is unlisted. The returned object is tagged as "hg38".
A GRanges-class in hg38 coordinates (with
GenomeInfoDb::genome(x) <- "hg38"). Intervals that cannot be mapped by the
chain are dropped (i.e., may return fewer ranges than provided).
rtracklayer::liftOver(), GenomicRanges::GRanges
# Data.frame input; mix of 'chr' and no 'chr' is fine data.frame( seqnames = c("1", "chr2"), start = c(100000, 200000), end = c(100100, 200100) ) %>% liftOverHg19() %>% { GenomeInfoDb::genome(.) } # GRanges input (some intervals may not map and can be dropped) gr <- GenomicRanges::GRanges("chr1", IRanges::IRanges(100000, 100300)) liftOverHg19(gr)# Data.frame input; mix of 'chr' and no 'chr' is fine data.frame( seqnames = c("1", "chr2"), start = c(100000, 200000), end = c(100100, 200100) ) %>% liftOverHg19() %>% { GenomeInfoDb::genome(.) } # GRanges input (some intervals may not map and can be dropped) gr <- GenomicRanges::GRanges("chr1", IRanges::IRanges(100000, 100300)) liftOverHg19(gr)
Construct a tibble of all pairwise contrasts between levels of a categorical variable in the sample table of a qsea::qseaSet.
makeAllContrasts(qseaSet, variable)makeAllContrasts(qseaSet, variable)
qseaSet |
|
variable |
|
Levels are inferred from unique(qsea::getSampleTable(qseaSet)[[variable]]).
Pairs are formed between all distinct levels; no self-contrasts are included.
A tibble with two columns:
group1 – the first level of the pair,
group2 – the second level of the pair.
Each row represents one unordered pair of distinct levels (i.e., all
combinations without repetition).
Other DMR-detection:
calculateDMRs(),
fitQseaGLM(),
getDMRsData()
data(exampleTumourNormal, package = "mesa") # All pairwise contrasts among levels of 'type' exampleTumourNormal %>% makeAllContrasts("type")data(exampleTumourNormal, package = "mesa") # All pairwise contrasts among levels of 'type' exampleTumourNormal %>% makeAllContrasts("type")
Build a qseaSet from a sampleTable that lists BAM files and sample
metadata, tile the genome into fixed windows, optionally remove blacklisted
regions, and load coverage and (optionally) CNV information according to the
selected methods. This is typically the first step in a mesa/qsea workflow.
makeQset( sampleTable, BSgenome, chrSelect, windowSize = 300, CNVwindowSize = 1e+06, fragmentType = NULL, fragmentLength = NULL, fragmentSD = NULL, CNVmethod = "HMMdefault", coverageMethod = "PairedAndR1s", minMapQual = 10, minInsertSize = 70, maxInsertSize = 1000, minReferenceLength = 30, badRegions = NULL, properPairsOnly = FALSE, hmmCopyGC = NULL, hmmCopyMap = NULL, maxPatternDensity = 0.05, enrichmentMethod = "blind1-15", parallel = getMesaParallel() )makeQset( sampleTable, BSgenome, chrSelect, windowSize = 300, CNVwindowSize = 1e+06, fragmentType = NULL, fragmentLength = NULL, fragmentSD = NULL, CNVmethod = "HMMdefault", coverageMethod = "PairedAndR1s", minMapQual = 10, minInsertSize = 70, maxInsertSize = 1000, minReferenceLength = 30, badRegions = NULL, properPairsOnly = FALSE, hmmCopyGC = NULL, hmmCopyMap = NULL, maxPatternDensity = 0.05, enrichmentMethod = "blind1-15", parallel = getMesaParallel() )
sampleTable |
|
BSgenome |
|
chrSelect |
|
windowSize |
|
CNVwindowSize |
|
fragmentType |
|
fragmentLength |
|
fragmentSD |
|
CNVmethod |
|
coverageMethod |
|
minMapQual |
|
minInsertSize |
|
maxInsertSize |
|
minReferenceLength |
|
badRegions |
|
properPairsOnly |
|
hmmCopyGC |
|
hmmCopyMap |
|
maxPatternDensity |
|
enrichmentMethod |
|
parallel |
|
Inputs & requirements
sampleTable must include at least:
sample_name (unique per sample),
file_name (path to MeDIP/capture BAM),
group (string label).
If the selected CNVmethod uses inputs ("HMMdefault", "qseaInput"),
also include input_file (path to matched Input BAM).
BAMs should be coordinate-sorted. For paired data, running samtools fixmate
is recommended so MAPQ tags are available (see minMapQual note below).
BSgenome must be an installed genome package string (e.g.
"BSgenome.Hsapiens.NCBI.GRCh38"), which provides chromosome lengths and
sequences for tiling windows.
Windows & blacklist
Chromosomes in chrSelect are tiled into non-overlapping windows of size
windowSize (bp). Windows overlapping badRegions (if provided) are
removed.
Coverage loading
coverageMethod = "PairedAndR1s" loads proper pairs and, optionally,
high-MAPQ R1 singletons; governed by minMapQual, minInsertSize,
maxInsertSize, properPairsOnly, minReferenceLength.
coverageMethod = "qseaPaired" delegates to qsea::addCoverage() with
paired settings.
fragmentType can set defaults for fragmentLength/fragmentSD
("Sheared"
or "cfDNA"); otherwise supply both explicitly.
CNV options
"qseaInput": run qsea::addCNV() using input_file BAMs.
"HMMdefault": use mesa's addHMMcopyCNV() with supplied defaults for
GRCh38
GC/mappability tracks (objects like gc_hg38_1000kb, map_hg38_1000kb,
chosen by CNVwindowSize).
"MeCap": estimate CNV from MeCap BAMs (file_name).
"None": do not compute CNV.
Parallelisation
If parallel = TRUE, computation uses the currently registered
BiocParallel backend (see BiocParallel::register()); otherwise runs
serially.
Use setMesaParallel() to toggle package-wide.
Additional processing
Adds CpG density via qsea::addPatternDensity(pattern = "CG"), and
enrichment parameters, allowing for estimation of beta values.
A qseaSet containing:
tiled (and optionally blacklisted) genomic windows;
the input sampleTable as sample metadata;
loaded coverage according to coverageMethod;
CNV results depending on CNVmethod;
CpG density and enrichment parameters;
recorded processing parameters in @parameters.
qsea::createQseaSet(), qsea::addCoverage(), qsea::addCNV(),
addHMMcopyCNV(), setMesaParallel(), BSgenome::available.genomes()
# Minimal runnable sketch if MEDIPSData is installed if (requireNamespace("MEDIPSData", quietly = TRUE)) { sampleTable <- data.frame( sample_name = c("Normal1", "Tumour1"), group = c("Normal", "Tumour"), file_name = c( system.file("extdata", "NSCLC_MeDIP_1N_fst_chr_20_21_22.bam", package = "MEDIPSData", mustWork = TRUE), system.file("extdata", "NSCLC_MeDIP_1T_fst_chr_20_21_22.bam", package = "MEDIPSData", mustWork = TRUE) ) ) sampleTable %>% makeQset( BSgenome = "BSgenome.Hsapiens.UCSC.hg19", chrSelect = paste0("chr", 20:22), windowSize = 300, fragmentLength = 200, fragmentSD = 50, CNVmethod = "None", coverageMethod = "PairedAndR1s", properPairsOnly = FALSE, minMapQual = 10 ) }# Minimal runnable sketch if MEDIPSData is installed if (requireNamespace("MEDIPSData", quietly = TRUE)) { sampleTable <- data.frame( sample_name = c("Normal1", "Tumour1"), group = c("Normal", "Tumour"), file_name = c( system.file("extdata", "NSCLC_MeDIP_1N_fst_chr_20_21_22.bam", package = "MEDIPSData", mustWork = TRUE), system.file("extdata", "NSCLC_MeDIP_1T_fst_chr_20_21_22.bam", package = "MEDIPSData", mustWork = TRUE) ) ) sampleTable %>% makeQset( BSgenome = "BSgenome.Hsapiens.UCSC.hg19", chrSelect = paste0("chr", 20:22), windowSize = 300, fragmentLength = 200, fragmentSD = 50, CNVmethod = "None", coverageMethod = "PairedAndR1s", properPairsOnly = FALSE, minMapQual = 10 ) }
Create a wide table for ML/visualisation where rows are samples and columns are genomic windows, using one normalisation/measure.
makeTransposedTable(qseaSet, normMethod = "nrpm", ...)makeTransposedTable(qseaSet, normMethod = "nrpm", ...)
qseaSet |
|
normMethod |
|
... |
tidyselect specification or |
Internally obtains a window × sample matrix for normMethod, transposes it
to sample × window, and (if requested) appends selected sample-table
columns. Window columns are typically named "chr:start-end". If
measure suffixes are present in column names, they may be cleaned to
bare sample/window names (see removeNormMethodSuffix()).
A tibble with one row per sample and one column per genomic window, plus any appended sample-level metadata.
getDataTable(), removeNormMethodSuffix(), countWindowsAboveCutoff()
Other table-helpers:
getBetaTable(),
getCountTable(),
getDataTable(),
getNRPMTable(),
getSampleGroups2(),
removeLibraryFactors(),
removeNormMethodSuffix()
data(exampleTumourNormal, package = "mesa") # NRPM features (sample × first few windows) with a group column appended exampleTumourNormal %>% makeTransposedTable(normMethod = "nrpm", group) %>% dplyr::select(1:6) %>% head() # Beta features; inspect dimensions exampleTumourNormal %>% makeTransposedTable(normMethod = "beta") %>% dim()data(exampleTumourNormal, package = "mesa") # NRPM features (sample × first few windows) with a group column appended exampleTumourNormal %>% makeTransposedTable(normMethod = "nrpm", group) %>% dplyr::select(1:6) %>% head() # Beta features; inspect dimensions exampleTumourNormal %>% makeTransposedTable(normMethod = "beta") %>% dim()
Fixed-size bins with average mappability per bin. Bins are ordered by chromosome size (not strictly numeric).
data(map_hg38_1000kb); data(map_hg38_500kb); data(map_hg38_50kb) map_hg38_50kb map_hg38_500kbdata(map_hg38_1000kb); data(map_hg38_500kb); data(map_hg38_50kb) map_hg38_50kb map_hg38_500kb
One of:
A data.table/data.frame with columns:
Chromosome (e.g., "chr1", ..., "chrX", "chrY").
0-based start of the bin.
1-based end of the bin.
Average mappability in the bin (0–1).
A GRanges with genomic bins and mcols(.)$map storing
the average mappability (0–1) per bin.
An object of class data.table (inherits from data.frame) with 61775 rows and 4 columns.
An object of class data.table (inherits from data.frame) with 6188 rows and 4 columns.
map_hg38_1000kb, map_hg38_500kb, and
map_hg38_50kb return objects as described in @format with
bin sizes of 1000 kb, 500 kb, and 50 kb, respectively.
https://github.com/broadinstitute/ichorCNA
Aggregates one or more dimensionality reduction (DR) results (e.g., PCA/UMAP) computed on a common set of samples.
mesaDimRed(res, sampleTable, samples, params, dataTable = data.frame()) ## S4 method for signature 'mesaDimRed' show(object)mesaDimRed(res, sampleTable, samples, params, dataTable = data.frame()) ## S4 method for signature 'mesaDimRed' show(object)
res |
|
sampleTable |
|
samples |
|
params |
|
dataTable |
|
object |
|
A mesaDimRed object:
stores DR results in res,
carries sample metadata in sampleTable,
records the samples in samples,
and persists parameters/data in params / dataTable.
reslist
Individual DR result objects (e.g., mesaPCA, mesaUMAP).
sampleTabledata.frame
Sample annotations; row names are sample IDs.
samplescharacter()
Vector of sample IDs used.
paramslist
Parameters used to generate results in res.
dataTabledata.frame
Optional matrix/data used to compute DR (for reproducibility).
st <- data.frame(sample_name = c("S1", "S2"), group = c("A", "B"), row.names = "sample_name") md <- mesaDimRed(res = list(), sampleTable = st, samples = rownames(st), params = list(), dataTable = data.frame()) mdst <- data.frame(sample_name = c("S1", "S2"), group = c("A", "B"), row.names = "sample_name") md <- mesaDimRed(res = list(), sampleTable = st, samples = rownames(st), params = list(), dataTable = data.frame()) md
Stores a PCA fit (from stats::prcomp()) computed over methylation windows.
mesaPCA(prcomp, windows) ## S4 method for signature 'mesaPCA' show(object)mesaPCA(prcomp, windows) ## S4 method for signature 'mesaPCA' show(object)
prcomp |
|
windows |
|
object |
|
A mesaPCA object containing the PCA fit and window IDs.
prcompprcomp
A PCA fit returned by stats::prcomp().
windowscharacter()
Window IDs used in the PCA.
set.seed(1) x <- matrix(rnorm(20), nrow = 5, ncol = 4, dimnames = list(paste0("S", 1:5), paste0("W", 1:4))) pc <- stats::prcomp(x, center = TRUE, scale. = FALSE) mp <- mesaPCA(prcomp = pc, windows = colnames(x)) mpset.seed(1) x <- matrix(rnorm(20), nrow = 5, ncol = 4, dimnames = list(paste0("S", 1:5), paste0("W", 1:4))) pc <- stats::prcomp(x, center = TRUE, scale. = FALSE) mp <- mesaPCA(prcomp = pc, windows = colnames(x)) mp
Stores per-sample coordinates from a UMAP embedding computed over methylation windows.
mesaUMAP(points, windows) ## S4 method for signature 'mesaUMAP' show(object)mesaUMAP(points, windows) ## S4 method for signature 'mesaUMAP' show(object)
points |
|
windows |
|
object |
|
A mesaUMAP object containing UMAP coordinates and window IDs.
pointsdata.frame
One row per sample with UMAP coordinates (e.g., UMAP1, UMAP2).
Row names are sample IDs.
windowscharacter()
Window IDs used to compute the embedding.
pts <- data.frame(UMAP1 = c(0.1, -0.2, 0.0), UMAP2 = c(0.3, 0.1, -0.1)) rownames(pts) <- paste0("S", 1:3) mu <- mesaUMAP(points = pts, windows = c("w1", "w2", "w3")) mupts <- data.frame(UMAP1 = c(0.1, -0.2, 0.0), UMAP2 = c(0.3, 0.1, -0.1)) rownames(pts) <- paste0("S", 1:3) mu <- mesaUMAP(points = pts, windows = c("w1", "w2", "w3")) mu
Create a new synthetic sample in a qseaSet by mixing reads from two
existing samples in user-specified proportions. Useful for benchmarking,
downsampling experiments, or simulating tumour–normal mixtures.
mixSamples( qseaSet, sample1, sample2, nReadsTotal, proportion, newName = NULL, groupName = NULL, onlyNew = FALSE, renormalise = TRUE )mixSamples( qseaSet, sample1, sample2, nReadsTotal, proportion, newName = NULL, groupName = NULL, onlyNew = FALSE, renormalise = TRUE )
qseaSet |
|
sample1 |
|
sample2 |
|
nReadsTotal |
|
proportion |
|
newName |
|
groupName |
|
onlyNew |
|
renormalise |
|
Note that if the qseaSet windows have been filtered prior to using this, the
fraction of fragments present in the current qseaSet is calculated, such that
the total number of reads would have been approximately nReadsTotal. E.g.
if there are 50% of the total fragments in the windows present in the current
samples, 0.5*nReadsTotal fragments will be sampled.
Input validation ensures sample1/sample2 exist, proportion in [0,1],
and nReadsTotal is non-negative.
The mixing strategy (e.g., proportional allocation vs sampling) follows
the package’s implementation; set renormalise = TRUE to recompute
offsets/enrichment after adding the new sample if required by your workflow.
A qseaSet containing the new synthetic sample:
If onlyNew = TRUE, a qseaSet with one (mixed) sample.
If onlyNew = FALSE, the input qseaSet plus the mixed sample.
The sampleTable, counts, and relevant slots are updated consistently.
mixThreeQsetSamples(), downSample(), addNormalisation()
Other sample-simulation:
mixThreeQsetSamples()
data(exampleTumourNormal, package = "mesa") # Mix two samples 50/50 into ~100k total fragments; append to the qseaSet exampleTumourNormal %>% mixSamples("Colon1_T", "Colon1_N", nReadsTotal = 100000, proportion = 0.5, renormalise = FALSE ) %>% # Only a few reads are included in this small subset of windows (82): getCountTable() %>% pull(Mix_Colon1_T_Colon1_N_0.5) %>% sum() # Mix two samples 80/20 and return only the synthetic sample, with an # explicit name and group exampleTumourNormal %>% mixSamples("Colon1_T", "Colon1_N", nReadsTotal = 50000, proportion = 0.8, newName = "Mix_Colon1_T_0.8_Colon1_N_0.2", groupName = "Synthetic", onlyNew = TRUE, renormalise = FALSE ) %>% # Only a few reads are included in this small subset of windows (45): getCountTable() %>% dplyr::pull(Mix_Colon1_T_0.8_Colon1_N_0.2) %>% sum()data(exampleTumourNormal, package = "mesa") # Mix two samples 50/50 into ~100k total fragments; append to the qseaSet exampleTumourNormal %>% mixSamples("Colon1_T", "Colon1_N", nReadsTotal = 100000, proportion = 0.5, renormalise = FALSE ) %>% # Only a few reads are included in this small subset of windows (82): getCountTable() %>% pull(Mix_Colon1_T_Colon1_N_0.5) %>% sum() # Mix two samples 80/20 and return only the synthetic sample, with an # explicit name and group exampleTumourNormal %>% mixSamples("Colon1_T", "Colon1_N", nReadsTotal = 50000, proportion = 0.8, newName = "Mix_Colon1_T_0.8_Colon1_N_0.2", groupName = "Synthetic", onlyNew = TRUE, renormalise = FALSE ) %>% # Only a few reads are included in this small subset of windows (45): getCountTable() %>% dplyr::pull(Mix_Colon1_T_0.8_Colon1_N_0.2) %>% sum()
Extend dplyr::mutate() to operate on the sampleTable slot of a
mesaDimRed object.
## S3 method for class 'mesaDimRed' mutate(.data, ...)## S3 method for class 'mesaDimRed' mutate(.data, ...)
.data |
|
... |
Arguments passed to |
A mesaDimRed object:
sampleTable updated with the mutated columns.
Sample identity is preserved; attempts to alter sample_name are rejected.
data(exampleTumourNormal, package = "mesa") md <- exampleTumourNormal %>% getPCA() %>% mutate(group2 = paste0(group, "_2")) stopifnot("group2" %in% colnames(getSampleTable(md)))data(exampleTumourNormal, package = "mesa") md <- exampleTumourNormal %>% getPCA() %>% mutate(group2 = paste0(group, "_2")) stopifnot("group2" %in% colnames(getSampleTable(md)))
Extends dplyr::mutate() to add or modify columns in a qseaSet's
sampleTable.
## S3 method for class 'qseaSet' mutate(.data, ...)## S3 method for class 'qseaSet' mutate(.data, ...)
.data |
|
... |
Column transformations passed to |
The order of samples is preserved.
The sample_name column cannot be changed with this function; use
renameQsetNames() or renameSamples() if sample names must be updated.
A qseaSet object with its sampleTable updated:
new columns are added,
existing columns are modified,
sample_name remains unchanged.
qsea::getSampleTable() to inspect metadata,
renameSamples() and renameQsetNames() for renaming,
filter.qseaSet() and selectQset() for other dplyr verbs.
data(exampleTumourNormal, package = "mesa") # Add a new logical column based on age exampleTumourNormal %>% mutate(over70 = age > 70) %>% qsea::getSampleTable() # Recode gender (better practice: use dplyr::case_when() or # stringr::str_replace()) exampleTumourNormal %>% mutate(gender = ifelse(gender == "F", "Female", "Male")) %>% qsea::getSampleTable() # Change group by removing digits from sample_name exampleTumourNormal %>% mutate(group = stringr::str_remove(sample_name, "[0-9]")) %>% qsea::getSampleTable()data(exampleTumourNormal, package = "mesa") # Add a new logical column based on age exampleTumourNormal %>% mutate(over70 = age > 70) %>% qsea::getSampleTable() # Recode gender (better practice: use dplyr::case_when() or # stringr::str_replace()) exampleTumourNormal %>% mutate(gender = ifelse(gender == "F", "Female", "Male")) %>% qsea::getSampleTable() # Change group by removing digits from sample_name exampleTumourNormal %>% mutate(group = stringr::str_remove(sample_name, "[0-9]")) %>% qsea::getSampleTable()
Convert wide-format DMR results into a long-format table with explicit columns for contrasts, effect sizes, and significance values.
pivotDMRsLonger(DMRtable, FDRthres = 0.05, makePositive = FALSE)pivotDMRsLonger(DMRtable, FDRthres = 0.05, makePositive = FALSE)
DMRtable |
|
FDRthres |
|
makePositive |
|
A tibble:
pivotDMRsLonger(): returns a long-format table with one row per
DMR–contrast combination, including columns group1, group2,
deltaBeta, log2FC, and adjPval.
tidyr::pivot_longer(), summariseDMRsByContrast()
Other DMR-helpers:
summariseDMRsByContrast(),
summariseDMRsByGene(),
writeDMRsToBed(),
writeDMRsToExcel()
data(exampleTumourNormal, package = "mesa") # Convert results to long format and filter at custom FDR threshold exampleTumourNormal %>% calculateDMRs( variable = "type", contrasts = "LUAD_vs_NormalLung", FDRthres = 0.1 ) %>% pivotDMRsLonger(FDRthres = 0.1)data(exampleTumourNormal, package = "mesa") # Convert results to long format and filter at custom FDR threshold exampleTumourNormal %>% calculateDMRs( variable = "type", contrasts = "LUAD_vs_NormalLung", FDRthres = 0.1 ) %>% pivotDMRsLonger(FDRthres = 0.1)
Plot per-window copy-number estimates stored in a qseaSet as a heatmap
using ComplexHeatmap. Each column is a sample; rows are genome windows.
plotCNVheatmap( qseaSet, sampleAnnotation = NULL, annotationColors = NA, clusterRows = TRUE )plotCNVheatmap( qseaSet, sampleAnnotation = NULL, annotationColors = NA, clusterRows = TRUE )
qseaSet |
|
sampleAnnotation |
tidyselect specification, |
annotationColors |
|
clusterRows |
|
Assumes CNV values are available per window and sample. Rows are windows
(typically in genomic order if clusterRows = FALSE), columns are samples.
Sample annotations (and optional colours) are added when sampleAnnotation
and annotationColors are provided.
Draws a heatmap on the active device and (invisibly) returns the underlying
ComplexHeatmap object for further composition with
draw.
addHMMcopyCNV(), runHMMcopy(),
Heatmap,
qsea::addCNV()
Other CNV:
addHMMcopyCNV(),
removeCNV(),
runHMMCopy()
data(exampleTumourNormal, package = "mesa") # Basic CNV heatmap with sample annotations exampleTumourNormal %>% plotCNVheatmap(sampleAnnotation = c(tumour, type)) # Custom annotation colours; disable row clustering exampleTumourNormal %>% plotCNVheatmap( sampleAnnotation = tumour, annotationColors = list( tumour = c(Tumour = "firebrick4", Normal = "blue") ), clusterRows = FALSE )data(exampleTumourNormal, package = "mesa") # Basic CNV heatmap with sample annotations exampleTumourNormal %>% plotCNVheatmap(sampleAnnotation = c(tumour, type)) # Custom annotation colours; disable row clustering exampleTumourNormal %>% plotCNVheatmap( sampleAnnotation = tumour, annotationColors = list( tumour = c(Tumour = "firebrick4", Normal = "blue") ), clusterRows = FALSE )
Compute and plot the correlation matrix across samples (or group means) using the selected normalisation measure and optional region filters.
plotCorrelationMatrix( qseaSet, regionsToOverlap = NULL, useGroupMeans = FALSE, sampleAnnotation = NULL, normMethod = "nrpm", minEnrichment = 3, annotationColors = NA, minDensity = 0, ... )plotCorrelationMatrix( qseaSet, regionsToOverlap = NULL, useGroupMeans = FALSE, sampleAnnotation = NULL, normMethod = "nrpm", minEnrichment = 3, annotationColors = NA, minDensity = 0, ... )
qseaSet |
|
regionsToOverlap |
|
useGroupMeans |
|
sampleAnnotation |
tidyselect specification or |
normMethod |
|
minEnrichment |
|
annotationColors |
|
minDensity |
|
... |
Additional arguments forwarded to |
Windows are optionally restricted by regionsToOverlap and filtered by
minDensity.
Correlations are computed on the chosen normMethod after any group
averaging.
For "beta", entries below minEnrichment are set to NA to down-weight
low-enrichment windows.
A pheatmap::pheatmap object.
plotRegionsHeatmap(), getDataTable(), pheatmap::pheatmap()
data(exampleTumourNormal, package = "mesa") # By default uses NRPM exampleTumourNormal %>% plotCorrelationMatrix() # Using beta values and adding sample annotations exampleTumourNormal %>% plotCorrelationMatrix(normMethod = "beta", sampleAnnotation = c(tumour, patient))data(exampleTumourNormal, package = "mesa") # By default uses NRPM exampleTumourNormal %>% plotCorrelationMatrix() # Using beta values and adding sample annotations exampleTumourNormal %>% plotCorrelationMatrix(normMethod = "beta", sampleAnnotation = c(tumour, patient))
Visualise PCA or UMAP coordinates stored in a mesaDimRed object. Wrappers
such as BiocGenerics::plotPCA() and plotUMAP() provide convenient shortcuts for common
use cases.
plotDimRed( object, components = list(c(1, 2), c(2, 3)), colour = NULL, colourPalette = NULL, NAcolour = "grey50", symDivColourScale = FALSE, shape = NULL, shapePalette = NULL, NAshape = NULL, showSampleNames = FALSE, pointSize = 2, alpha = 1, plotlyAnnotations = "" )plotDimRed( object, components = list(c(1, 2), c(2, 3)), colour = NULL, colourPalette = NULL, NAcolour = "grey50", symDivColourScale = FALSE, shape = NULL, shapePalette = NULL, NAshape = NULL, showSampleNames = FALSE, pointSize = 2, alpha = 1, plotlyAnnotations = "" )
object |
|
components |
|
colour |
|
colourPalette |
|
NAcolour |
|
symDivColourScale |
|
shape |
|
shapePalette |
|
NAshape |
|
showSampleNames |
|
pointSize |
|
alpha |
|
plotlyAnnotations |
|
A list of ggplot2 objects, one for each combination of:
component pairs in components, and
variables specified in colour.
Each plot depicts the requested dimensions with aesthetics mapped as specified.
Other dimred-helpers:
getPCA(),
plotUMAP()
data(exampleTumourNormal, package = "mesa") # PCA: colour by group exampleTumourNormal %>% getPCA(nPC = 3) %>% plotDimRed(colour = "group") # UMAP: colour by group, shape by tissue exampleTumourNormal %>% getUMAP(n_neighbors = 5, min_dist = 1) %>% plotDimRed( colour = "group", shape = "tissue" ) # Show sample names exampleTumourNormal %>% getPCA(nPC = 3) %>% plotDimRed( colour = "group", showSampleNames = TRUE )data(exampleTumourNormal, package = "mesa") # PCA: colour by group exampleTumourNormal %>% getPCA(nPC = 3) %>% plotDimRed(colour = "group") # UMAP: colour by group, shape by tissue exampleTumourNormal %>% getUMAP(n_neighbors = 5, min_dist = 1) %>% plotDimRed( colour = "group", shape = "tissue" ) # Show sample names exampleTumourNormal %>% getPCA(nPC = 3) %>% plotDimRed( colour = "group", showSampleNames = TRUE )
Visualise the overlap of significant DMR sets across contrasts (columns
ending
with *_adjPval) using an UpSet plot.
plotDMRUpset(DMRtable, string = NULL, removeVS = FALSE, minAdjPval = 0.05, ...)plotDMRUpset(DMRtable, string = NULL, removeVS = FALSE, minAdjPval = 0.05, ...)
DMRtable |
|
string |
|
removeVS |
|
minAdjPval |
|
... |
Additional arguments forwarded to |
The function discovers DMR sets by locating columns that end with
"_adjPval".
For each such column, a logical membership is formed at the chosen FDR cutoff
(minAdjPval). Optionally, set names are simplified with removeVS, and
then
subset with string if provided. The resulting membership matrix is
visualised
with UpSetR.
Draws an UpSet plot on the active device and invisibly returns the result
from UpSetR::upset() (for further customization if needed).
calculateDMRs(), UpSetR::upset()
data(exampleTumourNormal, package = "mesa") # Overlap of significant DMR sets across contrasts (default FDR 0.05) exampleTumourNormal %>% calculateDMRs(variable = "type", contrasts = "all_vs_NormalLung") %>% plotDMRUpset() # Clean set names by dropping the '_vs_*' suffix exampleTumourNormal %>% calculateDMRs(variable = "type", contrasts = "all_vs_NormalLung") %>% plotDMRUpset(removeVS = TRUE)data(exampleTumourNormal, package = "mesa") # Overlap of significant DMR sets across contrasts (default FDR 0.05) exampleTumourNormal %>% calculateDMRs(variable = "type", contrasts = "all_vs_NormalLung") %>% plotDMRUpset() # Clean set names by dropping the '_vs_*' suffix exampleTumourNormal %>% calculateDMRs(variable = "type", contrasts = "all_vs_NormalLung") %>% plotDMRUpset(removeVS = TRUE)
Plot sample signal over windows spanning a gene (± flanks) as a heatmap using ComplexHeatmap. The gene can be given as a HGNC symbol or Ensembl ID.
plotGeneHeatmap( qseaSet, gene, normMethod = "beta", useGroupMeans = FALSE, sampleAnnotation = NULL, minDensity = 0, minEnrichment = 3, maxScale = 1, clusterNum = NULL, annotationColors = NA, upstreamDist = 3000, scaleRows = FALSE, clusterCols = TRUE, mart = NULL, showSampleNames = NULL, downstreamDist = 1000, idType = NULL, ... )plotGeneHeatmap( qseaSet, gene, normMethod = "beta", useGroupMeans = FALSE, sampleAnnotation = NULL, minDensity = 0, minEnrichment = 3, maxScale = 1, clusterNum = NULL, annotationColors = NA, upstreamDist = 3000, scaleRows = FALSE, clusterCols = TRUE, mart = NULL, showSampleNames = NULL, downstreamDist = 1000, idType = NULL, ... )
qseaSet |
|
gene |
|
normMethod |
|
useGroupMeans |
|
sampleAnnotation |
tidyselect specification or |
minDensity |
|
minEnrichment |
|
maxScale |
|
clusterNum |
|
annotationColors |
|
upstreamDist |
|
scaleRows |
|
clusterCols |
|
mart |
|
showSampleNames |
|
downstreamDist |
|
idType |
|
... |
Additional arguments forwarded to ComplexHeatmap constructors. |
The function resolves the gene to genomic coordinates (using mart, or a
mart
stored on the object, or a built-in default for human builds), expands the
interval by upstreamDist/downstreamDist, filters windows by overlap and
minDensity, then draws a heatmap of "beta" or "nrpm". For "beta",
values
below minEnrichment are set to NA. If useGroupMeans = TRUE, samples are
aggregated by group prior to plotting. Column annotations can be added via
sampleAnnotation; colours can be customized via annotationColors.
Draws a heatmap on the active device and (invisibly) returns the underlying
ComplexHeatmap object (e.g., a Heatmap/HeatmapList) for further
composition
with draw.
plotRegionsHeatmap(), qsea::getSampleTable(), setMart(),
biomaRt::useMart(), ComplexHeatmap::Heatmap()
data(exampleTumourNormal, package = "mesa") # Basic gene heatmap (beta) with defaults tryCatch( exampleTumourNormal %>% plotGeneHeatmap("HOXA9"), error = function(e) message("Ensembl unavailable: ", conditionMessage(e)) ) # Add sample annotations (tidyselect bare names) and cluster columns into # 2 groups tryCatch( exampleTumourNormal %>% plotGeneHeatmap("HOXA9", sampleAnnotation = c(tumour, tissue), clusterNum = 2), error = function(e) message("Ensembl unavailable: ", conditionMessage(e)) ) # Custom colours and wider flanks tryCatch( exampleTumourNormal %>% plotGeneHeatmap("HOXA9", sampleAnnotation = tumour, annotationColors = list( tumour = c(Tumour = "firebrick4", Normal = "blue") ), upstreamDist = 1000, downstreamDist = 2000), error = function(e) message("Ensembl unavailable: ", conditionMessage(e)) )data(exampleTumourNormal, package = "mesa") # Basic gene heatmap (beta) with defaults tryCatch( exampleTumourNormal %>% plotGeneHeatmap("HOXA9"), error = function(e) message("Ensembl unavailable: ", conditionMessage(e)) ) # Add sample annotations (tidyselect bare names) and cluster columns into # 2 groups tryCatch( exampleTumourNormal %>% plotGeneHeatmap("HOXA9", sampleAnnotation = c(tumour, tissue), clusterNum = 2), error = function(e) message("Ensembl unavailable: ", conditionMessage(e)) ) # Custom colours and wider flanks tryCatch( exampleTumourNormal %>% plotGeneHeatmap("HOXA9", sampleAnnotation = tumour, annotationColors = list( tumour = c(Tumour = "firebrick4", Normal = "blue") ), upstreamDist = 1000, downstreamDist = 2000), error = function(e) message("Ensembl unavailable: ", conditionMessage(e)) )
Annotate windows (e.g., promoters/exons/introns) and plot the distribution per sample as stacked/dodged/filled bars.
plotGenomicFeatureDistribution( qseaSet, cutoff = 1, barType = "stack", normMethod = "nrpm", genome = NULL, TxDb = NULL, annoDb = NULL )plotGenomicFeatureDistribution( qseaSet, cutoff = 1, barType = "stack", normMethod = "nrpm", genome = NULL, TxDb = NULL, annoDb = NULL )
qseaSet |
|
cutoff |
|
barType |
|
normMethod |
|
genome |
|
TxDb |
|
annoDb |
|
Feature classes are taken from region annotations available on the windows
(e.g., columns produced by annotateWindows() such as
shortAnno/annotation,
if present). Bars are positioned according to barType
(stack/dodge/fill).
A ggplot2 object showing counts (or proportions, for "fill")
of feature classes per sample above cutoff.
annotateWindows(), qsea::makeTable(), ggplot2::geom_bar()
Other annotation-summaries:
getGenomicFeatureDistribution()
# Recommended workflow: set genome globally setMesaGenome("hg38") data(exampleTumourNormal, package = "mesa") # Uses global hg38 setting exampleTumourNormal %>% plotGenomicFeatureDistribution(normMethod = "beta", cutoff = 0.75) # Override for specific analysis exampleTumourNormal %>% plotGenomicFeatureDistribution( genome = "mm10", normMethod = "nrpm", cutoff = 2 ) # Advanced: manual control (bypasses mesa genome system) exampleTumourNormal %>% plotGenomicFeatureDistribution( TxDb = TxDb.Mmusculus.UCSC.mm10.knownGene:: TxDb.Mmusculus.UCSC.mm10.knownGene, annoDb = "org.Mm.eg.db" )# Recommended workflow: set genome globally setMesaGenome("hg38") data(exampleTumourNormal, package = "mesa") # Uses global hg38 setting exampleTumourNormal %>% plotGenomicFeatureDistribution(normMethod = "beta", cutoff = 0.75) # Override for specific analysis exampleTumourNormal %>% plotGenomicFeatureDistribution( genome = "mm10", normMethod = "nrpm", cutoff = 2 ) # Advanced: manual control (bypasses mesa genome system) exampleTumourNormal %>% plotGenomicFeatureDistribution( TxDb = TxDb.Mmusculus.UCSC.mm10.knownGene:: TxDb.Mmusculus.UCSC.mm10.knownGene, annoDb = "org.Mm.eg.db" )
Generate publication-ready plots from the output of getPCA(). The function
supports flexible visual encodings (colour, shape, size) of sample-level
metadata and can return multiple plots across different PC pairs and
annotation variables.
plotPCA.mesaDimRed( object, components = list(c(1, 2), c(2, 3)), colour = NULL, colourPalette = NULL, NAcolour = "grey50", symDivColourScale = FALSE, shape = NULL, shapePalette = NULL, NAshape = NULL, showSampleNames = FALSE, pointSize = 2, alpha = 1, plotlyAnnotations = "" )plotPCA.mesaDimRed( object, components = list(c(1, 2), c(2, 3)), colour = NULL, colourPalette = NULL, NAcolour = "grey50", symDivColourScale = FALSE, shape = NULL, shapePalette = NULL, NAshape = NULL, showSampleNames = FALSE, pointSize = 2, alpha = 1, plotlyAnnotations = "" )
object |
|
components |
|
colour |
|
colourPalette |
|
NAcolour |
|
symDivColourScale |
|
shape |
|
shapePalette |
|
NAshape |
|
showSampleNames |
|
pointSize |
|
alpha |
|
plotlyAnnotations |
|
Shape defaults
"mixture" is used for non-diverging or discrete colour scales (or no
colour).
"filled+border" is used for diverging colour scales.
These defaults aim to keep categories visually separable for larger cohorts.
A list of ggplot objects—one per combination of components
pairs and colour variables—each depicting the chosen PCs with requested
aesthetics. Specifically:
one plot per components pair × per colour variable;
shapes/labels applied per shape/showSampleNames;
consistent axis labelling (PC variance if available).
getPCA(), plotUMAP(), plotDimRed(), qsea::getSampleTable()
data(exampleTumourNormal, package = "mesa") # Basic PCA plot (PC1 vs PC2) with defaults exampleTumourNormal %>% getPCA() %>% plotPCA() # Colour by sample group; show names exampleTumourNormal %>% getPCA() %>% plotPCA( colour = "group", showSampleNames = TRUE ) # Plot PC1 vs PC3; shape by tissue exampleTumourNormal %>% getPCA() %>% plotPCA( components = list(c(1, 3)), colour = "group", shape = "tissue" )data(exampleTumourNormal, package = "mesa") # Basic PCA plot (PC1 vs PC2) with defaults exampleTumourNormal %>% getPCA() %>% plotPCA() # Colour by sample group; show names exampleTumourNormal %>% getPCA() %>% plotPCA( colour = "group", showSampleNames = TRUE ) # Plot PC1 vs PC3; shape by tissue exampleTumourNormal %>% getPCA() %>% plotPCA( components = list(c(1, 3)), colour = "group", shape = "tissue" )
Plot sample signal over a set of regions as a heatmap using
ComplexHeatmap.
Regions are selected by overlap with regionsToOverlap, values are taken
from
the qseaSet, and optional annotations from the sample/region metadata can
be added.
plotRegionsHeatmap( qseaSet, regionsToOverlap = NULL, normMethod = "beta", sampleAnnotation = NULL, windowAnnotation = NULL, annotationColors = NA, useGroupMeans = FALSE, clusterRows = FALSE, clusterCols = TRUE, minEnrichment = 3, maxScale = 5, clusterNum = NULL, clip = 1e+09, minDensity = 0, annotationPosition = "right", title = NULL, showSampleNames = NULL, clusterMethod = "ward.D2", ... )plotRegionsHeatmap( qseaSet, regionsToOverlap = NULL, normMethod = "beta", sampleAnnotation = NULL, windowAnnotation = NULL, annotationColors = NA, useGroupMeans = FALSE, clusterRows = FALSE, clusterCols = TRUE, minEnrichment = 3, maxScale = 5, clusterNum = NULL, clip = 1e+09, minDensity = 0, annotationPosition = "right", title = NULL, showSampleNames = NULL, clusterMethod = "ward.D2", ... )
qseaSet |
|
regionsToOverlap |
|
normMethod |
|
sampleAnnotation |
|
windowAnnotation |
|
annotationColors |
|
useGroupMeans |
|
clusterRows |
|
clusterCols |
|
minEnrichment |
|
maxScale |
|
clusterNum |
|
clip |
|
minDensity |
|
annotationPosition |
|
title |
|
showSampleNames |
|
clusterMethod |
|
... |
Additional arguments forwarded to ComplexHeatmap constructors. |
Windows are filtered by overlap (if regionsToOverlap is given) and by
minDensity.
For "beta", low-enrichment values are set to NA using minEnrichment.
For "nrpm",
clip and maxScale help stabilise colour scaling for outliers. If
useGroupMeans = TRUE,
samples are aggregated by group before plotting.
Draws a heatmap on the active device and (invisibly) returns the underlying
ComplexHeatmap object (e.g., a Heatmap/HeatmapList) for further
composition with
draw.
qsea::makeTable(), ComplexHeatmap::Heatmap(),
draw,
calculateDMRs(), qsea::getSampleTable(), getWindows()
data(exampleTumourNormal, package = "mesa") # Compute regions (DMRs) to plot DMRs <- exampleTumourNormal %>% calculateDMRs(variable = "tumour", contrasts = "first") # Basic heatmap of beta values over DMRs exampleTumourNormal %>% plotRegionsHeatmap(DMRs) # Cluster rows, add sample and window annotations exampleTumourNormal %>% plotRegionsHeatmap(DMRs, clusterRows = TRUE, sampleAnnotation = c(tumour, tissue)) # Group means, 2 column clusters, and custom annotation colours exampleTumourNormal %>% plotRegionsHeatmap(regionsToOverlap = DMRs, clusterRows = TRUE, clusterNum = 2, sampleAnnotation = tumour, windowAnnotation = CpG_density, annotationColors = list( tumour = c("Tumour" = "firebrick4", "Normal" = "blue") ) )data(exampleTumourNormal, package = "mesa") # Compute regions (DMRs) to plot DMRs <- exampleTumourNormal %>% calculateDMRs(variable = "tumour", contrasts = "first") # Basic heatmap of beta values over DMRs exampleTumourNormal %>% plotRegionsHeatmap(DMRs) # Cluster rows, add sample and window annotations exampleTumourNormal %>% plotRegionsHeatmap(DMRs, clusterRows = TRUE, sampleAnnotation = c(tumour, tissue)) # Group means, 2 column clusters, and custom annotation colours exampleTumourNormal %>% plotRegionsHeatmap(regionsToOverlap = DMRs, clusterRows = TRUE, clusterNum = 2, sampleAnnotation = tumour, windowAnnotation = CpG_density, annotationColors = list( tumour = c("Tumour" = "firebrick4", "Normal" = "blue") ) )
Convenience wrapper around plotDimRed() for UMAP embeddings returned by
getUMAP(). Supports flexible visual encodings (colour, shape, size) of
sample-level metadata, and can return multiple plots across UMAP component
pairs and annotation variables.
plotUMAP( object, components = list(c(1, 2)), colour = NULL, colourPalette = NULL, NAcolour = "grey50", symDivColourScale = FALSE, shape = NULL, shapePalette = NULL, NAshape = NULL, showSampleNames = FALSE, pointSize = 2, alpha = 1, plotlyAnnotations = "" )plotUMAP( object, components = list(c(1, 2)), colour = NULL, colourPalette = NULL, NAcolour = "grey50", symDivColourScale = FALSE, shape = NULL, shapePalette = NULL, NAshape = NULL, showSampleNames = FALSE, pointSize = 2, alpha = 1, plotlyAnnotations = "" )
object |
|
components |
|
colour |
|
colourPalette |
|
NAcolour |
|
symDivColourScale |
|
shape |
|
shapePalette |
|
NAshape |
|
showSampleNames |
|
pointSize |
|
alpha |
|
plotlyAnnotations |
|
A list of ggplot objects—one per combination of components
pairs and colour variables—each depicting the chosen UMAP dimensions with
requested aesthetics. Specifically:
one plot per components pair × per colour variable;
shapes/labels applied per shape/showSampleNames;
consistent axis labelling (UMAP1/UMAP2 etc.).
Other dimred-helpers:
getPCA(),
plotDimRed()
data(exampleTumourNormal, package = "mesa") # Default UMAP (beta-normalised, top 1000 most variable windows) exampleTumourNormal %>% getUMAP(n_neighbors = 5, min_dist = 1) %>% plotUMAP() # Colour by group; show names exampleTumourNormal %>% getUMAP(n_neighbors = 5, min_dist = 1) %>% plotUMAP( colour = "group", showSampleNames = TRUE ) # Custom components and shape mapping exampleTumourNormal %>% getUMAP(n_neighbors = 5, min_dist = 1) %>% plotUMAP( components = list(c(1, 2)), colour = "group", shape = "tissue" )data(exampleTumourNormal, package = "mesa") # Default UMAP (beta-normalised, top 1000 most variable windows) exampleTumourNormal %>% getUMAP(n_neighbors = 5, min_dist = 1) %>% plotUMAP() # Colour by group; show names exampleTumourNormal %>% getUMAP(n_neighbors = 5, min_dist = 1) %>% plotUMAP( colour = "group", showSampleNames = TRUE ) # Custom components and shape mapping exampleTumourNormal %>% getUMAP(n_neighbors = 5, min_dist = 1) %>% plotUMAP( components = list(c(1, 2)), colour = "group", shape = "tissue" )
Merge samples whose names share a common prefix by removing a suffix pattern
(mergeString) and summing counts across the resulting groups. CNV and
zygosity values are combined using fragment‐count weights. The result is a
new qseaSet with pooled samples and updated metadata.
poolSamples(qseaSet, mergeString)poolSamples(qseaSet, mergeString)
qseaSet |
|
mergeString |
|
Internally, pooled counts are simple sums. CNV values and zygosity are
combined by a weighted average using total_fragments from
@libraries$input_file. Library statistics are aggregated (sums for counts,
weighted means for rates).
A qseaSet object:
poolSamples(): returns a new qseaSet where samples with names sharing
a common prefix (after applying mergeString) are merged. Counts are summed,
CNV and zygosity values are combined using weighted averages, and library
statistics are aggregated.
## Not run: data(exampleTumourNormal) # Pool Tumour/Normal pairs by patient into a single sample per patient: # e.g., "Colon1_T","Colon1_N" -> "Colon1" poolSamples(exampleTumourNormal, mergeString = "_[TN]$") ## End(Not run)## Not run: data(exampleTumourNormal) # Pool Tumour/Normal pairs by patient into a single sample per patient: # e.g., "Colon1_T","Colon1_N" -> "Colon1" poolSamples(exampleTumourNormal, mergeString = "_[TN]$") ## End(Not run)
Extends dplyr::pull() to extract a column from the sampleTable
of a qseaSet.
## S3 method for class 'qseaSet' pull(.data, var = -1, name = NULL, ...)## S3 method for class 'qseaSet' pull(.data, var = -1, name = NULL, ...)
.data |
|
var |
Column to extract (name or position).
Default: |
name |
Optional column to use for names in the returned vector.
Default: |
... |
Additional arguments passed to |
A vector with length equal to the number of samples in the qseaSet.
If name is provided, the vector is named accordingly.
qsea::getSampleTable(),
dplyr::pull()
data(exampleTumourNormal, package = "mesa") # Pull the 'group' column as a vector exampleTumourNormal %>% pull(group) # Pull by column position (last column by default) exampleTumourNormal %>% pull() # Pull a column and name it by sample_name exampleTumourNormal %>% pull(group, name = sample_name)data(exampleTumourNormal, package = "mesa") # Pull the 'group' column as a vector exampleTumourNormal %>% pull(group) # Pull by column position (last column by default) exampleTumourNormal %>% pull() # Pull a column and name it by sample_name exampleTumourNormal %>% pull(group, name = sample_name)
Coerce a table of windows to a GRanges-class. Two input layouts are supported:
chr, window_start, window_end (as in qsea::makeTable() output), or
seqnames, start, end.
qseaTableToChrGRanges(dataTable)qseaTableToChrGRanges(dataTable)
dataTable |
|
If chromosome labels lack the "chr" prefix, it is added automatically so
that seqnames are in UCSC style (e.g., "chr1").
When given chr/window_start/window_end, the columns are renamed to
seqnames/start/end before coercion.
When given seqnames/start/end, seqnames are first coerced to
character and normalised to include the "chr" prefix.
The returned GRanges does not set a genome tag; set it yourself if
needed (e.g., GenomeInfoDb::genome(gr) <- "hg38").
A GRanges with seqnames in UCSC style. The genome is unset.
qsea::makeTable(), as_granges,
GenomeInfoDb::seqlevelsStyle()
# From makeTable-like columns data.frame(chr = c("1", "2"), window_start = c(100, 500), window_end = c(200, 600)) %>% qseaTableToChrGRanges() # From seqnames/start/end; adds 'chr' if missing data.frame(seqnames = c("chr3", "4"), start = c(1000, 2000), end = c(1100, 2100)) %>% qseaTableToChrGRanges()# From makeTable-like columns data.frame(chr = c("1", "2"), window_start = c(100, 500), window_end = c(200, 600)) %>% qseaTableToChrGRanges() # From seqnames/start/end; adds 'chr' if missing data.frame(seqnames = c("chr3", "4"), start = c(1000, 2000), end = c(1100, 2100)) %>% qseaTableToChrGRanges()
Set all per-window CNV values to zero while keeping genomic coordinates and sample metadata intact. Useful for resetting CNV prior to recomputation.
removeCNV(qseaSet)removeCNV(qseaSet)
qseaSet |
|
This operation preserves regions (windows) and sample metadata; only the
per-window CNV values are replaced with zeros. Use this to “clear”
existing CNV calls before running addHMMcopyCNV() or other CNV
routines again.
A qseaSet with the CNV matrix zeroed (same dimensions as before).
addHMMcopyCNV(), plotCNVheatmap(), qsea::addCNV()
Other CNV:
addHMMcopyCNV(),
plotCNVheatmap(),
runHMMCopy()
data(exampleTumourNormal, package = "mesa") # Zero out CNV and inspect the first rows exampleTumourNormal %>% removeCNV() %>% getCNV() %>% utils::head()data(exampleTumourNormal, package = "mesa") # Zero out CNV and inspect the first rows exampleTumourNormal %>% removeCNV() %>% getCNV() %>% utils::head()
Overwrite all library-factor values in a qseaSet (and its sampleTable)
with 1. Useful when you want to avoid library scaling (e.g., TMM) and
keep beta unchanged; NRPM may change depending on downstream use.
removeLibraryFactors(qseaSet)removeLibraryFactors(qseaSet)
qseaSet |
|
Setting library factors to 1 has no effect on beta (fractional measure)
but can affect NRPM since scaling factors are neutralised. This is
akin to calling qsea::addLibraryFactors(qseaSet, factors = 1) and
synchronising the sampleTable.
A qseaSet with all library factors set to 1 and sampleTable updated.
addLibraryInformation(), getNRPMTable(), qsea::addLibraryFactors()
Other table-helpers:
getBetaTable(),
getCountTable(),
getDataTable(),
getNRPMTable(),
getSampleGroups2(),
makeTransposedTable(),
removeNormMethodSuffix()
data(exampleTumourNormal, package = "mesa") # Show current factors then reset to 1 and show again exampleTumourNormal %>% addLibraryInformation() %>% pull(library_factor) %>% head()data(exampleTumourNormal, package = "mesa") # Show current factors then reset to 1 and show again exampleTumourNormal %>% addLibraryInformation() %>% pull(library_factor) %>% head()
Clean wide tables (e.g., from getDataTable()) by stripping the trailing
_{normMethod} or _{normMethod}_means suffixes from sample /
group-mean columns.
removeNormMethodSuffix(dataTable, normMethod)removeNormMethodSuffix(dataTable, normMethod)
dataTable |
|
normMethod |
|
Intended for post-processing tables where column names encode the measure,
e.g., "sample_beta", "group_beta_means". The function drops those
suffixes
to yield bare sample/group names, facilitating downstream joins and plotting.
A data.frame like dataTable but with cleaned column names (suffixes
_{normMethod} and _{normMethod}_means removed where present).
getDataTable(), selectQset(), pull.qseaSet()
Other table-helpers:
getBetaTable(),
getCountTable(),
getDataTable(),
getNRPMTable(),
getSampleGroups2(),
makeTransposedTable(),
removeLibraryFactors()
# Basic cleaning for 'beta' data.frame(A_beta = 1:3, B_beta_means = 4:6) %>% removeNormMethodSuffix("beta") %>% names() # Works similarly for other measures (e.g., 'nrpm') data.frame(S1_nrpm = 1:2, Tumour_nrpm_means = 3:4) %>% removeNormMethodSuffix("nrpm") %>% names()# Basic cleaning for 'beta' data.frame(A_beta = 1:3, B_beta_means = 4:6) %>% removeNormMethodSuffix("beta") %>% names() # Works similarly for other measures (e.g., 'nrpm') data.frame(S1_nrpm = 1:2, Tumour_nrpm_means = 3:4) %>% removeNormMethodSuffix("nrpm") %>% names()
Apply a regular expression replacement to sample names and update all
relevant slots consistently (counts, CNV, enrichment, zygosity, libraries,
and the sampleTable).
renameQsetNames(qseaSet, pattern, replacement = "")renameQsetNames(qseaSet, pattern, replacement = "")
qseaSet |
|
pattern |
|
replacement |
|
A qseaSet object:
renameQsetNames(): returns the input qseaSet with sample names
updated according to pattern and replacement. All dependent slots are
updated consistently.
data(exampleTumourNormal, package = "mesa") # Replace "T" with "Tumour" in sample names renameQsetNames(exampleTumourNormal, pattern = "T", replacement = "Tumour" )data(exampleTumourNormal, package = "mesa") # Replace "T" with "Tumour" in sample names renameQsetNames(exampleTumourNormal, pattern = "T", replacement = "Tumour" )
Replace sample names with values from a user-supplied column in the
sampleTable of a qseaSet, updating all dependent slots consistently.
renameSamples(qseaSet, newNameColumn)renameSamples(qseaSet, newNameColumn)
qseaSet |
|
newNameColumn |
|
A qseaSet object:
renameSamples(): returns the input qseaSet with sample names replaced
by values from newNameColumn. All associated slots are updated to reflect
the new naming.
data(exampleTumourNormal, package = "mesa") exampleTumourNormal %>% dplyr::mutate( newName = paste0( "Sample", seq_len(nrow(qsea::getSampleTable(.))) ) ) %>% renameSamples(newNameColumn = "newName")data(exampleTumourNormal, package = "mesa") exampleTumourNormal %>% dplyr::mutate( newName = paste0( "Sample", seq_len(nrow(qsea::getSampleTable(.))) ) ) %>% renameSamples(newNameColumn = "newName")
Given a table of per-window counts with GC and mappability, run HMMcopy correction and segmentation, and return a GRanges of CNV calls for the selected sample/column.
runHMMCopy(CNV_RegionsWithReads, colname, plotDir = NULL)runHMMCopy(CNV_RegionsWithReads, colname, plotDir = NULL)
CNV_RegionsWithReads |
|
colname |
|
plotDir |
|
Counts are GC/map corrected via HMMcopy::correctReadcount() and segmented
with HMMcopy::HMMsegment(). The result is mapped back to the input windows
and returned as a GRanges. Ensure that the binning (width) and covariate
columns (gc, map) are consistent across the table.
A GRanges with a metadata column named <colname> containing
per-window CNV estimates (typically HMM state means on the log2 scale).
addHMMcopyCNV(), HMMcopy::correctReadcount(), HMMcopy::HMMsegment()
Other CNV:
addHMMcopyCNV(),
plotCNVheatmap(),
removeCNV()
## Not run: # Minimal synthetic example: build a table and pipe into runHMMCopy() set.seed(1) n <- 2000L; w <- 5e4 tibble::tibble( chr = factor(rep(c("chr1", "chr2"), each = n / 2), levels = c("chr1", "chr2")), start = rep(seq(1, by = w, length.out = n / 2), 2), end = start + w - 1L, width = w, strand = "*", gc = runif(n, 0.05, 0.95), #' wide spread => stable LOESS map = runif(n, 0.60, 0.98), #' avoid extremes / exact 1.0 sampleA = rpois(n, 500) ) %>% runHMMCopy(colname = "sampleA", plotDir = NULL) ## End(Not run)## Not run: # Minimal synthetic example: build a table and pipe into runHMMCopy() set.seed(1) n <- 2000L; w <- 5e4 tibble::tibble( chr = factor(rep(c("chr1", "chr2"), each = n / 2), levels = c("chr1", "chr2")), start = rep(seq(1, by = w, length.out = n / 2), 2), end = start + w - 1L, width = w, strand = "*", gc = runif(n, 0.05, 0.95), #' wide spread => stable LOESS map = runif(n, 0.60, 0.98), #' avoid extremes / exact 1.0 sampleA = rpois(n, 500) ) %>% runHMMCopy(colname = "sampleA", plotDir = NULL) ## End(Not run)
Extends dplyr::select() to keep or rename columns in a qseaSet's
sampleTable. This allows column subsetting, renaming, and use of
tidyselect helpers while preserving key identifiers.
## S3 method for class 'qseaSet' select(.data, ...)## S3 method for class 'qseaSet' select(.data, ...)
.data |
|
... |
Additional arguments passed to |
This is a wrapper around selectQset().
Essential columns sample_name and group are always preserved (and appear
first if present).
A qseaSet with its sampleTable updated:
contains only selected/renamed columns,
always includes sample_name and group (if available).
selectQset() for the underlying implementation,
qsea::getSampleTable() to view results,
mutate.qseaSet(), filter.qseaSet() for related dplyr verbs.
data(exampleTumourNormal, package = "mesa") # Keep only specific columns (sample_name and group always preserved) exampleTumourNormal %>% dplyr::select(type, tumour) %>% qsea::getSampleTable() # Select and rename a column exampleTumourNormal %>% dplyr::select(age, tumour_new = tumour) %>% qsea::getSampleTable() # Use tidyselect helpers exampleTumourNormal %>% dplyr::select(matches("s")) %>% qsea::getSampleTable() # Negative selection (except essential columns) exampleTumourNormal %>% dplyr::select(-matches("s")) %>% qsea::getSampleTable()data(exampleTumourNormal, package = "mesa") # Keep only specific columns (sample_name and group always preserved) exampleTumourNormal %>% dplyr::select(type, tumour) %>% qsea::getSampleTable() # Select and rename a column exampleTumourNormal %>% dplyr::select(age, tumour_new = tumour) %>% qsea::getSampleTable() # Use tidyselect helpers exampleTumourNormal %>% dplyr::select(matches("s")) %>% qsea::getSampleTable() # Negative selection (except essential columns) exampleTumourNormal %>% dplyr::select(-matches("s")) %>% qsea::getSampleTable()
Keeps or renames columns from the sampleTable of a qseaSet.
Essential columns sample_name and group are always preserved (and placed
at the front of the table if present).
selectQset(qseaSet, ...)selectQset(qseaSet, ...)
qseaSet |
|
... |
Additional arguments passed to |
A qseaSet with its sampleTable updated:
contains only the selected/renamed columns,
always includes sample_name and group (if available).
select.qseaSet() for the dplyr S3 method,
qsea::getSampleTable() to inspect the updated table.
data(exampleTumourNormal, package = "mesa") # Keep only sample_name and group exampleTumourNormal %>% selectQset(sample_name, group) %>% qsea::getSampleTable() # Select and rename a column exampleTumourNormal %>% selectQset(age, tumour_type = tumour) %>% qsea::getSampleTable() # Use tidyselect helpers exampleTumourNormal %>% selectQset(matches("s")) %>% qsea::getSampleTable()data(exampleTumourNormal, package = "mesa") # Keep only sample_name and group exampleTumourNormal %>% selectQset(sample_name, group) %>% qsea::getSampleTable() # Select and rename a column exampleTumourNormal %>% selectQset(age, tumour_type = tumour) %>% qsea::getSampleTable() # Use tidyselect helpers exampleTumourNormal %>% selectQset(matches("s")) %>% qsea::getSampleTable()
Store and retrieve a “mart” handle inside a qseaSet for downstream
annotation tasks (e.g., resolving gene coordinates).
setMart(object, ...) ## S4 method for signature 'qseaSet' setMart(object, mart) getMart(object, ...) ## S4 method for signature 'qseaSet' getMart(object)setMart(object, ...) ## S4 method for signature 'qseaSet' setMart(object, mart) getMart(object, ...) ## S4 method for signature 'qseaSet' getMart(object)
object |
|
... |
Additional arguments passed to methods or to
|
mart |
|
These are S4 generics with methods for class "qseaSet". The value is not
validated or dereferenced here; functions that consume it (e.g., gene
annotation helpers) should perform any needed checks.
setMart() returns the updated qseaSet (with @parameters$mart set).
getMart() returns the stored value (whatever was set), or NULL if
absent.
setMart(object, mart)Set the handle on a qseaSet.
getMart(object)Retrieve the stored handle from a qseaSet.
annotateWindows(), setMesaGenome(), setMesaTxDb(), setMesaAnnoDb(),
biomaRt::useMart()
data(exampleTumourNormal, package = "mesa") # Store a label (or use a real biomaRt::Mart) and read it back exampleTumourNormal %>% setMart("ENSEMBL_110") %>% getMart()data(exampleTumourNormal, package = "mesa") # Store a label (or use a real biomaRt::Mart) and read it back exampleTumourNormal %>% setMart("ENSEMBL_110") %>% getMart()
Record a preferred OrgDb package to use when functions such as
annotateWindows() are called without an explicit annoDb.
setMesaAnnoDb(annoDb)setMesaAnnoDb(annoDb)
annoDb |
|
This sets the session option options(mesa_annoDb = <annoDb>). When present,
helpers like annotateWindows() will use this OrgDb by default (particularly
for GRCh38 workflows) unless an explicit annoDb is provided. Use
setMesaGenome() and setMesaTxDb() to configure complementary defaults for
the genome and TxDb, respectively.
Invisibly returns TRUE on success.
annotateWindows(), setMesaGenome(), setMesaTxDb(),
ChIPseeker::annotatePeak()
# Set default annoDb for human (only if the package is installed) if (requireNamespace("org.Hs.eg.db", quietly = TRUE)) { setMesaAnnoDb("org.Hs.eg.db") getOption("mesa_annoDb") } # Set default annoDb for mouse (only if the package is installed) if (requireNamespace("org.Mm.eg.db", quietly = TRUE)) { setMesaAnnoDb("org.Mm.eg.db") getOption("mesa_annoDb") } # Unset the default annoDb setMesaAnnoDb(NULL) is.null(getOption("mesa_annoDb"))# Set default annoDb for human (only if the package is installed) if (requireNamespace("org.Hs.eg.db", quietly = TRUE)) { setMesaAnnoDb("org.Hs.eg.db") getOption("mesa_annoDb") } # Set default annoDb for mouse (only if the package is installed) if (requireNamespace("org.Mm.eg.db", quietly = TRUE)) { setMesaAnnoDb("org.Mm.eg.db") getOption("mesa_annoDb") } # Unset the default annoDb setMesaAnnoDb(NULL) is.null(getOption("mesa_annoDb"))
Record a preferred genome string (e.g., "hg38" / "GRCh38") in the session
options so that functions like annotateWindows() can use it when genome
is not explicitly supplied.
setMesaGenome(genome)setMesaGenome(genome)
genome |
|
This function sets the session option options(mesa_genome = <genome>). It
does not modify TxDb or OrgDb options directly; set those via
setMesaTxDb() and setMesaAnnoDb() if you want global defaults for
transcript and gene annotation packages. Helpers such as annotateWindows()
consult getOption("mesa_genome") when genome is missing.
Invisibly returns TRUE on success.
annotateWindows(), setMesaTxDb(), setMesaAnnoDb()
# Set the default genome to hg38 setMesaGenome("hg38") getOption("mesa_genome") # Use the GRCh38 alias setMesaGenome("GRCh38") getOption("mesa_genome") # Reset/remove the default genome setMesaGenome(NULL) is.null(getOption("mesa_genome"))# Set the default genome to hg38 setMesaGenome("hg38") getOption("mesa_genome") # Use the GRCh38 alias setMesaGenome("GRCh38") getOption("mesa_genome") # Reset/remove the default genome setMesaGenome(NULL) is.null(getOption("mesa_genome"))
setMesaParallel() enables/disables parallelisation (and may register a
backend); getMesaParallel() returns the current setting.
setMesaParallel(nCores = NULL, useParallel = FALSE, verbose = TRUE) getMesaParallel(verbose = FALSE)setMesaParallel(nCores = NULL, useParallel = FALSE, verbose = TRUE) getMesaParallel(verbose = FALSE)
nCores |
|
useParallel |
|
verbose |
Boolean to determine whether to print messages or not. |
This function stores the flag in options(mesa_parallel = <TRUE/FALSE>).
On Unix/macOS, supplying nCores > 1 will register a
MulticoreParam backend via BiocParallel::register() and enable
parallelisation.
On Windows, forked backends are unavailable; you should manually
register a compatible backend (e.g., SnowParam) and then call
setMesaParallel(useParallel = TRUE).
You can always inspect the active backend with BiocParallel::bpparam()
and the worker count with BiocParallel::bpworkers().
setMesaParallel() — logical scalar (TRUE/FALSE), returned
invisibly;
primarily used for its side effects (setting the option and possibly
registering a backend).
getMesaParallel() — logical scalar indicating whether mesa
parallelisation
is currently enabled; with verbose = TRUE, also prints a status message.
getMesaParallel(): Get whether mesa is using parallelisation.
BiocParallel::register(), BiocParallel::MulticoreParam(),
BiocParallel::SnowParam(), BiocParallel::bpworkers()
# Turn parallelisation OFF (serial evaluation) setMesaParallel(useParallel = FALSE, verbose = FALSE) getMesaParallel() # FALSE # --- Unix/mac (MulticoreParam): enable and use 2 cores --- ## Not run: if (.Platform$OS.type != "windows") { old <- BiocParallel::bpparam() # save current backend setMesaParallel(nCores = 2, verbose = FALSE) # registers MulticoreParam(2) BiocParallel::bpworkers() # e.g. 2 getMesaParallel() # TRUE BiocParallel::register(old) # restore previous backend setMesaParallel(useParallel = FALSE, verbose = FALSE) # back to serial } ## End(Not run) # --- Windows: register SnowParam yourself, then enable --- ## Not run: if (.Platform$OS.type == "windows") { old <- BiocParallel::bpparam() BiocParallel::register(BiocParallel::SnowParam(workers = 2)) setMesaParallel(useParallel = TRUE, verbose = FALSE) BiocParallel::bpworkers() # e.g. 2 getMesaParallel() # TRUE BiocParallel::register(old) setMesaParallel(useParallel = FALSE, verbose = FALSE) } ## End(Not run)# Turn parallelisation OFF (serial evaluation) setMesaParallel(useParallel = FALSE, verbose = FALSE) getMesaParallel() # FALSE # --- Unix/mac (MulticoreParam): enable and use 2 cores --- ## Not run: if (.Platform$OS.type != "windows") { old <- BiocParallel::bpparam() # save current backend setMesaParallel(nCores = 2, verbose = FALSE) # registers MulticoreParam(2) BiocParallel::bpworkers() # e.g. 2 getMesaParallel() # TRUE BiocParallel::register(old) # restore previous backend setMesaParallel(useParallel = FALSE, verbose = FALSE) # back to serial } ## End(Not run) # --- Windows: register SnowParam yourself, then enable --- ## Not run: if (.Platform$OS.type == "windows") { old <- BiocParallel::bpparam() BiocParallel::register(BiocParallel::SnowParam(workers = 2)) setMesaParallel(useParallel = TRUE, verbose = FALSE) BiocParallel::bpworkers() # e.g. 2 getMesaParallel() # TRUE BiocParallel::register(old) setMesaParallel(useParallel = FALSE, verbose = FALSE) } ## End(Not run)
Record a preferred TxDb to use when functions such as annotateWindows() are
called without an explicit TxDb.
setMesaTxDb(TxDb)setMesaTxDb(TxDb)
TxDb |
|
This sets the session option options(mesa_TxDb = TxDb). When a string is
stored, helpers like annotateWindows() will load the TxDb object on demand
(e.g., "TxDb.Hsapiens.UCSC.hg38.knownGene"). Use setMesaGenome() and
setMesaAnnoDb() to configure complementary defaults for genome and OrgDb.
Invisibly returns TRUE on success.
annotateWindows(), setMesaGenome(), setMesaAnnoDb(),
ChIPseeker::annotatePeak()
# Set default TxDb for human (GRCh38/hg38) setMesaTxDb("TxDb.Hsapiens.UCSC.hg38.knownGene") getOption("mesa_TxDb") # Clear the default TxDb setMesaTxDb(NULL) getOption("mesa_TxDb") # (Alternatively) you can store the object itself if already loaded: # setMesaTxDb( # TxDb.Hsapiens.UCSC.hg38.knownGene::TxDb.Hsapiens.UCSC.hg38.knownGene # )# Set default TxDb for human (GRCh38/hg38) setMesaTxDb("TxDb.Hsapiens.UCSC.hg38.knownGene") getOption("mesa_TxDb") # Clear the default TxDb setMesaTxDb(NULL) getOption("mesa_TxDb") # (Alternatively) you can store the object itself if already loaded: # setMesaTxDb( # TxDb.Hsapiens.UCSC.hg38.knownGene::TxDb.Hsapiens.UCSC.hg38.knownGene # )
Take the top most DMRs per contrast, based on those with the largest value of the selected metric
sliceDMRs( DMRs, n = 1, metric = deltaBeta, makePositive = TRUE, FDRthres = 0.05 )sliceDMRs( DMRs, n = 1, metric = deltaBeta, makePositive = TRUE, FDRthres = 0.05 )
DMRs |
A data frame containing the output of calculateDMRs, potentially with multiple contrasts |
n |
How many DMRs to take of each contrast (if that many exists) |
metric |
Which metric to use to select the top DMRs. Options are
deltaBeta, log2FC, adjPval, CpG_density, position (using seqnames and start
columns) or any other column in the data frame.
If |
makePositive |
Whether to reverse the contrast when the window is hypomethylated in the contrast. |
FDRthres |
Threshold on the adjusted p values |
A data frame with the DMRs with the largest value of the selected metrics
# calculate some DMRs DMRs <- exampleTumourNormal %>% calculateDMRs( variable = "type", contrasts = "all", keepContrastMeans = FALSE ) # Find the DMRs with the largest deltaBeta between each comparison: DMRs %>% sliceDMRs(n = 1) # Or the windows with the largest log2FC: DMRs %>% sliceDMRs(n = 1, metric = log2FC) # Or the windows with the largest CpG_density: DMRs %>% sliceDMRs(n = 1, metric = CpG_density) # If adjPval is used, then the smallest value is chosen instead: DMRs %>% sliceDMRs(n = 1, metric = CpG_density) # If position is used, then the windows are sorted by genomic position: DMRs %>% sliceDMRs(n = 1, metric = position)# calculate some DMRs DMRs <- exampleTumourNormal %>% calculateDMRs( variable = "type", contrasts = "all", keepContrastMeans = FALSE ) # Find the DMRs with the largest deltaBeta between each comparison: DMRs %>% sliceDMRs(n = 1) # Or the windows with the largest log2FC: DMRs %>% sliceDMRs(n = 1, metric = log2FC) # Or the windows with the largest CpG_density: DMRs %>% sliceDMRs(n = 1, metric = CpG_density) # If adjPval is used, then the smallest value is chosen instead: DMRs %>% sliceDMRs(n = 1, metric = CpG_density) # If position is used, then the windows are sorted by genomic position: DMRs %>% sliceDMRs(n = 1, metric = position)
Extends base::sort() to reorder the samples of a qseaSet
using gtools::mixedsort() so that numeric parts sort naturally
(e.g., "2" comes before "10").
## S3 method for class 'qseaSet' sort(x, decreasing = FALSE, ...)## S3 method for class 'qseaSet' sort(x, decreasing = FALSE, ...)
x |
|
decreasing |
|
... |
Additional arguments passed on to |
A qseaSet object with reordered samples. The content of all slots
(e.g., count_matrix, sampleTable) is updated consistently.
qsea::getSampleNames(),
subsetQset(),
gtools::mixedsort()
data(exampleTumourNormal, package = "mesa") # Sort samples in natural (mixed) order exampleTumourNormal %>% sort() # Sort in reverse order exampleTumourNormal %>% sort(decreasing = TRUE)data(exampleTumourNormal, package = "mesa") # Sort samples in natural (mixed) order exampleTumourNormal %>% sort() # Sort in reverse order exampleTumourNormal %>% sort(decreasing = TRUE)
Restrict a qseaSet to a specified set of samples. All internal matrices and
slots are subset consistently. Use exactly one of samplesToKeep or
samplesToDrop.
subsetQset(qseaSet, samplesToKeep = NULL, samplesToDrop = NULL)subsetQset(qseaSet, samplesToKeep = NULL, samplesToDrop = NULL)
qseaSet |
|
samplesToKeep |
|
samplesToDrop |
|
A qseaSet object:
subsetQset(): returns the input qseaSet restricted to the
selected samples.
data(exampleTumourNormal, package = "mesa") # Keep only two samples subsetQset(exampleTumourNormal, samplesToKeep = c("Colon1_T", "Colon1_N")) # Drop one sample subsetQset(exampleTumourNormal, samplesToDrop = "Lung1_N")data(exampleTumourNormal, package = "mesa") # Keep only two samples subsetQset(exampleTumourNormal, samplesToKeep = c("Colon1_T", "Colon1_N")) # Drop one sample subsetQset(exampleTumourNormal, samplesToDrop = "Lung1_N")
Filter genomic windows based on a summary function applied across selected samples. Typical uses include keeping windows with median NRPM above a threshold, or retaining windows where the minimum beta is below 0.5.
subsetWindowsBySignal( qseaSet, fn, threshold, aboveThreshold, samples = NULL, normMethod = "nrpm", useGroupMeans = FALSE )subsetWindowsBySignal( qseaSet, fn, threshold, aboveThreshold, samples = NULL, normMethod = "nrpm", useGroupMeans = FALSE )
qseaSet |
|
fn |
|
threshold |
|
aboveThreshold |
|
samples |
|
normMethod |
|
useGroupMeans |
|
The function builds a window × sample matrix for the chosen normMethod,
optionally restricts to samples via samples (exact names or pattern match),
computes fn per row, and filters by threshold according to
aboveThreshold. Supply a summary function that accepts a numeric vector and
returns a scalar; include na.rm = TRUE inside fn if needed.
A filtered qseaSet containing only the selected windows.
getDataTable(), filterByOverlaps()
Other window-helpers:
calculateFractionReadsInGRanges(),
convertToArrayBetaTable(),
downSample(),
subsetWindowsOverBackground()
data(exampleTumourNormal, package = "mesa") # Keep windows with median NRPM > 1 across all samples exampleTumourNormal %>% subsetWindowsBySignal( fn = median, threshold = 1, aboveThreshold = TRUE ) # Keep windows where the MIN beta < 0.5 in any sample exampleTumourNormal %>% subsetWindowsBySignal( fn = min, threshold = 0.5, aboveThreshold = FALSE, normMethod = "beta" ) # Restrict to samples whose names contain "Lung" exampleTumourNormal %>% subsetWindowsBySignal( fn = median, threshold = 1, aboveThreshold = TRUE, samples = "Lung" ) # Use group means instead of individual samples exampleTumourNormal %>% subsetWindowsBySignal( fn = median, threshold = 1, aboveThreshold = TRUE, useGroupMeans = TRUE )data(exampleTumourNormal, package = "mesa") # Keep windows with median NRPM > 1 across all samples exampleTumourNormal %>% subsetWindowsBySignal( fn = median, threshold = 1, aboveThreshold = TRUE ) # Keep windows where the MIN beta < 0.5 in any sample exampleTumourNormal %>% subsetWindowsBySignal( fn = min, threshold = 0.5, aboveThreshold = FALSE, normMethod = "beta" ) # Restrict to samples whose names contain "Lung" exampleTumourNormal %>% subsetWindowsBySignal( fn = median, threshold = 1, aboveThreshold = TRUE, samples = "Lung" ) # Use group means instead of individual samples exampleTumourNormal %>% subsetWindowsBySignal( fn = median, threshold = 1, aboveThreshold = TRUE, useGroupMeans = TRUE )
Identify genomic windows with significantly more reads than expected under a
Poisson background model, given total reads per sample and the number of
genome windows. If numWindows is provided, then that value will be used as
the total original number of windows under consideration for the false
discovery rate, otherwise it will use the number of windows currently in the
qseaSet.
subsetWindowsOverBackground( qseaSet, keepAbove = FALSE, samples = NULL, numWindows = NULL, FDRthres = 0.01, numAbove = 1 )subsetWindowsOverBackground( qseaSet, keepAbove = FALSE, samples = NULL, numWindows = NULL, FDRthres = 0.01, numAbove = 1 )
qseaSet |
|
keepAbove |
|
samples |
|
numWindows |
|
FDRthres |
|
numAbove |
|
For each tested sample, an expected count per window is derived from its
total
reads and the supplied/estimated numWindows, and a Poisson test is used to
flag windows above background. This uses the valid_fragments column in the
library information attached to the qseaSet, which is the number of fragments
used in the generation of the original qseaSet. Windows are retained or
removed based on keepAbove and the requirement that at least numAbove
samples are significant at FDRthres.
A filtered qseaSet containing only windows passing the criteria.
Other window-helpers:
calculateFractionReadsInGRanges(),
convertToArrayBetaTable(),
downSample(),
subsetWindowsBySignal()
data(exampleTumourNormal, package = "mesa") # Keep windows above Poisson background in at least 2 samples whose names # contain "Lung", assuming there were 9 million original windows exampleTumourNormal %>% subsetWindowsOverBackground(keepAbove = TRUE, samples = "Lung", numAbove = 2, numWindows = 9e6 ) # Drop windows above background (retain only background-like windows) across # all samples, assuming there were 9 million original windows exampleTumourNormal %>% subsetWindowsOverBackground(keepAbove = FALSE, numWindows = 9e6)data(exampleTumourNormal, package = "mesa") # Keep windows above Poisson background in at least 2 samples whose names # contain "Lung", assuming there were 9 million original windows exampleTumourNormal %>% subsetWindowsOverBackground(keepAbove = TRUE, samples = "Lung", numAbove = 2, numWindows = 9e6 ) # Drop windows above background (retain only background-like windows) across # all samples, assuming there were 9 million original windows exampleTumourNormal %>% subsetWindowsOverBackground(keepAbove = FALSE, numWindows = 9e6)
Apply a summary function (e.g., mean, median, sd) over genomic windows per sample, optionally restricted to a set of regions and for one or more normalisation methods.
summariseAcrossWindows( qseaSet, regionsToOverlap = NULL, fn = mean, addSampleTable = TRUE, normMethod = c("nrpm", "beta"), naMethod = "na.rm", minEnrichment = 3, suffix = "", fnName = NULL )summariseAcrossWindows( qseaSet, regionsToOverlap = NULL, fn = mean, addSampleTable = TRUE, normMethod = c("nrpm", "beta"), naMethod = "na.rm", minEnrichment = 3, suffix = "", fnName = NULL )
qseaSet |
|
regionsToOverlap |
|
fn |
|
addSampleTable |
|
normMethod |
|
naMethod |
|
minEnrichment |
|
suffix |
|
fnName |
|
The function builds a window × sample matrix for each normMethod,
optionally
restricts to regionsToOverlap, then applies fn over windows for each
sample to produce a single summary value per sample (per method).
Missing-value
handling follows naMethod. When summarising betas, windows below
minEnrichment reads are NA prior to summarisation.
A tibble with one row per sample. For each requested normMethod, a summary
column is added (column naming typically reflects <method> and fn and may
include suffix). If addSampleTable = TRUE, sample-table columns are
joined.
addSummaryAcrossWindows(), getDataTable()
Other window-summaries:
addSummaryAcrossWindows(),
countWindowsAboveCutoff()
data(exampleTumourNormal, package = "mesa") # Mean NRPM and beta across all windows exampleTumourNormal %>% summariseAcrossWindows( fn = mean, normMethod = c("nrpm","beta") ) # Maximum NRPM within a small genomic region exampleTumourNormal %>% summariseAcrossWindows( regionsToOverlap = data.frame( seqnames = 7, start = 25002001, end = 25017900 ), fn = max, normMethod = "nrpm", suffix = "_chr7_slice" ) # Median beta over all windows exampleTumourNormal %>% summariseAcrossWindows( fn = median, normMethod = "beta", minEnrichment = 3 )data(exampleTumourNormal, package = "mesa") # Mean NRPM and beta across all windows exampleTumourNormal %>% summariseAcrossWindows( fn = mean, normMethod = c("nrpm","beta") ) # Maximum NRPM within a small genomic region exampleTumourNormal %>% summariseAcrossWindows( regionsToOverlap = data.frame( seqnames = 7, start = 25002001, end = 25017900 ), fn = max, normMethod = "nrpm", suffix = "_chr7_slice" ) # Median beta over all windows exampleTumourNormal %>% summariseAcrossWindows( fn = median, normMethod = "beta", minEnrichment = 3 )
Count the number of up- and down-regulated DMR windows per contrast. Internally, results are reshaped to long format before summarisation.
summariseDMRsByContrast( DMRtable, FDRthres = 0.05, log2FCthres = 0, deltaBetaThres = 0 )summariseDMRsByContrast( DMRtable, FDRthres = 0.05, log2FCthres = 0, deltaBetaThres = 0 )
DMRtable |
|
FDRthres |
|
log2FCthres |
|
deltaBetaThres |
|
A tibble:
summariseDMRsByContrast(): returns one row per contrast, with
counts of up-regulated (nUp) and down-regulated (nDown) DMRs that pass
the specified thresholds.
pivotDMRsLonger(), summariseDMRsByGene()
Other DMR-helpers:
pivotDMRsLonger(),
summariseDMRsByGene(),
writeDMRsToBed(),
writeDMRsToExcel()
data(exampleTumourNormal, package = "mesa") # Summarise DMRs for a single contrast, using custom FDR threshold exampleTumourNormal %>% calculateDMRs( variable = "type", contrasts = "LUAD_vs_NormalLung", FDRthres = 0.1 ) %>% summariseDMRsByContrast(FDRthres = 0.1)data(exampleTumourNormal, package = "mesa") # Summarise DMRs for a single contrast, using custom FDR threshold exampleTumourNormal %>% calculateDMRs( variable = "type", contrasts = "LUAD_vs_NormalLung", FDRthres = 0.1 ) %>% summariseDMRsByContrast(FDRthres = 0.1)
Aggregate differentially methylated region (DMR) windows by gene annotation.
summariseDMRsByGene(DMRtable)summariseDMRsByGene(DMRtable)
DMRtable |
|
A tibble:
summariseDMRsByGene(): returns one row per gene, with counts of associated DMRs and any aggregated metadata.
annotateWindows(), summariseDMRsByContrast()
Other DMR-helpers:
pivotDMRsLonger(),
summariseDMRsByContrast(),
writeDMRsToBed(),
writeDMRsToExcel()
data(exampleTumourNormal, package = "mesa") # Summarise DMRs with explicit annotation databases exampleTumourNormal %>% calculateDMRs(variable = "tumour", contrasts = "all") %>% annotateWindows( TxDb = "TxDb.Hsapiens.UCSC.hg38.knownGene", annoDb = "org.Hs.eg.db" ) %>% summariseDMRsByGene()data(exampleTumourNormal, package = "mesa") # Summarise DMRs with explicit annotation databases exampleTumourNormal %>% calculateDMRs(variable = "tumour", contrasts = "all") %>% annotateWindows( TxDb = "TxDb.Hsapiens.UCSC.hg38.knownGene", annoDb = "org.Hs.eg.db" ) %>% summariseDMRsByGene()
Export bigWig files with per-window scores for each sample (or group means).
writeBigWigs( qseaSet, folderName, normMethod = "nrpm", useGroupMeans = FALSE, naVal = -1 )writeBigWigs( qseaSet, folderName, normMethod = "nrpm", useGroupMeans = FALSE, naVal = -1 )
qseaSet |
|
folderName |
|
normMethod |
|
useGroupMeans |
|
naVal |
|
For each sample (or group), the function pairs the per-window scores from
qseaSet with the corresponding window genomic coordinates and writes a
bigWig via rtracklayer. When exporting beta, windows failing the minimum
read threshold used to compute beta may be NA; these are replaced by
naVal before writing.
File naming. Output files are typically named using the sample (or group)
name and the method, e.g. "<sample>_<method>.bw" or
"<group>_<method>_means.bw" when useGroupMeans = TRUE.
Seqinfo. bigWig export requires chromosome lengths; ensure the window
GRanges in qseaSet carries valid seqinfo (this is the case for the
example data on GRCh38).
(Invisibly) NULL. Files are written to folderName.
data(exampleTumourNormal, package = "mesa") # Per-sample NRPM bigWigs td <- tempfile() dir.create(td) exampleTumourNormal %>% writeBigWigs(folderName = td, normMethod = "nrpm", useGroupMeans = FALSE) list.files(td, pattern = "\\\\.bw$") # Group-mean beta bigWigs (replace NA beta with 0) td2 <- tempfile() dir.create(td2) exampleTumourNormal %>% writeBigWigs( folderName = td2, normMethod = "beta", useGroupMeans = TRUE, naVal = 0 ) list.files(td, pattern = "\\\\.bw$")data(exampleTumourNormal, package = "mesa") # Per-sample NRPM bigWigs td <- tempfile() dir.create(td) exampleTumourNormal %>% writeBigWigs(folderName = td, normMethod = "nrpm", useGroupMeans = FALSE) list.files(td, pattern = "\\\\.bw$") # Group-mean beta bigWigs (replace NA beta with 0) td2 <- tempfile() dir.create(td2) exampleTumourNormal %>% writeBigWigs( folderName = td2, normMethod = "beta", useGroupMeans = TRUE, naVal = 0 ) list.files(td, pattern = "\\\\.bw$")
Export differentially methylated region (DMR) results to a set of BED files, with one file generated per contrast.
writeDMRsToBed(dataTable, folder, FDRthres = 0.05)writeDMRsToBed(dataTable, folder, FDRthres = 0.05)
dataTable |
|
folder |
|
FDRthres |
|
(Invisibly) returns the input object:
writeDMRsToBed(): returns dataTable (invisibly), enabling use in a
pipeline.
Other DMR-helpers:
pivotDMRsLonger(),
summariseDMRsByContrast(),
summariseDMRsByGene(),
writeDMRsToExcel()
data(exampleTumourNormal, package = "mesa") # Export DMRs for a single contrast to BED files in a temp directory exampleTumourNormal %>% calculateDMRs( variable = "type", contrasts = "LUAD_vs_NormalLung" ) %>% writeDMRsToBed(folder = tempdir()) # Export DMRs with explicit annotation (requires TxDb/annotation packages) exampleTumourNormal %>% calculateDMRs(variable = "tumour", contrasts = "all") %>% annotateWindows( TxDb = "TxDb.Hsapiens.UCSC.hg38.knownGene", annoDb = "org.Hs.eg.db" ) %>% writeDMRsToBed(folder = tempdir(), FDRthres = 0.1)data(exampleTumourNormal, package = "mesa") # Export DMRs for a single contrast to BED files in a temp directory exampleTumourNormal %>% calculateDMRs( variable = "type", contrasts = "LUAD_vs_NormalLung" ) %>% writeDMRsToBed(folder = tempdir()) # Export DMRs with explicit annotation (requires TxDb/annotation packages) exampleTumourNormal %>% calculateDMRs(variable = "tumour", contrasts = "all") %>% annotateWindows( TxDb = "TxDb.Hsapiens.UCSC.hg38.knownGene", annoDb = "org.Hs.eg.db" ) %>% writeDMRsToBed(folder = tempdir(), FDRthres = 0.1)
Export differentially methylated region (DMR) results to an Excel workbook, creating one worksheet per contrast.
writeDMRsToExcel(dataTable, path, FDRthres = 0.05)writeDMRsToExcel(dataTable, path, FDRthres = 0.05)
dataTable |
|
path |
|
FDRthres |
|
One worksheet is created per contrast found in dataTable. If no contrast
column is present, all rows are written to a single worksheet. If file I/O is
restricted on the system (e.g., some HPC build environments), consider
writing to tempfile(fileext = ".xlsx") in examples or tests.
(Invisibly) returns the input object:
writeDMRsToExcel(): returns dataTable (invisibly), enabling use in
a pipeline.
Other DMR-helpers:
pivotDMRsLonger(),
summariseDMRsByContrast(),
summariseDMRsByGene(),
writeDMRsToBed()
data(exampleTumourNormal, package = "mesa") # Minimal example: write results for a single contrast exampleTumourNormal %>% calculateDMRs(variable = "type", contrasts = "LUAD_vs_NormalLung") %>% writeDMRsToExcel(path = file.path(tempdir(), "test.xlsx")) # With multiple contrasts and annotation exampleTumourNormal %>% calculateDMRs(variable = "tumour", contrasts = "all") %>% annotateWindows( TxDb = "TxDb.Hsapiens.UCSC.hg38.knownGene", annoDb = "org.Hs.eg.db" ) %>% writeDMRsToExcel(path = file.path(tempdir(), "test.xlsx"))data(exampleTumourNormal, package = "mesa") # Minimal example: write results for a single contrast exampleTumourNormal %>% calculateDMRs(variable = "type", contrasts = "LUAD_vs_NormalLung") %>% writeDMRsToExcel(path = file.path(tempdir(), "test.xlsx")) # With multiple contrasts and annotation exampleTumourNormal %>% calculateDMRs(variable = "tumour", contrasts = "all") %>% annotateWindows( TxDb = "TxDb.Hsapiens.UCSC.hg38.knownGene", annoDb = "org.Hs.eg.db" ) %>% writeDMRsToExcel(path = file.path(tempdir(), "test.xlsx"))