This operation is similar to bedtools cluster. It reports each set of overlapping or “book-ended” features in an interval file.

cluster_bed(x, max_dist = 0)

Arguments

x

A GRanges

max_dist

Maximum distance between features allowed for features to be merged. Default is 0. That is, overlapping and/or book-ended features are merged.

Value

A GRanges. Compared

References

Manual page of bedtools cluster: https://bedtools.readthedocs.io/en/latest/content/tools/cluster.html

See also

Examples

tbl <- read_bed(system.file("extdata", "example_merge.bed", package = "bedtorch"), use_gr = FALSE)

# Basic usage
clustered <- cluster_bed(tbl)
head(clustered)
#>    chrom start end score cluster
#> 1:    21     3   6     8       1
#> 2:    21    10  16     5       2
#> 3:    21    12  17     4       2
#> 4:    21    15  22     5       2
#> 5:    21    22  25     7       2
#> 6:    21    26  30     7       3
#> -------
#> genome: unspecified.

# Change the maximum distance allowed
clustered <- cluster_bed(tbl, max_dist = 10)
head(clustered)
#>    chrom start end score cluster
#> 1:    21     3   6     8       1
#> 2:    21    10  16     5       1
#> 3:    21    12  17     4       1
#> 4:    21    15  22     5       1
#> 5:    21    22  25     7       1
#> 6:    21    26  30     7       1
#> -------
#> genome: unspecified.