Merge branch 'develop' into features/JAL-2360colourSchemeApplicability
[jalview.git] / test / jalview / ext / so / SequenceOntologyTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
11  *  
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.
16  * 
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.
20  */
21 package jalview.ext.so;
22
23 import static org.testng.AssertJUnit.assertFalse;
24 import static org.testng.AssertJUnit.assertTrue;
25
26 import jalview.gui.JvOptionPane;
27 import jalview.io.gff.SequenceOntologyI;
28
29 import org.testng.annotations.BeforeClass;
30 import org.testng.annotations.Test;
31
32 public class SequenceOntologyTest
33 {
34
35   @BeforeClass(alwaysRun = true)
36   public void setUpJvOptionPane()
37   {
38     JvOptionPane.setInteractiveMode(false);
39     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
40   }
41
42   private SequenceOntologyI so;
43
44   @BeforeClass(alwaysRun = true)
45   public void setUp()
46   {
47     long now = System.currentTimeMillis();
48     try
49     {
50       so = new SequenceOntology();
51     } catch (Throwable t)
52     {
53       System.out.println("SOTest error ");
54       t.printStackTrace(System.err);
55     }
56     long elapsed = System.currentTimeMillis() - now;
57     System.out.println("Load and cache of Sequence Ontology took "
58             + elapsed + "ms");
59   }
60
61   @Test(groups = "Functional")
62   public void testIsA()
63   {
64     assertFalse(so.isA(null, null));
65     assertFalse(so.isA(null, "SO:0000087"));
66     assertFalse(so.isA("SO:0000087", null));
67     assertFalse(so.isA("complete", "garbage"));
68
69     assertTrue(so.isA("SO:0000087", "SO:0000704"));
70     assertFalse(so.isA("SO:0000704", "SO:0000087"));
71     assertTrue(so.isA("SO:0000736", "SO:0000735"));
72
73     // same thing:
74     assertTrue(so.isA("micronuclear_sequence", "micronuclear_sequence"));
75     // direct parent:
76     assertTrue(so.isA("micronuclear_sequence", "organelle_sequence"));
77     // grandparent:
78     assertTrue(so.isA("micronuclear_sequence", "sequence_location"));
79     // great-grandparent:
80     assertTrue(so.isA("micronuclear_sequence", "sequence_attribute"));
81
82     // same thing by name / description:
83     assertTrue(so.isA("micronuclear_sequence", "SO:0000084"));
84     assertTrue(so.isA("SO:0000084", "micronuclear_sequence"));
85     assertTrue(so.isA("SO:0000084", "SO:0000084"));
86
87     // SO name to description:
88     assertTrue(so.isA("SO:0000084", "organelle_sequence"));
89     assertTrue(so.isA("SO:0000084", "sequence_location"));
90     assertTrue(so.isA("SO:0000084", "sequence_attribute"));
91
92     // description to SO name:
93     assertTrue(so.isA("micronuclear_sequence", "SO:0000736"));
94     assertTrue(so.isA("micronuclear_sequence", "SO:0000735"));
95     assertTrue(so.isA("micronuclear_sequence", "SO:0000400"));
96   }
97
98   @Test(groups = "Functional")
99   public void testIsCDS()
100   {
101     assertTrue(so.isA("CDS", "CDS"));
102     assertTrue(so.isA("CDS_predicted", "CDS"));
103     assertTrue(so.isA("transposable_element_CDS", "CDS"));
104     assertTrue(so.isA("edited_CDS", "CDS"));
105     assertTrue(so.isA("CDS_independently_known", "CDS"));
106     assertTrue(so.isA("CDS_fragment", "CDS"));
107     assertFalse(so.isA("CDS_region", "CDS"));// part_of
108     assertFalse(so.isA("polypeptide", "CDS")); // derives_from
109   }
110 }