Learn R Programming

TmCalculator (version 1.1.0)

coor_to_genomic_ranges: Convert genomic coordinate strings to a GRanges object

Description

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).

Usage

coor_to_genomic_ranges(
  input,
  complement_seq = NULL,
  method = c("vectorized", "preload_chr")
)

Value

A GRanges object with metadata columns:

sequence

Reference sequence for each interval.

complement

Complementary sequence.

GC

GC percentage (0-100) per interval, computed as 100 * (G+C)/(A+C+G+T) so that N is excluded from the denominator.

region_id

Region identifier from the coordinate string.

genome_pkg

BSgenome package name used.

Arguments

input

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.

complement_seq

Optional complement coordinates in the same format as input$seq. When NULL, complements are generated automatically from sequence.

method

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.

Author

Junhui Li

Details

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.

See Also

to_genomic_ranges, to_genomic_ranges_fast

Examples

Run this code
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