Keep distinct ranges by including mcols

distinctMC(x, ..., .keep_all = FALSE)

Arguments

x

A GenomicRanges object

...

<data-masking> Passed to distinct

.keep_all

If TRUE, keep all columns in x

Value

A GRanges object

Details

Wrapper to distinct for GRanges objects. Finds unique ranges and mcols in combination and retains only the distinct combinations, in keeping with the dplyr function.

Will default to unique(granges(x)) if no columns are provided

Examples

gr <- GRanges(rep(c("chr1:1-10"), 2))
gr$id <- paste0("range", seq_along(gr))
gr$gene <- "gene1"
gr
#> GRanges object with 2 ranges and 2 metadata columns:
#>       seqnames    ranges strand |          id        gene
#>          <Rle> <IRanges>  <Rle> | <character> <character>
#>   [1]     chr1      1-10      * |      range1       gene1
#>   [2]     chr1      1-10      * |      range2       gene1
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
distinctMC(gr)
#> GRanges object with 1 range and 0 metadata columns:
#>       seqnames    ranges strand
#>          <Rle> <IRanges>  <Rle>
#>   [1]     chr1      1-10      *
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
distinctMC(gr, gene)
#> GRanges object with 1 range and 1 metadata column:
#>       seqnames    ranges strand |        gene
#>          <Rle> <IRanges>  <Rle> | <character>
#>   [1]     chr1      1-10      * |       gene1
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
distinctMC(gr, gene, .keep_all = TRUE)
#> GRanges object with 1 range and 2 metadata columns:
#>       seqnames    ranges strand |          id        gene
#>          <Rle> <IRanges>  <Rle> | <character> <character>
#>   [1]     chr1      1-10      * |      range1       gene1
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths