/** * Best string representation for a SAM file reader is the path of the source file. */ @Override public String toString() { return getSamFilePath(); }
public String getSource() { return reader.getSamFilePath(); }
/** * 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()); }
private FileInputStream openInputStream(final SAMReaderID reader) { try { return new FileInputStream(reader.getSamFilePath()); } catch(IOException ex) { throw new GATKException("Unable to open input file"); } }
/** * Checks whether there are SAM files that appear multiple times in the fully unpacked list of * SAM files (samReaderIDs). If there are, throws an ArgumentException listing the files in question. */ protected void checkForDuplicateSamFiles() { Set<SAMReaderID> encounteredSamFiles = new HashSet<SAMReaderID>(); Set<String> duplicateSamFiles = new LinkedHashSet<String>(); for ( SAMReaderID samFile : samReaderIDs ) { if ( encounteredSamFiles.contains(samFile) ) { duplicateSamFiles.add(samFile.getSamFilePath()); } else { encounteredSamFiles.add(samFile); } } if ( duplicateSamFiles.size() > 0 ) { throw new UserException("The following BAM files appear multiple times in the list of input files: " + duplicateSamFiles + " BAM files may be specified at most once."); } }
private Set<VCFHeaderLine> getSampleHeaderLines(){ final Set<VCFHeaderLine> sampleLines = new HashSet<>(); if (printTCGAsampleHeader) { //NOTE: This will only list the first bam file for each tumor/normal sample if there is more than one final Map<String, String> normalSampleHeaderAttributes = new HashMap<>(); normalSampleHeaderAttributes.put("ID", "NORMAL"); normalSampleHeaderAttributes.put("SampleName", normalSampleName); if (normalSAMReaderIDs.iterator().hasNext() && !getToolkit().getArguments().disableCommandLineInVCF) normalSampleHeaderAttributes.put("File", normalSAMReaderIDs.iterator().next().getSamFilePath()); final VCFSimpleHeaderLine normalSampleHeader = new VCFSimpleHeaderLine("SAMPLE", normalSampleHeaderAttributes); final Map<String, String> tumorSampleHeaderAttributes = new HashMap<>(); tumorSampleHeaderAttributes.put("ID", "TUMOR"); tumorSampleHeaderAttributes.put("SampleName", tumorSampleName); if (tumorSAMReaderIDs.iterator().hasNext() && !getToolkit().getArguments().disableCommandLineInVCF) tumorSampleHeaderAttributes.put("File", tumorSAMReaderIDs.iterator().next().getSamFilePath()); final VCFSimpleHeaderLine tumorSampleHeader = new VCFSimpleHeaderLine("SAMPLE", tumorSampleHeaderAttributes); sampleLines.add(normalSampleHeader); sampleLines.add(tumorSampleHeader); } return sampleLines; }
throw new ReviewedGATKException(String.format("Unable to read a complete bin header from BAM schedule file %s for BAM file %s. " + "The BAM schedule file is likely incomplete/corrupt.", scheduleFile.getAbsolutePath(), reader.getSamFilePath()));
throw new UserException(String.format("On-the fly sample renaming was requested for bam file %s, however this " + "bam file contains a read group (id: %s) with a null sample attribute", readerID.getSamFilePath(), readGroup.getId())); "all bams for which on-the-fly sample renaming is requested " + "contain reads from only a single sample per bam.", readerID.getSamFilePath(), firstEncounteredSample, thisReadGroupSample));
final String remappedSampleName = sampleRenameMap != null ? sampleRenameMap.get(readerID.getSamFilePath()) : null;
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(); } }