JAL-1705 added isSequenceVariant(), commonly used SO terms as constants
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 21 Jan 2016 14:44:15 +0000 (14:44 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 21 Jan 2016 14:44:15 +0000 (14:44 +0000)
src/jalview/io/gff/SequenceOntology.java

index 36ffaf8..441d296 100644 (file)
@@ -27,10 +27,35 @@ import org.biojava.nbio.ontology.utils.Annotation;
  */
 public class SequenceOntology
 {
+
+  /*
+   * selected commonly used values for quick reference
+   */
+  // SO:0000316
+  public static final String CDS = "CDS";
+
+  // SO:0001060
+  public static final String SEQUENCE_VARIANT = "sequence_variant";
+
+  // SO:0000147
+  public static final String EXON = "exon";
+
+  // SO:0000673
+  public static final String TRANSCRIPT = "transcript";
+
+  /*
+   * singleton instance of this class
+   */
   private static SequenceOntology instance;
 
+  /*
+   * the parsed Ontology data as modelled by BioJava
+   */
   private Ontology ontology;
 
+  /*
+   * the ontology term for the isA relationship
+   */
   private Term isA;
 
   /*
@@ -81,8 +106,10 @@ public class SequenceOntology
     ZipInputStream zipStream = null;
     try
     {
+      String zipFile = ontologyFile + ".zip";
+      System.out.println("Loading Sequence Ontology from " + zipFile);
       InputStream inStream = this.getClass().getResourceAsStream(
-              "/" + ontologyFile + ".zip");
+              "/" + zipFile);
       zipStream = new ZipInputStream(new BufferedInputStream(inStream));
       ZipEntry entry;
       while ((entry = zipStream.getNextEntry()) != null)
@@ -257,6 +284,14 @@ public class SequenceOntology
    */
   public boolean isA(String child, String parent)
   {
+    /*
+     * optimise trivial checks like isA("CDS", "CDS")
+     */
+    if (child.equals(parent))
+    {
+      return true;
+    }
+
     Term childTerm = getTerm(child);
     Term parentTerm = getTerm(parent);
 
@@ -361,4 +396,9 @@ public class SequenceOntology
     }
     return t;
   }
+
+  public boolean isSequenceVariant(String soTerm)
+  {
+    return isA(soTerm, "sequence_variant");
+  }
 }