public static QueryInterval[] padIntervals(SAMSequenceDictionary dictionary, QueryInterval[] intervals, int padding) { QueryInterval[] padded = Stream.of(intervals) .map(qi -> new QueryInterval(qi.referenceIndex, Math.max(1, qi.start - padding), Math.min(qi.end + padding, dictionary.getSequence(qi.referenceIndex).getSequenceLength()))) .toArray(QueryInterval[]::new); QueryInterval[] optimised = QueryInterval.optimizeIntervals(padded); return optimised; } public static boolean overlaps(QueryInterval[] intervals, int referenceIndex, int position) {
/** * Converts a List of SimpleIntervals into the format required by the SamReader query API * @param rawIntervals SimpleIntervals to be converted * @return A sorted, merged list of QueryIntervals suitable for passing to the SamReader query API */ static QueryInterval[] prepareQueryIntervals( final List<Interval> rawIntervals, final SAMSequenceDictionary sequenceDictionary ) { if ( rawIntervals == null || rawIntervals.isEmpty() ) { return null; } // Convert each SimpleInterval to a QueryInterval final QueryInterval[] convertedIntervals = rawIntervals.stream() .map(rawInterval -> convertSimpleIntervalToQueryInterval(rawInterval, sequenceDictionary)) .toArray(QueryInterval[]::new); // Intervals must be optimized (sorted and merged) in order to use the htsjdk query API return QueryInterval.optimizeIntervals(convertedIntervals); } /**
/** * Converts a List of SimpleIntervals into the format required by the SamReader query API * @param rawIntervals SimpleIntervals to be converted * @return A sorted, merged list of QueryIntervals suitable for passing to the SamReader query API */ static QueryInterval[] prepareQueryIntervals( final List<Interval> rawIntervals, final SAMSequenceDictionary sequenceDictionary ) { if ( rawIntervals == null || rawIntervals.isEmpty() ) { return null; } // Convert each SimpleInterval to a QueryInterval final QueryInterval[] convertedIntervals = rawIntervals.stream() .map(rawInterval -> convertSimpleIntervalToQueryInterval(rawInterval, sequenceDictionary)) .toArray(QueryInterval[]::new); // Intervals must be optimized (sorted and merged) in order to use the htsjdk query API return QueryInterval.optimizeIntervals(convertedIntervals); } /**
/** * Converts a List of SimpleIntervals into the format required by the SamReader query API * @param rawIntervals SimpleIntervals to be converted * @return A sorted, merged list of QueryIntervals suitable for passing to the SamReader query API */ static QueryInterval[] prepareQueryIntervals( final List<Interval> rawIntervals, final SAMSequenceDictionary sequenceDictionary ) { if ( rawIntervals == null || rawIntervals.isEmpty() ) { return null; } // Convert each SimpleInterval to a QueryInterval final QueryInterval[] convertedIntervals = rawIntervals.stream() .map(rawInterval -> convertSimpleIntervalToQueryInterval(rawInterval, sequenceDictionary)) .toArray(QueryInterval[]::new); // Intervals must be optimized (sorted and merged) in order to use the htsjdk query API return QueryInterval.optimizeIntervals(convertedIntervals); } /**
@Test(dataProvider="multipleIntervalOverlapping") public void testQueryOverlappingMultipleIntervals( final File cramFileName, final File referenceFileName, final QueryInterval[] intervals, final String[] expectedNames) throws IOException { QueryInterval[] optimizedIntervals = QueryInterval.optimizeIntervals(intervals); Assert.assertTrue(optimizedIntervals.length > 1); doQueryTest( reader -> reader.queryOverlapping(optimizedIntervals), cramFileName, referenceFileName, expectedNames ); }
@Test(dataProvider="multipleIntervalContained") public void testQueryContainedMultipleIntervals( final File cramFileName, final File referenceFileName, final QueryInterval[] intervals, final String[] expectedNames) throws IOException { QueryInterval[] optimizedIntervals = QueryInterval.optimizeIntervals(intervals); Assert.assertTrue(optimizedIntervals.length > 1); doQueryTest( reader -> reader.queryContained(optimizedIntervals), cramFileName, referenceFileName, expectedNames ); }
}; final QueryInterval[] optimizedOverlapping = QueryInterval.optimizeIntervals(overlappingIntervals); }; final QueryInterval[] optimizedAbutting = QueryInterval.optimizeIntervals(abuttingIntervals); }; final QueryInterval[] optimizedSeparated = QueryInterval.optimizeIntervals(nonOptimizableSeparatedIntervals);
final QueryInterval[] optimizedIntervals = QueryInterval.optimizeIntervals(intervals); consumeAll(multiIntervalRecords, reader.query(optimizedIntervals, contained)); final Iterator<SAMRecord> singleIntervalRecordIterator = singleIntervalRecords.iterator();
@Test(dataProvider="otherMultipleIntervals") public void testOtherMultipleIntervals( final File cramFileName, final File referenceFileName, final QueryInterval[] intervals, final String[] expectedNames) throws IOException { QueryInterval[] optimizedIntervals = QueryInterval.optimizeIntervals(intervals); doQueryTest( reader -> reader.queryContained(optimizedIntervals), cramFileName, referenceFileName, expectedNames ); doQueryTest( reader -> reader.queryOverlapping(optimizedIntervals), cramFileName, referenceFileName, expectedNames ); }