JAL-2189 apply license
[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.io.gff.SequenceOntologyI;
27
28 import org.testng.annotations.BeforeClass;
29 import org.testng.annotations.Test;
30
31 public class SequenceOntologyTest
32 {
33   private SequenceOntologyI so;
34
35   @BeforeClass(alwaysRun = true)
36   public void setUp()
37   {
38     long now = System.currentTimeMillis();
39     try
40     {
41       so = new SequenceOntology();
42     } catch (Throwable t)
43     {
44       System.out.println("SOTest error ");
45       t.printStackTrace(System.err);
46     }
47     long elapsed = System.currentTimeMillis() - now;
48     System.out.println("Load and cache of Sequence Ontology took "
49             + elapsed + "ms");
50   }
51
52   @Test(groups = "Functional")
53   public void testIsA()
54   {
55     assertFalse(so.isA(null, null));
56     assertFalse(so.isA(null, "SO:0000087"));
57     assertFalse(so.isA("SO:0000087", null));
58     assertFalse(so.isA("complete", "garbage"));
59
60     assertTrue(so.isA("SO:0000087", "SO:0000704"));
61     assertFalse(so.isA("SO:0000704", "SO:0000087"));
62     assertTrue(so.isA("SO:0000736", "SO:0000735"));
63
64     // same thing:
65     assertTrue(so.isA("micronuclear_sequence", "micronuclear_sequence"));
66     // direct parent:
67     assertTrue(so.isA("micronuclear_sequence", "organelle_sequence"));
68     // grandparent:
69     assertTrue(so.isA("micronuclear_sequence", "sequence_location"));
70     // great-grandparent:
71     assertTrue(so.isA("micronuclear_sequence", "sequence_attribute"));
72
73     // same thing by name / description:
74     assertTrue(so.isA("micronuclear_sequence", "SO:0000084"));
75     assertTrue(so.isA("SO:0000084", "micronuclear_sequence"));
76     assertTrue(so.isA("SO:0000084", "SO:0000084"));
77
78     // SO name to description:
79     assertTrue(so.isA("SO:0000084", "organelle_sequence"));
80     assertTrue(so.isA("SO:0000084", "sequence_location"));
81     assertTrue(so.isA("SO:0000084", "sequence_attribute"));
82
83     // description to SO name:
84     assertTrue(so.isA("micronuclear_sequence", "SO:0000736"));
85     assertTrue(so.isA("micronuclear_sequence", "SO:0000735"));
86     assertTrue(so.isA("micronuclear_sequence", "SO:0000400"));
87   }
88
89   @Test(groups = "Functional")
90   public void testIsCDS()
91   {
92     assertTrue(so.isA("CDS", "CDS"));
93     assertTrue(so.isA("CDS_predicted", "CDS"));
94     assertTrue(so.isA("transposable_element_CDS", "CDS"));
95     assertTrue(so.isA("edited_CDS", "CDS"));
96     assertTrue(so.isA("CDS_independently_known", "CDS"));
97     assertTrue(so.isA("CDS_fragment", "CDS"));
98     assertFalse(so.isA("CDS_region", "CDS"));// part_of
99     assertFalse(so.isA("polypeptide", "CDS")); // derives_from
100   }
101 }