Bug in follow and precede
1
0
Entering edit mode
abc • 0
@abc-18446
Last seen 4.5 years ago

In my code, I want to get the row of the y range that comes after the x range by using the code below. But when I run the code, I get the row of the y range that comes before the x range. Precede gives the opposite.

y <- data.frame('seqnames' = c('chr11', 'chr11'), 'start' = c(62789197, 62789292), 'end' = c(62789210, 62789426), strand = c('+', '+'))

x <- data.frame('seqnames' = 'chr11', 'start' = 62789211, 'end' = 62789271, strand = '+')

x <- GenomicRanges::makeGRangesFromDataFrame(x, ignore.strand = F)
y <- GenomicRanges::makeGRangesFromDataFrame(y, ignore.strand = F)

x <- GenomicRanges::GRanges(seqnames(x), IRanges(end(x),   end(x)),   strand = strand(x))
y <- GenomicRanges::GRanges(seqnames(y), IRanges(start(y), start(y)), strand = strand(y))

IRanges::follow(x, y, select = 'last', ignore.strand = F)
software error genomicranges iranges • 1.2k views
ADD COMMENT
2
Entering edit mode
@valerie-obenchain-4275
Last seen 2.9 years ago
United States

Hi,

There is a GRanges method for follow() so no need to call IRanges::follow(). By definition the IRanges method will ignore strand because IRanges objects do have have a strand. If you want to ignore strand in the GRanges, just use ignore.strand=TRUE.

From the ?follow man page:

        • precede: For each range in ‘x’, ‘precede’ returns the index
          of the interval in ‘subject’ that is directly preceded by the
          query range. Overlapping ranges are excluded. ‘NA’ is
          returned when there are no qualifying ranges in ‘subject’.

        • follow: The opposite of ‘precede’, this function returns the
          index of the range in ‘subject’ that a query range in ‘x’
          directly follows. Overlapping ranges are excluded. ‘NA’ is
          returned when there are no qualifying ranges in ‘subject’.

Based on the description in the man page, these functions are returning what they should.

Your 'x' and 'y':

> x
GRanges object with 1 range and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]    chr11  62789271      +
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths
> y
GRanges object with 2 ranges and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]    chr11  62789197      +
  [2]    chr11  62789292      +
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

'x' precedes 'y':
> precede(x, y)
[1] 2

'x' follows 'y':

> follow(x, y)
[1] 1


Valerie

ADD COMMENT

Login before adding your answer.

Traffic: 521 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6