/** * Determines whether this interval overlaps the provided locatable. * * @param other interval to check * @return true if this interval overlaps other, otherwise false */ default boolean overlaps(Locatable other) { return withinDistanceOf(other, 0); }
/** * Determines whether this interval contains the entire region represented by other * (in other words, whether it covers it). * * * @param other interval to check * @return true if this interval contains all of the base positions spanned by other, otherwise false */ default boolean contains(Locatable other) { return contigsMatch(other) && CoordMath.encloses(getStart(), getEnd(), other.getStart(), other.getEnd()); }
/** * Determine if this is on the same contig as other * this must be equivalent to this.getContig().equals(other.getContig()) but may be implemented more efficiently * * @return true iff this.getContig().equals(other.getContig()) */ default boolean contigsMatch(Locatable other) { return getContig() != null && other != null && Objects.equals(this.getContig(), other.getContig()); } }
@Test(dataProvider = "IntervalContainsData") public void testContains(final Locatable firstInterval, final Locatable secondInterval, final boolean expectedContainsResult ) { Assert.assertEquals(firstInterval.contains(secondInterval), expectedContainsResult, "contains() returned incorrect result for intervals " + firstInterval + " and " + secondInterval); } }
@Test(dataProvider = "IntervalSizeData") public void testGetSize(final Locatable interval, final int expectedSize ) { Assert.assertEquals(interval.getLengthOnReference(), expectedSize, "size() incorrect for interval " + interval); }
/** * Determine if this is on the same contig as other * this must be equivalent to this.getContig().equals(other.getContig()) but may be implemented more efficiently * * @return true iff this.getContig().equals(other.getContig()) */ default boolean contigsMatch(Locatable other) { return getContig() != null && other != null && Objects.equals(this.getContig(), other.getContig()); } }
/** * Determines whether this interval comes within {@code distance} of overlapping the provided locatable. * When distance = 0 this is equal to {@link #overlaps(Locatable)} * * @param other interval to check * @param distance how many bases may be between the two intervals for us to still consider them overlapping. * @return true if this interval overlaps other, otherwise false */ default boolean withinDistanceOf(Locatable other, int distance) { return contigsMatch(other) && CoordMath.overlaps(getStart(), getEnd(), other.getStart()-distance, other.getEnd()+distance); }
/** * Determines whether this interval overlaps the provided locatable. * * @param other interval to check * @return true if this interval overlaps other, otherwise false */ default boolean overlaps(Locatable other) { return withinDistanceOf(other, 0); }
/** * Queries for records overlapping the {@link Locatable} specified. * Note that this method requires VCF files with an associated index. If no index exists a TribbleException will be thrown. * * @return non-null iterator over VariantContexts */ public CloseableIterator<VariantContext> query(final Locatable locatable) { return query(locatable.getContig(), locatable.getStart(), locatable.getEnd()); }
/** * Determines whether this interval contains the entire region represented by other * (in other words, whether it covers it). * * * @param other interval to check * @return true if this interval contains all of the base positions spanned by other, otherwise false */ default boolean contains(Locatable other) { return contigsMatch(other) && CoordMath.encloses(getStart(), getEnd(), other.getStart(), other.getEnd()); }
@Test(dataProvider = "overlapsWithMargin") public void testOverlapWithMargin(final Locatable firstInterval, final Locatable secondInterval, int margin, final boolean expectedOverlapResult ) { Assert.assertEquals(firstInterval.withinDistanceOf(secondInterval, margin), expectedOverlapResult, "overlap() returned incorrect result for intervals " + firstInterval + " and " + secondInterval); }
/** * Query the reader for a particular interval corresponding to a contig and a 1-based closed * * @param locus The locus to be queried * @return an iterator containing the features that at in the interval. * @throws IOException If there's a problem reading or if the reader is not queryable, e.g. if it doesn't have an index. */ default CloseableTribbleIterator<T> query(Locatable locus) throws IOException { return query(locus.getContig(), locus.getStart(), locus.getEnd()); }
/** * Determines whether this interval comes within {@code distance} of overlapping the provided locatable. * When distance = 0 this is equal to {@link #overlaps(Locatable)} * * @param other interval to check * @param distance how many bases may be between the two intervals for us to still consider them overlapping. * @return true if this interval overlaps other, otherwise false */ default boolean withinDistanceOf(Locatable other, int distance) { return contigsMatch(other) && CoordMath.overlaps(getStart(), getEnd(), other.getStart()-distance, other.getEnd()+distance); }
/** * Queries for records overlapping the {@link Locatable} specified. * Note that this method requires VCF files with an associated index. If no index exists a TribbleException will be thrown. * * @return non-null iterator over VariantContexts */ public CloseableIterator<VariantContext> query(final Locatable locatable) { return query(locatable.getContig(), locatable.getStart(), locatable.getEnd()); }
/** * Query the reader for a particular interval corresponding to a contig and a 1-based closed * * @param locus The locus to be queried * @return an iterator containing the features that at in the interval. * @throws IOException If there's a problem reading or if the reader is not queryable, e.g. if it doesn't have an index. */ default CloseableTribbleIterator<T> query(Locatable locus) throws IOException { return query(locus.getContig(), locus.getStart(), locus.getEnd()); }
/** * Test overlapping interval * @param key the Locatable * @return true if it contains an object overlapping the interval */ public boolean containsOverlapping(final Locatable key) { final IntervalTree<T> tree = mSequenceMap.get(key.getContig()); return tree!=null && tree.overlappers(key.getStart(), key.getEnd()).hasNext(); }