coor_to_genomic_ranges: Convert genomic coordinate strings to a GRanges object

View source: R/coor_to_genomic_ranges.R

coor_to_genomic_rangesR Documentation

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

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

"preload_chr"

Load each chromosome once and extract windows with subseq(). Faster for dense whole-chromosome tiling; uses more memory.

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.

Value

A GRanges object with metadata columns:

sequence

Reference sequence for each interval.

complement

Complementary sequence.

GC

GC fraction (0-1) per interval.

region_id

Region identifier from the coordinate string.

genome_pkg

BSgenome package name used.

Author(s)

Junhui Li

See Also

to_genomic_ranges, to_genomic_ranges_fast

Examples

## Not run: 
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

## End(Not run)


TmCalculator documentation built on Aug. 28, 2026, 5:09 p.m.