Changeset 1770:48af55b8e628 in orange-bioinformatics


Ignore:
Timestamp:
04/30/13 15:30:04 (12 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

'Ontology.getitem' now raises a KeyError for an unknown term id.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • _bioinformatics/obiGO.py

    r1769 r1770  
    444444 
    445445    def __getitem__(self, id): 
    446         """ Return object with id (same as ontology.terms[id] 
    447         """ 
    448         return self.terms.get(id, self.terms.get(self.aliasMapper.get(id, id))) 
     446        """ 
     447        Return a object with id. 
     448        """ 
     449        if id in self.terms: 
     450            return self.terms[id] 
     451        elif id in self.aliasMapper: 
     452            return self.terms[self.aliasMapper[id]] 
     453        else: 
     454            raise KeyError(id) 
    449455 
    450456    def __iter__(self): 
    451         """ Iterate over all ids in ontology 
     457        """ 
     458        Iterate over all ids in ontology. 
    452459        """ 
    453460        return iter(self.terms) 
    454461 
    455462    def __len__(self): 
    456         """ Return number of objects in ontology 
     463        """ 
     464        Return number of objects in ontology. 
    457465        """ 
    458466        return len(self.terms) 
    459467 
    460468    def __contains__(self, id): 
     469        """ 
     470        Return `True` if a term with `id` is present in the ontology. 
     471        """ 
    461472        return id in self.terms or id in self.aliasMapper 
    462473 
Note: See TracChangeset for help on using the changeset viewer.