/** * Gets the library name from the header for the record. If the RG tag is not present on * the record, or the library isn't denoted on the read group, a constant string is * returned. */ public static String getLibraryName(final SAMFileHeader header, final SAMRecord rec) { final String readGroupId = (String) rec.getAttribute(ReservedTagConstants.READ_GROUP_ID); if (readGroupId != null) { final SAMReadGroupRecord rg = header.getReadGroup(readGroupId); if (rg != null) { final String libraryName = rg.getLibrary(); if (null != libraryName) return libraryName; } } return UNKNOWN_LIBRARY; }
private static SAMFileHeader mergeHeaders(List<RecordSource> sources) { SAMFileHeader header = new SAMFileHeader(); for (RecordSource source : sources) { SAMFileHeader h = source.reader.getFileHeader(); for (SAMSequenceRecord seq : h.getSequenceDictionary().getSequences()) { if (header.getSequenceDictionary().getSequence(seq.getSequenceName()) == null) header.addSequence(seq); } for (SAMProgramRecord pro : h.getProgramRecords()) { if (header.getProgramRecord(pro.getProgramGroupId()) == null) header.addProgramRecord(pro); } for (String comment : h.getComments()) header.addComment(comment); for (SAMReadGroupRecord rg : h.getReadGroups()) { if (header.getReadGroup(rg.getReadGroupId()) == null) header.addReadGroup(rg); } } return header; }
/** * Gets the library name from the header for the record. If the RG tag is not present on * the record, or the library isn't denoted on the read group, a constant string is * returned. */ public static String getLibraryName(final SAMFileHeader header, final SAMRecord rec) { final String readGroupId = (String) rec.getAttribute(ReservedTagConstants.READ_GROUP_ID); if (readGroupId != null) { final SAMReadGroupRecord rg = header.getReadGroup(readGroupId); if (rg != null) { final String libraryName = rg.getLibrary(); if (null != libraryName) return libraryName; } } return UNKNOWN_LIBRARY; }
/** * Get the SAMReadGroupRecord for this SAMRecord. * @return The SAMReadGroupRecord from the SAMFileHeader for this SAMRecord, or null if * 1) this record has no RG tag, or 2) the header doesn't contain the read group with * the given ID. * @throws NullPointerException if this.getHeader() returns null. * @throws ClassCastException if RG tag does not have a String value. */ public SAMReadGroupRecord getReadGroup() { final String rgId = (String)getAttribute(SAMTagUtil.getSingleton().RG); if (rgId == null) { return null; } return getHeader().getReadGroup(rgId); }
/** * Gets the library name from the header for the record. If the RG tag is not present on * the record, or the library isn't denoted on the read group, a constant string is * returned. */ private static String getLibraryName(final SAMRecord rec) { final String readGroupId = (String) rec.getAttribute("RG"); if (readGroupId != null) { final SAMFileHeader samHeader = rec.getHeader(); if (null != samHeader) { final SAMReadGroupRecord rg = samHeader.getReadGroup(readGroupId); if (rg != null) { final String libraryName = rg.getLibrary(); if (null != libraryName) return libraryName; } } } return "Unknown Library"; }
/** * Gets the library name from the header for the record. If the RG tag is not present on * the record, or the library isn't denoted on the read group, a constant string is * returned. */ private static String getLibraryName(final SAMRecord rec) { final String readGroupId = (String) rec.getAttribute("RG"); if (readGroupId != null) { final SAMFileHeader samHeader = rec.getHeader(); if (null != samHeader) { final SAMReadGroupRecord rg = samHeader.getReadGroup(readGroupId); if (rg != null) { final String libraryName = rg.getLibrary(); if (null != libraryName) return libraryName; } } } return "Unknown Library"; }
/** * Get the SAMReadGroupRecord for this SAMRecord. * @return The SAMReadGroupRecord from the SAMFileHeader for this SAMRecord, or null if * 1) this record has no RG tag, or 2) the header doesn't contain the read group with * the given ID.or 3) this record has no SAMFileHeader * @throws ClassCastException if RG tag does not have a String value. */ public SAMReadGroupRecord getReadGroup() { final String rgId = (String)getAttribute(SAMTag.RG.getBinaryTag()); if (rgId == null || getHeader() == null) { return null; } else { return getHeader().getReadGroup(rgId); } }
/** * Get the SAMReadGroupRecord for this SAMRecord. * @return The SAMReadGroupRecord from the SAMFileHeader for this SAMRecord, or null if * 1) this record has no RG tag, or 2) the header doesn't contain the read group with * the given ID.or 3) this record has no SAMFileHeader * @throws ClassCastException if RG tag does not have a String value. */ public SAMReadGroupRecord getReadGroup() { final String rgId = (String)getAttribute(SAMTag.RG.getBinaryTag()); if (rgId == null || getHeader() == null) { return null; } else { return getHeader().getReadGroup(rgId); } }
private void validateStreamParameters() { if ( header == null || readGroupID == null ) { throw new ReviewedGATKException("null SAMFileHeader or read group ID") ; } if ( header.getReadGroup(readGroupID) == null ) { throw new ReviewedGATKException(String.format("Read group %s not found in SAMFileHeader", readGroupID)); } if ( numContigs < 0 || numStacksPerContig < 0 || minReadsPerStack < 0 || maxReadsPerStack < 0 || minDistanceBetweenStacks < 0 || maxDistanceBetweenStacks < 0 || minReadLength < 0 || maxReadLength < 0 || numUnmappedReads < 0 ) { throw new ReviewedGATKException("Read stream parameters must be >= 0"); } if ( (numContigs == 0 && numStacksPerContig != 0) || (numContigs != 0 && numStacksPerContig == 0) ) { throw new ReviewedGATKException("numContigs and numStacksPerContig must either both be > 0, or both be 0"); } if ( minReadsPerStack > maxReadsPerStack ) { throw new ReviewedGATKException("minReadsPerStack > maxReadsPerStack"); } if ( minDistanceBetweenStacks > maxDistanceBetweenStacks ) { throw new ReviewedGATKException("minDistanceBetweenStacks > maxDistanceBetweenStacks"); } if ( minReadLength > maxReadLength ) { throw new ReviewedGATKException("minReadLength > maxReadLength"); } }
private void validateReadGroup(final SAMRecord record, final SAMFileHeader header) { final SAMReadGroupRecord rg = record.getReadGroup(); if (rg == null) { addError(new SAMValidationError(Type.RECORD_MISSING_READ_GROUP, "A record is missing a read group", record.getReadName())); } else if (header.getReadGroup(rg.getId()) == null) { addError(new SAMValidationError(Type.READ_GROUP_NOT_FOUND, "A record has a read group not found in the header: ", record.getReadName() + ", " + rg.getReadGroupId())); } }
private void validateReadGroup(final SAMRecord record, final SAMFileHeader header) { final SAMReadGroupRecord rg = record.getReadGroup(); if (rg == null) { addError(new SAMValidationError(Type.RECORD_MISSING_READ_GROUP, "A record is missing a read group", record.getReadName())); } else if (header.getReadGroup(rg.getId()) == null) { addError(new SAMValidationError(Type.READ_GROUP_NOT_FOUND, "A record has a read group not found in the header: ", record.getReadName() + ", " + rg.getReadGroupId())); } }
private void validateReadGroup(final SAMRecord record, final SAMFileHeader header) { final SAMReadGroupRecord rg = record.getReadGroup(); if (rg == null) { addError(new SAMValidationError(Type.RECORD_MISSING_READ_GROUP, "A record is missing a read group", record.getReadName())); } else if (header.getReadGroup(rg.getId()) == null) { addError(new SAMValidationError(Type.READ_GROUP_NOT_FOUND, "A record has a read group not found in the header: ", record.getReadName() + ", " + rg.getReadGroupId())); } }
int alignmentStart = 0; for (int x = 1; x <= getReadGroupCount(); x++) { SAMReadGroupRecord groupRecord = getHeader().getReadGroup(getReadGroupId(x)); for (int y = 1; y <= recordsPerGroup; y++) { SAMRecord record = ArtificialSAMUtils.createArtificialRead(getHeader(), "readUno", 0, ++alignmentStart, 20);
int alignmentStart = 0; for (int x = 1; x <= getReadGroupCount(); x++) { SAMReadGroupRecord groupRecord = getHeader().getReadGroup(getReadGroupId(x)); for (int y = 1; y <= recordsPerGroup; y++) { SAMRecord record = ArtificialSAMUtils.createArtificialRead(getHeader(), "readUno", 0, ++alignmentStart, 20);
@BeforeClass public void beforeClass() { header = composeHeader(); dataSource = composeDataSource(); final List<String> readGroupIDs = new ArrayList<String>(); final List<String> sampleNames = new ArrayList<String>(); for (int i = 1; i <= getReadGroupCount(); i++) { final String readGroupId = composeReadGroupId(i); readGroupIDs.add(readGroupId); sampleNames.add(readGroupId); } ArtificialSAMUtils.createEnumeratedReadGroups( header, readGroupIDs, sampleNames); for (int i = 1; i <= getReadGroupCount(); i++) { final String readGroupId = readGroupIDs.get(i-1); final SAMReadGroupRecord groupRecord = header.getReadGroup(readGroupId); groupRecord.setAttribute("PL", composePlatformName(i)); groupRecord.setAttribute("PU", composePlatformUnitName(i)); } }
int alignmentStart = 0; for (int x = 1; x <= getReadGroupCount(); x++) { SAMReadGroupRecord groupRecord = getHeader().getReadGroup(getReadGroupId(x)); for (int y = 1; y <= recordsPerGroup; y++) { SAMRecord record = ArtificialSAMUtils.createArtificialRead(getHeader(), "readUno", 0, ++alignmentStart, 20);
int alignmentStart = 0; for (int x = 1; x <= getReadGroupCount(); x++) { SAMReadGroupRecord groupRecord = getHeader().getReadGroup(getReadGroupId(x)); for (int y = 1; y <= recordsPerGroup; y++) { SAMRecord record = ArtificialSAMUtils.createArtificialRead(getHeader(), "readUno", 0, ++alignmentStart, 20);
@BeforeClass private void init() throws IOException { referenceFile = new File(b37KGReference); reference = new CachingIndexedFastaSequenceFile(referenceFile); dictionary = reference.getSequenceDictionary(); genomeLocParser = new GenomeLocParser(dictionary); header = ArtificialSAMUtils.createDefaultReadGroup(new SAMFileHeader(), "test", "test"); header.setSequenceDictionary(dictionary); header.setSortOrder(SAMFileHeader.SortOrder.coordinate); readGroup = new GATKSAMReadGroupRecord(header.getReadGroup("test")); final List<GATKSAMRecord> reads = new ArrayList<>(); for ( final String contig : contigs ) { for ( int i = 1; i <= numReadsPerContig; i++ ) { reads.add(buildSAMRecord("read" + contig + "_" + i, contig, i)); } } createBAM(reads); }
Assert.assertEquals(sequenceRecord.getSequenceLength(), sequenceLength); Assert.assertEquals(sequenceRecord.getAttribute(intTag), Integer.toString(intValue)); Assert.assertEquals(fileHeader.getReadGroup("L1").getAttribute(floatTag), Float.toString(floatValue)); Assert.assertEquals(fileHeader.getProgramRecord("0").getAttribute(stringTag), stringValue);
protected GATKSAMRecord buildSAMRecord(String readName, String contig, int alignmentStart, int alignmentEnd) { SAMFileHeader header = ArtificialSAMUtils.createDefaultReadGroup(new SAMFileHeader(), "test", "test"); header.setSequenceDictionary(dictionary); header.setSortOrder(SAMFileHeader.SortOrder.coordinate); GATKSAMRecord record = new GATKSAMRecord(header); record.setReadName(readName); record.setReferenceIndex(dictionary.getSequenceIndex(contig)); record.setAlignmentStart(alignmentStart); Cigar cigar = new Cigar(); int len = alignmentEnd - alignmentStart + 1; cigar.add(new CigarElement(len, CigarOperator.M)); record.setCigar(cigar); record.setReadString(new String(new char[len]).replace("\0", "A")); record.setBaseQualities(new byte[len]); record.setReadGroup(new GATKSAMReadGroupRecord(header.getReadGroup("test"))); return record; }