Search
Question: Bug in follow and precede
0
gravatar for Luukperdaems
25 days ago by
Luukperdaems0 wrote:

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)
ADD COMMENTlink modified 13 days ago by Valerie Obenchain ♦♦ 6.7k • written 25 days ago by Luukperdaems0
2
gravatar for Valerie Obenchain
13 days ago by
Valerie Obenchain ♦♦ 6.7k
United States
Valerie Obenchain ♦♦ 6.7k wrote:

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 COMMENTlink written 13 days ago by Valerie Obenchain ♦♦ 6.7k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.2.0
Traffic: 407 users visited in the last hour