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.ext.so;
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertFalse;
25 import static org.testng.Assert.assertNull;
26 import static org.testng.Assert.assertTrue;
28 import jalview.datamodel.ontology.OntologyI;
29 import jalview.gui.JvOptionPane;
31 import java.util.Arrays;
32 import java.util.Collections;
33 import java.util.HashSet;
34 import java.util.List;
37 import org.testng.annotations.BeforeClass;
38 import org.testng.annotations.Test;
40 public class SequenceOntologyTest
43 @BeforeClass(alwaysRun = true)
44 public void setUpJvOptionPane()
46 JvOptionPane.setInteractiveMode(false);
47 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
52 @BeforeClass(alwaysRun = true)
55 long now = System.currentTimeMillis();
58 so = new SequenceOntology();
61 System.out.println("SOTest error ");
62 t.printStackTrace(System.err);
64 long elapsed = System.currentTimeMillis() - now;
65 System.out.println("Load and cache of Sequence Ontology took "
69 @Test(groups = "Functional")
72 assertFalse(so.isA(null, null));
73 assertFalse(so.isA(null, "SO:0000087"));
74 assertFalse(so.isA("SO:0000087", null));
75 assertFalse(so.isA("complete", "garbage"));
77 assertTrue(so.isA("SO:0000087", "SO:0000704"));
78 assertFalse(so.isA("SO:0000704", "SO:0000087"));
79 assertTrue(so.isA("SO:0000736", "SO:0000735"));
82 assertTrue(so.isA("micronuclear_sequence", "micronuclear_sequence"));
84 assertTrue(so.isA("micronuclear_sequence", "organelle_sequence"));
86 assertTrue(so.isA("micronuclear_sequence", "sequence_location"));
88 assertTrue(so.isA("micronuclear_sequence", "sequence_attribute"));
90 // same thing by name / description:
91 assertTrue(so.isA("micronuclear_sequence", "SO:0000084"));
92 assertTrue(so.isA("SO:0000084", "micronuclear_sequence"));
93 assertTrue(so.isA("SO:0000084", "SO:0000084"));
95 // SO name to description:
96 assertTrue(so.isA("SO:0000084", "organelle_sequence"));
97 assertTrue(so.isA("SO:0000084", "sequence_location"));
98 assertTrue(so.isA("SO:0000084", "sequence_attribute"));
100 // description to SO name:
101 assertTrue(so.isA("micronuclear_sequence", "SO:0000736"));
102 assertTrue(so.isA("micronuclear_sequence", "SO:0000735"));
103 assertTrue(so.isA("micronuclear_sequence", "SO:0000400"));
106 @Test(groups = "Functional")
107 public void testIsCDS()
109 assertTrue(so.isA("CDS", "CDS"));
110 assertTrue(so.isA("CDS_predicted", "CDS"));
111 assertTrue(so.isA("transposable_element_CDS", "CDS"));
112 assertTrue(so.isA("edited_CDS", "CDS"));
113 assertTrue(so.isA("CDS_independently_known", "CDS"));
114 assertTrue(so.isA("CDS_fragment", "CDS"));
115 assertFalse(so.isA("CDS_region", "CDS"));// part_of
116 assertFalse(so.isA("polypeptide", "CDS")); // derives_from
119 @Test(groups = "Functional")
120 public void testIsSequenceVariant()
122 assertFalse(so.isA("CDS", "sequence_variant"));
123 assertTrue(so.isA("sequence_variant", "sequence_variant"));
126 * these should all be sub-types of sequence_variant
128 assertTrue(so.isA("structural_variant", "sequence_variant"));
129 assertTrue(so.isA("feature_variant", "sequence_variant"));
130 assertTrue(so.isA("gene_variant", "sequence_variant"));
131 assertTrue(so.isA("transcript_variant", "sequence_variant"));
132 assertTrue(so.isA("NMD_transcript_variant", "sequence_variant"));
133 assertTrue(so.isA("missense_variant", "sequence_variant"));
134 assertTrue(so.isA("synonymous_variant", "sequence_variant"));
135 assertTrue(so.isA("frameshift_variant", "sequence_variant"));
136 assertTrue(so.isA("5_prime_UTR_variant", "sequence_variant"));
137 assertTrue(so.isA("3_prime_UTR_variant", "sequence_variant"));
138 assertTrue(so.isA("stop_gained", "sequence_variant"));
139 assertTrue(so.isA("stop_lost", "sequence_variant"));
140 assertTrue(so.isA("inframe_deletion", "sequence_variant"));
141 assertTrue(so.isA("inframe_insertion", "sequence_variant"));
144 @Test(groups = "Functional")
145 public void testGetChildTerms()
147 List<String> terms = Collections.<String> emptyList();
148 List<String> children = so.getChildTerms("exon", terms);
149 assertTrue(children.isEmpty());
151 terms = Arrays.asList("gene", "transcript", "snRNA", "junk", "mRNA");
152 children = so.getChildTerms("exon", terms);
153 assertTrue(children.isEmpty());
154 children = so.getChildTerms("transcript", terms);
155 assertEquals(children.size(), 2);
156 assertTrue(children.contains("snRNA"));
157 assertTrue(children.contains("mRNA"));
159 terms = Arrays.asList("gene", "transcript", "synonymous_variant",
160 "stop_lost", "chain");
161 children = so.getChildTerms("sequence_variant", terms);
162 assertEquals(children.size(), 2);
163 assertTrue(children.contains("synonymous_variant"));
164 assertTrue(children.contains("stop_lost"));
167 @Test(groups = "Functional")
168 public void testGetParentTerms()
170 Set<String> terms = new HashSet<>();
171 terms.add("sequence_variant");
172 terms.add("NMD_transcript_variant");
173 terms.add("stop_lost");
174 terms.add("chain"); // not an SO term
176 Set<String> parents = so.getParentTerms(terms);
177 assertEquals(parents.size(), 2);
178 assertTrue(parents.contains("sequence_variant"));
179 assertTrue(parents.contains("chain"));
182 @Test(groups = "Functional")
183 public void testGetRootParents()
185 List<String> roots = so.getRootParents("xyz");
187 roots = so.getRootParents(null);
190 roots = so.getRootParents("stop_gained");
191 assertEquals(roots.size(), 1);
192 assertEquals(roots.get(0), "sequence_variant");
194 roots = so.getRootParents("sequence_variant");
195 assertEquals(roots.size(), 1);
196 assertEquals(roots.get(0), "sequence_variant");
198 roots = so.getRootParents("alanine");
199 assertEquals(roots.size(), 1);
200 assertEquals(roots.get(0), "sequence_feature");