@Override public void remove() { underlyingIterator.remove(); } }
public void close() { if(currentIterator != null) { currentIterator.close(); } }
public SAMQueryIterator(CloseableIterator<SAMRecord> wrappedIterator) { this.chr = null; this.wrappedIterator = wrappedIterator; currentRecord = wrappedIterator.next(); }
@Override public boolean hasNext() { try { return reader.hasNext(); } catch (final NullPointerException npe) { return false; } } }
@Test public static void testQueryAlignmentStartNone() throws IOException { // the first read starts from 1519 final CloseableIterator<SAMRecord> baiIterator = bamFileReaderBAI.queryAlignmentStart("chrM", 1500); final CloseableIterator<SAMRecord> csiIterator = bamFileReaderCSI.queryAlignmentStart("chrM", 1500); Assert.assertFalse(baiIterator.hasNext()); Assert.assertFalse(csiIterator.hasNext()); baiIterator.close(); csiIterator.close(); }
/** If the current iterator is null or exhausted, move to the next interval. */ private void advance() { while ((currentIterator == null || !currentIterator.hasNext()) && this.intervals.hasNext()) { if (currentIterator != null) currentCloseableIterator.close(); final Interval interval = this.intervals.next(); final Interval previousInterval = this.lastInterval; this.currentCloseableIterator = this.reader.query(interval.getContig(), interval.getStart(), interval.getEnd()); this.currentIterator = this.currentCloseableIterator.stream().filter ( ctx -> null == previousInterval || !overlapsInterval(ctx, previousInterval) ).iterator(); this.lastInterval = interval; } }
/** * Creates a {@code Stream} of {@code VariantContext} from the indicated VCF file. * * @param vcfPath path of the VCF file * @return a {@code Stream} of {@code VariantContext} */ public static Stream<VariantContext> readVariantContexts(Path vcfPath) { Objects.requireNonNull(vcfPath, "Cannot read from null vcfPath"); logger.info("Reading variants from VCF file {}", vcfPath); try (VCFFileReader vcfReader = new VCFFileReader(vcfPath, false)) { return vcfReader.iterator().stream(); } }
/** * Close down all open iterators. */ @Override public void close() { // Iterators not in the priority queue have already been closed; only close down the iterators that are still in the priority queue. for (CloseableIterator<SAMRecord> iterator : pq) iterator.close(); }
/** * Try to get the next read in the list. If a next read is available, increment the position. * @return next read in the list, if available. */ public SAMRecord next() { try { return iterator.next(); } finally { position++; } }
/** * {@inheritDoc} */ public boolean hasNext() { return iterator.hasNext(); }
@Test public void testIterator() throws Exception { String entriesFile = TestUtils.DATA_DIR + "goby/GDFQPGI-pickrellNA18486_yale.entries"; GobyAlignmentQueryReader reader = new GobyAlignmentQueryReader(entriesFile); CloseableIterator<Alignment> iter = reader.iterator(); assertTrue(iter.hasNext()); iter.close(); reader.close(); }
/** If the current iterator is null or exhausted, move to the next interval. */ private void advance() { while ((currentIterator == null || !currentIterator.hasNext()) && this.intervals.hasNext()) { if (currentIterator != null) currentCloseableIterator.close(); final Interval interval = this.intervals.next(); final Interval previousInterval = this.lastInterval; this.currentCloseableIterator = this.reader.query(interval.getContig(), interval.getStart(), interval.getEnd()); this.currentIterator = this.currentCloseableIterator.stream().filter ( ctx -> null == previousInterval || !overlapsInterval(ctx, previousInterval) ).iterator(); this.lastInterval = interval; } }
@Test(dataProvider = "vcfshards") public void TestGatherFiles(final List<File> inputFiles, final File expectedOutput, final int expectedRetVal) throws IOException { final List<String> args = new ArrayList<>(); final File output = VcfTestUtils.createTemporaryIndexedFile("result", expectedOutput.getAbsolutePath().endsWith(".vcf") ? ".vcf" : ".vcf.gz"); inputFiles.forEach(f -> args.add("INPUT=" + f.getAbsolutePath())); args.add("OUTPUT=" + output.getAbsolutePath()); Assert.assertEquals(runPicardCommandLine(args.toArray(new String[args.size()])), expectedRetVal, "Program was expected to run successfully, but didn't."); if (expectedRetVal == 0) { final VCFFileReader expectedReader = new VCFFileReader(expectedOutput, false); final VCFFileReader outputReader = new VCFFileReader(output, false); Assert.assertEquals(expectedReader.iterator().stream().count(), outputReader.iterator().stream().count(), "The wrong number of variants was found."); } } }
@Override public void close() { if (iterator instanceof CloseableIterator) { ((CloseableIterator) this.iterator).close(); } }
public SAMRecord next() { try { return it.next(); } catch ( RuntimeException e ) { // we need to catch RuntimeExceptions here because the Picard code is throwing them (among SAMFormatExceptions) sometimes throw new UserException.MalformedBAM(source, e.getMessage()); } }