GRanges
coordinates based on another GRanges
objectR/AllGenerics.R
, R/shiftGenomicToTranscript.R
shiftGenomicToTranscript.Rd
shiftGenomicToTranscript
shifts positions of a
GRanges
object based on coordinates of another GRanges
object. The most common
application is to shift genomic coordinates to transcript coordinates, which
is reflected in the name. shiftTranscriptToGenomic
implements the
reverse operation.
Matches are determined by
findOverlaps
for
shiftGenomicToTranscript
and by
findMatches
for
shiftTranscriptToGenomic
using the seqnames
of the
subject
and the names
of tx
.
shiftTranscriptToGenomic(subject, tx)
shiftGenomicToTranscript(subject, tx)
# S4 method for GRanges,GRangesList
shiftTranscriptToGenomic(subject, tx)
# S4 method for GRangesList,GRangesList
shiftTranscriptToGenomic(subject, tx)
# S4 method for GRanges,GRangesList
shiftGenomicToTranscript(subject, tx)
# S4 method for GRangesList,GRangesList
shiftGenomicToTranscript(subject, tx)
a GRanges
or
GRangesList
object
a named GRangesList
object.
library(GenomicRanges)
# Construct some example data
subject1 <- GRanges("chr1", IRanges(3, 6),
strand = "+")
subject2 <- GRanges("chr1", IRanges(c(17,23), width=3),
strand = c("+","-"))
subject3 <- GRanges("chr2", IRanges(c(51, 54), c(53, 59)),
strand = "-")
subject <- GRangesList(a=subject1, b=subject2, c=subject3)
tx1 <- GRanges("chr1", IRanges(1, 40),
strand="+")
tx2 <- GRanges("chr1", IRanges(10, 30),
strand="+")
tx3 <- GRanges("chr2", IRanges(50, 60),
strand="-")
tx <- GRangesList(a=tx1, b=tx2, c=tx3)
# shift to transcript coordinates. Since the third subject does not have
# a match in tx it is dropped with a warning
shifted_grl <- shiftGenomicToTranscript(subject,tx)
#> Warning: Dropping elements of 'subject' which could not be repositioned.
# ... and back
shifted_grl2 <- shiftTranscriptToGenomic(shifted_grl,tx)
# comparison of ranges work. However the seqlevels differ
ranges(shifted_grl2) == ranges(subject[list(1,c(1,1),c(1,2))])
#> Warning: longer argument not a multiple of length of shorter
#> LogicalList of length 4
#> [["a"]] TRUE
#> [["a"]] FALSE FALSE
#> [["b"]] FALSE FALSE
#> [["c"]] FALSE FALSE