加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

下载kegg代谢通路图以及对应的html文件

(2018-09-04 11:10:04)
标签:

python

kegg

ko

png

html

分类: 生物信息学
# coding:utf-8
# Email:fanyucai1@126.com
# 2018.3.15

import subprocess
import os
import sys

if len(sys.argv) !=3:
    sys.stderr.write("\nThis script is used to download KEGG pathway maps.\n")
    sys.stderr.write("usage:python %s hsa hsa/\n\n" %(sys.argv[0]))
    sys.exit(1)

abb=sys.argv[1]
outdir=sys.argv[2]
pathway = "http://rest.kegg.jp/list/pathway/"
pathway+=abb
subprocess.check_call('mkdir -p %s' % (outdir), shell=True)
os.chdir(outdir)

def ko(pathway,abb):
   subprocess.check_call('curl -s %s -o ID.list' % (pathway), shell=True)
   subprocess.check_call('awk \'{print $1}\' ID.list|awk -F":" \'{print $2}\'|sort -u >abb_ID.list && mv abb_ID.list ID.list',shell=True)
   file = open("ID.list", "r")
   for line in file:
       line = line.strip()
       if not os.path.exists('%s.png' %(line)):
           subprocess.check_call('curl http://rest.kegg.jp/get/%s/image -o %s.png' % (line, line),shell=True)
       if not os.path.exists('%s.html' %(line)):
           subprocess.check_call('curl https://www.kegg.jp/kegg-bin/show_pathway?%s -o %s.html' % (line,line), shell=True)
   file.close()

if __name__ =="__main__":
   ko(pathway, abb)


0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有