How to use the goatools.base.get_godag 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_wr_sections_txt.py View on Github external
def _get_godag():
    """Get GO DAG."""
    fin = os.path.join(REPO, 'go-basic.obo')
    return get_godag(fin, prt=None, loading_bar=False, optional_attrs=['relationship'])
github tanghaibao / goatools / tests / test_goea_errors.py View on Github external
def init_goea(**kws):
    """Initialize GODag and GOEnrichmentStudy."""
    godag = get_godag(os.path.join(os.getcwd(), "go-basic.obo"), loading_bar=None)
    fin_assc = ROOT + "association"
    assoc = read_associations(fin_assc, 'id2gos', no_top=True)
    popul_ids = [line.rstrip() for line in open(ROOT + "population")]
    methods = kws['methods'] if 'methods' in kws else ['not_bonferroni']
    study_ids = [line.rstrip() for line in open(ROOT + "study")]
    return GOEnrichmentStudy(popul_ids, assoc, godag, methods=methods), study_ids
github tanghaibao / goatools / tests / test_sorter_desc2nts.py View on Github external
def _get_sortobj():
    """Get object for grouping GO IDs."""
    fin_godag = os.path.join(REPO, "go-basic.obo")
    godag = get_godag(fin_godag, prt=None, loading_bar=False, optional_attrs=['relationship'])
    gosubdag = GoSubDag(USER_GOS, godag, relationships=True, tcntobj=None)
    grprdflt = GrouperDflts(gosubdag)
    hdrobj = HdrgosSections(gosubdag, grprdflt.hdrgos_dflt, SECTIONS)
    grprobj = Grouper("wrusrgos", USER_GOS, hdrobj, gosubdag)
    return Sorter(grprobj)
github tanghaibao / goatools / tests / test_plot_get_parents.py View on Github external
def test_go_parents():
    """Run GO parent tests"""
    gosubdag_all = GoSubDag(None, get_godag("go-basic.obo", prt=None), rcntobj=True)
    run_1(gosubdag_all)
    run_2(gosubdag_all)
github tanghaibao / goatools / tests / test_find_enrichment_script.py View on Github external
def test_find_enrichment():
    """RUn an enrichments using all annotation file formats"""

    godag = get_godag("go-basic.obo", optional_attrs=['relationship'])
    e_goids = _get_enriched_e_goids('GO:0006959', godag)  # GO IDs related to humoral response

    # pylint: disable=superfluous-parens
    print('- DOWNLOAD AND LOAD -----------------------------------------------')
    annoobjs = [
        _get_objanno('gene2go', taxid=10090),
        _get_objanno('gene2go', taxid=9606),
        _get_objanno('goa_human.gaf'),
        _get_objanno('goa_human.gpad', godag=godag),
        _get_objanno('data/association', anno_type='id2gos', godag=godag),
    ]

    pat = ('python3 scripts/find_enrichment.py {STU} {POP} {ASSC} '
           '--pval=0.05 --method=fdr_bh --pval_field=fdr_bh '
           '--taxid={TAXID} {INC} {EXC} --outfile=results_{NAME}.xlsx')
    cmds = []
github tanghaibao / goatools / tests / test_get_lower_select.py View on Github external
def test_get_lowerselect(prt=sys.stdout):
    """Test getting parents and user-specfied ancestor relationships"""
    # Load GO-DAG
    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
github tanghaibao / goatools / tests / test_get_parents.py View on Github external
def test_get_parent(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 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())
github tanghaibao / goatools / tests / test_semantic_similarity.py View on Github external
def test_semantic_similarity():
    """Computing basic semantic similarities between GO terms."""
    godag = get_godag(os.path.join(REPO, "go-basic.obo"), loading_bar=None)
    # Get all the annotations from arabidopsis.
    associations = dnld_assc(os.path.join(REPO, 'tair.gaf'), godag)


    # Now we can calculate the semantic distance and semantic similarity, as so:
    #       "The semantic similarity between terms GO:0048364 and GO:0044707 is 0.25.
    go_id3 = 'GO:0048364' # BP level-03 depth-04 root development
    go_id4 = 'GO:0044707' # BP level-02 depth-02 single-multicellular organism process
    sim = semantic_similarity(go_id3, go_id4, godag)
    print('\nThe semantic similarity between terms {GO1} and {GO2} is {VAL}.'.format(
        GO1=go_id3, GO2=go_id4, VAL=sim))
    print(godag[go_id3])
    print(godag[go_id4])

    # Then we can calculate the information content of the single term, <code>GO:0048364</code>.
    #       "Information content (GO:0048364) = 7.75481392334
github tanghaibao / goatools / goatools / grouper / grprdflts.py View on Github external
def get_gosubdag(gosubdag=None):
        """Gets a GoSubDag initialized for use by a Grouper object."""
        if gosubdag is not None:
            if gosubdag.rcntobj is not None:
                return gosubdag
            else:
                gosubdag.init_auxobjs()
                return gosubdag
        else:
            go2obj = get_godag()
            return GoSubDag(None, go2obj, rcntobj=True)