/** * Convenience method that constructs a downsampling iterator for all the reads available from a SamReader. * See {@link DownsamplingIteratorFactory#make(Iterator, Strategy, double, double, int)} for detailed parameter information. */ public static DownsamplingIterator make(final SamReader reader, final Strategy strategy, final double proportion, final double accuracy, final int seed) { return make(reader.iterator(), strategy, proportion, accuracy, seed); } }
/** * Iterate through the the file. * * @param chunks List of chunks for which to retrieve data. * @return An iterator. */ @Override public SAMRecordIterator iterator(SAMFileSpan chunks) { return new SamReader.AssertingIterator(this.reader.iterator()); }
/** * Convenience method that constructs a downsampling iterator for all the reads available from a SamReader. * See {@link DownsamplingIteratorFactory#make(Iterator, Strategy, double, double, int)} for detailed parameter information. */ public static DownsamplingIterator make(final SamReader reader, final Strategy strategy, final double proportion, final double accuracy, final int seed) { return make(reader.iterator(), strategy, proportion, accuracy, seed); } }
/** * Adds the provided reader's records to the detector. * * @return The number of records read */ public long add(final long maxRecords, final SamReader reader) { return add(maxRecords, reader.iterator()); }
public CloseableIterator<PicardAlignment> iterator() { SamReader reader = getSamReader(samFile, -1); CloseableIterator<SAMRecord> iter = reader.iterator(); return new SAMQueryIterator(iter); }
private void startIterationIfRequired() { if (initialized) return; for (final SamReader reader : readers) addIfNotEmpty(new ComparableSamRecordIterator(reader, reader.iterator(), comparator)); initialized = true; }
@Override public boolean open() { if(!Files.exists(input)) return false; reader = SamReaderFactory.make().validationStringency(ValidationStringency.LENIENT).open(input.toFile()); // if(enableFileSource){ // reader.enableFileSource(true); // } // reader.setValidationStringency(SAMFileReader.getDefaultValidationStringency().LENIENT); iterator = reader.iterator(); return true; }
/** * Reads through the records in the provided SAM reader and uses their quality scores to sanity check the expected * quality passed in. If the expected quality format is sane we just hand this back otherwise we throw a * {@link SAMException}. */ public static FastqQualityFormat detect(final SamReader reader, final FastqQualityFormat expectedQualityFormat) { //sanity check expectedQuality final QualityEncodingDetector detector = new QualityEncodingDetector(); final long recordCount = detector.add(DEFAULT_MAX_RECORDS_TO_ITERATE, reader.iterator()); log.debug(String.format("Read %s records from %s.", recordCount, reader)); return detector.generateBestGuess(FileContext.SAM, expectedQualityFormat); }
public <T> BamIterator<T> iterator(AlignmentFilters<SAMRecord> filters, AlignmentOptions options, Class<T> clazz) throws IOException { init(); checkBaiFileExists(); SAMRecordIterator samRecordIterator = samReader.iterator(); return getAlignmentIterator(filters, options, clazz, samRecordIterator); }
private int countReads(File samFile) { SamReader reader = SamReaderFactory.makeDefault().open(samFile); int count = 0; for (Iterator it = reader.iterator(); it.hasNext(); ) { it.next(); count++; } CloserUtil.close(reader); return count; } }
@Test public void testGoodSamStrict() throws IOException { final SamReaderFactory factory = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.STRICT); Assert.assertEquals(0, ((Number) factory.open(createSamForIntAttr(0)).iterator().next().getAttribute("UI")).intValue()); Assert.assertEquals(-1, ((Number) factory.open(createSamForIntAttr(-1)).iterator().next().getAttribute("UI")).intValue()); Assert.assertEquals(Integer.MIN_VALUE, ((Number) factory.open(createSamForIntAttr(Integer.MIN_VALUE)).iterator().next().getAttribute("UI")).intValue()); Assert.assertEquals(Integer.MAX_VALUE, ((Number) factory.open(createSamForIntAttr(Integer.MAX_VALUE)).iterator().next().getAttribute("UI")).intValue()); Assert.assertEquals(1L + (long) Integer.MAX_VALUE, ((Number) factory.open(createSamForIntAttr(1L + (long) Integer.MAX_VALUE)).iterator().next().getAttribute("UI")).longValue()); Assert.assertEquals(BinaryCodec.MAX_UINT, ((Number) factory.open(createSamForIntAttr(BinaryCodec.MAX_UINT)).iterator().next().getAttribute("UI")).longValue()); }
@Test public void testCigarOverflow() throws Exception { final SamReader reader = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.LENIENT).open(new File(TEST_DATA_DIR, "BAMCigarOverflowTest/CigarOverflowTest.bam")); //Load the single read from the BAM file. final SAMRecord testBAMRecord = reader.iterator().next(); CloserUtil.close(reader); //The BAM file that exposed the bug triggered a SAM validation error because the bin field of the BAM record did not equal the computed value. Here we test for this error. //Cast to int to avoid an ambiguity in the assertEquals() call between assertEquals(int,int) and assertEquals(Object,Object). assertEquals(testBAMRecord.computeIndexingBin(), 0); } }
@Test(expectedExceptions = SAMException.class) public void testBadSamStrict() throws IOException { final SamReader reader = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.STRICT).open(createSamForIntAttr(BinaryCodec.MAX_UINT + 1L)); reader.iterator().next(); }
@Test public void testBadSamSilent() throws IOException { final SamReader reader = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.SILENT).open(createSamForIntAttr(BinaryCodec.MAX_UINT + 1L)); reader.iterator().next(); }
@Test(dataProvider = "testCounts") public void testCounts(String acc, int expectedNumMapped, int expectedNumUnmapped) { SamReader reader = SamReaderFactory.make().validationStringency(ValidationStringency.SILENT).open( SamInputResource.of(new SRAAccession(acc)) ); final SAMRecordIterator samRecordIterator = reader.iterator(); assertCorrectCountsOfMappedAndUnmappedRecords(samRecordIterator, expectedNumMapped, expectedNumUnmapped); }
@Test(dataProvider = "testSameUnclipped5PrimeOppositeStrandData") public void testSameUnclipped5PrimeOppositeStrand(final File input) throws IOException { final AbstractMarkDuplicatesCommandLineProgramTester tester = new BySumOfBaseQAndInOriginalOrderMDTester(); try (final SamReader reader = SamReaderFactory.makeDefault().open(input)) { tester.setHeader(reader.getFileHeader()); reader.iterator().stream().forEach(tester::addRecord); } tester.setExpectedOpticalDuplicate(0); tester.runTest(); }
@Test(dataProvider = "queryGroupedInput") public void testQueryGroupedInput(final File input) throws IOException { final AbstractMarkDuplicatesCommandLineProgramTester tester = new BySumOfBaseQAndInOriginalOrderMDTester(); try(final SamReader reader = SamReaderFactory.makeDefault().open(input)) { tester.setHeader(reader.getFileHeader()); reader.iterator().stream().forEach(tester::addRecord); } tester.setExpectedOpticalDuplicate(0); tester.addArg("ASSUME_SORT_ORDER=queryname"); tester.runTest(); } }
private void validateUq(final File input, final File reference) { final SamReader reader = SamReaderFactory.makeDefault().referenceSequence(reference).open(input); final SAMRecordIterator iterator = reader.iterator(); while (iterator.hasNext()){ SAMRecord rec = iterator.next(); if (!rec.getReadUnmappedFlag()) Assert.assertNotNull(rec.getAttribute("UQ")); } }
public void timeDecompressBamFile(int reps) throws IOException { for(int i = 0; i < reps; i++) { final SamReader reader = SamReaderFactory.makeDefault().open(inputFile); CloseableIterator<SAMRecord> iterator = reader.iterator(); while(iterator.hasNext()) iterator.next(); iterator.close(); reader.close(); } }
public void timeExtractTag(int reps) throws IOException { for(int i = 0; i < reps; i++) { final SamReader reader = SamReaderFactory.makeDefault().open(inputFile); CloseableIterator<SAMRecord> iterator = reader.iterator(); while(iterator.hasNext()) { SAMRecord read = iterator.next(); read.getAttribute("OQ"); } iterator.close(); reader.close(); } }