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" },
40 { "rRNA_gene", "gene" },
43 * transcript sub-types:
45 { "transcript", "transcript" },
46 { "mature_transcript", "transcript" },
47 { "processed_transcript", "transcript" },
48 { "aberrant_processed_transcript", "transcript" },
49 { "ncRNA", "transcript" },
50 { "snRNA", "transcript" },
51 { "miRNA", "transcript" },
52 { "lincRNA", "transcript" },
53 { "rRNA", "transcript" },
54 // there are many more sub-types of ncRNA...
57 * sequence_variant sub-types:
59 { "sequence_variant", "sequence_variant" },
60 { "feature_variant", "sequence_variant" },
61 { "gene_variant", "sequence_variant" },
62 // NB Ensembl uses NMD_transcript_variant as if a 'transcript'
63 // but we model it here correctly as per the SO
64 { "NMD_transcript_variant", "sequence_variant" },
65 { "transcript_variant", "sequence_variant" },
66 { "structural_variant", "sequence_variant" },
69 * no sub-types of exon or CDS yet seen in Ensembl
70 * some added here for testing purposes
73 { "coding_exon", "exon" },
75 { "CDS_predicted", "CDS" },
78 * terms used in exonerate or PASA GFF
80 { "protein_match", "protein_match"},
81 { "nucleotide_match", "nucleotide_match"},
82 { "cDNA_match", "nucleotide_match"},
85 * used in InterProScan GFF
87 { "polypeptide", "polypeptide" }
92 * hard-coded list of any parents (direct or indirect)
93 * that we care about for a term
95 private Map<String, List<String>> parents;
97 private List<String> termsFound;
99 private List<String> termsNotFound;
101 public SequenceOntologyLite()
103 termsFound = new ArrayList<String>();
104 termsNotFound = new ArrayList<String>();
109 * Loads hard-coded data into a lookup table of {term, {list_of_parents}}
111 private void loadStaticData()
113 parents = new HashMap<String, List<String>>();
114 for (String [] pair : TERMS) {
115 List<String> p = parents.get(pair[0]);
118 p = new ArrayList<String>();
119 parents.put(pair[0], p);
126 * Answers true if 'child' isA 'parent' (including equality). In this
127 * implementation, based only on hard-coded values.
130 public boolean isA(String child, String parent)
132 if (child == null || parent == null)
136 if (child.equals(parent))
142 List<String> p = parents.get(child);
149 if (p.contains(parent))
157 * Records a valid term queried for, for reporting purposes
161 private void termFound(String term)
163 if (!termsFound.contains(term))
165 synchronized (termsFound)
167 termsFound.add(term);
173 * Records an invalid term queried for, for reporting purposes
177 private void termNotFound(String term)
179 synchronized (termsNotFound)
181 if (!termsNotFound.contains(term))
183 System.out.println("SO term " + term
184 + " not known - may be invalid, or model if needed in "
185 + getClass().getName());
186 termsNotFound.add(term);
192 * Sorts (case-insensitive) and returns the list of valid terms queried for
195 public List<String> termsFound()
197 synchronized (termsFound)
199 Collections.sort(termsFound, String.CASE_INSENSITIVE_ORDER);
205 * Sorts (case-insensitive) and returns the list of invalid terms queried for
208 public List<String> termsNotFound()
210 synchronized (termsNotFound)
212 Collections.sort(termsNotFound, String.CASE_INSENSITIVE_ORDER);
213 return termsNotFound;