public PgIdGenerator(final SAMFileHeader header) { for (final SAMProgramRecord pgRecord : header.getProgramRecords()) { idsThatAreAlreadyTaken.add(pgRecord.getProgramGroupId()); } recordCounter = idsThatAreAlreadyTaken.size(); }
private boolean compareProgramRecords(final SAMFileHeader h1, final SAMFileHeader h2) { final List<SAMProgramRecord> l1 = h1.getProgramRecords(); final List<SAMProgramRecord> l2 = h2.getProgramRecords(); if (!compareValues(l1.size(), l2.size(), "Number of program records")) { return false; } boolean ret = true; for (int i = 0; i < l1.size(); ++i) { ret = compareProgramRecord(l1.get(i), l2.get(i)) && ret; } return ret; }
private boolean compareProgramRecords(final SAMFileHeader h1, final SAMFileHeader h2) { final List<SAMProgramRecord> l1 = h1.getProgramRecords(); final List<SAMProgramRecord> l2 = h2.getProgramRecords(); if (!compareValues(l1.size(), l2.size(), "Number of program records")) { return false; } boolean ret = true; for (int i = 0; i < l1.size(); ++i) { ret = compareProgramRecord(l1.get(i), l2.get(i)) && ret; } return ret; }
public PgIdGenerator(final SAMFileHeader header) { for (final SAMProgramRecord pgRecord : header.getProgramRecords()) { idsThatAreAlreadyTaken.add(pgRecord.getProgramGroupId()); } recordCounter = idsThatAreAlreadyTaken.size(); }
@Override List<? extends AbstractSAMHeaderRecord> getGroups(SAMFileHeader header) { return header.getProgramRecords(); }
/** * Generate the list of program records seen in the SAM file, approximating this with those in the header that were not * themselves mentioned elsewhere. */ private void setPGIdsSeen(final SAMFileHeader header) { final Set<String> pgIdsSeenAsPrevious = new HashSet<String>(); // get all program record ids that are mentioned as previously seen for (final SAMProgramRecord samProgramRecord : header.getProgramRecords()) { final String previousProgramGroupID = samProgramRecord.getPreviousProgramGroupId(); if (null != previousProgramGroupID) pgIdsSeenAsPrevious.add(previousProgramGroupID); } // ignore those that were previously seen for (final SAMProgramRecord samProgramRecord : header.getProgramRecords()) { final String pgId = samProgramRecord.getId(); if (!pgIdsSeenAsPrevious.contains(pgId)) this.pgIdsSeen.add(pgId); } } }
/** * Generate the list of program records seen in the SAM file, approximating this with those in the header that were not * themselves mentioned elsewhere. */ private void setPGIdsSeen(final SAMFileHeader header) { final Set<String> pgIdsSeenAsPrevious = new HashSet<String>(); // get all program record ids that are mentioned as previously seen for (final SAMProgramRecord samProgramRecord : header.getProgramRecords()) { final String previousProgramGroupID = samProgramRecord.getPreviousProgramGroupId(); if (null != previousProgramGroupID) pgIdsSeenAsPrevious.add(previousProgramGroupID); } // ignore those that were previously seen for (final SAMProgramRecord samProgramRecord : header.getProgramRecords()) { final String pgId = samProgramRecord.getId(); if (!pgIdsSeenAsPrevious.contains(pgId)) this.pgIdsSeen.add(pgId); } } }
/** * Checks whether the provided SAM header if from a reduced bam file. * @param header the SAM header for a given file * @throws UserException if the header is from a reduced bam */ private void checkForUnsupportedBamFile(final SAMFileHeader header) { for ( final SAMProgramRecord PGrecord : header.getProgramRecords() ) { if ( unsupportedPGs.containsKey(PGrecord.getId()) ) throw new UserException("The GATK no longer supports running off of BAMs produced by " + unsupportedPGs.get(PGrecord.getId())); } }
private boolean compareProgramRecords(final SAMFileHeader h1, final SAMFileHeader h2) throws Exception { final List<SAMProgramRecord> l1 = h1.getProgramRecords(); final List<SAMProgramRecord> l2 = h2.getProgramRecords(); if (!compareValues(l1.size(), l2.size(), "Number of program records")) { return false; } boolean ret = true; for (SAMProgramRecord pr1 : l1) { for (SAMProgramRecord pr2 : l2) { if (pr1.getId().equals(pr2.getId())) { ret = compareProgramRecord(pr1, pr2) && ret; } } } return ret; }
private boolean compareProgramRecords(final SAMFileHeader h1, final SAMFileHeader h2) throws Exception { final List<SAMProgramRecord> l1 = h1.getProgramRecords(); final List<SAMProgramRecord> l2 = h2.getProgramRecords(); if (!compareValues(l1.size(), l2.size(), "Number of program records")) { return false; } boolean ret = true; for (SAMProgramRecord pr1 : l1) { for (SAMProgramRecord pr2 : l2) { if (pr1.getId().equals(pr2.getId())) { ret = compareProgramRecord(pr1, pr2) && ret; } } } return ret; }
private void setupWriter(SAMFileHeader header) { if ( !NO_PG_TAG ) { final SAMProgramRecord programRecord = createProgramRecord(); List<SAMProgramRecord> oldRecords = header.getProgramRecords(); List<SAMProgramRecord> newRecords = new ArrayList<SAMProgramRecord>(oldRecords.size()+1); for ( SAMProgramRecord record : oldRecords ) { if ( !record.getId().startsWith(PROGRAM_RECORD_NAME) || KEEP_ALL_PG_RECORDS ) newRecords.add(record); } newRecords.add(programRecord); header.setProgramRecords(newRecords); } writer.writeHeader(header); writer.setPresorted(true); }
/** * Creates a program record for the program, adds it to the list of program records (@PG tags) in the bam file and sets * up the writer with the header and presorted status. * * @param originalHeader original header * @param programRecord the program record for this program */ public static SAMFileHeader setupWriter(final SAMFileHeader originalHeader, final SAMProgramRecord programRecord) { final SAMFileHeader header = originalHeader.clone(); final List<SAMProgramRecord> oldRecords = header.getProgramRecords(); final List<SAMProgramRecord> newRecords = new ArrayList<SAMProgramRecord>(oldRecords.size()+1); for ( SAMProgramRecord record : oldRecords ) if ( (programRecord != null && !record.getId().startsWith(programRecord.getId()))) newRecords.add(record); if (programRecord != null) { newRecords.add(programRecord); header.setProgramRecords(newRecords); } return header; }
private SAMFileHeader createOutHeader( final SAMFileHeader inHeader, final SAMFileHeader.SortOrder sortOrder, final boolean removeAlignmentInformation) { final SAMFileHeader outHeader = new SAMFileHeader(); outHeader.setSortOrder(sortOrder); if (!removeAlignmentInformation) { outHeader.setSequenceDictionary(inHeader.getSequenceDictionary()); outHeader.setProgramRecords(inHeader.getProgramRecords()); } return outHeader; }
private SAMFileHeader createOutHeader( final SAMFileHeader inHeader, final SAMFileHeader.SortOrder sortOrder, final boolean removeAlignmentInformation) { final SAMFileHeader outHeader = new SAMFileHeader(); outHeader.setSortOrder(sortOrder); if (!removeAlignmentInformation) { outHeader.setSequenceDictionary(inHeader.getSequenceDictionary()); outHeader.setProgramRecords(inHeader.getProgramRecords()); } return outHeader; }
protected ReadDestination(final SAMFileHeader header, final String readGroupID) { // prepare the bam header if ( header == null ) throw new IllegalArgumentException("header cannot be null"); bamHeader = new SAMFileHeader(); bamHeader.setSequenceDictionary(header.getSequenceDictionary()); bamHeader.setSortOrder(SAMFileHeader.SortOrder.coordinate); bamHeader.setProgramRecords(header.getProgramRecords()); // include the original read groups plus an artificial one for haplotypes final List<SAMReadGroupRecord> readGroups = new ArrayList<>(header.getReadGroups()); SAMReadGroupRecord rg = new SAMReadGroupRecord(readGroupID); rg.setSample("HC"); rg.setSequencingCenter("BI"); readGroups.add(rg); bamHeader.setReadGroups(readGroups); }
public static SAMFileHeader duplicateSAMFileHeader(SAMFileHeader toCopy) { SAMFileHeader copy = new SAMFileHeader(); copy.setSortOrder(toCopy.getSortOrder()); copy.setGroupOrder(toCopy.getGroupOrder()); copy.setProgramRecords(toCopy.getProgramRecords()); copy.setReadGroups(toCopy.getReadGroups()); copy.setSequenceDictionary(toCopy.getSequenceDictionary()); for (Map.Entry<String, String> e : toCopy.getAttributes()) copy.setAttribute(e.getKey(), e.getValue()); return copy; }
@Override List<? extends AbstractSAMHeaderRecord> createGroups(final String[] groupIds) { final List<SamReader> readers = new ArrayList<SamReader>(); for (final String groupId : groupIds) { final SamReader samReader = newFileReader(); final List<SAMProgramRecord> records = new ArrayList<SAMProgramRecord>(); final SAMProgramRecord record = new SAMProgramRecord(groupId); records.add(record); samReader.getFileHeader().setProgramRecords(records); readers.add(samReader); } final List<SAMFileHeader> headers = new ArrayList<SAMFileHeader>(); for (final SamReader reader : readers) { headers.add(reader.getFileHeader()); } CloserUtil.close(readers); final SamFileHeaderMerger fileHeaderMerger = new SamFileHeaderMerger(SAMFileHeader.SortOrder.coordinate, headers, false); return fileHeaderMerger.getMergedHeader().getProgramRecords(); }
private void checkProgramRecords() { final SamReader in = SamReaderFactory .makeDefault() .referenceSequence(REFERENCE_SEQUENCE) .open(INPUT); for (final SAMProgramRecord pg : in.getFileHeader().getProgramRecords()) { if (pg.getProgramName() != null && pg.getProgramName().equals(PG_PROGRAM_NAME)) { final String outText = "Found previous Program Record that indicates that this BAM has been downsampled already with this program. Operation not supported! Previous PG: " + pg.toString(); if (ALLOW_MULTIPLE_DOWNSAMPLING_DESPITE_WARNINGS) { log.warn(outText); } else { log.error(outText); throw new PicardException(outText); } } } CloserUtil.close(in); }
/** * Check that the bamout program records (@PG) contain all of the program records forwarded from the input BAMs */ private void validateForwardedProgramRecords(final List<File> bamInFiles, final String bamOutMd5) throws IOException { final List<SAMProgramRecord> bamInProgramRecords = new ArrayList<>(); for (final File file : bamInFiles) { final SamReader bamInReader = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.SILENT).open(file); bamInProgramRecords.addAll(bamInReader.getFileHeader().getProgramRecords()); bamInReader.close(); } final String bamOutFilePath = new MD5DB().getMD5FilePath(bamOutMd5, null); if (bamOutFilePath == null) { throw new FileNotFoundException("Could not find " + bamOutMd5 + " in the MD5 DB"); } final SamReader bamOutReader = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.SILENT). open(new File(bamOutFilePath)); final List<SAMProgramRecord> bamOutProgramRecords = bamOutReader.getFileHeader().getProgramRecords(); bamOutReader.close(); Assert.assertTrue(bamOutProgramRecords.containsAll(bamInProgramRecords)); }
private void checkProgramRecords() { final SamReader in = SamReaderFactory .makeDefault() .referenceSequence(REFERENCE_SEQUENCE) .open(INPUT); for (final SAMProgramRecord pg : in.getFileHeader().getProgramRecords()) { if (pg.getProgramName() != null && pg.getProgramName().equals(PG_PROGRAM_NAME)) { final String outText = "Found previous Program Record that indicates that this BAM has been downsampled already with this program. Operation not supported! Previous PG: " + pg.toString(); if (ALLOW_MULTIPLE_DOWNSAMPLING_DESPITE_WARNINGS) { log.warn(outText); } else { log.error(outText); throw new PicardException(outText); } } } CloserUtil.close(in); }