@Override public SAMFileSpan getFilePointerSpanningReads() { return this.reader.indexing().getFilePointerSpanningReads(); }
void processHeader() { contigsByReference = Maps.newHashMap(); for (Contig contig : requestedContigs) { contigsByReference.put(contig.referenceName != null ? contig.referenceName : "", contig); } if (contigsByReference.size() == 0 || contigsByReference.containsKey("*")) { LOG.info("Outputting unmapped reads shard "); output.output(new BAMShard(filePath, null, new Contig("*", 0, -1))); } allReferences = contigsByReference.size() == 0 || contigsByReference.containsKey(""); LOG.info("All references = " + allReferences); LOG.info("BAM has index = " + reader.hasIndex()); LOG.info("BAM has browseable index = " + reader.indexing().hasBrowseableIndex()); LOG.info("Class for index = " + reader.indexing().getIndex().getClass().getName()); }
void processHeader() { contigsByReference = Maps.newHashMap(); for (Contig contig : requestedContigs) { contigsByReference.put(contig.referenceName != null ? contig.referenceName : "", contig); } if (contigsByReference.size() == 0 || contigsByReference.containsKey("*")) { LOG.info("Outputting unmapped reads shard "); output.output(new BAMShard(filePath, null, new Contig("*", 0, -1))); } allReferences = contigsByReference.size() == 0 || contigsByReference.containsKey(""); LOG.info("All references = " + allReferences); LOG.info("BAM has index = " + reader.hasIndex()); LOG.info("BAM has browseable index = " + reader.indexing().hasBrowseableIndex()); LOG.info("Class for index = " + reader.indexing().getIndex().getClass().getName()); }
void openFile() throws IOException { LOG.info("Processing shard " + shard); final SamReader reader = BAMIO.openBAM(storageClient, shard.file, options.getStringency()); iterator = null; if (reader.hasIndex() && reader.indexing() != null) { if (filter == Filter.UNMAPPED_ONLY) { LOG.info("Processing unmapped"); iterator = reader.queryUnmapped(); } else if (shard.span != null) { LOG.info("Processing span for " + shard.contig); iterator = reader.indexing().iterator(shard.span); } else if (shard.contig.referenceName != null && !shard.contig.referenceName.isEmpty()) { LOG.info("Processing all bases for " + shard.contig); iterator = reader.query(shard.contig.referenceName, (int) shard.contig.start, (int) shard.contig.end, false); } } if (iterator == null) { LOG.info("Processing all reads"); iterator = reader.iterator(); } }
void openFile() throws IOException { LOG.info("Processing shard " + shard); final SamReader reader = BAMIO.openBAM(storageClient, shard.file, options.getStringency()); iterator = null; if (reader.hasIndex() && reader.indexing() != null) { if (filter == Filter.UNMAPPED_ONLY) { LOG.info("Processing unmapped"); iterator = reader.queryUnmapped(); } else if (shard.span != null) { LOG.info("Processing span for " + shard.contig); iterator = reader.indexing().iterator(shard.span); } else if (shard.contig.referenceName != null && !shard.contig.referenceName.isEmpty()) { LOG.info("Processing all bases for " + shard.contig); iterator = reader.query(shard.contig.referenceName, (int) shard.contig.start, (int) shard.contig.end, false); } } if (iterator == null) { LOG.info("Processing all reads"); iterator = reader.iterator(); } }
/** * Get the initial reader positions across all BAM files * * @return the start positions of the first chunk of reads for all BAM files */ protected Map<SAMReaderID, GATKBAMFileSpan> getInitialReaderPositions() { Map<SAMReaderID, GATKBAMFileSpan> initialPositions = new HashMap<SAMReaderID, GATKBAMFileSpan>(); SAMReaders readers = resourcePool.getAvailableReaders(); for ( SAMReaderID id: getReaderIDs() ) { final GATKBAMFileSpan span = new GATKBAMFileSpan(readers.getReader(id).indexing().getFilePointerSpanningReads()); initialPositions.put(id, span); } resourcePool.releaseReaders(readers); return initialPositions; }
@Test(enabled = true) public void testSamTextFileError2() { File samFile = new File(publicTestDir + "testfile.sam"); try { final SamInputResource samInputResource = SamInputResource.of(samFile); final SamReader reader = SamReaderFactory.makeDefault().open(samInputResource); reader.indexing().getFilePointerSpanningReads(); // we shouldn't get here Assert.fail("We should have exceptioned out when trying to call getFilePointerSpanningReads() for a textual SAM file"); } catch (RuntimeException e) { Assert.assertTrue(e.getMessage().indexOf(CommandLineGATK.PICARD_TEXT_SAM_FILE_ERROR_2) != -1); } } }
void openFile() throws IOException { final BAMIO.ReaderAndIndex r = BAMIO.openBAMAndExposeIndex(storageClient, filePath, ValidationStringency.DEFAULT_STRINGENCY); reader = r.reader; indexStream = r.index; header = reader.getFileHeader(); hasIndex = reader.hasIndex() && reader.indexing().hasBrowseableIndex(); LOG.info("Has index = " + hasIndex); if (hasIndex) { index = new BAMFileIndexImpl( IOUtil.maybeBufferedSeekableStream(indexStream),header.getSequenceDictionary()); } else { index = null; } }
void openFile() throws IOException { final BAMIO.ReaderAndIndex r = BAMIO.openBAMAndExposeIndex(storageClient, filePath, ValidationStringency.DEFAULT_STRINGENCY); reader = r.reader; indexStream = r.index; header = reader.getFileHeader(); hasIndex = reader.hasIndex() && reader.indexing().hasBrowseableIndex(); LOG.info("Has index = " + hasIndex); if (hasIndex) { index = new BAMFileIndexImpl( IOUtil.maybeBufferedSeekableStream(indexStream),header.getSequenceDictionary()); } else { index = null; } }
@Test(dataProvider = "composeAllPermutationsOfSamInputResource") public void exhaustInputResourcePermutation(final SamInputResource resource) throws IOException { try(final SamReader reader = SamReaderFactory.makeDefault().open(resource)) { LOG.info(String.format("Reading from %s ...", resource)); final List<SAMRecord> slurped = Iterables.slurp(reader); final SAMFileHeader fileHeader = reader.getFileHeader(); reader.hasIndex(); reader.indexing().hasBrowseableIndex(); /* Ensure all tests have read the same records in the same order or, if this is the first test, set it as the template. */ observedHeaders.add(fileHeader); observedRecordOrdering.add(slurped); } Assert.assertEquals(observedHeaders.size(), 1, "read different headers than other testcases"); Assert.assertEquals(observedRecordOrdering.size(), 1, "read different records than other testcases"); }
@BeforeClass public void init() throws IOException { final SamReader reader = SamReaderFactory.makeDefault().enable(SamReaderFactory.Option.CACHE_FILE_BASED_INDEXES).open(bamFile); Assert.assertTrue(reader.hasIndex()); Assert.assertTrue(reader.indexing().hasBrowseableIndex()); bamIndex = new GATKBAMIndexFromDataSource(bamFile, reader.getFileHeader(), reader.indexing().getBrowseableIndex()); reader.close(); }
SAMFileHeader header = SAMHeaderReader.readSAMHeaderFromStream(in, conf); SAMSequenceDictionary dict = header.getSequenceDictionary(); BAMIndex idx = samReader.indexing().getIndex(); QueryInterval[] queryIntervals = prepareQueryIntervals(intervals, dict); fileToSpan.put(bamFile, BAMFileReader.getFileSpan(queryIntervals, idx));
Indexing index = samReader.indexing(); BAMIndex bai = index.getIndex(); for (int i = 0; i < numRefs; i++) {
public static long getAlignedReadCount(String bam) throws IOException{ /* ------------------------------------------------------ */ /* This chunk prepares SamReader from local bam or URL bam */ UrlValidator urlValidator = new UrlValidator(); SamReaderFactory srf=SamReaderFactory.make(); srf.validationStringency(ValidationStringency.SILENT); SamReader samReader; if(urlValidator.isValid(bam)){ samReader = SamReaderFactory.makeDefault().open( SamInputResource.of(new URL(bam)).index(new URL(bam + ".bai")) ); } else { samReader= srf.open(new File(bam)); } /* ------------------------------------------------------ */ List<SAMSequenceRecord> sequences = samReader.getFileHeader().getSequenceDictionary().getSequences(); long alnCount= 0; for(SAMSequenceRecord x : sequences){ alnCount += samReader.indexing().getIndex().getMetaData(x.getSequenceIndex()).getAlignedRecordCount(); } samReader.close(); return alnCount; }
public static long countSamTotalRecord(final File samFile) { final SamReader reader = SamReaderFactory.make().open(samFile); assert reader.hasIndex(); long total = 0; for (int i = 0; i < reader.getFileHeader().getSequenceDictionary().size(); i++) { total += reader.indexing().getIndex().getMetaData(i).getAlignedRecordCount(); total += reader.indexing().getIndex().getMetaData(i).getUnalignedRecordCount(); } return total; } }
public static int exhaustivelyTestIndex(final SamReader reader) { // throws Exception { if (reader.indexing().hasBrowseableIndex()) { final CachingBAMFileIndex existingIndex = (CachingBAMFileIndex) reader.indexing().getBrowseableIndex(); // new CachingBAMFileIndex(inputBai, null); final int numRefs = existingIndex.getNumberOfReferences();
Assert.assertTrue(reader.indexing().hasBrowseableIndex()); BrowseableBAMIndex index = reader.indexing().getBrowseableIndex(); } else { long chunkStart = index.getStartOfLastLinearBin(); long totalRecordRange = ((BAMFileSpan) reader.indexing().getFilePointerSpanningReads()).toCoordinateArray()[1]; span = new BAMFileSpan(new Chunk(chunkStart, totalRecordRange));
} else { long totalRefLength = header.getSequenceDictionary().getReferenceLength(); long totalRecordRange = ((BAMFileSpan)reader.indexing().getFilePointerSpanningReads()).toCoordinateArray()[1]; chunk = new Chunk(totalRefLength, totalRecordRange);
Assert.assertTrue(reader.hasIndex()); final int sequenceIndex = reader.getFileHeader().getSequenceIndex("11"); BAMIndexMetaData metaData = reader.indexing().getIndex().getMetaData(sequenceIndex); Assert.assertEquals(EXPECTED_ALL_READS - EXPECTED_UNMAPPED_READS, metaData.getAlignedRecordCount());