def test_nb(): """Test notebook code""" godag = get_godag("go-basic.obo", optional_attrs={'relationship'}) go_leafs = set(o.item_id for o in godag.values() if not o.children) virion = 'GO:0019012' gosubdag_r0 = GoSubDag(go_leafs, godag) nt_virion = gosubdag_r0.go2nt[virion] print(nt_virion) print('r0 THE VALUE OF dcnt IS: {dcnt}'.format(dcnt=nt_virion.dcnt)) gosubdag_r1 = GoSubDag(go_leafs, godag, relationships=True) nt_virion = gosubdag_r1.go2nt[virion] print(nt_virion) print('r1 THE VALUE OF dcnt IS: {dcnt}'.format(dcnt=nt_virion.dcnt)) gosubdag_partof = GoSubDag(go_leafs, godag, relationships={'part_of'}) nt_virion = gosubdag_partof.go2nt[virion] print(nt_virion) print('THE VALUE OF dcnt IS: {dcnt}'.format(dcnt=nt_virion.dcnt)) virion_descendants = gosubdag_partof.rcntobj.go2descendants[virion] print('{N} descendants of virion were found'.format( N=len(virion_descendants))) # Limit plot of descendants to get a smaller plot virion_capsid_fiber = {'GO:0098033', 'GO:0098032'} gosubdag_partof.prt_goids(virion_capsid_fiber, '{NS} {GO} dcnt({dcnt}) D-{depth:02} {GO_name}') # Limit plot size by choosing just two virion descendants # Get a subset containing only a couple virion descendants and their ancestors pltdag = GoSubDag(virion_capsid_fiber, godag, relationships={'part_of'}) pltobj = GoSubDagPlot(pltdag) pltobj.plt_dag('virion_capsid_fiber.png')
def plt_goea_results(fout_img, goea_results, **kws): """Plot a single page.""" go_sources = [rec.GO for rec in goea_results] go2obj = {rec.GO: rec.goterm for rec in goea_results} gosubdag = GoSubDag(go_sources, go2obj, rcntobj=True) godagplot = GoSubDagPlot(gosubdag, goea_results=goea_results, **kws) godagplot.plt_dag(fout_img)
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 _plt_gosubdag(self, goids, go2color, **kws): """Plot GO IDs.""" fout_img = self.get_outfile(kws['outfile'], goids) objcolor = Go2Color(self.gosubdag, objgoea=None, go2color=go2color) objplt = GoSubDagPlot(self.gosubdag, Go2Color=objcolor, **kws) objplt.prt_goids(sys.stdout) objplt.plt_dag(fout_img) return fout_img
def plt_goids(gosubdag, fout_img, goids, **kws_plt): """Plot GO IDs in a DAG (Directed Acyclic Graph).""" gosubdag_plt = GoSubDag(goids, gosubdag.go2obj, rcntobj=gosubdag.rcntobj, **kws_plt) godagplot = GoSubDagPlot(gosubdag_plt, **kws_plt) godagplot.plt_dag(fout_img) return godagplot
def _plot_grouped_gos(self, fout_img, pltgosusr, kws_plt, kws_dag): gosubdag_plt = GoSubDag(pltgosusr, self.grprobj.gosubdag.get_go2obj(pltgosusr), self.grprobj.gosubdag.relationships, rcntobj=self.grprobj.gosubdag.rcntobj, go2nt=self.grprobj.gosubdag.go2nt, **kws_dag) godagplot = GoSubDagPlot(gosubdag_plt, **kws_plt) godagplot.plt_dag(fout_img)
def _plt_gosubdag(self, goids, go2color, **kws): """Plot GO IDs.""" print("PLOTTING KWS", kws) fout_img = self.get_outfile(kws['outfile'], goids, 'relationship' in kws) objcolor = Go2Color(self.gosubdag, objgoea=None, go2color=go2color) print("kws:") print(kws) objplt = GoSubDagPlot(self.gosubdag, Go2Color=objcolor, **kws) objplt.prt_goids(sys.stdout) objplt.plt_dag(fout_img) return fout_img
def plt_goids(self, fout_img, go_sources): """Plot GO IDs.""" # % src/bin/go_plot.py GOs --obo=../goatools/data/i86.obo --outfile=t00.jpg --mark_alt_id gosubdag = GoSubDag(go_sources, self.gosubdag_all.go2obj, prt=self.prt, # rcntobj=False, rcntobj=self.gosubdag_all.rcntobj, go2nt=self.gosubdag_all.go2nt) prtfmt = gosubdag.prt_attr['fmta'] goids_plt = GoSubDagPlot(gosubdag).get_goids_plt() self.prt.write("\n{N} GO IDs\n".format(N=len(goids_plt))) gosubdag.prt_goids(goids_plt, prtfmt=prtfmt, prt=self.prt) objplt = GoSubDagPlot(gosubdag, mark_alt_id=True) objplt.plt_dag(os.path.join(self.cwd, fout_img))
def _plt(self, goid, exp_goids, act_goids, diff_exp, diff_act): """Plot GO IDs, colored by differences in expected and actual""" fout_png = '{NAME}_{GO}.png'.format(NAME=self.name, GO=goid.replace(':', '')) go_sources = set.union(exp_goids, act_goids, {goid}) gosubdag = GoSubDag(go_sources, self.godag, relationships=True) go2color = {goid: '#c8ffb0'} # xkcd light light green for go_diff in diff_exp: go2color[go_diff] = '#cafffb' # xkcd light light blue for go_diff in diff_act: go2color[go_diff] = '#ffd1df' # xkcd light pink goploter = GoSubDagPlot(gosubdag, go2color=go2color) goploter.plt_dag(fout_png)
def plt_goids(self, fout_img, go_sources): """Plot GO IDs.""" # % src/bin/go_plot.py GOs --obo=../goatools/data/i86.obo --outfile=t00.jpg --mark_alt_id gosubdag = GoSubDag( go_sources, self.gosubdag_all.go2obj, prt=self.prt, # rcntobj=False, rcntobj=self.gosubdag_all.rcntobj, go2nt=self.gosubdag_all.go2nt) prtfmt = gosubdag.prt_attr['fmta'] goids_plt = GoSubDagPlot(gosubdag).get_goids_plt() self.prt.write("\n{N} GO IDs\n".format(N=len(goids_plt))) gosubdag.prt_goids(goids_plt, prtfmt=prtfmt, prt=self.prt) objplt = GoSubDagPlot(gosubdag, mark_alt_id=True) objplt.plt_dag(os.path.join(self.cwd, fout_img))
def plot_all(self, goids, name, prt=sys.stdout): """Create plots with various numbers of relationships.""" prt.write("\nCreate GoSubDag not loading any relationship") gosubdag_orig = GoSubDag(goids, self.go2obj, relationships=False, prt=prt) gosubdag_orig.prt_goids(gosubdag_orig.go2obj, prt=prt) prt.write("{N} GO IDS".format(N=len(gosubdag_orig.go2obj))) gopltdag = GoSubDagPlot(gosubdag_orig, mark_alt_id=True) gopltdag.plt_dag(os.path.join(REPO, "a_relationship_{NAME}_r0.png".format(NAME=name))) # goids.update(['GO:0007507'], ['GO:0072359']) prt.write("\nCreate GoSubDag while loading only the 'part_of' relationship") gosubdag = GoSubDag(goids, self.go2obj, relationships=['part_of'], prt=prt) gosubdag.prt_goids(gosubdag.go2obj, prt=prt) prt.write("{N} GO IDS".format(N=len(gosubdag.go2obj))) gopltdag = GoSubDagPlot(gosubdag, mark_alt_id=True) prt.write("GO SOURCES:") gosubdag.prt_goids(gosubdag.go_sources, prt=prt) gopltdag.plt_dag(os.path.join(REPO, "a_relationship_{NAME}_partof.png".format(NAME=name))) prt.write("\nCreate GoSubDag while loading all relationships") gosubdag = GoSubDag(goids, self.go2obj, relationships=True, prt=prt) prt.write("ALL {N} GO IDS:".format(N=len(gosubdag.go2obj))) gosubdag.prt_goids(gosubdag.go2obj, prt=prt) prt.write("2 GO SOURCES:") gosubdag.prt_goids(gosubdag.go_sources, prt=prt) goids_new = set(gosubdag.go2obj).difference(set(gosubdag_orig.go2obj)) go2color = {go:'#d5ffff' for go in goids_new} prt.write("{N} NEW GO IDS:".format(N=len(goids_new))) gosubdag.prt_goids(goids_new, prt=prt) prt.write("{N} GO IDS".format(N=len(gosubdag.go2obj))) gopltdag = GoSubDagPlot(gosubdag, mark_alt_id=True, go2color=go2color) gopltdag.plt_dag(os.path.join(REPO, "a_relationship_{NAME}_r1.png".format(NAME=name)))
def plot_all(self, goids, name, prt=sys.stdout): """Create plots with various numbers of relationships.""" prt.write("\nCreate GoSubDag not loading any relationship") gosubdag_orig = GoSubDag(goids, self.go2obj, relationships=False, prt=prt) gosubdag_orig.prt_goids(gosubdag_orig.go2obj, prt=prt) prt.write("{N} GO IDS".format(N=len(gosubdag_orig.go2obj))) gopltdag = GoSubDagPlot(gosubdag_orig, mark_alt_id=True) gopltdag.plt_dag( os.path.join(REPO, "a_relationship_{NAME}_r0.png".format(NAME=name))) # goids.update(['GO:0007507'], ['GO:0072359']) prt.write( "\nCreate GoSubDag while loading only the 'part_of' relationship") gosubdag = GoSubDag(goids, self.go2obj, relationships=['part_of'], prt=prt) gosubdag.prt_goids(gosubdag.go2obj, prt=prt) prt.write("{N} GO IDS".format(N=len(gosubdag.go2obj))) gopltdag = GoSubDagPlot(gosubdag, mark_alt_id=True) prt.write("GO SOURCES:") gosubdag.prt_goids(gosubdag.go_sources, prt=prt) gopltdag.plt_dag( os.path.join(REPO, "a_relationship_{NAME}_partof.png".format(NAME=name))) prt.write("\nCreate GoSubDag while loading all relationships") gosubdag = GoSubDag(goids, self.go2obj, relationships=True, prt=prt) prt.write("ALL {N} GO IDS:".format(N=len(gosubdag.go2obj))) gosubdag.prt_goids(gosubdag.go2obj, prt=prt) prt.write("2 GO SOURCES:") gosubdag.prt_goids(gosubdag.go_sources, prt=prt) goids_new = set(gosubdag.go2obj).difference(set(gosubdag_orig.go2obj)) go2color = {go: '#d5ffff' for go in goids_new} prt.write("{N} NEW GO IDS:".format(N=len(goids_new))) gosubdag.prt_goids(goids_new, prt=prt) prt.write("{N} GO IDS".format(N=len(gosubdag.go2obj))) gopltdag = GoSubDagPlot(gosubdag, mark_alt_id=True, go2color=go2color) gopltdag.plt_dag( os.path.join(REPO, "a_relationship_{NAME}_r1.png".format(NAME=name)))
def plot_gos(fout_img, goids, go2obj, **kws): """Given GO ids and the obo_dag, create a plot of paths from GO ids.""" gosubdag = GoSubDag(goids, go2obj, rcntobj=True) godagplot = GoSubDagPlot(gosubdag, **kws) godagplot.plt_dag(fout_img)
def plt_goids(self, fout_img, go_sources): """Plot GO IDs.""" # % src/bin/go_plot.py GOs --obo=../goatools/data/i86.obo --outfile=t00.jpg --mark_alt_id gosubdag = GoSubDag(go_sources, self.go2obj_all) objplt = GoSubDagPlot(gosubdag, mark_alt_id=True) objplt.plt_dag(os.path.join(self.cwd, fout_img))
def plt_goids(self, fout_img, go_sources): """Plot GO IDs.""" # % src/bin/go_plot.py GOs --obo=../goatools/data/i86.obo --outfile=t00.jpg --mark_alt_id gosubdag = GoSubDag(go_sources, self.go2obj_all) objplt = GoSubDagPlot(gosubdag, mark_alt_id=True) objplt.plt_dag(os.path.join(self.cwd, fout_img))