用python丰富内容——pandas与networkx相遇
goenrich的Python项目详细描述
戈恩里奇
python提供的方便go enrichments。用于python项目。
- 构建go本体图
- 在图形中向上传播go注释
- 对所有类别执行充实测试
- 执行多次测试更正
- 允许导出到pandas进行处理,并允许导出到graphviz进行处理 可视化
安装
从pypi安装包并下载本体和所需的注释。
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
运行go浓缩
importgoenrich# build the ontologyO=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 yeastgene2go=goenrich.read.gene2go('db/gene2go.gz')# use values = {k: set(v) for k,v in annot.groupby('go_id')['db_object_symbol']} for uniprot/yeastvalues={k:set(v)fork,vingene2go.groupby('GO_ID')['GeneID']}# propagate the background through the ontologybackground_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 smalldf=goenrich.enrich.analyze(O,query,background_attribute,gvfile='test.dot')# generate htmldf.dropna().head().to_html('example.html')# call to graphvizimportsubprocesssubprocess.check_call(['dot','-Tpng','test.dot','-o','test.png'])
使用graphviz生成png图像:
dot -Tpng example.dot > example.png
或者直接从python:
importsubprocesssubprocess.check_call(['dot','-Tpng','example.dot','-o','example.png'])
查看文档以了解所有可用参数
许可证和贡献者
这项工作是根据麻省理工学院的许可证颁发的
欢迎投稿!
特别感谢
- @lukauskas用于实现对类文件对象的I/O支持。
- @zfrenchee用于在测试统计量的计算中修正bug。
- @pommy1用于实现对
networkx >= 2.0.0
的支持。
建立文档
sphinx-apidoc -f -o docs goenrich goenrich/tests