return new SRAIndexedSequenceFile(new SRAAccession(fastaFile.getPath()));
@Test(dataProvider = "testReference") public void testReference(String acc, String refContig, int refStart, int refStop, String refBases) { final ReferenceSequenceFile refSeqFile = new SRAIndexedSequenceFile(new SRAAccession(acc)); final ReferenceSequence refSeq = refSeqFile.getSubsequenceAt(refContig, refStart, refStop); Assert.assertEquals(new String(refSeq.getBases()), refBases); }
@Test(dataProvider = "testReferenceMt") public void testReferenceMt(String acc, List<TestReferenceMtData> parallelTests) throws Exception { final ReferenceSequenceFile refSeqFile = new SRAIndexedSequenceFile(new SRAAccession(acc)); final long timeout = 1000L * 5; // just in case final List<Thread> threads = new ArrayList<Thread>(parallelTests.size());
@Test(dataProvider = "testReferences") public void testReferences(String acc, int numberFirstReferenceFound, List<String> references, List<Integer> refLengths) { SamReader reader = SamReaderFactory.make().validationStringency(ValidationStringency.SILENT).open( SamInputResource.of(new SRAAccession(acc)) );
@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 = "testQueryCounts") public void testQueryCounts(String acc, String reference, int referenceStart, int referenceEnd, boolean contained, int expectedNumMapped, int expectedNumUnmapped) { SamReader reader = SamReaderFactory.make().validationStringency(ValidationStringency.SILENT).open( SamInputResource.of(new SRAAccession(acc)) ); final SAMRecordIterator samRecordIterator = reader.query(reference, referenceStart, referenceEnd, contained); assertCorrectCountsOfMappedAndUnmappedRecords(samRecordIterator, expectedNumMapped, expectedNumUnmapped); }
@Test(dataProvider = "testUnmappedCounts") public void testUnmappedCounts(String acc, int expectedNumUnmapped) { SamReader reader = SamReaderFactory.make().validationStringency(ValidationStringency.SILENT).open( SamInputResource.of(new SRAAccession(acc)) ); final SAMRecordIterator samRecordIterator = reader.queryUnmapped(); assertCorrectCountsOfMappedAndUnmappedRecords(samRecordIterator, 0, expectedNumUnmapped); }
@Test(dataProvider = "testReferenceAlignedCounts") public void testReferenceAlignedCounts(String acc, String reference, int referenceStart, int expectedNumMapped) { SamReader reader = SamReaderFactory.make().validationStringency(ValidationStringency.SILENT).open( SamInputResource.of(new SRAAccession(acc)) ); final SAMRecordIterator samRecordIterator = reader.queryAlignmentStart(reference, referenceStart); assertCorrectCountsOfMappedAndUnmappedRecords(samRecordIterator, expectedNumMapped, 0); }
@Test(dataProvider = "testGroups") public void testGroups(String acc, Set<String> groups) { SamReader reader = SamReaderFactory.make().validationStringency(ValidationStringency.SILENT).open( SamInputResource.of(new SRAAccession(acc)) ); final SAMRecordIterator samRecordIterator = reader.iterator(); SAMFileHeader header = reader.getFileHeader(); Set<String> headerGroups = new TreeSet<>(); for (SAMReadGroupRecord group : header.getReadGroups()) { Assert.assertEquals(group.getReadGroupId(), group.getId()); headerGroups.add(group.getReadGroupId()); } Assert.assertEquals(groups, headerGroups); Set<String> foundGroups = new TreeSet<>(); for (int i = 0; i < 10000; i++) { if (!samRecordIterator.hasNext()) { break; } SAMRecord record = samRecordIterator.next(); String groupName = (String)record.getAttribute("RG"); foundGroups.add(groupName); } // please note that some groups may be introduced after 10k records, which is not an error Assert.assertEquals(groups, foundGroups); }
@Test(dataProvider = "testCountsBySpan") public void testCountsBySpan(String acc, List<Chunk> chunks, int expectedNumMapped, int expectedNumUnmapped) { SamReader reader = SamReaderFactory.make().validationStringency(ValidationStringency.SILENT).open( SamInputResource.of(new SRAAccession(acc)) ); final SAMRecordIterator samRecordIterator = ((SamReader.Indexing) reader).iterator(new BAMFileSpan(chunks)); assertCorrectCountsOfMappedAndUnmappedRecords(samRecordIterator, expectedNumMapped, expectedNumUnmapped); }
public ReaderInitializer call() { try { if (threadAllocation.getNumIOThreads() > 0) blockInputStream = new BlockInputStream(dispatcher,readerID,false); SamReaderFactory factory = SamReaderFactory.makeDefault() .validationStringency(validationStringency) .setOption(SamReaderFactory.Option.EAGERLY_DECODE, false); if (SRAAccession.isValid(readerID.getSamFile().getPath())) { reader = factory.open(SamInputResource.of(new SRAAccession(readerID.getSamFile().getPath()))); } else { reader = factory.referenceSequence(referenceFile) .setOption(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, true) .open(readerID.getSamFile()); } } catch ( RuntimeIOException e ) { throw new UserException.CouldNotReadInputFile(readerID.getSamFile(), e); } catch ( SAMFormatException e ) { throw new UserException.MalformedBAM(readerID.getSamFile(), e.getMessage()); } // Picard is throwing a RuntimeException here when BAMs are malformed with bad headers (and so look like SAM files). // Let's keep this separate from the SAMFormatException (which ultimately derives from RuntimeException) case, // just in case we want to change this behavior later. catch ( RuntimeException e ) { throw new UserException.MalformedBAM(readerID.getSamFile(), e.getMessage()); } return this; } }
private SAMRecord getRecordByIndex(String acc, int recordIndex, boolean detach) { SamReader reader = SamReaderFactory.make().validationStringency(ValidationStringency.SILENT).open( SamInputResource.of(new SRAAccession(acc)) ); final SAMRecordIterator samRecordIterator = reader.iterator(); while (recordIndex != 0) { Assert.assertTrue(samRecordIterator.hasNext(), "Record set is too small"); samRecordIterator.next(); recordIndex--; } Assert.assertTrue(samRecordIterator.hasNext(), "Record set is too small"); SAMRecord record = samRecordIterator.next(); if (detach) { samRecordIterator.next(); } return record; }
ref = new SRAIndexedSequenceFile(new SRAAccession(referenceFile.getPath())); } else { ref = ReferenceSequenceFileFactory.getReferenceSequenceFile(referenceFile);
bufferedStream.close(); primitiveSamReader = new SRAFileReader(new SRAAccession(sourceFile.getPath())); } else { if (indexDefined) {
bufferedStream.close(); primitiveSamReader = new SRAFileReader(new SRAAccession(sourceFile.getPath())); } else { if (indexDefined) {
boolean isSecondOfPair, boolean isSecondaryAlignment) { SamReader reader = SamReaderFactory.make().validationStringency(ValidationStringency.SILENT).open( SamInputResource.of(new SRAAccession(acc)) );
boolean isSecondOfPair, boolean isSecondaryAlignment) { SamReader reader = SamReaderFactory.make().validationStringency(ValidationStringency.SILENT).open( SamInputResource.of(new SRAAccession(acc)) );