From 9c1dd670f293d8f33de55133397b4cd2d4baf38e Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 21 Sep 2016 16:40:07 +0100 Subject: [PATCH] JAL-2214 test for strict Watson-Crick pairing --- src/jalview/analysis/Rna.java | 48 ++++++++++++++++++++++++++++++++++++ test/jalview/analysis/RnaTest.java | 27 ++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/src/jalview/analysis/Rna.java b/src/jalview/analysis/Rna.java index e3d999a..7c07708 100644 --- a/src/jalview/analysis/Rna.java +++ b/src/jalview/analysis/Rna.java @@ -416,6 +416,54 @@ public class Rna return false; } + public static boolean isCanonicalPair(char first, char second) + { + + if (first > 'Z') + { + first -= 32; + } + if (second > 'Z') + { + second -= 32; + } + + switch (first) + { + case 'A': + switch (second) + { + case 'T': + case 'U': + return true; + } + break; + case 'G': + switch (second) + { + case 'C': + return true; + } + break; + case 'C': + switch (second) + { + case 'G': + return true; + } + break; + case 'T': + case 'U': + switch (second) + { + case 'A': + return true; + } + break; + } + return false; + } + /** * Returns the matching close pair symbol for the given opening symbol. * Currently returns a-z for A-Z, or )]}> for ([{<, or the input symbol if it diff --git a/test/jalview/analysis/RnaTest.java b/test/jalview/analysis/RnaTest.java index f33525f..f96d2c9 100644 --- a/test/jalview/analysis/RnaTest.java +++ b/test/jalview/analysis/RnaTest.java @@ -188,6 +188,33 @@ public class RnaTest } } + @Test(groups = { "Functional" }) + public void testIsCanonicalPair() + { + String bases = "acgtuACGTU"; + for (int i = 0; i < bases.length(); i++) + { + for (int j = 0; j < bases.length(); j++) + { + char first = bases.charAt(i); + char second = bases.charAt(j); + boolean result = Rna.isCanonicalPair(first, second); + String pair = new String(new char[] { first, second }) + .toUpperCase(); + if (pair.equals("AT") || pair.equals("TA") || pair.equals("AU") + || pair.equals("UA") || pair.equals("GC") + || pair.equals("CG")) + { + assertTrue(pair + " should be valid", result); + } + else + { + assertFalse(pair + " should be invalid", result); + } + } + } + } + /** * Tests for isOpeningParenthesis with char or String argument */ -- 1.7.10.2