How to use the goatools.godag.prttime.prt_hms function in goatools

To help you get started, we’ve selected a few goatools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tanghaibao / goatools / tests / test_get_lower_select.py View on Github external
rels_combo = run.get_relationship_combos()
    print('{N} COMBINATIONS OF RELATIONSHIPS'.format(N=len(rels_combo)))

    for relidx, rels_set in enumerate(rels_combo, 1):
        print('{I}) RELATIONSHIPS[{N}]: {Rs}'.format(
            I=relidx, N=len(rels_set), Rs=' '.join(sorted(rels_set))))
        # ------------------------------------------------------------------------
        # Get all parents for all GO IDs using get_all_parents in GOTerm class
        tic = timeit.default_timer()
        # pylint: disable=line-too-long
        go2lowerselect_orig = {o.item_id:get_all_lowerselect(o, rels_set) for o in run.go2obj.values()}
        tic = prt_hms(tic, "Get all goobj's parents using get_all_lowerselect(GOTerm)", prt)
        # ------------------------------------------------------------------------
        # Get all parents for all GO IDs using GOTerm get_all_parents
        go2lowerselect_fast = get_id2lowerselect(run.go2obj.values(), rels_set)
        tic = prt_hms(tic, "Get all goobj's parents using go_tasks::get_id2lowerselect", prt)
        # ------------------------------------------------------------------------
        # Compare parent lists
        chkr = CheckGOs('test_get_lower_select', godag)
        chkr.chk_a2bset(go2lowerselect_orig, go2lowerselect_fast)  # EXPECTED, ACTUAL
        print("PASSED: get_lowerselect RELATIONSHIPS[{N}]: {Rs}".format(
            N=len(rels_set), Rs=' '.join(sorted(rels_set))))
github tanghaibao / goatools / tests / test_get_parents.py View on Github external
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 parents for all GO IDs using get_all_parents in GOTerm class
    tic = timeit.default_timer()
    go2parents_orig = {}
    ## go_noparents = set()
    for goterm in go2obj.values():
        parents = goterm.get_all_parents()
        #if parents:
        go2parents_orig[goterm.id] = parents
        #else:
        #    go_noparents.add(goterm.id)
    tic = prt_hms(tic, "Get all goobj's parents using GOTerm.get_all_parents()", prt)
    # ------------------------------------------------------------------------
    # Get all parents for all GO IDs using GOTerm get_all_parents
    go2parents_fast = get_id2parents(go2obj.values())
    tic = prt_hms(tic, "Get all goobj's parents using go_tasks::get_id2parents", prt)
    # ------------------------------------------------------------------------
    go2parents_fast2 = get_id2parents2(go2obj.values())
    tic = prt_hms(tic, "Get all goobj's parents using go_tasks::get_id2parents2", prt)
    # ------------------------------------------------------------------------
    # Compare parent lists
    chkr = CheckGOs('test_get_parents', go2obj)
    chkr.chk_a2bset_equiv(go2parents_orig, go2parents_fast)
    chkr.chk_a2bset_equiv(go2parents_orig, go2parents_fast2)
    print("PASSED: get_parent test")
github tanghaibao / goatools / tests / test_update_association_compare.py View on Github external
def test_update_association():
    """Compare new propagate cnts function with original function. Test assc results is same."""

    print('\n1) READ GODAG:')
    assc_name = "goa_human.gaf" # gene_association.fb gene_association.mgi
    obo = os.path.join(REPO, "go-basic.obo")
    tic = timeit.default_timer()
    godag = get_godag(obo)
    tic = prt_hms(tic, "Created two GODags: One for original and one for new propagate counts")

    print('\n2) READ ANNOTATIONS:')
    assc_orig = dnld_assc(os.path.join(REPO, assc_name), godag)
    tic = prt_hms(tic, "Associations Read")
    objanno = get_objanno(os.path.join(REPO, assc_name), 'gaf', godag=godag)
    tic = prt_hms(tic, "Associations Read")

    print('\n3) MAKE COPIES OF ASSOCIATIONS:')
    assc1 = {g:set(gos) for g, gos in assc_orig.items()}
    assc2 = {g:set(gos) for g, gos in assc_orig.items()}
    tic = prt_hms(tic, "Associations Copied: One for original and one for new")

    print('\n4) UPDATE ASSOCIATIONS (PROPAGATE COUNTS):')
    godag.update_association(assc1)
    tic = prt_hms(tic, "ORIG: godag.update_association(assc)")
    update_association(assc2, godag)
github tanghaibao / goatools / tests / test_get_upper_select.py View on Github external
repo = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
    godag = get_godag(os.path.join(repo, 'go-basic.obo'), optional_attrs='relationship')
    run = RelationshipCombos(godag)
    run.chk_relationships_all()
    rels_combo = run.get_relationship_combos()
    print('{N} COMBINATIONS OF RELATIONSHIPS'.format(N=len(rels_combo)))

    for relidx, rels_set in enumerate(rels_combo, 1):
        print('{I}) RELATIONSHIPS[{N}]: {Rs}'.format(
            I=relidx, N=len(rels_set), Rs=' '.join(sorted(rels_set))))
        # ------------------------------------------------------------------------
        # Get all parents for all GO IDs using get_all_parents in GOTerm class
        tic = timeit.default_timer()
        # pylint: disable=line-too-long
        go2upperselect_orig = {o.item_id:get_all_upperselect(o, rels_set) for o in run.go2obj.values()}
        tic = prt_hms(tic, "Get all goobj's parents using get_all_upperselect(GOTerm)", prt)
        # ------------------------------------------------------------------------
        # Get all parents for all GO IDs using GOTerm get_all_parents
        go2upperselect_fast = get_id2upperselect(run.go2obj.values(), rels_set)
        tic = prt_hms(tic, "Get all goobj's parents using go_tasks::get_id2upperselect", prt)
        # ------------------------------------------------------------------------
        # Compare parent lists
        chkr = CheckGOs('test_get_upper_select', godag)
        chkr.chk_a2bset(go2upperselect_orig, go2upperselect_fast)  # EXPECTED, ACTUAL
        print("PASSED: get_upperselect RELATIONSHIPS[{N}]: {Rs}".format(
            N=len(rels_set), Rs=' '.join(sorted(rels_set))))
github tanghaibao / goatools / tests / test_i154_godagoptfld_consider.py View on Github external
def test_i154_semsim_lin():
    """Test for issue 148, Lin Similarity if a term has no annotations"""
    fin_dag = download_go_basic_obo()
    tic = timeit.default_timer()

    optional_attrs = {'consider', 'replaced_by'}
    load_obsolete = True
    prt = sys.stdout

    godag = GODag(fin_dag, optional_attrs, load_obsolete, prt)
    prt_hms(tic, 'Loaded GO DAG')
    assert godag['GO:0000067'].consider
    assert godag['GO:0003734'].replaced_by == 'GO:0030532'

    godag = GODag(fin_dag, 'consider', load_obsolete, prt)
    prt_hms(tic, 'Loaded GO DAG')
    assert godag['GO:0000067'].consider
github tanghaibao / goatools / tests / test_i154_godagoptfld_consider.py View on Github external
def test_i154_semsim_lin():
    """Test for issue 148, Lin Similarity if a term has no annotations"""
    fin_dag = download_go_basic_obo()
    tic = timeit.default_timer()

    optional_attrs = {'consider', 'replaced_by'}
    load_obsolete = True
    prt = sys.stdout

    godag = GODag(fin_dag, optional_attrs, load_obsolete, prt)
    prt_hms(tic, 'Loaded GO DAG')
    assert godag['GO:0000067'].consider
    assert godag['GO:0003734'].replaced_by == 'GO:0030532'

    godag = GODag(fin_dag, 'consider', load_obsolete, prt)
    prt_hms(tic, 'Loaded GO DAG')
    assert godag['GO:0000067'].consider
github tanghaibao / goatools / tests / test_update_association_compare.py View on Github external
print('\n2) READ ANNOTATIONS:')
    assc_orig = dnld_assc(os.path.join(REPO, assc_name), godag)
    tic = prt_hms(tic, "Associations Read")
    objanno = get_objanno(os.path.join(REPO, assc_name), 'gaf', godag=godag)
    tic = prt_hms(tic, "Associations Read")

    print('\n3) MAKE COPIES OF ASSOCIATIONS:')
    assc1 = {g:set(gos) for g, gos in assc_orig.items()}
    assc2 = {g:set(gos) for g, gos in assc_orig.items()}
    tic = prt_hms(tic, "Associations Copied: One for original and one for new")

    print('\n4) UPDATE ASSOCIATIONS (PROPAGATE COUNTS):')
    godag.update_association(assc1)
    tic = prt_hms(tic, "ORIG: godag.update_association(assc)")
    update_association(assc2, godag)
    tic = prt_hms(tic, "NEW SA:    update_association(go2obj, assc_orig)")
    assc3 = objanno.get_id2gos(namespace='BP', propagate_counts=True)
    tic = prt_hms(tic, "NEW BASE:  update_association(go2obj, assc_orig)")

    print('\n5) RUN CHECKS')
    _chk_assc(assc1, assc2)
    _chk_assc(assc1, assc3)
    _chk_godag(godag, obo)
github tanghaibao / goatools / tests / test_get_lower_select.py View on Github external
repo = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
    godag = get_godag(os.path.join(repo, 'go-basic.obo'), optional_attrs='relationship')
    run = RelationshipCombos(godag)
    run.chk_relationships_all()
    rels_combo = run.get_relationship_combos()
    print('{N} COMBINATIONS OF RELATIONSHIPS'.format(N=len(rels_combo)))

    for relidx, rels_set in enumerate(rels_combo, 1):
        print('{I}) RELATIONSHIPS[{N}]: {Rs}'.format(
            I=relidx, N=len(rels_set), Rs=' '.join(sorted(rels_set))))
        # ------------------------------------------------------------------------
        # Get all parents for all GO IDs using get_all_parents in GOTerm class
        tic = timeit.default_timer()
        # pylint: disable=line-too-long
        go2lowerselect_orig = {o.item_id:get_all_lowerselect(o, rels_set) for o in run.go2obj.values()}
        tic = prt_hms(tic, "Get all goobj's parents using get_all_lowerselect(GOTerm)", prt)
        # ------------------------------------------------------------------------
        # Get all parents for all GO IDs using GOTerm get_all_parents
        go2lowerselect_fast = get_id2lowerselect(run.go2obj.values(), rels_set)
        tic = prt_hms(tic, "Get all goobj's parents using go_tasks::get_id2lowerselect", prt)
        # ------------------------------------------------------------------------
        # Compare parent lists
        chkr = CheckGOs('test_get_lower_select', godag)
        chkr.chk_a2bset(go2lowerselect_orig, go2lowerselect_fast)  # EXPECTED, ACTUAL
        print("PASSED: get_lowerselect RELATIONSHIPS[{N}]: {Rs}".format(
            N=len(rels_set), Rs=' '.join(sorted(rels_set))))
github tanghaibao / goatools / tests / test_david_nts.py View on Github external
"""Read in a small obo, print list of GO terms and plot."""
    repo = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
    david_dir = "{REPO}/data/gjoneska_pfenning".format(REPO=repo)
    ntobj = cx.namedtuple("david6p8", "TOTAL FDR Bonferroni Benjamini PValue")
    # pylint: disable=bad-whitespace
    fin2exp = {
        "david_chart6p8_Consistent_Decrease.txt": ntobj._make([ 1773, 259, 249,  432, 1316]),
        "david_chart6p8_Transient_Decrease.txt":  ntobj._make([  423,   0,   2,    2,  246]),
        "david_chart6p8_Consistent_Increase.txt": ntobj._make([ 2359, 353, 308,  781, 1868]),
        "david_chart6p8_Transient_Increase.txt":  ntobj._make([ 2191, 658, 652, 1105, 1786]),
        "david_chart6p8_Late_Decrease.txt":       ntobj._make([ 2752, 591, 568, 1153, 2187]),
        "david_chart6p8_Late_Increase.txt":       ntobj._make([ 4597, 708, 616, 1715, 3603]),
    }
    tic = timeit.default_timer()
    fin2obj = {f:DavidChartReader(os.path.join(david_dir, f)) for f in fin2exp.keys()}
    prt_hms(tic, "Created DavidChartReader objects")
    for fin, obj in fin2obj.items():
        ntexp = fin2exp[fin]
        assert ntexp.TOTAL == len(obj.nts)
        obj.prt_num_sig()
        ctr = obj.get_num_sig()
        for fld, cnt_actual in ctr.most_common():
            assert cnt_actual == getattr(ntexp, fld), "{FIN}: {FLD} Act({ACT}) Exp({EXP})".format(
                FIN=fin, FLD=fld, ACT=cnt_actual, EXP=getattr(ntexp, fld))
github tanghaibao / goatools / tests / test_update_association_compare.py View on Github external
tic = prt_hms(tic, "Associations Read")
    objanno = get_objanno(os.path.join(REPO, assc_name), 'gaf', godag=godag)
    tic = prt_hms(tic, "Associations Read")

    print('\n3) MAKE COPIES OF ASSOCIATIONS:')
    assc1 = {g:set(gos) for g, gos in assc_orig.items()}
    assc2 = {g:set(gos) for g, gos in assc_orig.items()}
    tic = prt_hms(tic, "Associations Copied: One for original and one for new")

    print('\n4) UPDATE ASSOCIATIONS (PROPAGATE COUNTS):')
    godag.update_association(assc1)
    tic = prt_hms(tic, "ORIG: godag.update_association(assc)")
    update_association(assc2, godag)
    tic = prt_hms(tic, "NEW SA:    update_association(go2obj, assc_orig)")
    assc3 = objanno.get_id2gos(namespace='BP', propagate_counts=True)
    tic = prt_hms(tic, "NEW BASE:  update_association(go2obj, assc_orig)")

    print('\n5) RUN CHECKS')
    _chk_assc(assc1, assc2)
    _chk_assc(assc1, assc3)
    _chk_godag(godag, obo)