前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python从零开始第五章生物信息学④kegg查询续

Python从零开始第五章生物信息学④kegg查询续

作者头像
用户1359560
发布2019-02-22 15:22:20
6960
发布2019-02-22 15:22:20
举报
文章被收录于专栏:生信小驿站生信小驿站

正文

  • 导入必须的python包
%clear
%reset -f
# In[*]
# 加载Python库
from bioservices.kegg import KEGG
s = KEGG()
  • 查询某一通路的信息
# In[*]
print(s.get("hsa04660"))


# In[*]
data = s.get("hsa04660")
dict_data = s.parse(data)
print(dict_data['GENE'])

通过这里可以输出kegg的通路信息,包括通路里面的基因,基因间的联系方式,以及链接等等。

其中Gene这一个对象就是包含基因name的数据框,完全可以提取出来

  • 将kegg通路信息保存成其他格式的文件
# In[*]

res = s.get("hsa04660", "kgml")
res = s.parse_kgml_pathway("hsa04660")
res['relations']

res['relations'][0]
res['entries']
  • 建立人类kegg通路中所有关系的直方图 这一步比较耗费时间,大概需要三分钟。 可以通过将Nmax设置为较小的值(例如,Nmax = 10)来查看子集。
# In[*]
from pylab import *
# extract all relations from all pathways
from bioservices.kegg import KEGG
s = KEGG()
s.organism = "hsa"

# retrieve more than 260 pathways so it takes time
results = [s.parse_kgml_pathway(x) for x in s.pathwayIds]
relations = [x['relations'] for x in results]

hist([len(r) for r in relations], 20)
xlabel('number of relations')
ylabel('\#')
title("number of relations per pathways")
grid(True)
  • 同样地,我们可以提取更多信息,例如关系类型:
import collections # for python 2.7.0 and above

# we extract from all pathways, all relations, where we retrieve the type of
# relation (name)
data = list(flatten([[x['name'] for x in rel] for rel in relations]))

counter = collections.Counter(data)
print(counter)
Counter({'activation': 6593, 'compound': 6183, 'phosphorylation': 1587, 'expression': 1574, 'inhibition': 1530, 'binding/association': 1342, 'indirect effect': 975, 'missing interaction': 227, 'dephosphorylation': 145, 'dissociation': 99, 'ubiquitination': 73, 'repression': 36, 'state change': 34, 'glycosylation': 11, 'methylation': 2})
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018.12.12 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 正文
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档