A convenient wrapper to match seqlevels of a query GRanges object to a reference object that contain seqlevels information. Reference can be a GRanges, GRangesList, BioString or DNAString object. Seqlevels which fail to match will be dropped.

matchChromosomes(x, to)

Arguments

x

GRanges object with seqnames to change

to

GRanges object from which seqnames is referenced

Value

Corrected input GRanges

Author

Fursham Hamid

Examples

## ---------------------------------------------------------------------
## EXAMPLE USING TOY DATASET
## ---------------------------------------------------------------------
require(GenomicRanges)

## Create toy GRanges objects
gr1 <- GRanges("1", IRanges(start = c(1, 101), width = c(20, 20)), "+")
gr2 <- GRanges("chr1", IRanges(start = c(1, 101), width = c(20, 20)), "+")

## Match Ensembl-style chromosomes from gr1 to UCSC-style gr2
matchChromosomes(gr1, gr2)
#> GRanges object with 2 ranges and 0 metadata columns:
#>       seqnames    ranges strand
#>          <Rle> <IRanges>  <Rle>
#>   [1]     chr1      1-20      +
#>   [2]     chr1   101-120      +
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths

## Possible to match chrosomomes from GRanges object to a Biostrings 
#    object containing seqlevels
x0 <- c("chr2" = "CTCACCAGTAT", "chr3" = "TGTCAGTCGA")
dna <- Biostrings::DNAStringSet(x0)

## Match gr1 to dna
matchChromosomes(gr1, dna)
#> Warning: 1 seqlevel(s) in `x` are not found in `to`
#> GRanges object with 2 ranges and 0 metadata columns:
#>       seqnames    ranges strand
#>          <Rle> <IRanges>  <Rle>
#>   [1]     chr1      1-20      +
#>   [2]     chr1   101-120      +
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths