1 package jalview.io.gff;
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.HashMap;
10 * An implementation of SequenceOntologyI that hard codes terms of interest.
12 * Use this in unit testing by calling SequenceOntology.setInstance(new
13 * SequenceOntologyLite()).
15 * May also become a stand-in for SequenceOntology in the applet if we want to
16 * avoid the additional jars needed for parsing the full SO.
21 public class SequenceOntologyLite implements SequenceOntologyI
24 * initial selection of types of interest when processing Ensembl features
27 private final String[][] TERMS = new String[][] {
33 { "ncRNA_gene", "gene" },
34 { "snRNA_gene", "gene" },
37 * transcript sub-types:
39 { "transcript", "transcript" },
40 { "mature_transcript", "transcript" },
41 { "ncRNA", "transcript" },
42 { "snRNA", "transcript" },
43 { "aberrant_processed_transcript", "transcript" },
46 * sequence_variant sub-types:
48 { "sequence_variant", "sequence_variant" },
49 { "feature_variant", "sequence_variant" },
50 { "gene_variant", "sequence_variant" },
51 // NB Ensembl uses NMD_transcript_variant as if a 'transcript'
52 // but we model it here correctly as per the SO
53 { "NMD_transcript_variant", "sequence_variant" },
54 { "transcript_variant", "sequence_variant" },
55 { "structural_variant", "sequence_variant" },
58 * no sub-types of exon or CDS yet encountered; add if needed
66 * hard-coded list of any parents (direct or indirect)
67 * that we care about for a term
69 private Map<String, List<String>> parents;
71 private List<String> termsFound;
73 private List<String> termsNotFound;
75 public SequenceOntologyLite()
77 termsFound = new ArrayList<String>();
78 termsNotFound = new ArrayList<String>();
83 * Loads hard-coded data into a lookup table of {term, {list_of_parents}}
85 private void loadStaticData()
87 parents = new HashMap<String, List<String>>();
88 for (String [] pair : TERMS) {
89 List<String> p = parents.get(pair[0]);
92 p = new ArrayList<String>();
93 parents.put(pair[0], p);
100 * Answers true if 'child' isA 'parent' (including equality). In this
101 * implementation, based only on hard-coded values.
104 public boolean isA(String child, String parent)
106 if (child == null || parent == null)
110 if (child.equals(parent))
116 List<String> p = parents.get(child);
123 if (p.contains(parent))
131 * Records a valid term queried for, for reporting purposes
135 private void termFound(String term)
137 if (!termsFound.contains(term))
139 synchronized (termsFound)
141 termsFound.add(term);
147 * Records an invalid term queried for, for reporting purposes
151 private void termNotFound(String term)
153 synchronized (termsNotFound)
155 if (!termsNotFound.contains(term))
157 System.out.println("SO term " + term
158 + " not known - either invalid or needs modelled in "
159 + getClass().getName());
160 termsNotFound.add(term);
166 * Sorts (case-insensitive) and returns the list of valid terms queried for
169 public List<String> termsFound()
171 synchronized (termsFound)
173 Collections.sort(termsFound, String.CASE_INSENSITIVE_ORDER);
179 * Sorts (case-insensitive) and returns the list of invalid terms queried for
182 public List<String> termsNotFound()
184 synchronized (termsNotFound)
186 Collections.sort(termsNotFound, String.CASE_INSENSITIVE_ORDER);
187 return termsNotFound;