Skip to content

Nearest range missing from the return of nearest_ranges when ranges are touching. #111

Description

@brechtmann

Thank you for this package!

However, I noticed some behavior that seems unexpected. In the example below, I initialize a PyRanges object with three ranges, and a second one with a single range. Since the range in the second object touches the middle range from the first object, I would expect the range [6-7) to be among the nearest ranges.

import pyranges as pr
f1 = pr.PyRanges(dict(Chromosome="chr1", Start=[1, 6, 20], End=[2, 7, 22], Strand=["+", "+", "+"]))
f1

Chromosome Start End Strand
chr1 1 2 +
chr1 6 7 +
chr1 20 22 +
f2 = pr.PyRanges(dict(Chromosome="chr1", Start=[5], End=[6], Strand=["+"]))
Chromosome Start End Strand
chr1 5 6 +

f1.nearest_ranges(f2)
Chromosome Start End Strand Chromosome_b Start_b End_b Strand_b Distance
chr1 1 2 + chr1 5 6 + 4
chr1 20 22 + chr1 5 6 + 15

When swapping the ranges the closest range is reported.

f2.nearest_ranges(f1)
Chromosome Start End Strand Chromosome_b Start_b End_b Strand_b Distance
chr1 5 6 + chr1 6 7 + 1
pr.__version__

'1.1.4'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions