<jupyter_start><jupyter_text>Do enrichment analyses using the Human Phenotype Ontology (HPO)HPO files located in goatools/notebooks/data/hpo<jupyter_code>fin_study = 'data/hpo/genes.list'         # Study genes
fin_pop   = 'data/hpo/gobackground.list'  # Population genes
fin_obo   = 'data/hpo/hp.obo'             # DAG containing HPO terms
fin_anno  = 'data/hpo/hpo.annotation.tab' # Annotation of genes-to-HPO terms<jupyter_output><empty_output><jupyter_text>1) Read list of study genes and population genes<jupyter_code>from goatools.utils import read_geneset

study_ids = read_geneset(fin_study)
population_ids = read_geneset(fin_pop)<jupyter_output>2,252 READ: data/hpo/genes.list
   14,446 READ: data/hpo/gobackground.list<jupyter_text>2) Load the human phenotype ontology DAG<jupyter_code>from goatools.obo_parser import GODag

godag = GODag(fin_obo)<jupyter_output>data/hpo/hp.obo: fmt(1.2) rel(hp/2021-02-28) 19,498 Terms<jupyter_text>3) Load the annotations of genes to sets of HPO terms<jupyter_code>from goatools.anno.idtogos_reader import IdToGosReader

annoobj = IdToGosReader(fin_anno, godag=godag)

id2gos = annoobj.get_id2gos()<jupyter_output>HMS:0:00:00.594349 187,934 annotations READ: data/hpo/hpo.annotation.tab 
4531 IDs in loaded association branch, human_phenotype<jupyter_text>4) Run enrichment analysis on HPO terms<jupyter_code>from goatools.go_enrichment import GOEnrichmentStudy

goeaobj = GOEnrichmentStudy(
    population_ids,
    annoobj.get_id2gos(),
    godag,
    methods=['bonferroni', 'fdr_bh'],
    pvalcalc='fisher_scipy_stats')<jupyter_output>4531 IDs in loaded association branch, human_phenotype

Load  Ontology Enrichment Analysis ...
Propagating term counts up: is_a
 26%  3,823 of 14,446 population items found in association<jupyter_text>5) Run an enrichment analysis on HPO terms<jupyter_code>results = goeaobj.run_study_nts(study_ids)<jupyter_output>Runing  Ontology Analysis: current study set of 2252 IDs.
 29%    650 of  2,252 study items found in association
100%  2,252 of  2,252 study items found in population(14446)
Calculating 9,331 uncorrected p-values using fisher_scipy_stats
   9,331 terms are associated with  3,823 of 14,446 population items
   5,802 terms are associated with    650 of  2,252 study items
  METHOD bonferroni:
       2 GO terms found significant (< 0.05=alpha) (  2 enriched +   0 purified): local bonferroni
     489 study items associated with significant GO IDs (enriched)
       0 study items associated with significant GO IDs (purified)
  METHOD fdr_bh:
      12 GO terms found significant (< 0.05=alpha) ( 12 enriched +   0 purified): statsmodels fdr_bh
     498 study items associated with significant GO IDs (enriched)
       0 study items associated with significant GO IDs (purified)<jupyter_text>6) Print the results<jupyter_code>print('namespace       term_id  e/p pval_uncorr Benjamimi/Hochberg Bonferroni  study_ratio population_ratio')
print('--------------- -------- --- ----------- ------------------ ----------  ----------- ----------------')
pat = '{NS} {GO} {e}    {PVAL:8.2e}           {BH:8.2e}   {BONF:8.2e} {RS:>12} {RP:>12}'
for ntd in sorted(results, key=lambda nt: [nt.p_uncorrected, nt.GO]):
    if ntd.p_fdr_bh < 0.05:
        print(pat.format(
            NS=ntd.NS,
            GO=ntd.GO,
            e=ntd.enrichment,
            RS='{}/{}'.format(*ntd.ratio_in_study),
            RP='{}/{}'.format(*ntd.ratio_in_pop),
            PVAL=ntd.p_uncorrected,
            BONF=ntd.p_bonferroni,
            BH=ntd.p_fdr_bh))
print('e: enriched')
print('p: purified')<jupyter_output>namespace       term_id  e/p pval_uncorr Benjamimi/Hochberg Bonferroni  study_ratio population_ratio
--------------- -------- --- ----------- ------------------ ----------  ----------- ----------------
human_phenotype HP:0000007 e    3.40e-09           3.18e-05   3.18e-05     459/2252   2322/14446
human_phenotype HP:0000080 e    4.22e-08           1.97e-04   3.94e-04     142/2252    590/14446
human_phenotype HP:0000556 e    7.80e-06           2.26e-02   7.28e-02      74/2252    288/14446
human_phenotype HP:0000512 e    1.21e-05           2.26e-02   1.13e-01      48/2252    166/14446
human_phenotype HP:0000572 e    1.21e-05           2.26e-02   1.13e-01      48/2252    166/14446
human_phenotype HP:0012868 e    2.69e-05           3.85e-02   2.51e-01      10/2252     16/14446
human_phenotype HP:0003138 e    3.65e-05           3.85e-02   3.40e-01       8/2252     11/14446
human_phenotype HP:0031970 e    3.65e-05           3.85e-02   3.40e-01       8/2252     11/14446
human_phenotype HP:000[...]
{'fraction_non_alphanumeric': 0.1305767138193689, 'fraction_numerical': 0.09793253536452666, 'mean_word_length': 2.849246231155779, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '626626', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1606, 'n_words': 378, 'path': 'notebooks/Enrichment_analyses_human_phenotype_ontology.ipynb', 'repo_name': 'bravokid47/goatools', 'size': '4595'}