Disjoin then aggregate a Ranges object

disjoin_ranges(.data, ...)

disjoin_ranges_directed(.data, ...)

Arguments

.data

a Ranges object to disjoin

...

Name-value pairs of summary functions.

Value

a Ranges object that is now disjoint (no bases overlap).

Examples

df <- data.frame(start = 1:10, width = 5,  seqnames = "seq1",
strand = sample(c("+", "-", "*"), 10, replace = TRUE), gc = runif(10))
rng <- as_granges(df)
rng %>% disjoin_ranges()
#> GRanges object with 14 ranges and 0 metadata columns:
#>        seqnames    ranges strand
#>           <Rle> <IRanges>  <Rle>
#>    [1]     seq1         1      *
#>    [2]     seq1         2      *
#>    [3]     seq1         3      *
#>    [4]     seq1         4      *
#>    [5]     seq1         5      *
#>    ...      ...       ...    ...
#>   [10]     seq1        10      *
#>   [11]     seq1        11      *
#>   [12]     seq1        12      *
#>   [13]     seq1        13      *
#>   [14]     seq1        14      *
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
rng %>% disjoin_ranges(gc = mean(gc))
#> GRanges object with 14 ranges and 1 metadata column:
#>        seqnames    ranges strand |        gc
#>           <Rle> <IRanges>  <Rle> | <numeric>
#>    [1]     seq1         1      * | 0.0378026
#>    [2]     seq1         2      * | 0.3078700
#>    [3]     seq1         3      * | 0.4496847
#>    [4]     seq1         4      * | 0.3994491
#>    [5]     seq1         5      * | 0.3797066
#>    ...      ...       ...    ... .       ...
#>   [10]     seq1        10      * |  0.531335
#>   [11]     seq1        11      * |  0.480802
#>   [12]     seq1        12      * |  0.338751
#>   [13]     seq1        13      * |  0.403219
#>   [14]     seq1        14      * |  0.448299
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
rng %>% disjoin_ranges_directed(gc = mean(gc))
#> GRanges object with 15 ranges and 1 metadata column:
#>        seqnames    ranges strand |        gc
#>           <Rle> <IRanges>  <Rle> | <numeric>
#>    [1]     seq1       4-8      + | 0.2487424
#>    [2]     seq1         1      - | 0.0378026
#>    [3]     seq1       2-4      - | 0.3078700
#>    [4]     seq1         5      - | 0.3054922
#>    [5]     seq1         6      - | 0.4393370
#>    ...      ...       ...    ... .       ...
#>   [11]     seq1         9      * |  0.433807
#>   [12]     seq1        10      * |  0.437430
#>   [13]     seq1     11-12      * |  0.338751
#>   [14]     seq1        13      * |  0.403219
#>   [15]     seq1        14      * |  0.448299
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths