Operations can be performed on merged intervals by specifying name-value pairs. Default max_dist of 0 means book-ended intervals are merged.

bed_merge(x, max_dist = 0, ...)

Arguments

x

tbl_interval()

max_dist

maximum distance between intervals to merge

...

name-value pairs that specify operations on merged intervals

Value

tbl_interval()

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().

See also

Examples

x <- trbl_interval( ~chrom, ~start, ~end, 'chr1', 1, 50, 'chr1', 10, 75, 'chr1', 100, 120 ) bed_glyph(bed_merge(x))
x <- trbl_interval( ~chrom, ~start, ~end, ~value, ~strand, "chr1", 1, 50, 1, '+', "chr1", 100, 200, 2, '+', "chr1", 150, 250, 3, '-', "chr2", 1, 25, 4, '+', "chr2", 200, 400, 5, '-', "chr2", 400, 500, 6, '+', "chr2", 450, 550, 7, '+' ) bed_merge(x)
#> # A tibble: 4 x 3 #> chrom start end #> <chr> <int> <int> #> 1 chr1 1 50 #> 2 chr1 100 250 #> 3 chr2 1 25 #> 4 chr2 200 550
bed_merge(x, max_dist = 100)
#> # A tibble: 3 x 3 #> chrom start end #> <chr> <int> <int> #> 1 chr1 1 200 #> 2 chr2 1 25 #> 3 chr2 200 550
# merge intervals on same strand bed_merge(dplyr::group_by(x, strand))
#> # A tibble: 6 x 4 #> # Groups: strand [2] #> chrom start end strand #> <chr> <int> <int> <chr> #> 1 chr1 150 250 - #> 2 chr2 200 400 - #> 3 chr1 1 50 + #> 4 chr1 100 200 + #> 5 chr2 1 25 + #> 6 chr2 400 550 +
bed_merge(x, .value = sum(value))
#> # A tibble: 4 x 4 #> chrom start end .value #> <chr> <dbl> <dbl> <dbl> #> 1 chr1 1 50 1 #> 2 chr1 100 250 5 #> 3 chr2 1 25 4 #> 4 chr2 200 550 18