python 读取kegg绘图配置文件中的kgml文件内容

kgml

kegg有个kgml文件需要我们读取里面的内容,分享python代码如下:


# -*- coding: utf-8 -*- 
'''
'''
import sys, os, argparse, glob, os.path,time
reload(sys)
sys.setdefaultencoding('utf8')
from pyh import *
import numpy as np
import math
import re
import xml.dom.minidom 
from xml.dom.minidom import  parseString, getDOMImplementation
from collections import OrderedDict
import urllib
import shutil
import codecs
import uuid
from PIL import Image
Bin=os.path.split(os.path.realpath(__file__))[0]    
##########################################################################
dom = xml.dom.minidom.parse(sys.argv[1])
root = dom.documentElement
ff=open(sys.argv[2],"w")
if root.nodeName=='pathway':
    for i in root.childNodes:
        if i.nodeType==1:
            if i.nodeName=='entry':
                link=i.getAttribute('link')
                #print link+'\n'
            for g in i.childNodes:
                if g.nodeName=='graphics':
                    type=g.getAttribute('type')
                    x=g.getAttribute('x')
                    y=g.getAttribute('y')
                    width=g.getAttribute('width')
                    height=g.getAttribute('height')
                    #print "%s\t%s\t%s\t%s\t%s\n"%(type,x,y,width,height)
            ff.write("%s\t(%s)\t%s\n"%(type,x+','+y+","+width+","+height,link))
                

                

                

                

                

                


  • 发表于 2019-04-11 16:24
  • 阅读 ( 3194 )
  • 分类:python

0 条评论

请先 登录 后评论
omicsgene
omicsgene

生物信息

654 篇文章

作家榜 »

  1. omicsgene 654 文章
  2. 安生水 325 文章
  3. Daitoue 167 文章
  4. 生物女学霸 120 文章
  5. 红橙子 78 文章
  6. CORNERSTONE 72 文章
  7. rzx 67 文章
  8. xun 66 文章