def _plt_gogrouped(self, goids, go2color_usr, **kws): """Plot grouped GO IDs.""" fout_img = self.get_outfile(kws['outfile'], goids) sections = read_sections(kws['sections'], exclude_ungrouped=True) print("KWWSSSSSSSS", kws) # kws_plt = {k:v for k, v in kws.items if k in self.kws_plt} grprobj_cur = self._get_grprobj(goids, sections) # GO: purple=hdr-only, green=hdr&usr, yellow=usr-only # BORDER: Black=hdr Blu=hdr&usr grpcolor = GrouperColors( grprobj_cur) # get_bordercolor get_go2color_users grp_go2color = grpcolor.get_go2color_users() grp_go2bordercolor = grpcolor.get_bordercolor() for goid, color in go2color_usr.items(): grp_go2color[goid] = color objcolor = Go2Color(self.gosubdag, objgoea=None, go2color=grp_go2color, go2bordercolor=grp_go2bordercolor) go2txt = GrouperPlot.get_go2txt(grprobj_cur, grp_go2color, grp_go2bordercolor) objplt = GoSubDagPlot(self.gosubdag, Go2Color=objcolor, go2txt=go2txt, **kws) objplt.prt_goids(sys.stdout) objplt.plt_dag(fout_img) sys.stdout.write("{N:>6} sections read\n".format( N="NO" if sections is None else len(sections))) return fout_img
def _get_objpltg(self, goids, go2color_usr, **kws): """Plot grouped GO IDs.""" #### fout_img = self.get_outfile(kws['outfile'], goids) sections = read_sections(kws['sections'], exclude_ungrouped=True) # print ("KWWSSSSSSSS", kws) # kws_plt = {k:v for k, v in kws.items if k in self.kws_plt} grprobj_cur = self._get_grprobj(goids, sections) # GO: purple=hdr-only, green=hdr&usr, yellow=usr-only # BORDER: Black=hdr Blu=hdr&usr grpcolor = GrouperColors( grprobj_cur) # get_bordercolor get_go2color_users grp_go2color = grpcolor.get_go2color_users() grp_go2bordercolor = grpcolor.get_bordercolor() for goid, color in go2color_usr.items(): grp_go2color[goid] = color objcolor = Go2Color(self.gosubdag, objgoea=None, go2color=grp_go2color, go2bordercolor=grp_go2bordercolor) go2txt = GrouperPlot.get_go2txt(grprobj_cur, grp_go2color, grp_go2bordercolor) return GoSubDagPlot(self.gosubdag, Go2Color=objcolor, go2txt=go2txt, **kws)
def test_grouper_d2(do_plot=False): """Group depth-02 GO terms under their most specific depth-01 GO parent(s).""" # Get GOs to be grouped # Since no "Grouping GOs" were provided, depth-01 GOs are used for grouping. grprdflt = GrouperDflts() hdrobj = HdrgosSections(grprdflt.gosubdag, grprdflt.hdrgos_dflt, sections=None, hdrgos=None) grprobj = Grouper("Transient Increase", get_data0(), hdrobj, grprdflt.gosubdag, go2nt=None) objwr = WrSections(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)
def test_dflthdrs(prt=sys.stdout, do_plt=False): """Group depth-02 GO terms under their most specific depth-01 GO parent(s).""" # Initialize GoSubDag for grouping use once, since it takes a few seconds to initialize grprdflt = _get_grprdflt() # Get GOs to be grouped data = get_data0() # This may need to be updated if default hdrgos are changed exp_hdrs0 = set([ "GO:0050789", # BP 11,095 L01 D01 B regulation of biological process "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) 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) assert nts1_go.difference(nts0_go) == set(["GO:0099536"]) assert act_hdrs1.difference(act_hdrs0) == set(hdrgos) hdrgo_prt = False sys.stdout.write("\n{NAME}: PRINT GOs hdrgo_prt({H}):\n".format( H=hdrgo_prt, NAME=name)) sortobj1.prt_gos(hdrgo_prt=hdrgo_prt) nts2 = sortobj1.get_nts_flat(hdrgo_prt) nts2_go = set([nt.GO for nt in nts2]) assert len(nts1_go) > len(nts2_go) assert nts1_go.intersection(data) == nts2_go assert nts2_go == data