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
25 * NB unlike the full SequenceOntology we don't traverse indirect
26 * child-parent relationships here so e.g. need to list every sub-type
27 * of gene (direct or indirect) that is of interest
30 private final String[][] TERMS = new String[][] {
36 { "ncRNA_gene", "gene" },
37 { "snRNA_gene", "gene" },
38 { "miRNA_gene", "gene" },
39 { "lincRNA_gene", "gene" },
42 * transcript sub-types:
44 { "transcript", "transcript" },
45 { "mature_transcript", "transcript" },
46 { "processed_transcript", "transcript" },
47 { "aberrant_processed_transcript", "transcript" },
48 { "ncRNA", "transcript" },
49 { "snRNA", "transcript" },
50 { "miRNA", "transcript" },
51 { "lincRNA", "transcript" },
52 // there are many more sub-types of ncRNA...
55 * sequence_variant sub-types:
57 { "sequence_variant", "sequence_variant" },
58 { "feature_variant", "sequence_variant" },
59 { "gene_variant", "sequence_variant" },
60 // NB Ensembl uses NMD_transcript_variant as if a 'transcript'
61 // but we model it here correctly as per the SO
62 { "NMD_transcript_variant", "sequence_variant" },
63 { "transcript_variant", "sequence_variant" },
64 { "structural_variant", "sequence_variant" },
67 * no sub-types of exon or CDS yet seen in Ensembl
68 * some added here for testing purposes
71 { "coding_exon", "exon" },
73 { "CDS_predicted", "CDS" },
76 * terms used in exonerate or PASA GFF
78 { "protein_match", "protein_match"},
79 { "nucleotide_match", "nucleotide_match"},
80 { "cDNA_match", "nucleotide_match"},
83 * used in InterProScan GFF
85 { "polypeptide", "polypeptide" }
90 * hard-coded list of any parents (direct or indirect)
91 * that we care about for a term
93 private Map<String, List<String>> parents;
95 private List<String> termsFound;
97 private List<String> termsNotFound;
99 public SequenceOntologyLite()
101 termsFound = new ArrayList<String>();
102 termsNotFound = new ArrayList<String>();
107 * Loads hard-coded data into a lookup table of {term, {list_of_parents}}
109 private void loadStaticData()
111 parents = new HashMap<String, List<String>>();
112 for (String [] pair : TERMS) {
113 List<String> p = parents.get(pair[0]);
116 p = new ArrayList<String>();
117 parents.put(pair[0], p);
124 * Answers true if 'child' isA 'parent' (including equality). In this
125 * implementation, based only on hard-coded values.
128 public boolean isA(String child, String parent)
130 if (child == null || parent == null)
134 if (child.equals(parent))
140 List<String> p = parents.get(child);
147 if (p.contains(parent))
155 * Records a valid term queried for, for reporting purposes
159 private void termFound(String term)
161 if (!termsFound.contains(term))
163 synchronized (termsFound)
165 termsFound.add(term);
171 * Records an invalid term queried for, for reporting purposes
175 private void termNotFound(String term)
177 synchronized (termsNotFound)
179 if (!termsNotFound.contains(term))
181 System.out.println("SO term " + term
182 + " not known - may be invalid, or model if needed in "
183 + getClass().getName());
184 termsNotFound.add(term);
190 * Sorts (case-insensitive) and returns the list of valid terms queried for
193 public List<String> termsFound()
195 synchronized (termsFound)
197 Collections.sort(termsFound, String.CASE_INSENSITIVE_ORDER);
203 * Sorts (case-insensitive) and returns the list of invalid terms queried for
206 public List<String> termsNotFound()
208 synchronized (termsNotFound)
210 Collections.sort(termsNotFound, String.CASE_INSENSITIVE_ORDER);
211 return termsNotFound;