/** * Best string representation for a SAM file reader is the path of the source file. */ @Override public String toString() { return getSamFilePath(); }
@Override public int hashCode() { return key.hashCode(); } }
@Override public boolean equals(Object other) { if(!(other instanceof UniqueKey)) return false; UniqueKey otherUniqueKey = (UniqueKey)other; return key.equals(otherUniqueKey.key) && this.uniqueID == otherUniqueKey.uniqueID; }
try { for ( String fileName : new XReadLines(new File(inputFileName), true, LIST_FILE_COMMENT_START) ) { unpackedReads.add(new SAMReaderID(fileName,parser.getTags(inputFileName))); unpackedReads.add(new SAMReaderID(inputFileName,inputFileNameTags)); unpackedReads.add(new SAMReaderID(inputFileName,inputFileNameTags)); unpackedReads.add(new SAMReaderID(inputFileName,inputFileNameTags));
private void createTestBAM() { header = ArtificialSAMUtils.createArtificialSamHeader(numContigs, 1, 100000); SAMReadGroupRecord readGroup = new SAMReadGroupRecord("foo"); readGroup.setSample("testSample"); header.addReadGroup(readGroup); ArtificialSingleSampleReadStream artificialReads = new ArtificialSingleSampleReadStream(header, "foo", numContigs, numStacksPerContig, stackSize, stackSize, 1, 100, 50, 150, numUnmappedReads); final File testBAMFile = createTempFile("SAMDataSourceFillShardBoundaryTest", ".bam"); SAMFileWriter bamWriter = new SAMFileWriterFactory().setCreateIndex(true).makeBAMWriter(header, true, testBAMFile); for ( SAMRecord read : artificialReads ) { bamWriter.addAlignment(read); } bamWriter.close(); testBAM = new SAMReaderID(testBAMFile, new Tags()); new File(testBAM.getSamFilePath().replace(".bam", ".bai")).deleteOnExit(); new File(testBAM.getSamFilePath() + ".bai").deleteOnExit(); } }
@Test public void testSAMReaderIDHashingAndEquality() { // Test to make sure that two SAMReaderIDs that point at the same file via an absolute vs. relative // path are equal according to equals() and have the same hash code final File relativePathToBAMFile = new File(publicTestDir + "exampleBAM.bam"); final File absolutePathToBAMFile = new File(relativePathToBAMFile.getAbsolutePath()); final SAMReaderID relativePathSAMReaderID = new SAMReaderID(relativePathToBAMFile, new Tags()); final SAMReaderID absolutePathSAMReaderID = new SAMReaderID(absolutePathToBAMFile, new Tags()); Assert.assertEquals(relativePathSAMReaderID, absolutePathSAMReaderID, "Absolute-path and relative-path SAMReaderIDs not equal according to equals()"); Assert.assertEquals(relativePathSAMReaderID.hashCode(), absolutePathSAMReaderID.hashCode(), "Absolute-path and relative-path SAMReaderIDs have different hash codes"); } }
logger.debug(String.format("Processing file (%d of %d) %s...", readerNumber++, totalNumberOfFiles, readerID.getSamFile())); readers.put(init.readerID,init.reader); if ( ++nExecutedTotal % tickSize == 0) { final String remappedSampleName = sampleRenameMap != null ? sampleRenameMap.get(readerID.getSamFilePath()) : null;
/** * Gets the SAM file associated with a given reader ID. * @param id The reader for which to retrieve the source file. * @return the file actually associated with the id. */ public File getSAMFile(SAMReaderID id) { return id.getSamFile(); }
int compareValue = thisIterator.peek().getKey().compareTo(otherIterator.peek().getKey());
if (id.getTags().getPositionalTags().isEmpty()) throw new UserException.BadInput("BAMs must be tagged with " + GENOTYPE_BAM_TAG + " and " + EVAL_BAM_TAG + " when running in array-free mode. Please see the ContEst documentation for more details"); for (String tag : id.getTags().getPositionalTags()) { if (GENOTYPE_BAM_TAG.equalsIgnoreCase(tag)) { try {
@Test(expectedExceptions=UserException.class) public void testDuplicateSamFileHandlingMultipleDuplicates() throws Exception { GenomeAnalysisEngine testEngine = new GenomeAnalysisEngine(); Collection<SAMReaderID> samFiles = new ArrayList<SAMReaderID>(); samFiles.add(new SAMReaderID(new File(publicTestDir + "exampleBAM.bam"), new Tags())); samFiles.add(new SAMReaderID(new File(publicTestDir + "exampleNORG.bam"), new Tags())); samFiles.add(new SAMReaderID(new File(publicTestDir + "exampleBAM.bam"), new Tags())); samFiles.add(new SAMReaderID(new File(publicTestDir + "exampleNORG.bam"), new Tags())); testEngine.setSAMFileIDs(samFiles); testEngine.checkForDuplicateSamFiles(); }
/** * Returns true if the reader caches its SAMFileHeader for each iterator. * @return true if this reader caches its SAMFileHeader for each iterator. */ private boolean isIteratorSAMFileHeaderCached(final SAMReaderID readerID) { // example: https://github.com/samtools/htsjdk/blob/ee4308ede60962f3ab4275473ac384724b471149/src/java/htsjdk/samtools/CRAMFileReader.java#L183 return !readerID.getSamFile().getName().toLowerCase().endsWith(SamReader.Type.CRAM_TYPE.fileExtension()); }
compareValue = 1; else compareValue = thisIterator.peek().getKey().compareTo(otherIterator.peek().getKey());
@Test(expectedExceptions=UserException.class) public void testDuplicateSamFileHandlingSingleDuplicate() throws Exception { GenomeAnalysisEngine testEngine = new GenomeAnalysisEngine(); Collection<SAMReaderID> samFiles = new ArrayList<SAMReaderID>(); samFiles.add(new SAMReaderID(new File(publicTestDir + "exampleBAM.bam"), new Tags())); samFiles.add(new SAMReaderID(new File(publicTestDir + "exampleBAM.bam"), new Tags())); testEngine.setSAMFileIDs(samFiles); testEngine.checkForDuplicateSamFiles(); }
public String getSource() { return reader.getSamFilePath(); }
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; } }
@Test public void testIgnoreBlankLinesInBAMListFiles() throws Exception { File tempListFile = createTempListFile("testIgnoreBlankLines", "", publicTestDir + "exampleBAM.bam", " " ); List<SAMReaderID> expectedBAMFileListAfterUnpacking = new ArrayList<SAMReaderID>(); expectedBAMFileListAfterUnpacking.add(new SAMReaderID(new File(publicTestDir + "exampleBAM.bam"), new Tags())); performBAMListFileUnpackingTest(tempListFile, expectedBAMFileListAfterUnpacking); }
/** * Compare two IDs to see whether they're equal. * @param other The other identifier. * @return True iff the two readers point to the same file. */ @Override public boolean equals(Object other) { if(other == null) return false; if(!(other instanceof SAMReaderID)) return false; SAMReaderID otherID = (SAMReaderID)other; return this.getSamFilePath().equals(otherID.getSamFilePath()); }
this.length = reader.getSamFile().length(); if(validate) { System.out.printf("BlockInputStream %s: BGZF block validation mode activated%n",this); validatingInputStream = new BlockCompressedInputStream(reader.getSamFile());