import org.biojava.nbio.ontology.Term.Impl;
import org.biojava.nbio.ontology.Triple;
import org.biojava.nbio.ontology.io.OboParser;
+import org.biojava.nbio.ontology.utils.Annotation;
/**
* A wrapper class that parses the Sequence Ontology and exposes useful access
*/
public class SequenceOntology
{
- private static SequenceOntology instance = new SequenceOntology();
+ private static SequenceOntology instance;
private Ontology ontology;
*/
private Map<Term, List<Term>> termIsA;
- public static SequenceOntology getInstance()
+ public synchronized static SequenceOntology getInstance()
{
+ if (instance == null)
+ {
+ instance = new SequenceOntology();
+ }
return instance;
}
}
/**
- * Store a lookup table of terms by their description. Note that description
- * is not guaranteed unique - currently reporting 8 duplicates.
+ * Stores a lookup table of terms by description. Note that description is not
+ * guaranteed unique. Where duplicate descriptions are found, try to discard
+ * the term that is flagged as obsolete. However we do store obsolete terms
+ * where there is no duplication of description.
*/
protected void storeTermNames()
{
String description = term.getDescription();
if (description != null)
{
- // System.out.println(term.getName() + "=" + term.getDescription());
- Term replaced = termsByDescription.put(description, term);
+ Term replaced = termsByDescription.get(description);
if (replaced != null)
{
+ boolean newTermIsObsolete = isObsolete(term);
+ boolean oldTermIsObsolete = isObsolete(replaced);
+ if (newTermIsObsolete && !oldTermIsObsolete)
+ {
+ System.err.println("Ignoring " + term.getName()
+ + " as obsolete and duplicated by "
+ + replaced.getName());
+ term = replaced;
+ }
+ else if (!newTermIsObsolete && oldTermIsObsolete)
+ {
+ System.err.println("Ignoring " + replaced.getName()
+ + " as obsolete and duplicated by " + term.getName());
+ }
+ else
+ {
System.err.println("Warning: " + term.getName()
+ " has replaced " + replaced.getName()
+ " for lookup of '" + description + "'");
+ }
}
+ termsByDescription.put(description, term);
}
}
}
}
/**
+ * Answers true if the term has property "is_obsolete" with value true, else
+ * false
+ *
+ * @param term
+ * @return
+ */
+ public static boolean isObsolete(Term term)
+ {
+ Annotation ann = term.getAnnotation();
+ if (ann != null)
+ {
+ try
+ {
+ if (Boolean.TRUE.equals(ann.getProperty("is_obsolete")))
+ {
+ return true;
+ }
+ } catch (NoSuchElementException e)
+ {
+ // fall through to false
+ }
+ }
+ return false;
+ }
+
+ /**
* Test whether the given Sequence Ontology term is nucleotide_match (either
* directly or via is_a relationship)
*