I found out that NROW(dist) is one row shorter than NROW(rt.gr), meaning thate is one range in rt.gr that does not have a corresponding nearest range in mop. How do I find the missing row equivalent in rt.gr? Possibly did not return a value? I have checked ranges(rt.gr) for non-numeric values and did not find any.
You shouldn't expect that the length of dist will be the same as the length as your rt.gr object. Also, by 'self-contained' example, I meant something that other people could run. Just showing your code is not self-contained because I don't have your data. But here is an example.
## run this first
> example(distanceToNearest)
> query
GRanges object with 2 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] A 1 *
[2] B 5 *
-------
seqinfo: 2 sequences from an unspecified genome; no seqlengths
> subject
GRanges object with 3 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] A 6-10 *
[2] A 5-10 *
[3] A 13-15 *
-------
seqinfo: 1 sequence from an unspecified genome; no seqlengths
## this will return a Hits object that conforms to the 'subject' GRanges object
> distanceToNearest(subject, query)
Hits object with 3 hits and 1 metadata column:
queryHits subjectHits | distance
<integer> <integer> | <integer>
[1] 1 1 | 4
[2] 2 1 | 3
[3] 3 1 | 11
-------
queryLength: 3 / subjectLength: 2
## this will return a Hits object that DOES NOT conform to the 'query' GRanges object.
> distanceToNearest(query,subject)
Hits object with 1 hit and 1 metadata column:
queryHits subjectHits | distance
<integer> <integer> | <integer>
[1] 1 2 | 3
-------
queryLength: 2 / subjectLength: 3
Will you provide a self-contained example that shows the issue? It's hard to respond otherwise.
After issuing this cmd:
I proceeded to do the following:
Then I got the following error: