Fast conversion of genomic coordinate strings to a GRanges object with
reference sequences fetched from installed BSgenome.* packages.
Designed for large sliding-window inputs: genome packages are loaded once,
coordinate strings are parsed in one pass, and sequences are extracted with
vectorized getSeq (or optional chromosome
preloading).
coor_to_genomic_ranges(
input,
complement_seq = NULL,
method = c("vectorized", "preload_chr")
)A GRanges object with metadata columns:
sequenceReference sequence for each interval.
complementComplementary sequence.
GCGC percentage (0-100) per interval, computed as
100 * (G+C)/(A+C+G+T) so that N is excluded from the denominator.
region_idRegion identifier from the coordinate string.
genome_pkgBSgenome package name used.
Coordinate input. Either:
A list with pkg_name (BSgenome package name) and seq
(character vector of coordinate strings). Preferred for many windows
on the same genome.
A plain character vector of coordinate strings (legacy format; genome package name is read from field 4 when present).
Supported colon-separated formats:
chr:start-end:strand:region_id - requires pkg_name
in the input list.
chr:start-end:strand:pkg_name:region_id - as produced by
make_genomiccoord.
Optional complement coordinates in the same format as
input$seq. When NULL, complements are generated automatically
from sequence.
Sequence extraction strategy:
"vectorized"One getSeq() call per genome package
(default). Best when windows are scattered across many chromosomes.
"preload_chr"Load each chromosome once and extract all
of its windows in a single extractAt() call. Recommended for
dense tiling of one or a few chromosomes (e.g. genome-wide sliding
windows), where it is several times faster than getSeq();
holds one chromosome in memory at a time.
Junhui Li
For genome-wide tiling with thousands of windows, pass coordinates as
list(pkg_name = "BSgenome.Hsapiens.UCSC.hg38", seq = ...) so the
genome package is loaded once instead of per interval.
to_genomic_ranges, to_genomic_ranges_fast
if (FALSE) {
coords <- c(
"chr1:1000-1199:+:win1",
"chr1:1200-1399:+:win2"
)
gr <- coor_to_genomic_ranges(
list(pkg_name = "BSgenome.Hsapiens.UCSC.hg38", seq = coords)
)
gr
}
Run the code above in your browser using DataLab