/** * Same as above, but use <code>readBaseMatchesRefBaseWithAmbiguity</code> instead of <code>basesEqual</code>. * Note that <code>isBisulfiteConverted</code> is not affected because it only applies when the * reference base is non-ambiguous. */ public static boolean bisulfiteBasesMatchWithAmbiguity(final boolean negativeStrand, final byte read, final byte reference) { return (readBaseMatchesRefBaseWithAmbiguity(read, reference)) || (isBisulfiteConverted(read, reference, negativeStrand)); }
/** * Same as above, but use <code>readBaseMatchesRefBaseWithAmbiguity</code> instead of <code>basesEqual</code>. * Note that <code>isBisulfiteConverted</code> is not affected because it only applies when the * reference base is non-ambiguous. */ public static boolean bisulfiteBasesMatchWithAmbiguity(final boolean negativeStrand, final byte read, final byte reference) { return (readBaseMatchesRefBaseWithAmbiguity(read, reference)) || (isBisulfiteConverted(read, reference, negativeStrand)); }
/** * Helper method to handle the various use cases of base comparison. * * @param readBase the read base to match * @param refBase the reference base to match * @param negativeStrand set to true if the base to test is on the negative strand and should be reverse complemented (only applies if bisulfiteSequence is true) * @param bisulfiteSequence set to true if the base to match is a bisulfite sequence and needs to be converted * @param matchAmbiguousRef causes the match to return true when the read base is a subset of the possible IUPAC reference bases, but not the other way around * @return true if the bases match, false otherwise */ private static boolean basesMatch(final byte readBase, final byte refBase, final boolean negativeStrand, final boolean bisulfiteSequence, final boolean matchAmbiguousRef) { if (bisulfiteSequence) { if (matchAmbiguousRef) return bisulfiteBasesMatchWithAmbiguity(negativeStrand, readBase, refBase); else return bisulfiteBasesEqual(negativeStrand, readBase, refBase); } else { if (matchAmbiguousRef) return readBaseMatchesRefBaseWithAmbiguity(readBase, refBase); else return basesEqual(readBase, refBase); } }
/** * Helper method to handle the various use cases of base comparison. * * @param readBase the read base to match * @param refBase the reference base to match * @param negativeStrand set to true if the base to test is on the negative strand and should be reverse complemented (only applies if bisulfiteSequence is true) * @param bisulfiteSequence set to true if the base to match is a bisulfite sequence and needs to be converted * @param matchAmbiguousRef causes the match to return true when the read base is a subset of the possible IUPAC reference bases, but not the other way around * @return true if the bases match, false otherwise */ private static boolean basesMatch(final byte readBase, final byte refBase, final boolean negativeStrand, final boolean bisulfiteSequence, final boolean matchAmbiguousRef) { if (bisulfiteSequence) { if (matchAmbiguousRef) return bisulfiteBasesMatchWithAmbiguity(negativeStrand, readBase, refBase); else return bisulfiteBasesEqual(negativeStrand, readBase, refBase); } else { if (matchAmbiguousRef) return readBaseMatchesRefBaseWithAmbiguity(readBase, refBase); else return basesEqual(readBase, refBase); } }
@Test(dataProvider = "basesEqualDataProvider") public void testBasesEqual(final char base1, final char base2, final boolean expectedB1EqualsB2, final boolean expectedB1ReadMatchesB2Ref, final boolean expectedB2ReadMatchesB1Ref) { final char[] base1UcLc = new char[] { toUpperCase(base1), toLowerCase(base1) }; final char[] base2UcLc = new char[] { toUpperCase(base2), toLowerCase(base2) }; // Test over all permutations - uc vs uc, uc vs lc, lc vs uc, lc vs lc for (char theBase1 : base1UcLc) { for (char theBase2 : base2UcLc) { // for equality, order should not matter final boolean b1EqualsB2 = SequenceUtil.basesEqual((byte) theBase1, (byte) theBase2); Assert.assertEquals(b1EqualsB2, expectedB1EqualsB2, "basesEqual test failed for '" + theBase1 + "' vs. '" + theBase2 + "'"); final boolean b2EqualsB1 = SequenceUtil.basesEqual((byte) theBase2, (byte) theBase1); Assert.assertEquals(b2EqualsB1, expectedB1EqualsB2, "basesEqual test failed for '" + theBase1 + "' vs. '" + theBase2 + "'"); // for ambiguous read/ref matching, the order does matter final boolean b1ReadMatchesB2Ref = SequenceUtil.readBaseMatchesRefBaseWithAmbiguity((byte) theBase1, (byte) theBase2); Assert.assertEquals(b1ReadMatchesB2Ref, expectedB1ReadMatchesB2Ref, "readBaseMatchesRefBaseWithAmbiguity test failed for '" + theBase1 + "' vs. '" + theBase2 + "'"); final boolean b2ReadMatchesB1Ref = SequenceUtil.readBaseMatchesRefBaseWithAmbiguity((byte) theBase2, (byte) theBase1); Assert.assertEquals(b2ReadMatchesB1Ref, expectedB2ReadMatchesB1Ref, "readBaseMatchesRefBaseWithAmbiguity test failed for '" + theBase1 + "' vs. '" + theBase2 + "'"); } } }