X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2Fgff%2FSequenceOntologyLite.java;h=2cbec369e9e345945c6c31e3b1bc5942b0370751;hb=6a05eb3f55d97e685f0c723822384633d5636778;hp=7d354e0a039d362e1f0805b6ffdb94a09c8597f6;hpb=fa2429b3c8cd5eb56c4a56572af6e9c4adc916c9;p=jalview.git diff --git a/src/jalview/io/gff/SequenceOntologyLite.java b/src/jalview/io/gff/SequenceOntologyLite.java index 7d354e0..2cbec36 100644 --- a/src/jalview/io/gff/SequenceOntologyLite.java +++ b/src/jalview/io/gff/SequenceOntologyLite.java @@ -20,6 +20,8 @@ */ package jalview.io.gff; +import jalview.datamodel.ontology.OntologyBase; + import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -38,7 +40,8 @@ import java.util.Map; * @author gmcarstairs * */ -public class SequenceOntologyLite implements SequenceOntologyI +public class SequenceOntologyLite extends OntologyBase + implements SequenceOntologyI { /* * initial selection of types of interest when processing Ensembl features @@ -81,8 +84,11 @@ public class SequenceOntologyLite implements SequenceOntologyI { "sequence_variant", "sequence_variant" }, { "structural_variant", "sequence_variant" }, { "feature_variant", "sequence_variant" }, + { "upstream_gene_variant", "sequence_variant" }, { "gene_variant", "sequence_variant" }, { "transcript_variant", "sequence_variant" }, + { "non_coding_transcript_variant", "sequence_variant" }, + { "non_coding_transcript_exon_variant", "sequence_variant" }, // NB Ensembl uses NMD_transcript_variant as if a 'transcript' // but we model it here correctly as per the SO { "NMD_transcript_variant", "sequence_variant" }, @@ -248,4 +254,70 @@ public class SequenceOntologyLite implements SequenceOntologyI return termsNotFound; } } + + @Override + public List getRootParents(final String term) + { + /* + * check in cache first + */ + if (rootParents.containsKey(term)) + { + return rootParents.get(term); + } + + List top = new ArrayList<>(); + List query = new ArrayList<>(); + query.add(term); + + while (!query.isEmpty()) + { + List nextQuery = new ArrayList<>(); + for (String q : query) + { + List theParents = parents.get(q); + if (theParents != null) + { + if (theParents.size() == 1 && theParents.get(0).equals(q)) + { + /* + * top-level term + */ + if (!top.contains(q)) + { + top.add(q); + } + } + else + { + for (String p : theParents) + { + if (!p.equals(q)) + { + nextQuery.add(p); + } + } + } + } + } + query = nextQuery; + } + + rootParents.put(term, top); + + return top.isEmpty() ? null : top; + } + + @Override + public List getParents(String term) + { + List result = parents.get(term); + return result == null ? new ArrayList<>() : result; + } + + @Override + public boolean isValidTerm(String term) + { + return parents.containsKey(term); + } }