Commits

Aleš Erjavec  committed c0c6b64

Filter out terms from the annotations that are not present in the ontology.

If the annotations are newer then the ontology they can contain terms not yet
present in the ontology. This leads to an error when extracting the term's
parents.

  • Participants
  • Parent commits 9cb3894

Comments (0)

Files changed (1)

File _bioinformatics/obiGO.py

                           "Using 'goslim_generic' subset", UserWarning)
             self.ontology.SetSlimsSubset("goslim_generic")
 
-        terms = self.ontology.ExtractSuperGraph(annotationsDict.keys())
+        terms = annotationsDict.keys()
+        filteredTerms = [term for term in terms if term in self.ontology]
+
+        if len(terms) != len(filteredTerms):
+            termDiff = set(terms) - set(filteredTerms)
+            warnings.warn("%s terms in the annotations were not found in the "
+                          "ontology." % ",".join(map(repr, termDiff)),
+                          UserWarning)
+
+        terms = self.ontology.ExtractSuperGraph(filteredTerms)
         res = {}
 
         milestones = orngMisc.progressBarMilestones(len(terms), 100)
         for ann in annotations:
             dd[ann.GO_ID].add(revGenesDict.get(ann.geneName, ann.geneName))
         if not directAnnotationOnly:
-            terms = self.ontology.ExtractSuperGraph(dd.keys())
+            terms = dd.keys()
+            filteredTerms = [term for term in terms if term in self.ontology]
+            if len(terms) != len(filteredTerms):
+                termDiff = set(terms) - set(filteredTerms)
+                warnings.warn(
+                    "%s terms in the annotations were not found in the "
+                    "ontology." % ",".join(map(repr, termDiff)),
+                    UserWarning)
+
+            terms = self.ontology.ExtractSuperGraph(filteredTerms)
             for i, term in enumerate(terms):
                 termAnnots = self.GetAllAnnotations(term).intersection(annotations)
 ##                termAnnots.intersection_update(annotations)