package jalview.datamodel.ontology;
+import jalview.io.gff.SequenceOntologyFactory;
+import jalview.io.gff.SequenceOntologyI;
+
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
}
return children;
}
+
+ /**
+ * Answers a (possibly empty) map of any Ontology terms (from the given term
+ * and its parents) which subsume one or more of the target terms. The map key
+ * is an ontology term, and the entry is the list of target terms that are
+ * sub-terms of the key.
+ * <p>
+ * For example if {@code stop_gained} and {@code stop_lost} are known feature
+ * types, then SO term {@ nonsynonymous_variant} is the first common parent of
+ * both terms
+ *
+ * @param givenTerm
+ * the term to search from
+ * @param targetTerms
+ * candidate terms to 'capture' in ontology groupings
+ * @return
+ */
+ public Map<String, List<String>> findSequenceOntologyGroupings(
+ String givenTerm, List<String> targetTerms)
+ {
+ List<String> sortedTypes = new ArrayList<>(targetTerms);
+ Collections.sort(sortedTypes);
+
+ Map<String, List<String>> parents = new HashMap<>();
+
+ /*
+ * method:
+ * walk up featureType and all of its parents
+ * find other feature types which are subsumed by each term
+ * add each distinct aggregation of included feature types to the map
+ */
+ List<String> candidates = new ArrayList<>();
+ SequenceOntologyI so = SequenceOntologyFactory.getInstance();
+ candidates.add(givenTerm);
+ while (!candidates.isEmpty())
+ {
+ String term = candidates.remove(0);
+ List<String> includedFeatures = new ArrayList<>();
+ for (String type : sortedTypes)
+ {
+ if (!type.equals(givenTerm) && so.isA(type, term))
+ {
+ includedFeatures.add(type);
+ }
+ }
+ if (!includedFeatures.isEmpty()
+ && !parents.containsValue(includedFeatures))
+ {
+ parents.put(term, includedFeatures);
+ }
+ candidates.addAll(so.getParents(term));
+ }
+
+ return parents;
+ }
}
package jalview.datamodel.ontology;
import java.util.List;
+import java.util.Map;
import java.util.Set;
public interface OntologyI
*/
List<String> getRootParents(String term);
+ /**
+ * Answers a (possibly empty) map of any Ontology terms (from the given term
+ * and its parents) which subsume one or more of the target terms. The map key
+ * is an ontology term, and the entry is the list of target terms that are
+ * sub-terms of the key.
+ * <p>
+ * For example if {@code stop_gained} and {@code stop_lost} are known feature
+ * types, then SO term {@ nonsynonymous_variant} is the first common parent of
+ * both terms
+ *
+ * @param givenTerm
+ * the term to search from
+ * @param targetTerms
+ * candidate terms to 'capture' in ontology groupings
+ * @return
+ */
+ Map<String, List<String>> findSequenceOntologyGroupings(String givenTerm,
+ List<String> targetTerms);
}
\ No newline at end of file
this.featureType = theType;
ap = fr.ap;
- relatedSoTerms = findSequenceOntologyGroupings(this.featureType,
- fr.getRenderOrder());
+ SequenceOntologyI so = SequenceOntologyFactory.getInstance();
+ relatedSoTerms = so.findSequenceOntologyGroupings(
+ this.featureType, fr.getRenderOrder());
/*
* save original colours and filters for this feature type,
-package jalview.gui;
+package jalview.datamodel.ontology;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-public class FeatureTypeSettingsTest
+public class OntologyBaseTest
{
@BeforeClass(alwaysRun = true)
public void setUp()
SequenceOntologyFactory.setInstance(null);
}
- @Test(groups="Functional")
+ @Test(groups = "Functional")
public void testfindSequenceOntologyGroupings()
{
/*
* feature_variant further adds upstream_gene_variant
* sequence_variant further adds sequence_variant
*/
- Map<String, List<String>> map = FeatureTypeSettings
+ Map<String, List<String>> map = SequenceOntologyFactory.getInstance()
.findSequenceOntologyGroupings("stop_gained", featureTypes);
assertEquals(map.size(), 10);
+ "non_coding_transcript_exon_variant, sequence_variant, splice_region_variant, "
+ "stop_lost, synonymous_variant, upstream_gene_variant]");
}
+
}