@Override public int deduceIdealSplitWeight(final IntervalList intervalList, final int nCount) { final int splitWidth = super.deduceIdealSplitWeight(intervalList, nCount); final int widestIntervalLength = intervalList.getIntervals().stream() .mapToInt(Interval::length) .max() .orElse(1); // There is no purpose to splitting with more granularity than the widest interval return Math.max(widestIntervalLength, splitWidth); } }
@Override public int deduceIdealSplitWeight(final IntervalList intervalList, final int nCount) { final int splitWidth = super.deduceIdealSplitWeight(intervalList, nCount); final int widestIntervalLength = intervalList.getIntervals().stream() .mapToInt(Interval::length) .max() .orElse(1); // There is no purpose to splitting with more granularity than the widest interval return Math.max(widestIntervalLength, splitWidth); } }
/** Return true if the sequence/position lie in the provided interval list. */ public static boolean contains(final IntervalList intervalList, final String sequenceName, final long position) { for (final Interval interval : intervalList.uniqued().getIntervals()) { if (contains(interval, sequenceName, position)) return true; } return false; }
private List<Interval> getIntervalList (final File intervalFile) throws IOException { IOUtil.assertFileIsReadable(intervalFile); return IntervalList.fromFile(intervalFile).getIntervals(); }
/** Return true if the sequence/position lie in the provided interval list. */ public static boolean contains(final IntervalList intervalList, final String sequenceName, final long position) { for (final Interval interval : intervalList.uniqued().getIntervals()) { if (contains(interval, sequenceName, position)) return true; } return false; }
private List<Interval> getIntervalList (final File intervalFile) throws IOException { IOUtil.assertFileIsReadable(intervalFile); return IntervalList.fromFile(intervalFile).getIntervals(); }
@Test(dataProvider = "testScatterTestcases") public void testScatter(final Testcase tc) { final IntervalListScatterer scatterer = tc.mode.make(); final List<IntervalList> scatter = scatterer.scatter(tc.source, tc.scatterWidth); Assert.assertEquals(scatter.size(), tc.expectedScatter.size()); for (int i = 0; i < scatter.size(); i++) { Assert.assertEquals(scatter.get(i).getIntervals(), tc.expectedScatter.get(i).getIntervals(), "Problem with the " + i + " scatter"); } }
@Test(dataProvider = "actionAndTotalBasesData") public void testActions(final IntervalListTools.Action action, final long bases, final int intervals) throws IOException { final IntervalList il = tester(action); Assert.assertEquals(il.getBaseCount(), bases, "unexpected number of bases found."); Assert.assertEquals(il.getIntervals().size(), intervals, "unexpected number of intervals found."); }
@Test(dataProvider = "actionAndTotalBasesWithInvertData") public void testActionsWithInvert(final IntervalListTools.Action action, final long bases, final int intervals) throws IOException { final IntervalList il = tester(action, true); Assert.assertEquals(il.getBaseCount(), bases, "unexpected number of bases found."); Assert.assertEquals(il.getIntervals().size(), intervals, "unexpected number of intervals found."); }
static OverlapDetector<Interval> getOverlapDetectorFromIntervalListFile(File intervalList, int lhsBuffer, int rhsBuffer) { if (intervalList == null) { return null; } List<Interval> intervals = IntervalList.fromFile(intervalList).uniqued().getIntervals(); OverlapDetector<Interval> detector = new OverlapDetector<>(lhsBuffer, rhsBuffer); detector.addAll(intervals, intervals); return detector; }
static OverlapDetector<Interval> getOverlapDetectorFromIntervalListFile(File intervalList, int lhsBuffer, int rhsBuffer) { if (intervalList == null) { return null; } List<Interval> intervals = IntervalList.fromFile(intervalList).uniqued().getIntervals(); OverlapDetector<Interval> detector = new OverlapDetector<>(lhsBuffer, rhsBuffer); detector.addAll(intervals, intervals); return detector; }
@Test(dataProvider="VcfToIntervalListData") public void testExcludingFiltered( final File inputFile, final boolean includeFiltered, final int expectedIntervalsSize) throws IOException { final File outputFile = File.createTempFile("vcftointervallist_", ".interval_list"); outputFile.deleteOnExit(); final List<String> arguments = new ArrayList<>(); arguments.add("I=" + inputFile.getAbsolutePath()); arguments.add("O=" + outputFile.getAbsolutePath()); if (includeFiltered) { arguments.add(VcfToIntervalList.INCLUDE_FILTERED_SHORT_NAME + "=true"); } runPicardCommandLine(arguments); Assert.assertTrue(outputFile.exists()); final List<Interval> intervals = IntervalList.fromFile(outputFile).getIntervals(); Assert.assertEquals(intervals.size(), expectedIntervalsSize); } }
public IntervalListReferenceSequenceMask(final IntervalList intervalList) { this.header = intervalList.getHeader(); if (intervalList.getHeader().getSortOrder() != SAMFileHeader.SortOrder.coordinate) { intervalList.sorted(); } final List<Interval> uniqueIntervals = intervalList.uniqued().getIntervals(); if (uniqueIntervals.isEmpty()) { lastSequenceIndex = -1; lastPosition = 0; } else { final Interval lastInterval = uniqueIntervals.get(uniqueIntervals.size() - 1); lastSequenceIndex = header.getSequenceIndex((lastInterval.getContig())); lastPosition = lastInterval.getEnd(); } intervalIterator = new PeekableIterator<Interval>(uniqueIntervals.iterator()); }
@Test(dataProvider = "testReadsData") public void testReads(final IntervalList list, final SAMFileHeader fileHeader, final Collection<SAMRecord> recordCollection, final int expectedPassing, final int expectedTotal ) { IntervalFilter intervalFilter = new IntervalFilter(list.getIntervals(), fileHeader); FilteringSamIterator filteringSamIterator = new FilteringSamIterator(recordCollection.iterator(), intervalFilter); // check that the total number of passing reads is the expected number Assert.assertEquals(filteringSamIterator.stream() // check that the reads that pass have the word "intersecting" in their name .peek(s -> Assert.assertTrue(s.getReadName().contains("intersecting"))) .count(), expectedPassing); //check that the total number of reads given in the Collection, is the expected number Assert.assertEquals(recordCollection.size(), expectedTotal); } }
public IntervalListReferenceSequenceMask(final IntervalList intervalList) { this.header = intervalList.getHeader(); if (intervalList.getHeader().getSortOrder() != SAMFileHeader.SortOrder.coordinate) { intervalList.sorted(); } final List<Interval> uniqueIntervals = intervalList.uniqued().getIntervals(); if (uniqueIntervals.isEmpty()) { lastSequenceIndex = -1; lastPosition = 0; } else { final Interval lastInterval = uniqueIntervals.get(uniqueIntervals.size() - 1); lastSequenceIndex = header.getSequenceIndex((lastInterval.getContig())); lastPosition = lastInterval.getEnd(); } intervalIterator = new PeekableIterator<Interval>(uniqueIntervals.iterator()); }
@Test public void testUnionSamePosition() { final IntervalList iList= new IntervalList(fileHeader); final List<Interval> intervals = Arrays.asList( new Interval("1", 2, 100, true, "test1"), new Interval("1", 2, 100, true, "test2") ); iList.addall(intervals); final List<Interval> uniqued = iList.uniqued().getIntervals(); Assert.assertEquals(uniqued.size(),1); Assert.assertEquals(uniqued.get(0).getName(),"test1|test2"); }
public static OverlapDetector<Interval> makeOverlapDetector(final File samFile, final SAMFileHeader header, final File ribosomalIntervalsFile, final Log log) { final OverlapDetector<Interval> ribosomalSequenceOverlapDetector = new OverlapDetector<Interval>(0, 0); if (ribosomalIntervalsFile != null) { final IntervalList ribosomalIntervals = IntervalList.fromFile(ribosomalIntervalsFile); if (ribosomalIntervals.size() == 0) { log.warn("The RIBOSOMAL_INTERVALS file, " + ribosomalIntervalsFile.getAbsolutePath() + " does not contain intervals"); } try { SequenceUtil.assertSequenceDictionariesEqual(header.getSequenceDictionary(), ribosomalIntervals.getHeader().getSequenceDictionary()); } catch (SequenceUtil.SequenceListsDifferException e) { throw new PicardException("Sequence dictionaries differ in " + samFile.getAbsolutePath() + " and " + ribosomalIntervalsFile.getAbsolutePath(), e); } final IntervalList uniquedRibosomalIntervals = ribosomalIntervals.uniqued(); final List<Interval> intervals = uniquedRibosomalIntervals.getIntervals(); ribosomalSequenceOverlapDetector.addAll(intervals, intervals); } return ribosomalSequenceOverlapDetector; }
public static OverlapDetector<Interval> makeOverlapDetector(final File samFile, final SAMFileHeader header, final File ribosomalIntervalsFile, final Log log) { final OverlapDetector<Interval> ribosomalSequenceOverlapDetector = new OverlapDetector<Interval>(0, 0); if (ribosomalIntervalsFile != null) { final IntervalList ribosomalIntervals = IntervalList.fromFile(ribosomalIntervalsFile); if (ribosomalIntervals.size() == 0) { log.warn("The RIBOSOMAL_INTERVALS file, " + ribosomalIntervalsFile.getAbsolutePath() + " does not contain intervals"); } try { SequenceUtil.assertSequenceDictionariesEqual(header.getSequenceDictionary(), ribosomalIntervals.getHeader().getSequenceDictionary()); } catch (SequenceUtil.SequenceListsDifferException e) { throw new PicardException("Sequence dictionaries differ in " + samFile.getAbsolutePath() + " and " + ribosomalIntervalsFile.getAbsolutePath(), e); } final IntervalList uniquedRibosomalIntervals = ribosomalIntervals.uniqued(); final List<Interval> intervals = uniquedRibosomalIntervals.getIntervals(); ribosomalSequenceOverlapDetector.addAll(intervals, intervals); } return ribosomalSequenceOverlapDetector; }
@Test(dataProvider = "testFromSequenceData") public void testFromSequenceName(final Path intervalList, final String referenceName, final Integer length) { final IntervalList intervals = IntervalList.fromPath(intervalList); final IntervalList test = IntervalList.fromName(intervals.getHeader(), referenceName); Assert.assertEquals(test.getIntervals(), CollectionUtil.makeList(new Interval(referenceName, 1, length))); }
/** Calculates a few statistics about the bait design that can then be output. */ void calculateStatistics(final IntervalList targets, final IntervalList baits) { this.TARGET_TERRITORY = (int) targets.getUniqueBaseCount(); this.TARGET_COUNT = targets.size(); this.BAIT_TERRITORY = (int) baits.getUniqueBaseCount(); this.BAIT_COUNT = baits.size(); this.DESIGN_EFFICIENCY = this.TARGET_TERRITORY / (double) this.BAIT_TERRITORY; // Figure out the intersection between all targets and all baits final IntervalList tmp = new IntervalList(targets.getHeader()); final OverlapDetector<Interval> detector = new OverlapDetector<Interval>(0, 0); detector.addAll(baits.getIntervals(), baits.getIntervals()); for (final Interval target : targets) { final Collection<Interval> overlaps = detector.getOverlaps(target); if (overlaps.isEmpty()) { this.ZERO_BAIT_TARGETS++; } else { for (final Interval i : overlaps) tmp.add(target.intersect(i)); } } tmp.uniqued(); this.BAIT_TARGET_TERRITORY_INTERSECTION = (int) tmp.getBaseCount(); }