Skip to main content

GO enrichment with python -- pandas meets networkx

Project description

goenrich

https://badges.gitter.im/Join%20Chat.svg https://readthedocs.org/projects/goenrich/badge/?version=latest https://travis-ci.org/jdrudolph/goenrich.svg?branch=master

Convenient GO enrichments from python. For use in python projects.

  1. Builds the GO-ontology graph

  2. Propagates GO-annotations up the graph

  3. Performs enrichment test for all categories

  4. Performs multiple testing correction

  5. Allows for export to pandas for processing and graphviz for visualization

Installation

Install package from pypi and download ontology and needed annotations.
pip install goenrich
mkdir db
# Ontology
wget http://purl.obolibrary.org/obo/go/go-basic.obo -O db/go-basic.obo
# UniprotACC
wget http://geneontology.org/gene-associations/goa_human.gaf.gz -O db/gene_association.goa_human.gaf.gz
# Yeast SGD
wget http://downloads.yeastgenome.org/curation/literature/gene_association.sgd.gz -O db/gene_association.sgd.gz
# Entrez GeneID
wget ftp://ftp.ncbi.nlm.nih.gov/gene/DATA/gene2go.gz -O db/gene2go.gz

Run GO enrichment

import goenrich

# build the ontology
O = goenrich.obo.ontology('db/go-basic.obo')

# use all entrez geneid associations form gene2go as background
# use annot = goenrich.read.goa('db/gene_association.goa_human.gaf.gz') for uniprot
# use annot = goenrich.read.sgd('db/gene_association.sgd.gz') for yeast
gene2go = goenrich.read.gene2go('db/gene2go.gz')
# use values = {k: set(v) for k,v in annot.groupby('go_id')['db_object_symbol']} for uniprot/yeast
values = {k: set(v) for k,v in gene2go.groupby('GO_ID')['GeneID']}

# propagate the background through the ontology
background_attribute = 'gene2go'
goenrich.enrich.propagate(O, values, background_attribute)

# extract some list of entries as example query
# use query = annot['db_object_symbol'].unique()[:20]
query = gene2go['GeneID'].unique()[:20]

# for additional export to graphviz just specify the gvfile argument
# the show argument keeps the graph reasonably small
df = goenrich.enrich.analyze(O, query, background_attribute, gvfile='test.dot')

# generate html
df.dropna().head().to_html('example.html')

# call to graphviz
import subprocess
subprocess.check_call(['dot', '-Tpng', 'test.dot', '-o', 'test.png'])

Generate png image using graphviz:

dot -Tpng example.dot > example.png

or directly from python:

import subprocess
subprocess.check_call(['dot', '-Tpng', 'example.dot', '-o', 'example.png'])
https://cloud.githubusercontent.com/assets/2606663/8525018/cad3a288-23fe-11e5-813c-bd205a47eed8.png

Check the documentation for all available parameters

Licence & Contributors

This work is licenced under the MIT licence

Contributions are welcome!

Special thanks

  • @lukauskas for implementing i/o support for file-like objects.

  • @zfrenchee for fixing a bug in the calculation of the test statistic.

  • @pommy1 for implementing support for networkx >= 2.0.0.

Building the documentation

sphinx-apidoc -f -o docs goenrich goenrich/tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

goenrich-1.12.tar.gz (28.1 kB view details)

Uploaded Source

File details

Details for the file goenrich-1.12.tar.gz.

File metadata

  • Download URL: goenrich-1.12.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

File hashes

Hashes for goenrich-1.12.tar.gz
Algorithm Hash digest
SHA256 f9b8bf3ba1a7c086381a3a333c25eb7367e37a43172113627e5ba254f356c165
MD5 fe68dd571d7d58544ccf36a33fc67ab3
BLAKE2b-256 14fc12ca805cd5a146c68d3960116239862f688552068d01cd245f03f533faa5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page