/** * @see htsjdk.samtools.SAMRecord#setAttribute(java.lang.String, java.lang.Object) * @param tag Binary representation of a 2-char String tag as created by SAMTagUtil. */ protected void setAttribute(final short tag, final Object value) { setAttribute(tag, value, false); }
@Override protected void setAttribute(final short tag, final Object value, final boolean isUnsignedArray) { LazyAttribute attr = lazyAttributeTags.get(tag); if (attr != null && !initializedAttributes.contains(attr)) { initializedAttributes.add(attr); } super.setAttribute(tag, value, isUnsignedArray); }
/** * Do this unconditionally, not just for aligned records, for two reasons: * - An unaligned read has been processed by the aligner, so it is more truthful. * - When chaining additional PG records, having all the records in the output file refer to the same PG * record means that only one chain will need to be created, rather than a chain for the mapped reads * and a separate chain for the unmapped reads. */ private void maybeSetPgTag(final SAMRecord rec) { if (this.programRecord != null && addPGTagToReads) { rec.setAttribute(ReservedTagConstants.PROGRAM_GROUP_ID, this.programRecord.getProgramGroupId()); } }
/** Removes the NM, MD, and UQ tags. This is useful if we modify the read and are not able to recompute these tags, * for example when no reference is available. * @param rec the record to modify. */ private static void removeNmMdAndUqTags(final SAMRecord rec) { rec.setAttribute(SAMTag.NM.name(), null); rec.setAttribute(SAMTag.MD.name(), null); rec.setAttribute(SAMTag.UQ.name(), null); } }
/** * Do this unconditionally, not just for aligned records, for two reasons: * - An unaligned read has been processed by the aligner, so it is more truthful. * - When chaining additional PG records, having all the records in the output file refer to the same PG * record means that only one chain will need to be created, rather than a chain for the mapped reads * and a separate chain for the unmapped reads. */ private void maybeSetPgTag(final SAMRecord rec) { if (this.programRecord != null && addPGTagToReads) { rec.setAttribute(ReservedTagConstants.PROGRAM_GROUP_ID, this.programRecord.getProgramGroupId()); } }
/** * Sets the original base quality scores into the "OQ" tag as a String. Supplied value should be * as phred-scaled numeric qualities. */ public void setOriginalBaseQualities(final byte[] oq) { setAttribute("OQ", SAMUtils.phredToFastq(oq)); }
/** * Sets the original base quality scores into the "OQ" tag as a String. Supplied value should be * as phred-scaled numeric qualities. */ public void setOriginalBaseQualities(final byte[] oq) { setAttribute("OQ", SAMUtils.phredToFastq(oq)); }
@Override protected void setAttribute(final short tag, final Object value, final boolean isUnsignedArray) { // populate all the attributes from the binary block before overwriting one getBinaryAttributes(); super.setAttribute(tag, value, isUnsignedArray); mBinaryDataStale = true; }
/** * Sets the original base quality scores into the "OQ" tag as a String. Supplied value should be * as phred-scaled numeric qualities. */ public void setOriginalBaseQualities(final byte[] oq) { setAttribute("OQ", SAMUtils.phredToFastq(oq)); }
private void fixAlreadySeenReads() { //remove all the reads for the selected adapters Arrays.stream(adapters.get()).forEach(adapter -> preAdapterPrunedRecords.remove(adapter)); //anything left is marked with the incorrect adapter and needs its XT tag removed preAdapterPrunedRecords.values().forEach(readList -> readList.parallelStream().forEach(read -> { Stream<SAMRecord.SAMTagAndValue> filterAttributes = read.getAttributes().stream().filter(tag -> !tag.tag.equals(ReservedTagConstants.XT)); read.clearAttributes(); filterAttributes.forEach(tag -> read.setAttribute(tag.tag, tag.value)); })); preAdapterPrunedRecords.clear(); }
public static final SAMRecord simplifyRead(SAMRecord read) { // the only attribute we keep is the RG Object rg = read.getAttribute("RG"); read.clearAttributes(); read.setAttribute("RG", rg); return read; }
public SAMRecord createTestSamRec() { final SAMFileHeader header = new SAMFileHeader(); final SAMRecord rec = new SAMRecord(header); rec.setReadString("ACACACACAC"); rec.setBaseQualityString("HHHHHIIIII"); rec.setAttribute("X1", new byte[] {1,2,3,4,5}); rec.setAttribute("X2", new short[] {1,2,3,4,5}); rec.setAttribute("X3", new int[] {1,2,3,4,5}); rec.setAttribute("X4", new float[] {1.0f,2.0f,3.0f,4.0f,5.0f}); rec.setAttribute("Y1", "AAAAGAAAAC"); return(rec); }
@Test public void testEmptyArrayAttributeHasNoCommaWhenWrittenToSAM(){ final SAMFileHeader header = new SAMFileHeader(); final SAMRecord record = new SAMRecord(header); record.setAttribute("xa", new int[0]); Assert.assertTrue(record.getSAMString().endsWith("xa:B:i\n")); } }
/** * Should be able to write empty and non-empty strings */ @Test(dataProvider = "formatsAndValues2") public void testWriteAndReadCharacters(final String format,final Character value) throws Exception { final SAMRecord rec = createSamRecord(); rec.setAttribute(STRING_TAG, value); writeAndReadSamRecord(format, rec); Assert.assertEquals(rec.getCharacterAttribute(STRING_TAG),value); }
@Test(dataProvider = "brokenUmiProvider", expectedExceptions = PicardException.class) public void testBrokenUmi(final String brokenUmi) { SAMFileHeader header = new SAMFileHeader(); SAMRecord rec = new SAMRecord(header); rec.setAttribute("RX", brokenUmi); // This should throw an exception due to a broken UMI in rec UmiUtil.getTopStrandNormalizedUmi(rec, "RX", true); } }
@Test(expectedExceptions = SAMException.class) public void test_getUnsignedIntegerAttribute_negative() { SAMFileHeader header = new SAMFileHeader(); SAMRecord record = new SAMRecord(header); record.setAttribute("UI", -1L); record.getUnsignedIntegerAttribute("UI"); }
@Test public void testFilterPlatformUnit() { SAMRecord filteredRecord = ArtificialSAMUtils.createArtificialRead(getHeader(), "readUno", 0, 1, 20); filteredRecord.setAttribute("RG", getReadGroupId(1)); SAMRecord unfilteredRecord = ArtificialSAMUtils.createArtificialRead(getHeader(), "readDos", 0, 2, 20); unfilteredRecord.setAttribute("RG", getReadGroupId(2)); List<String> filterList = new ArrayList<String>(); filterList.add("PU:" + getPlatformUnit(1)); ReadGroupBlackListFilter filter = new ReadGroupBlackListFilter(filterList); Assert.assertTrue(filter.filterOut(filteredRecord)); Assert.assertFalse(filter.filterOut(unfilteredRecord)); }
@Test() public void test_setAttribute_empty_string() { final SAMFileHeader header = new SAMFileHeader(); final SAMRecord record = new SAMRecord(header); Assert.assertNull(record.getStringAttribute(SAMTag.MD.name())); record.setAttribute(SAMTag.MD.name(), ""); Assert.assertNotNull(record.getStringAttribute(SAMTag.MD.name())); Assert.assertEquals(record.getStringAttribute(SAMTag.MD.name()),""); record.setAttribute(SAMTag.MD.name(), null); Assert.assertNull(record.getStringAttribute(SAMTag.MD.name())); }
@Test(dataProvider = "makeReferenceFromAlignment") public void testMakeReferenceFromAlignment(final String seq, final String cigar, final String md, boolean includeReferenceBasesForDeletions, final String expectedReference) { final SAMRecord rec = new SAMRecord(null); rec.setReadName("test"); rec.setReadString(seq); rec.setCigarString(cigar); rec.setAttribute(SAMTag.MD.name(), md); final byte[] refBases = SequenceUtil.makeReferenceFromAlignment(rec, includeReferenceBasesForDeletions); Assert.assertEquals(StringUtil.bytesToString(refBases), expectedReference); }
@Test public void testWithBarcodeFragmentDuplicate() { final AbstractMarkDuplicatesCommandLineProgramTester tester = getTester(); tester.addMappedFragment(2, 41212324, false, "50M", DEFAULT_BASE_QUALITY); tester.addMappedFragment(2, 41212324, true, "50M", DEFAULT_BASE_QUALITY); final String barcodeTag = "BC"; for (final SAMRecord record : new IterableAdapter<SAMRecord>(tester.getRecordIterator())) { record.setAttribute(barcodeTag, "GACT"); } tester.addArg("BARCODE_TAG=" + barcodeTag); tester.runTest(); }