Skip to contents

Calculates the distance to the next range in the target and query genome.

Usage

dist2next(x, step = 1, ignore.strand = FALSE)

# S4 method for class 'GRanges'
dist2next(x, step = 1, ignore.strand = FALSE)

# S4 method for class 'GBreaks'
dist2next(x, step = 1, ignore.strand = FALSE)

Arguments

x

A GenomicRanges::GRanges or a GBreaks object.

step

Distance to the nth block (default: first).

ignore.strand

Calculate distance for ranges on different strands.

Value

For GRanges, returns the object with one extra metadata colums, dist, and for GBreaks two extra columns tdist and qdist, containing the distance to the next range in the reference and query genomes respectively.

Details

The distance is defined by the GenomicRanges::distance function: it is the number of bases between the two ranges, so it is 0 for adjacent ranges, and also for overlapping ranges. It is NA for ranges on different sequences, or on different strands unless ignore.strand = TRUE. Note that because the last range has not next neighbor, the last value is set to Inf arbitrarily.

Examples

dist2next(exampleInversion)
#> GBreaks object with 3 ranges and 3 metadata columns:
#>       seqnames    ranges strand |        query     tdist     qdist
#>          <Rle> <IRanges>  <Rle> |    <GRanges> <numeric> <numeric>
#>   [1]     chrA   100-190      + | chrB:100-190        NA        19
#>   [2]     chrA   210-291      - | chrB:210-291        NA         9
#>   [3]     chrA   301-400      + | chrB:301-400       Inf       Inf
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome
dist2next(granges(exampleInversion))
#> GRanges object with 3 ranges and 1 metadata column:
#>       seqnames    ranges strand |      dist
#>          <Rle> <IRanges>  <Rle> | <numeric>
#>   [1]     chrA   100-190      + |        NA
#>   [2]     chrA   210-291      - |        NA
#>   [3]     chrA   301-400      + |       Inf
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome
dist2next(exampleInversion, ignore.strand = TRUE)
#> GBreaks object with 3 ranges and 3 metadata columns:
#>       seqnames    ranges strand |        query     tdist     qdist
#>          <Rle> <IRanges>  <Rle> |    <GRanges> <numeric> <numeric>
#>   [1]     chrA   100-190      + | chrB:100-190        19        19
#>   [2]     chrA   210-291      - | chrB:210-291         9         9
#>   [3]     chrA   301-400      + | chrB:301-400       Inf       Inf
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome
dist2next(exampleInversion - 20, ignore.strand = TRUE)
#> GBreaks object with 3 ranges and 3 metadata columns:
#>       seqnames    ranges strand |        query     tdist     qdist
#>          <Rle> <IRanges>  <Rle> |    <GRanges> <numeric> <numeric>
#>   [1]     chrA   120-170      + | chrB:100-190        59        19
#>   [2]     chrA   230-271      - | chrB:210-291        49         9
#>   [3]     chrA   321-380      + | chrB:301-400       Inf       Inf
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome
dist2next(exampleInversion, 2)
#> GBreaks object with 3 ranges and 3 metadata columns:
#>       seqnames    ranges strand |        query     tdist     qdist
#>          <Rle> <IRanges>  <Rle> |    <GRanges> <numeric> <numeric>
#>   [1]     chrA   100-190      + | chrB:100-190       110       110
#>   [2]     chrA   210-291      - | chrB:210-291       Inf       Inf
#>   [3]     chrA   301-400      + | chrB:301-400       Inf       Inf
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome