/** * Returns true if the read has a BAQ tag, or false otherwise * @param read * @return */ public static boolean hasBAQTag(SAMRecord read) { return read.getStringAttribute(BAQ_TAG) != null; }
public static String getAttr(SAMRecord record, String attributeName) { try { return record.getStringAttribute(attributeName); } catch (SAMException ex) { return ""; } }
public static String getAttr(SAMRecord record, String attributeName) { try { return record.getStringAttribute(attributeName); } catch (SAMException ex) { return ""; } }
public static int getReadBarcodeValue(final SAMRecord record, final String tag) { if (null == tag) return 0; final String attr = record.getStringAttribute(tag); if (null == attr) return 0; else return attr.hashCode(); }
/** * Get the BAQ attribute from the tag in read. Returns null if no BAQ tag is present. * @param read * @return */ public static byte[] getBAQTag(SAMRecord read) { String s = read.getStringAttribute(BAQ_TAG); return s != null ? s.getBytes() : null; }
public static int getReadBarcodeValue(final SAMRecord record, final String tag) { if (null == tag) return 0; final String attr = record.getStringAttribute(tag); if (null == attr) return 0; else return attr.hashCode(); }
/** * Returns the Mate Cigar String as stored in the attribute 'MC'. * @param rec the SAM record * @return Mate Cigar String, or null if there is none. */ public static String getMateCigarString(final SAMRecord rec) { return rec.getStringAttribute(SAMTag.MC.name()); }
/** * Returns the Mate Cigar String as stored in the attribute 'MC'. * * @param rec the SAM record * @return Mate Cigar String, or null if there is none. */ public static String getMateCigarString(final SAMRecord rec) { return rec.getStringAttribute(SAMTag.MC.name()); }
/** * Returns the Mate Cigar String as stored in the attribute 'MC'. * * @param rec the SAM record * @return Mate Cigar String, or null if there is none. */ public static String getMateCigarString(final SAMRecord rec) { return rec.getStringAttribute(SAMTag.MC.name()); }
private String assertTagExists(final SAMRecord record, final String tag) { String value = record.getStringAttribute(tag); if (value == null) { throw new PicardException("Record: " + record.getReadName() + " does have a value for tag: " + tag); } return value; }
private String assertTagExists(final SAMRecord record, final String tag) { String value = record.getStringAttribute(tag); if (value == null) { throw new PicardException("Record: " + record.getReadName() + " does have a value for tag: " + tag); } return value; }
@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())); }
public void addAlignment(SAMRecord samRecord) { final SAMReaderID id = toolkit.getReaderIDForRead(samRecord); String rg = samRecord.getStringAttribute("RG"); if ( rg != null ) { String rg_orig = toolkit.getReadsDataSource().getOriginalReadGroupId(rg); samRecord.setAttribute("RG",rg_orig); } addAlignment(samRecord, id); }
@Test public void test_setAttribute_empty_array() { final SAMFileHeader header = new SAMFileHeader(); final SAMRecord record = new SAMRecord(header); Assert.assertNull(record.getStringAttribute(ARRAY_TAG)); record.setAttribute(ARRAY_TAG, new int[0]); Assert.assertNotNull(record.getSignedIntArrayAttribute(ARRAY_TAG)); Assert.assertEquals(record.getSignedIntArrayAttribute(ARRAY_TAG), new int[0]); Assert.assertEquals(record.getAttribute(ARRAY_TAG), new char[0]); record.setAttribute(ARRAY_TAG, null); Assert.assertNull(record.getStringAttribute(ARRAY_TAG)); }
/** * Should be able to write empty and non-empty strings */ @Test(dataProvider = "formatsAndValues") public void testWriteAndReadStrings(final String format,final String value) throws Exception { final SAMRecord rec = createSamRecord(); rec.setAttribute(STRING_TAG, value); writeAndReadSamRecord(format, rec); Assert.assertEquals(rec.getStringAttribute(STRING_TAG),value); }
@Test public void testReverseComplement() { final SAMRecord rec = createTestSamRec(); rec.reverseComplement(Arrays.asList("Y1"), Arrays.asList("X1", "X2", "X3", "X4", "X5"), false); Assert.assertEquals(rec.getReadString(), "GTGTGTGTGT"); Assert.assertEquals(rec.getBaseQualityString(), "IIIIIHHHHH"); Assert.assertEquals(rec.getByteArrayAttribute("X1"), new byte[] {5,4,3,2,1}); Assert.assertEquals(rec.getSignedShortArrayAttribute("X2"), new short[] {5,4,3,2,1}); Assert.assertEquals(rec.getSignedIntArrayAttribute("X3"), new int[] {5,4,3,2,1}); Assert.assertEquals(rec.getFloatArrayAttribute("X4"), new float[] {5.0f,4.0f,3.0f,2.0f,1.0f}); Assert.assertEquals(rec.getStringAttribute("Y1"), "GTTTTCTTTT"); }
private void testConvertedSAMRecord(final SAMRecord converted, final SAMRecord original) { Assert.assertEquals(converted.getReadName(), original.getReadName()); Assert.assertEquals(converted.getBaseQualities(), original.getBaseQualities()); Assert.assertEquals(converted.getReadBases(), original.getReadBases()); Assert.assertEquals(converted.getStringAttribute(SAMTag.CO.name()), original.getStringAttribute(SAMTag.CO.name())); Assert.assertTrue(converted.getReadUnmappedFlag()); } }
private void testRecord(final String expectedReadName, final FastqRecord fastqRecord, final SAMRecord samRecord) { Assert.assertEquals(fastqRecord.getReadName(), expectedReadName); Assert.assertEquals(fastqRecord.getBaseQualities(), samRecord.getBaseQualities()); Assert.assertEquals(fastqRecord.getReadBases(), samRecord.getReadBases()); Assert.assertEquals(fastqRecord.getBaseQualityHeader(), samRecord.getStringAttribute(SAMTag.CO.name())); }
/** * Converts a {@link SAMRecord} into a {@link FastqRecord}. */ public static FastqRecord asFastqRecord(final SAMRecord record) { String readName = record.getReadName(); if(record.getReadPairedFlag() && (record.getFirstOfPairFlag() || record.getSecondOfPairFlag())) { readName += (record.getFirstOfPairFlag()) ? FastqConstants.FIRST_OF_PAIR : FastqConstants.SECOND_OF_PAIR; } return new FastqRecord(readName, record.getReadString(), record.getStringAttribute(SAMTag.CO.name()), record.getBaseQualityString()); }
/** * Converts a {@link SAMRecord} into a {@link FastqRecord}. */ public static FastqRecord asFastqRecord(final SAMRecord record) { String readName = record.getReadName(); if(record.getReadPairedFlag() && (record.getFirstOfPairFlag() || record.getSecondOfPairFlag())) { readName += (record.getFirstOfPairFlag()) ? FastqConstants.FIRST_OF_PAIR : FastqConstants.SECOND_OF_PAIR; } return new FastqRecord(readName, record.getReadString(), record.getStringAttribute(SAMTag.CO.name()), record.getBaseQualityString()); }