Compute bias-corrected deviation scores for every motif and every sample listed in a sample annotation file.
Usage
runMethylTFR(
sample_ann,
sample_dir,
tf_bindsites = NULL,
gcfreqs = NULL,
gc_dist = NULL,
sampleColName = "bedFile",
chunkSize = 20,
full_path = FALSE,
annfile = NULL,
threads = 1,
enhancer = NULL,
filetype = NULL,
ignoreStrand = TRUE,
cov_threshold = 1,
tempDir = file.path(tempdir(), "methylTFR")
)Arguments
- sample_ann
Name of a tab-separated (
.tsv) or comma-separated (.csv) sample annotation file insample_dir. It must have a header and contain the column named bysampleColName, which holds the methylation file names. All columns are kept ascolDataof the result. Not used whenannfileis given.- sample_dir
Directory holding the methylation call files (and, usually, the sample annotation file).
- tf_bindsites
A
GRangesListnamed by motif. Each element is aGRangesof the occurrences of that motif. The names must include every name innames(gcfreqs). Get it withgetTFbindsites(motifSet = "jaspar2020")from the methylTFRAnnotationHg38 (or methylTFRAnnotationMm10) package, or build a custom set with methylTFRAnnotationBuilder.- gcfreqs
A named
listwith one element per motif, named as intf_bindsites. Each element is a numeric matrix with the five GC bins in rows and the positions across the binding-site window in columns. Get it withgetGCfreq(motifSet = ...)from the annotation package.- gc_dist
A
GRangesobject of 30-bp genomic windows with an integer metadata columnGC_bin(1 to 5). Get it withgetGenomeGC()from the annotation package.- sampleColName
Name of the column in
sample_annthat holds the methylation file names. Default"bedFile".- chunkSize
Number of motifs processed together in one block. Default 20.
- full_path
Logical. If
TRUE, the file names insampleColNameare full paths andsample_diris not prepended. DefaultFALSE.- annfile
Optional path to the sample annotation file. If given, it is used instead of
sample_anninsample_dir.- threads
Number of workers used to process the motifs of a chunk in parallel. Default 1 (serial).
- enhancer
An optional
GRangesobject of regions, for example distal regulatory elements. Binding sites outside these regions are dropped. Any region set imported asGRangesworks, for example the ENCODE candidate cis-regulatory elements (SCREEN) read withrtracklayer::import(). DefaultNULLuses all binding sites.- filetype
Format of the methylation call files, one of
"bissnp","epp","allc","bismarkCytosine","bismarkCov"or"encode"(case-insensitive). SeereadMethylome.- ignoreStrand
Logical. If
TRUE(default), strand is ignored when overlapping methylation sites with annotations.- cov_threshold
Numeric. Sites with fewer reads than this are dropped. Default 1.
- tempDir
Directory for the temporary HDF5 files written during a run. Default is a folder under
tempdir(). The files are deleted when the run finishes.
Value
A methylTFRdeviations object with the assays
deviations, z and expected, motifs in rows and
samples in columns.
Details
Each sample is read with readMethylome, binned by
GC content with addGCBinToMethylome and scored per motif
with computeDeviation.
See also
runMethylTFRFromRnBeads for running methylTFR
directly on a preprocessed RnBeads object, deviations and
deviationZScores to extract the scores.
Examples
# A minimal end-to-end run on the BATF example data bundled with the
# package. The annotation objects cover a single motif, so the result
# has one row.
load(system.file("extdata", "example_data.rda", package = "methylTFR"))
load(system.file("extdata", "BATF_tf_bindsites.rda", package = "methylTFR"))
load(system.file("extdata", "BATF_gcfreqs.rda", package = "methylTFR"))
load(system.file("extdata", "gcdist_subset.rda", package = "methylTFR"))
# runMethylTFR() reads per-sample calls from disk, so the bundled sites
# are written out as a bismarkCov file first.
sample_dir <- tempfile("methylTFR_example")
dir.create(sample_dir)
n_meth <- round(msites$score * msites$coverage)
write.table(
data.frame(
chr = as.character(GenomicRanges::seqnames(msites)),
start = GenomicRanges::start(msites),
end = GenomicRanges::end(msites),
percent = msites$score * 100,
meth = n_meth,
unmeth = msites$coverage - n_meth
),
file.path(sample_dir, "sample_1.cov"),
sep = "\t", row.names = FALSE, col.names = FALSE, quote = FALSE
)
write.table(
data.frame(sampleName = "sample_1", bedFile = "sample_1.cov"),
file.path(sample_dir, "samples.tsv"),
sep = "\t", row.names = FALSE, quote = FALSE
)
devs <- runMethylTFR(
sample_ann = "samples.tsv",
sample_dir = sample_dir,
tf_bindsites = tf_bindsites,
gcfreqs = gcfreqs,
gc_dist = gcdist,
filetype = "bismarkCov"
)
#> SUCCESS [2026-11-20 14:13:52] The samples are successfully located
#> INFO [2026-11-20 14:13:52] Initializing the temp sink: /tmp/RtmpS15ZYq/methylTFR/methylTFR19663e34581b.h5
#> INFO [2026-11-20 14:13:52] Initializing the temp sink: /tmp/RtmpS15ZYq/methylTFR/methylTFR196658801599.h5
#> INFO [2026-11-20 14:13:52] Processing sample_1.cov
#> INFO [2026-11-20 14:13:53] Finished processing sample_1.cov
#> SUCCESS [2026-11-20 14:13:53] Computed all deviations successfully
deviations(devs)
#> sample_1.cov
#> BATF -0.1167365
unlink(sample_dir, recursive = TRUE)
