Esempio n. 1
0
def test_get_children(prt=sys.stdout):
    """Semantic Similarity test for Issue #86."""
    # Load GO-DAG
    fin_obo = "go-basic.obo"
    repo = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
    godag = get_godag(os.path.join(repo, fin_obo))
    go2obj = {go: o for go, o in godag.items() if go == o.id}
    # Get all children for all GO IDs using get_all_children in GOTerm class
    tic = timeit.default_timer()
    go2children_orig = {}
    go2children_empty = set()
    for goobj in go2obj.values():
        children = goobj.get_all_children()
        if children:
            go2children_orig[goobj.id] = children
        else:
            go2children_empty.add(goobj.id)
    tic = prt_hms(tic,
                  "Get all goobj's children using GOTerm.get_all_children()",
                  prt)
    # Get all children for all GO IDs using GOTerm get_all_children
    go2children_fast = get_id2children(go2obj.values())
    prt_hms(tic, "Get all goobj's children using go_tasks::get_id2children",
            prt)
    # Compare children lists
    CheckGOs('test_get_children', go2obj).chk_a2bset(go2children_orig,
                                                     go2children_fast)
Esempio n. 2
0
 def _init_dcnt(self):
     """Initialize descendant count."""
     id2descendants = get_id2children(self.name2obj.values())
     for id_, descendants in id2descendants.items():
         obj = self.name2obj[id_]
         obj.descendants = descendants
         obj.dcnt = len(descendants)
Esempio n. 3
0
 def __init__(self, go2obj, relationships, dcnt, go2letter):
     # Subset go2obj contains only items needed by go_sources
     self.go2obj = go2obj
     self.relationships = relationships
     self.dcnt = dcnt
     self.go2letter = go2letter
     # Ex: set(['part_of', 'regulates', 'negatively_regulates', 'positively_regulates'])
     _goobjs, _altgo2goobj = get_goobjs_altgo2goobj(self.go2obj)
     _r0 = not relationships  # True if not using relationships
     self.go2descendants = get_id2children(
         _goobjs) if _r0 else get_id2lower(_goobjs)
     self.go2parents = get_id2parents(_goobjs) if _r0 else get_id2upper(
         _goobjs)
     self.go2dcnt = {go: len(p) for go, p in self.go2descendants.items()}
     add_alt_goids(self.go2parents, _altgo2goobj)
     add_alt_goids(self.go2descendants, _altgo2goobj)
     add_alt_goids(self.go2dcnt, _altgo2goobj)
Esempio n. 4
0
def test_get_children(prt=sys.stdout):
    """Semantic Similarity test for Issue #86."""
    # Load GO-DAG
    fin_obo = "go-basic.obo"
    repo = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
    godag = get_godag(os.path.join(repo, fin_obo))
    go2obj = {go:o for go, o in godag.items() if go == o.id}
    # Get all children for all GO IDs using get_all_children in GOTerm class
    tic = timeit.default_timer()
    go2children_orig = {}
    for goobj in go2obj.values():
        go2children_orig[goobj.id] = goobj.get_all_children()
    tic = prt_hms(tic, "Get all goobj's children using GOTerm.get_all_children()", prt)
    # Get all children for all GO IDs using GOTerm get_all_children
    go2children_fast = get_id2children(go2obj.values())
    prt_hms(tic, "Get all goobj's children using go_tasks::get_go3children", prt)
    # Compare children lists
    _chk_a2bset(go2children_orig, go2children_fast)
Esempio n. 5
0
def get_go2children_go2obj(go2obj):
    """Return go2children (set of child GO IDs) for all GO ID keys in go2obj."""
    goobjs, altgo2goobj = get_goobjs_altgo2goobj(go2obj)
    go2children = get_id2children(goobjs)
    add_alt_goids(go2children, altgo2goobj)
    return go2children
Esempio n. 6
0
def get_go2children_go2obj(go2obj):
    """Return go2children (set of child GO IDs) for all GO ID keys in go2obj."""
    goobjs, altgo2goobj = get_goobjs_altgo2goobj(go2obj)
    go2children = get_id2children(goobjs)
    add_alt_goids(go2children, altgo2goobj)
    return go2children