From 07a67b3f441901cb1c802afac8fac249a8ebc576 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 21 Jan 2016 14:44:15 +0000 Subject: [PATCH] JAL-1705 added isSequenceVariant(), commonly used SO terms as constants --- src/jalview/io/gff/SequenceOntology.java | 42 +++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/jalview/io/gff/SequenceOntology.java b/src/jalview/io/gff/SequenceOntology.java index 36ffaf8..441d296 100644 --- a/src/jalview/io/gff/SequenceOntology.java +++ b/src/jalview/io/gff/SequenceOntology.java @@ -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"); + } } -- 1.7.10.2