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))
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!