[BioC] nearest for GRanges ignoring overlapping ranges

Janet Young jayoung at fhcrc.org
Mon Aug 20 22:42:10 CEST 2012


Hi there,

I'm using the release version of GenomicRanges (1.8.12).   The nearest function is giving me an answer on my GRanges objects, but it's not including overlapping ranges (the help page says it should, and that behaviour makes sense to me).  The GRanges version of nearest is ignoring overlapping ranges, whereas the IRanges version is reporting them.   I think the code below will demonstrate the issue(?)

thanks very much,

Janet

------------------------------------------------------------------- 

Dr. Janet Young 

Tapscott and Malik labs

Fred Hutchinson Cancer Research Center
1100 Fairview Avenue N., C3-168, 
P.O. Box 19024, Seattle, WA 98109-1024, USA.

tel: (206) 667 1471 fax: (206) 667 6524
email: jayoung  ...at...  fhcrc.org


------------------------------------------------------------------- 





library(GenomicRanges)

gr1 <- GRanges(seqnames=c("chr1","chr1","chr1","chr2"),ranges=IRanges(start=c(10,20,30,10),width=10) )

gr2 <- GRanges(seqnames=c("chr1","chr1"),ranges=IRanges(start=c(15,20),width=2) )

### using the GRanges version of nearest ignores overlapping ranges
near1 <- nearest( gr1, gr2)
# [1]  2  1  2 NA
### but gr1[1] overlaps gr2[1], so near1[1] should be 1
### and gr1[2] overlaps gr2[2], so near1[2] should be 2

#### using the IRanges version of nearest gives us the right answer. Just doing the chr1 ranges here:
near2 <- nearest( ranges( gr1[which(seqnames(gr1)=="chr1")]), ranges(gr2[which(seqnames(gr2)=="chr1")])  ) 
# [1] 1 2 2
#### this looks right

sessionInfo()

R version 2.15.1 (2012-06-22)
Platform: i386-apple-darwin9.8.0/i386 (32-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] GenomicRanges_1.8.12 IRanges_1.14.4       BiocGenerics_0.2.0  

loaded via a namespace (and not attached):
[1] stats4_2.15.1



More information about the Bioconductor mailing list