2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.analysis;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertNull;
26 import static org.testng.AssertJUnit.assertTrue;
27 import static org.testng.AssertJUnit.fail;
29 import jalview.analysis.SecStrConsensus.SimpleBP;
31 import java.util.Vector;
33 import org.testng.annotations.Test;
37 @Test(groups = { "Functional" })
38 public void testGetSimpleBPs() throws WUSSParseException
40 String rna = "([{})]"; // JAL-1081 example
41 Vector<SimpleBP> bps = Rna.getSimpleBPs(rna);
42 assertEquals(3, bps.size());
45 * the base pairs are added in the order in which the matching base is found
46 * (popping the stack of unmatched opening brackets)
48 assertEquals(2, bps.get(0).bp5); // {
49 assertEquals(3, bps.get(0).bp3); // }
50 assertEquals(0, bps.get(1).bp5); // (
51 assertEquals(4, bps.get(1).bp3); // )
52 assertEquals(1, bps.get(2).bp5); // [
53 assertEquals(5, bps.get(2).bp3); // ]
56 @Test(groups = { "Functional" })
57 public void testGetSimpleBPs_unmatchedOpener()
59 String rna = "(([{})]";
62 Rna.getSimpleBPs(rna);
63 fail("expected exception");
64 } catch (WUSSParseException e)
66 // error reported as after end of input string
67 assertEquals(rna.length(), e.getProblemPos());
71 @Test(groups = { "Functional" })
72 public void testGetSimpleBPs_unmatchedCloser()
74 String rna = "([{})]]]";
77 Rna.getSimpleBPs(rna);
78 fail("expected exception");
79 } catch (WUSSParseException e)
81 // error reported as at first unmatched close
82 assertEquals(6, e.getProblemPos());
86 * a variant where we have no opening bracket of the same type
87 * as the unmatched closing bracket (no stack rather than empty stack)
92 Rna.getSimpleBPs(rna);
93 fail("expected exception");
94 } catch (WUSSParseException e)
96 assertEquals(4, e.getProblemPos());
100 @Test(groups = { "Functional" })
101 public void testGetRNASecStrucState()
103 assertNull(Rna.getRNASecStrucState(null));
104 for (int i = 0; i <= 255; i++)
106 String s = String.valueOf((char) i);
107 String ss = Rna.getRNASecStrucState(s);
110 * valid SS chars are a-z, A-Z, and various brackets;
111 * anything else is returned as a space
113 if ((i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z')
114 || "()[]{}<>".indexOf(s) > -1)
116 assertEquals("" + i, s, ss);
120 assertEquals(" ", ss);
125 * a string is processed character by character
127 assertEquals("a [K ]z} {Q b(w)p><i",
128 Rna.getRNASecStrucState("a.[K-]z}?{Q b(w)p><i"));
131 @Test(groups = { "Functional" })
132 public void testIsClosingParenthesis()
135 * only a-z, )]}> are closing bracket symbols
137 for (int i = 0; i <= 255; i++)
139 boolean isClosing = Rna.isClosingParenthesis((char) i);
140 if ((i >= 'a' && i <= 'z') || i == ')' || i == '}' || i == ']'
143 assertTrue(String.format("close base pair %c", i), isClosing);
147 assertFalse(String.format("close base pair %c", i), isClosing);
152 @Test(groups = { "Functional" })
153 public void testIsCanonicalOrWobblePair()
155 String bases = "acgtuACGTU";
156 for (int i = 0; i < bases.length(); i++)
158 for (int j = 0; j < bases.length(); j++)
160 char first = bases.charAt(i);
161 char second = bases.charAt(j);
162 boolean result = Rna.isCanonicalOrWobblePair(first, second);
163 String pair = new String(new char[] { first, second })
165 if (pair.equals("AT") || pair.equals("TA") || pair.equals("AU")
166 || pair.equals("UA") || pair.equals("GC")
167 || pair.equals("CG") || pair.equals("GT")
168 || pair.equals("TG") || pair.equals("GU")
169 || pair.equals("UG"))
171 assertTrue(pair + " should be valid", result);
175 assertFalse(pair + " should be invalid", result);
181 @Test(groups = { "Functional" })
182 public void testIsOpeningParenthesis()
185 * only A-Z, ([{< are opening bracket symbols
187 for (int i = 0; i <= 255; i++)
189 boolean isOpening = Rna.isOpeningParenthesis((char) i);
190 if ((i >= 'A' && i <= 'Z') || i == '(' || i == '{' || i == '['
193 assertTrue(String.format("Open base pair %c", i), isOpening);
197 assertFalse(String.format("Open base pair %c", i), isOpening);