bed_closest: Identify closest intervals.

Description Usage Arguments Details Value See Also Examples

View source: R/bed_closest.r

Description

Identify closest intervals.

Usage

1
bed_closest(x, y, overlap = TRUE, suffix = c(".x", ".y"))

Arguments

x

tbl_interval()

y

tbl_interval()

overlap

report overlapping intervals

suffix

colname suffixes in output

Details

input tbls are grouped by chrom by default, and additional groups can be added using dplyr::group_by(). For example, grouping by strand will constrain analyses to the same strand. To compare opposing strands across two tbls, strands on the y tbl can first be inverted using flip_strands().

Value

tbl_interval() with additional columns:

See Also

http://bedtools.readthedocs.io/en/latest/content/tools/closest.html

Other multiple set operations: bed_coverage, bed_intersect, bed_map, bed_subtract, bed_window

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
x <- trbl_interval(
  ~chrom, ~start, ~end,
  'chr1', 100,    125
)

y <- trbl_interval(
  ~chrom, ~start, ~end,
  'chr1', 25,     50,
  'chr1', 140,    175
)

bed_glyph(bed_closest(x, y))

x <- trbl_interval(
  ~chrom, ~start, ~end,
  "chr1", 500,    600,
  "chr2", 5000,   6000
)

y <- trbl_interval(
  ~chrom, ~start, ~end,
  "chr1", 100,    200,
  "chr1", 150,    200,
  "chr1", 550,    580,
  "chr2", 7000,   8500
)

bed_closest(x, y)

bed_closest(x, y, overlap = FALSE)

# Report distance based on strand
x <- trbl_interval(
  ~chrom, ~start, ~end, ~name, ~score, ~strand,
  "chr1", 10,	   20,   "a",   1,      "-"
)

y <- trbl_interval(
  ~chrom, ~start, ~end, ~name, ~score, ~strand,
  "chr1", 8,	     9,	   "b",   1,      "+",
  "chr1", 21,	   22,	 "b",   1,      "-"
)

res <- bed_closest(x, y)

# convert distance based on strand
res$.dist_strand <- ifelse(res$strand.x == "+", res$.dist, -(res$.dist))
res

# report absolute distances
res$.abs_dist <- abs(res$.dist)
res

rnabioco/valr documentation built on Jan. 6, 2019, 9:06 a.m.