How to use the goatools.grouper.hdrgos.HdrgosSections 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_grprobj.py View on Github external
def test_grouper_d2(do_plot=False):
    """Group depth-02 GO terms under their most specific depth-01 GO parent(s)."""
    print('CWD', os.getcwd())
    # Get GOs to be grouped
    # Since no "Grouping GOs" were provided, depth-01 GOs are used for grouping.
    grprdflt = _get_grprdflt()
    hdrobj = HdrgosSections(grprdflt.gosubdag, grprdflt.hdrgos_dflt, sections=None, hdrgos=None)
    grprobj = Grouper("Transient Increase", get_data0(), hdrobj, _get_gosubdag(), go2nt=None)
    objwr = WrSectionsTxt(grprobj)
    objwr.wr_txt_section_hdrgos("transient_increase_hdrgos.txt")
    objwr.wr_txt_grouping_gos()
    if do_plot:
        # Don't run in Travis-CI because it does not contain 'dot'
        from goatools.grouper.grprplt import GrouperPlot
        GrouperPlot(grprobj).plot_groups_unplaced()
    chk_hdrs(grprobj)
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_sorter.py View on Github external
# Since no "GO group headers" (None) were provided, depth-01 GOs are used for grouping.
    hdrobj0 = HdrgosSections(grprdflt.gosubdag, grprdflt.hdrgos_dflt, sections=None, hdrgos=None)
    grprobj0 = Grouper("dflt", data, hdrobj0, grprdflt.gosubdag, go2nt=None)
    _, _, nts0_go, act_hdrs0 = run(grprobj0, hdrobj0, exp_hdrs0)

    # Grouping GOs are provided, these are added to the depth-01 defaults GOs are used for grouping.
    hdrgos = set([
        "GO:0099536", # BP     40 L04 D05 CDR   regulation of response to stimulus
        "GO:0051239", # BP  2,532 L02 D02 AB    regulation of multicellular organismal process
        "GO:0048519", # BP  3,293 L02 D02 AB    negative regulation of biological process
        "GO:0048518"])# BP  3,353 L02 D02 AB    positive regulation of biological process

    exp_hdrs1 = exp_hdrs0.union(hdrgos)
    name = "usrhdrs4"
    hdrobj1 = HdrgosSections(grprdflt.gosubdag, grprdflt.hdrgos_dflt, sections=None, hdrgos=hdrgos)
    grprobj1 = Grouper(name, data, hdrobj1, grprdflt.gosubdag, go2nt=None)
    sortobj1, _, nts1_go, act_hdrs1 = run(grprobj1, hdrobj1, exp_hdrs1)

    if do_plt:
        from goatools.grouper.grprplt import GrouperPlot
        prt.write("\nPLOT DAG\n")
        GrouperPlot(grprobj1).plot_grouped_gos()

    # GO:0099536 was a "middle" term (neither usrgo, not hdrgo) in run0, but is a hdrgo in run1

    # print "THIS"
    # grprdflt.gosubdag.prt_goids(nts1_go)
    # print "MINUS"
    # grprdflt.gosubdag.prt_goids(nts0_go)
    # print "EQUALS"
    # print nts1_go.difference(nts0_go)
github tanghaibao / goatools / tests / test_grpr_get_sections_2d.py View on Github external
def test_fnc():
    """Test function, get_sections_2d, in the Grouper class."""
    usrgo2nt = {getattr(nt, 'GO'):nt for nt in goea_results if getattr(nt, 'p_fdr_bh') < 0.05}
    usrgos = usrgo2nt.keys()
    grprdflt = _get_grprdflt()
    hdrobj = HdrgosSections(grprdflt.gosubdag, grprdflt.hdrgos_dflt, sections=SECTIONS, hdrgos=None)
    grprobj = Grouper("test", usrgos, hdrobj, grprdflt.gosubdag, go2nt=usrgo2nt)
    assert set(usrgos) == grprobj.usrgos
    sections_act = grprobj.get_sections_2d()
    chk_results(sections_act, grprobj)
github tanghaibao / goatools / tests / test_sorter.py View on Github external
"GO:0044848",  # BP     62 L01 D01 S     biological phase
        "GO:0050794",  # BP  8,031 L02 D02 AB    regulation of cellular process
        "GO:0019222",  # BP  3,227 L02 D02 AB    regulation of metabolic process
        "GO:0048583",  # BP  2,377 L02 D02 AB    regulation of response to stimulus
        "GO:0050793",  # BP  1,789 L02 D02 AB    regulation of developmental process
        "GO:0023051",  # BP  1,364 L02 D02 AB    regulation of signaling
        "GO:0002682",  # BP  1,183 L02 D02 AB    regulation of immune system process
        "GO:0007155",  # BP    165 L02 D02 P     cell adhesion
        "GO:0080134",  # BP    940 L03 D03 AB    regulation of response to stress
        "GO:0007165",  # BP    717 L03 D03 AB    signal transduction
        "GO:0050877",  # BP     96 L03 D03 K     neurological system process
        "GO:0007267"]) # BP     99 L03 D04 CDR   cell-cell signaling


    # Since no "GO group headers" (None) were provided, depth-01 GOs are used for grouping.
    hdrobj0 = HdrgosSections(grprdflt.gosubdag, grprdflt.hdrgos_dflt, sections=None, hdrgos=None)
    grprobj0 = Grouper("dflt", data, hdrobj0, grprdflt.gosubdag, go2nt=None)
    _, _, nts0_go, act_hdrs0 = run(grprobj0, hdrobj0, exp_hdrs0)

    # Grouping GOs are provided, these are added to the depth-01 defaults GOs are used for grouping.
    hdrgos = set([
        "GO:0099536", # BP     40 L04 D05 CDR   regulation of response to stimulus
        "GO:0051239", # BP  2,532 L02 D02 AB    regulation of multicellular organismal process
        "GO:0048519", # BP  3,293 L02 D02 AB    negative regulation of biological process
        "GO:0048518"])# BP  3,353 L02 D02 AB    positive regulation of biological process

    exp_hdrs1 = exp_hdrs0.union(hdrgos)
    name = "usrhdrs4"
    hdrobj1 = HdrgosSections(grprdflt.gosubdag, grprdflt.hdrgos_dflt, sections=None, hdrgos=hdrgos)
    grprobj1 = Grouper(name, data, hdrobj1, grprdflt.gosubdag, go2nt=None)
    sortobj1, _, nts1_go, act_hdrs1 = run(grprobj1, hdrobj1, exp_hdrs1)
github tanghaibao / goatools / goatools / cli / gosubdag_plot.py View on Github external
def _get_grprobj(self, goids, sections):
        """Get Grouper, given GO IDs and sections."""
        grprdflt = GrouperDflts(self.gosubdag, "goslim_generic.obo")
        hdrobj = HdrgosSections(self.gosubdag, grprdflt.hdrgos_dflt, sections)
        return Grouper("sections", goids, hdrobj, self.gosubdag)
github tanghaibao / goatools / goatools / cli / wr_sections.py View on Github external
def cli(self, prt=sys.stdout):
        """Command-line interface for go_draw script."""
        kws = self.objdoc.get_docargs(prt=None)
        godag = get_godag(kws['obo'], prt=None, loading_bar=False, optional_attrs=['relationship'])
        usrgos = GetGOs(godag, max_gos=200).get_usrgos(kws.get('GO_FILE'), prt)
        tcntobj = self._get_tcntobj(usrgos, godag, **kws)  # Gets TermCounts or None
        self.gosubdag = GoSubDag(usrgos, godag, relationships=True, tcntobj=tcntobj, prt=None)
        grprdflt = GrouperDflts(self.gosubdag, kws['slims'])
        ver_list = [godag.version, grprdflt.ver_goslims]
        prt.write("{VER}\n".format(VER="\n".join(ver_list)))
        sections = self._read_sections(kws['ifile'])
        # print("SECSECSEC", sections)
        hdrobj = HdrgosSections(self.gosubdag, grprdflt.hdrgos_dflt, sections)
        grprobj = Grouper("init", usrgos, hdrobj, self.gosubdag)
        # Write sections
        objsecwr = WrSectionsTxt(grprobj, ver_list)
        if not os.path.exists(kws['ifile']):
            objsecwr.wr_txt_section_hdrgos(kws['ifile'])
        objsecwr.wr_txt_section_hdrgos(kws['ofile'])
        objsecpy = WrSectionsPy(grprobj, ver_list)
        if 'py' in kws:
            objsecpy.wr_py_sections(kws['py'], sections, doc=godag.version)
        # Write user GO IDs in sections
        sortobj = Sorter(grprobj)
        objgowr = WrXlsxSortedGos("init", sortobj, ver_list)
        objgowr.wr_txt_gos(kws['txt'], sortby=objsecpy.fncsortnt)
        #objwr.wr_txt_section_hdrgos(kws['ofile'], sortby=objwr.fncsortnt)
        self._prt_cnt_usrgos(usrgos, sys.stdout)
github tanghaibao / goatools / goatools / cli / find_enrichment.py View on Github external
def __init__(self, objcli, godag_version):
        # _goids = set(o.id for o in godag.values() if not o.children)
        _goids = set(r.GO for r in objcli.results_all)
        _tobj = TermCounts(objcli.godag, objcli.objgoeans.get_assoc())
        # pylint: disable=line-too-long
        self.gosubdag = GoSubDag(_goids, objcli.godag, relationships=True, tcntobj=_tobj, prt=sys.stdout)
        self.grprdflt = GrouperDflts(self.gosubdag, objcli.args.goslim)
        self.hdrobj = HdrgosSections(self.grprdflt.gosubdag, self.grprdflt.hdrgos_dflt, objcli.sections)
        self.pval_fld = objcli.get_pval_field()  # primary pvalue of interest
        self.ver_list = [godag_version,
                         self.grprdflt.ver_goslims,
                         "Sections: {S}".format(S=objcli.args.sections)]
        # self.objaartall = self._init_objaartall()