def GOs_to_nx(goea_results, sig=0.05): sig_go = [go for go in goea_results if go.p_fdr_bh <= sig] godagsmall = OboToGoDagSmall( goea_results=sig_go).godag try: import networkx as nx except ImportError as e: print('NetworkX not installed') node_info = [(go.GO, {"depth": go.depth, "enrichment": go.enrichment, "name": go.name, "p_uncorrected": go.p_uncorrected, "p_fdr_bh": go.p_fdr_bh, "pop_count": go.pop_count, "pop_items": go.pop_items, "pop_n": go.pop_n, "ratio_in_pop": go.ratio_in_pop, "ratio_in_study": go.ratio_in_study, "study_count": go.study_count, "study_items": go.study_items, "study_n": go.study_n}) for go in sig_go] conns = godagsmall.p_from_cs edges = [] for k, v in dict(conns).items(): if 'GO' in str(k): vals = list(v) for g in vals: edges.append((k, g)) G = nx.Graph() G.add_nodes_from(node_info) G.add_edges_from(edges) return G
def plot_gos(fout_png, goids, obo_dag, *args, **kws): """Given GO ids and the obo_dag, create a plot of paths from GO ids.""" engine = kws['engine'] if 'engine' in kws else 'pydot' godagsmall = OboToGoDagSmall(goids=goids, obodag=obo_dag).godag # godagplot = GODagSmallPlot(godagsmall, *args, **kws) godagplot = GODagSmallPlot(godagsmall, obo=obo_dag, *args, **kws) # add by gdq godagplot.plt(fout_png, engine)
def plt_goea_results(fout_png, goea_results, *args, **kws): """Plot a single page.""" engine = kws['engine'] if 'engine' in kws else 'pydot' godagsmall = OboToGoDagSmall(goea_results=goea_results).godag godagplot = GODagSmallPlot(godagsmall, *args, goea_results=goea_results, **kws) godagplot.plt(fout_png, engine)
def plot_goid2goobj(fout_png, goid2goobj, *args, **kws): """Given a dict containing GO id and its goobj, create a plot of paths from GO ids.""" engine = kws['engine'] if 'engine' in kws else 'pydot' godagsmall = OboToGoDagSmall(goid2goobj=goid2goobj).godag godagplot = GODagSmallPlot(godagsmall, *args, **kws) godagplot.plt(fout_png, engine)
def parent_terms(go_dag, go_id): '''Return parent terms of `go_id` in a `go_dag`. ''' sub_dag = OboToGoDagSmall(goids=[go_id], obodag=go_dag).godag all_parents = list(sub_dag.go2obj.keys()) return all_parents