Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_example():
"""Run Gene Ontology Enrichment Analysis (GOEA) on Nature data."""
# --------------------------------------------------------------------
# --------------------------------------------------------------------
# Gene Ontology Enrichment Analysis (GOEA)
# --------------------------------------------------------------------
# --------------------------------------------------------------------
taxid = 10090 # Mouse study
# Load ontologies, associations, and population ids
geneids_pop = GeneID2nt_mus.keys()
geneids2symbol_study = get_geneid2symbol("nbt.3102-S4_GeneIDs.xlsx")
geneids_study = geneids2symbol_study.keys()
goeaobj = get_goeaobj("fdr_bh", geneids_pop, taxid)
# Run GOEA on study
goea_results_all = goeaobj.run_study(geneids_study)
goea_results_sig = [r for r in goea_results_all if r.p_fdr_bh < 0.05]
goea_results_sub = [r for r in goea_results_sig if r.study_count > r.study_n/10]
# Print GOEA results to files: With study genes printed as geneids or symbols
goeaobj.wr_xlsx("nbt3102_symbols.xlsx", goea_results_sub, itemid2name=geneids2symbol_study)
goeaobj.wr_xlsx("nbt3102_geneids.xlsx", goea_results_sub)
def test_example(log=sys.stdout):
"""Run Gene Ontology Enrichment Analysis (GOEA) on Nature data."""
# --------------------------------------------------------------------
# --------------------------------------------------------------------
# Gene Ontology Enrichment Analysis (GOEA)
# --------------------------------------------------------------------
# --------------------------------------------------------------------
taxid = 10090 # Mouse study
# Load ontologies, associations, and population ids
geneids_pop = GeneID2nt_mus.keys()
geneids_study = get_geneid2symbol("nbt.3102-S4_GeneIDs.xlsx")
goeaobj = get_goeaobj("fdr_bh", geneids_pop, taxid)
# Run GOEA on study
#keep_if = lambda nt: getattr(nt, "p_fdr_bh" ) < 0.05 # keep if results are significant
goea_results_all = goeaobj.run_study(geneids_study)
goea_results_sig = [r for r in goea_results_all if r.p_fdr_bh < 0.05]
compare_results(goea_results_all)
geneids = get_study_items(goea_results_sig)
# Print GOEA results to files
goeaobj.wr_xlsx("nbt3102.xlsx", goea_results_sig)
goeaobj.wr_txt("nbt3102_sig.txt", goea_results_sig)
goeaobj.wr_txt("nbt3102_all.txt", goea_results_all)
# Plot all significant GO terms w/annotated study info (large plots)
#plot_results("nbt3102_{NS}.png", goea_results_sig)
#plot_results("nbt3102_{NS}_sym.png", goea_results_sig, study_items=5, items_p_line=2, id2symbol=geneids_study)
def test_example():
"""Run Gene Ontology Enrichment Analysis (GOEA) on Nature data."""
# --------------------------------------------------------------------
# --------------------------------------------------------------------
# Gene Ontology Enrichment Analysis (GOEA)
# --------------------------------------------------------------------
# --------------------------------------------------------------------
taxid = 10090 # Mouse study
# Load ontologies, associations, and population ids
geneids_pop = GeneID2nt_mus.keys()
geneids2symbol_study = get_geneid2symbol("nbt.3102-S4_GeneIDs.xlsx")
geneids_study = geneids2symbol_study.keys()
goeaobj = get_goeaobj("fdr_bh", geneids_pop, taxid)
# Run GOEA on study
goea_results_all = goeaobj.run_study(geneids_study)
goea_results_sig = [r for r in goea_results_all if r.p_fdr_bh < 0.05]
# Print GOEA results to files: With study genes printed as geneids or symbols
goeaobj.wr_xlsx("nbt3102_sig_symbols.xlsx", goea_results_sig, itemid2name=geneids2symbol_study)
goeaobj.wr_xlsx("nbt3102_sig_geneids.xlsx", goea_results_sig)
goeaobj.wr_xlsx("nbt3102_all_symbols.xlsx", goea_results_all, itemid2name=geneids2symbol_study)
goeaobj.wr_xlsx("nbt3102_all_geneids.xlsx", goea_results_all)
def _get_pvals(pvalfnc_names, prt=sys.stdout):
fisher2pvals = {}
taxid = 10090 # Mouse study
file_obo = os.path.join(os.getcwd(), "go-basic.obo")
obo_dag = get_godag(file_obo, prt, loading_bar=None)
geneids_pop = set(GeneID2nt_mus.keys())
assoc_geneid2gos = get_assoc_ncbi_taxids([taxid], loading_bar=None)
geneids_study = get_geneid2symbol("nbt.3102-S4_GeneIDs.xlsx")
for fisher in pvalfnc_names:
goeaobj = GOEnrichmentStudy(
geneids_pop,
assoc_geneid2gos,
obo_dag,
propagate_counts=False,
alpha=0.05,
methods=None,
pvalcalc=fisher)
fisher2pvals[fisher] = goeaobj.get_pval_uncorr(geneids_study, prt)
return fisher2pvals
def test_example():
"""Test GoeaPrintFunctions::print_results."""
# --------------------------------------------------------------------
# --------------------------------------------------------------------
# Gene Ontology Enrichment Analysis (GOEA)
# --------------------------------------------------------------------
# --------------------------------------------------------------------
taxid = 10090 # Mouse study
# Load ontologies, associations, and population ids
geneids_pop = GeneID2nt_mus.keys()
geneids2symbol_study = get_geneid2symbol("nbt.3102-S4_GeneIDs.xlsx")
geneids_study = geneids2symbol_study.keys()
goeaobj = get_goeaobj("fdr_bh", geneids_pop, taxid)
# Run GOEA on study
goea_results_all = goeaobj.run_study(geneids_study)
goea_results_sig = [r for r in goea_results_all if r.p_fdr_bh < 0.05]
#goea_results_nt = MgrNtGOEAs(goea_results_sig).get_goea_nts_all()
objprtres = GoeaPrintFunctions()
objprtres.print_results(goea_results_sig)
objprtres.print_date()
def test_example():
"""Test GoeaResults in plotting package."""
# --------------------------------------------------------------------
# --------------------------------------------------------------------
# Gene Ontology Enrichment Analysis (GOEA)
# --------------------------------------------------------------------
# --------------------------------------------------------------------
taxid = 10090 # Mouse study
# Load ontologies, associations, and population ids
geneids_pop = GeneID2nt_mus.keys()
geneids2symbol_study = get_geneid2symbol("nbt.3102-S4_GeneIDs.xlsx")
geneids_study = geneids2symbol_study.keys()
goeaobj = get_goeaobj("fdr_bh", geneids_pop, taxid)
go2obj = goeaobj.obo_dag
# Run GOEA on study
goea_results_all = goeaobj.run_study(geneids_study)
goea_results_sig = [r for r in goea_results_all if r.p_fdr_bh < 0.05]
goea_results_nt = MgrNtGOEAs(goea_results_sig).get_goea_nts_all()
assert goea_results_nt
ns2gos = get_ns2gos(goea_results_sig)
# Test plotting GOEA results
gosubdag = GoSubDag(set(r.GO for r in goea_results_sig), go2obj)
plot_results("test_plot_goids_a_goea_{NS}.png", goea_results_sig,
id2symbol=geneids2symbol_study, parentcnt=True, childcnt=True)
for nss, goids in ns2gos.items():
plt_goids(gosubdag, "test_plot_goids_b_{NS}.png".format(NS=nss), goids)
plot_gos("test_plot_goids_c_{NS}.png".format(NS=nss), goids, go2obj)
def test_example():
"""Test GoeaPrintFunctions::print_results."""
# --------------------------------------------------------------------
# --------------------------------------------------------------------
# Gene Ontology Enrichment Analysis (GOEA)
# --------------------------------------------------------------------
# --------------------------------------------------------------------
taxid = 10090 # Mouse study
# Load ontologies, associations, and population ids
geneids_pop = GeneID2nt_mus.keys()
geneids2symbol_study = get_geneid2symbol("nbt.3102-S4_GeneIDs.xlsx")
goeaobj = get_goeaobj("fdr_bh", geneids_pop, taxid)
# No study genes at all
geneids_study_none = set()
goea_results_all = goeaobj.run_study(geneids_study_none)
assert not goea_results_all, 'NO STUDY GENES TEST FAILED: {R}'.format(R=goea_results_all)
# No study genes in population or association
geneids_study_bad = set(['BADVAL'])
goea_results_all = goeaobj.run_study(geneids_study_bad)
# goea_results_sig = [r for r in goea_results_all if r.p_fdr_bh < 0.05]
assert not goea_results_all, 'NO VALID STUDY GENES TEST FAILED: {R}'.format(R=goea_results_all)
# goea_results_all = goeaobj.run_study(geneids_study)
objprtres = GoeaPrintFunctions()
objprtres.print_results(goea_results_all, pval=None)
objprtres.print_date()
def _get_results(godag, propagate_counts, relationships, prt=sys.stdout):
"""Run a GOEA. Return results"""
taxid = 10090 # Mouse study
geneids_pop = set(GeneID2nt_mus.keys())
assoc_geneid2gos = get_assoc_ncbi_taxids([taxid], loading_bar=None)
geneids_study = get_geneid2symbol("nbt.3102-S4_GeneIDs.xlsx")
goeaobj = GOEnrichmentStudy(
geneids_pop,
assoc_geneid2gos,
godag,
propagate_counts=propagate_counts,
relationships=relationships,
alpha=0.05,
methods=['fdr_bh'])
return goeaobj.run_study(geneids_study, prt=prt)