Reduce then aggregate a Ranges object

reduce_ranges(.data, ...)

reduce_ranges_directed(.data, ...)

Arguments

.data

a Ranges object to reduce

...

Name-value pairs of summary functions.

Value

a Ranges object with the

Examples

set.seed(10) df <- data.frame(start = sample(1:10), width = 5, seqnames = "seq1", strand = sample(c("+", "-", "*"), 10, replace = TRUE), gc = runif(10)) rng <- as_granges(df) rng %>% reduce_ranges()
#> GRanges object with 1 range and 0 metadata columns: #> seqnames ranges strand #> <Rle> <IRanges> <Rle> #> [1] seq1 1-14 * #> ------- #> seqinfo: 1 sequence from an unspecified genome; no seqlengths
rng %>% reduce_ranges(gc = mean(gc))
#> GRanges object with 1 range and 1 metadata column: #> seqnames ranges strand | gc #> <Rle> <IRanges> <Rle> | <numeric> #> [1] seq1 1-14 * | 0.583195869973861 #> ------- #> seqinfo: 1 sequence from an unspecified genome; no seqlengths
rng %>% reduce_ranges_directed(gc = mean(gc))
#> GRanges object with 4 ranges and 1 metadata column: #> seqnames ranges strand | gc #> <Rle> <IRanges> <Rle> | <numeric> #> [1] seq1 1-5 + | 0.500503229675815 #> [2] seq1 9-13 + | 0.535597037756816 #> [3] seq1 3-12 - | 0.558134701044764 #> [4] seq1 2-14 * | 0.64082990703173 #> ------- #> seqinfo: 1 sequence from an unspecified genome; no seqlengths
x <- data.frame(start = c(11:13, 2, 7:6), width=3, id=sample(letters[1:3], 6, replace = TRUE), score= sample(1:6)) x <- as_iranges(x) x %>% reduce_ranges()
#> IRanges object with 3 ranges and 0 metadata columns: #> start end width #> <integer> <integer> <integer> #> [1] 2 4 3 #> [2] 6 9 4 #> [3] 11 15 5
x %>% reduce_ranges(score = sum(score))
#> IRanges object with 3 ranges and 1 metadata column: #> start end width | score #> <integer> <integer> <integer> | <integer> #> [1] 2 4 3 | 5 #> [2] 6 9 4 | 5 #> [3] 11 15 5 | 11
x %>% group_by(id) %>% reduce_ranges(score = sum(score))
#> IRanges object with 4 ranges and 2 metadata columns: #> start end width | id score #> <integer> <integer> <integer> | <factor> <integer> #> [1] 11 13 3 | c 2 #> [2] 2 4 3 | b 5 #> [3] 12 15 4 | b 9 #> [4] 6 9 4 | a 5