Hello,

I have to grange-objects - gr1 and gr2. And I wish to know:
1) What are the neigbouring intervals of gr1 in gr2 - upstream and
downstream?
2) What is the distance in bp between the neighbouring intervals?

Could anybody give me a hint how this is done?
Thanks
Hermann

> dput (gr1)
new("GRanges"
    , seqnames = new("Rle"
    , values = structure(1L, .Label = c("chr1", "chr10", "chr11", "chr12",
"chr13",
"chr14", "chr15", "chr16", "chr17", "chr18", "chr19", "chr2",
"chr20", "chr21", "chr22", "chr3", "chr4", "chr5", "chr6", "chr7",
"chr8", "chr9", "chrX", "chrY"), class = "factor")
    , lengths = 4L
    , elementMetadata = NULL
    , metadata = list()
)
    , ranges = new("IRanges"
    , start = c(540823L, 752809L, 771015L, 773361L)
    , width = c(221L, 230L, 520L, 247L)
    , NAMES = NULL
    , elementType = "integer"
    , elementMetadata = NULL
    , metadata = list()
)
    , strand = new("Rle"
    , values = structure(3L, .Label = c("+", "-", "*"), class = "factor")
    , lengths = 4L
    , elementMetadata = NULL
    , metadata = list()
)
    , elementMetadata = new("DataFrame"
    , rownames = NULL
    , nrows = 4L
    , listData = structure(list(edensity = c(589L, 574L, 578L, 571L), epeak
= c(111L,
89L, 234L, 136L), over = c(0L, 1L, 1L, 1L)), .Names = c("edensity",
"epeak", "over"))
    , elementType = "ANY"
    , elementMetadata = NULL
    , metadata = list()
)
    , seqinfo = new("Seqinfo"
    , seqnames = c("chr1", "chr10", "chr11", "chr12", "chr13", "chr14",
"chr15",
"chr16", "chr17", "chr18", "chr19", "chr2", "chr20", "chr21",
"chr22", "chr3", "chr4", "chr5", "chr6", "chr7", "chr8", "chr9",
"chrX", "chrY")
    , seqlengths = c(NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_)
    , is_circular = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA)
    , genome = c(NA_character_, NA_character_, NA_character_,
NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_
)
)
    , metadata = list()
)
> dput (gr1)
new("GRanges"
    , seqnames = new("Rle"
    , values = structure(1L, .Label = c("chr1", "chr10", "chr11", "chr12",
"chr13",
"chr14", "chr15", "chr16", "chr17", "chr18", "chr19", "chr2",
"chr20", "chr21", "chr22", "chr3", "chr4", "chr5", "chr6", "chr7",
"chr8", "chr9", "chrX", "chrY"), class = "factor")
    , lengths = 4L
    , elementMetadata = NULL
    , metadata = list()
)
    , ranges = new("IRanges"
    , start = c(540823L, 752809L, 771015L, 773361L)
    , width = c(221L, 230L, 520L, 247L)
    , NAMES = NULL
    , elementType = "integer"
    , elementMetadata = NULL
    , metadata = list()
)
    , strand = new("Rle"
    , values = structure(3L, .Label = c("+", "-", "*"), class = "factor")
    , lengths = 4L
    , elementMetadata = NULL
    , metadata = list()
)
    , elementMetadata = new("DataFrame"
    , rownames = NULL
    , nrows = 4L
    , listData = structure(list(edensity = c(589L, 574L, 578L, 571L), epeak
= c(111L,
89L, 234L, 136L), over = c(0L, 1L, 1L, 1L)), .Names = c("edensity",
"epeak", "over"))
    , elementType = "ANY"
    , elementMetadata = NULL
    , metadata = list()
)
    , seqinfo = new("Seqinfo"
    , seqnames = c("chr1", "chr10", "chr11", "chr12", "chr13", "chr14",
"chr15",
"chr16", "chr17", "chr18", "chr19", "chr2", "chr20", "chr21",
"chr22", "chr3", "chr4", "chr5", "chr6", "chr7", "chr8", "chr9",
"chrX", "chrY")
    , seqlengths = c(NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_)
    , is_circular = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA)
    , genome = c(NA_character_, NA_character_, NA_character_,
NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_
)
)
    , metadata = list()
)

> gr1
GRanges with 4 ranges and 3 metadata columns:
      seqnames           ranges strand |  edensity     epeak      over
         <Rle>        <IRanges>  <Rle> | <integer> <integer> <integer>
  [1]     chr1 [540823, 541043]      * |       589       111         0
  [2]     chr1 [752809, 753038]      * |       574        89         1
  [3]     chr1 [771015, 771534]      * |       578       234         1
  [4]     chr1 [773361, 773607]      * |       571       136         1
  ---
  seqlengths:
    chr1 chr10 chr11 chr12 chr13 chr14 ...  chr6  chr7  chr8  chr9  chrX
chrY
      NA    NA    NA    NA    NA    NA ...    NA    NA    NA    NA    NA
NA
> gr2
GRanges with 3 ranges and 3 metadata columns:
      seqnames           ranges strand |  edensity     epeak      over
         <Rle>        <IRanges>  <Rle> | <integer> <integer> <integer>
  [1]     chr1 [ 53141,  53685]      * |       601       212         0
  [2]     chr1 [521536, 521622]      * |       568        37         1
  [3]     chr1 [805002, 805650]      * |      1000       326         1
  ---
  seqlengths:
    chr1 chr10 chr11 chr12 chr13 chr14 ...  chr6  chr7  chr8  chr9  chrX
chrY
      NA    NA    NA    NA    NA    NA ...    NA    NA    NA    NA    NA
NA

	[[alternative HTML version deleted]]

