/** * Calculates the sum of qualities for mismatched bases in the read. * * @param referenceBases Array of ASCII bytes in which the 0th position in the array corresponds * to the first element of the reference sequence to which read is aligned. */ public static int sumQualitiesOfMismatches(final SAMRecord read, final byte[] referenceBases) { return sumQualitiesOfMismatches(read, referenceBases, 0, false); }
/** * Calculates the sum of qualities for mismatched bases in the read. * * @param referenceBases Array of ASCII bytes that covers at least the the portion of the reference sequence * to which read is aligned from getReferenceStart to getReferenceEnd. * @param referenceOffset 0-based offset of the first element of referenceBases relative to the start * of that reference sequence. */ public static int sumQualitiesOfMismatches(final SAMRecord read, final byte[] referenceBases, final int referenceOffset) { return sumQualitiesOfMismatches(read, referenceBases, referenceOffset, false); }
/** * Calculates the sum of qualities for mismatched bases in the read. * @param referenceBases Array of ASCII bytes that covers at least the the portion of the reference sequence * to which read is aligned from getReferenceStart to getReferenceEnd. * @param referenceOffset 0-based offset of the first element of referenceBases relative to the start * of that reference sequence. */ public static int sumQualitiesOfMismatches(final SAMRecord read, final byte[] referenceBases, final int referenceOffset) { return sumQualitiesOfMismatches(read, referenceBases, referenceOffset, false); }
/** * Calculates the sum of qualities for mismatched bases in the read. * * @param referenceBases Array of ASCII bytes that covers at least the the portion of the reference sequence * to which read is aligned from getReferenceStart to getReferenceEnd. * @param referenceOffset 0-based offset of the first element of referenceBases relative to the start * of that reference sequence. */ public static int sumQualitiesOfMismatches(final SAMRecord read, final byte[] referenceBases, final int referenceOffset) { return sumQualitiesOfMismatches(read, referenceBases, referenceOffset, false); }
/** * Calculates the sum of qualities for mismatched bases in the read. * @param referenceBases Array of ASCII bytes in which the 0th position in the array corresponds * to the first element of the reference sequence to which read is aligned. */ public static int sumQualitiesOfMismatches(final SAMRecord read, final byte[] referenceBases) { return sumQualitiesOfMismatches(read, referenceBases, 0, false); }
/** * Calculates the sum of qualities for mismatched bases in the read. * * @param referenceBases Array of ASCII bytes in which the 0th position in the array corresponds * to the first element of the reference sequence to which read is aligned. */ public static int sumQualitiesOfMismatches(final SAMRecord read, final byte[] referenceBases) { return sumQualitiesOfMismatches(read, referenceBases, 0, false); }
/** Calculates and sets UQ tag from the record and the reference * * @param record the record to be fixed * @param refSeqWalker a ReferenceSequenceWalker that will be used to traverse the reference * @param isBisulfiteSequence a flag indicating whether the sequence came from bisulfite-sequencing. * * No return value, modifies the provided record. */ public static void fixUq(final SAMRecord record, final ReferenceSequenceFileWalker refSeqWalker, final boolean isBisulfiteSequence) { if (record.getBaseQualities() != SAMRecord.NULL_QUALS) { final byte[] referenceBases = refSeqWalker.get(record.getReferenceIndex()).getBases(); record.setAttribute(SAMTag.UQ.name(), SequenceUtil.sumQualitiesOfMismatches(record, referenceBases, 0, isBisulfiteSequence)); } }
/** Calculates and sets UQ tag from the record and the reference * * @param record the record to be fixed * @param refSeqWalker a ReferenceSequenceWalker that will be used to traverse the reference * @param isBisulfiteSequence a flag indicating whether the sequence came from bisulfite-sequencing. * * No return value, modifies the provided record. */ public static void fixUq(final SAMRecord record, final ReferenceSequenceFileWalker refSeqWalker, final boolean isBisulfiteSequence) { if (record.getBaseQualities() != SAMRecord.NULL_QUALS) { final byte[] referenceBases = refSeqWalker.get(record.getReferenceIndex()).getBases(); record.setAttribute(SAMTag.UQ.name(), SequenceUtil.sumQualitiesOfMismatches(record, referenceBases, 0, isBisulfiteSequence)); } }
@Test(dataProvider = "mismatchBisulfiteCountsDataProvider") public void testMismatchBisulfiteCounts(final String readString, final String cigar, final String reference, final boolean positiveStrand, final int expectedMismatches) { final byte baseQuality = 30; final SAMRecord rec = new SAMRecord(null); rec.setReadName("test"); rec.setReadString(readString); rec.setReadNegativeStrandFlag(!positiveStrand); final byte[] byteArray = new byte[readString.length()]; Arrays.fill(byteArray,baseQuality); rec.setBaseQualities(byteArray); rec.setCigarString(cigar); final byte[] refBases = StringUtil.stringToBytes(reference); final int nExact = SequenceUtil.countMismatches(rec, refBases, -1, true, false); Assert.assertEquals(nExact, expectedMismatches); final int sumMismatchesQualityExact = SequenceUtil.sumQualitiesOfMismatches(rec, refBases, -1, true); Assert.assertEquals(sumMismatchesQualityExact, expectedMismatches * baseQuality); }
read.setAttribute(SAMTag.NM.name(), SequenceUtil.calculateSamNmTag(read, reference, leftmostIndex - 1)); if ( read.getAttribute(SAMTag.UQ.name()) != null ) read.setAttribute(SAMTag.UQ.name(), SequenceUtil.sumQualitiesOfMismatches(read, reference, leftmostIndex-1)); } catch (Exception e) {
@Test(dataProvider = "mismatchCountsDataProvider") public void testCountMismatches(final String readString, final String cigar, final String reference, final int expectedMismatchesExact, final int expectedMismatchesAmbiguous) { final SAMRecord rec = new SAMRecord(null); rec.setReadName("test"); rec.setReadString(readString); final byte[] byteArray = new byte[readString.length()]; Arrays.fill(byteArray, (byte)33); rec.setBaseQualities(byteArray); rec.setCigarString(cigar); final byte[] refBases = StringUtil.stringToBytes(reference); final int nExact = SequenceUtil.countMismatches(rec, refBases, -1, false, false); Assert.assertEquals(nExact, expectedMismatchesExact); final int sumMismatchesQualityExact = SequenceUtil.sumQualitiesOfMismatches(rec, refBases, -1, false); Assert.assertEquals(sumMismatchesQualityExact, expectedMismatchesExact * 33); final int nAmbiguous = SequenceUtil.countMismatches(rec, refBases, -1, false, true); Assert.assertEquals(nAmbiguous, expectedMismatchesAmbiguous); }