0
|
1 __author__ = 'cbarnett'
|
|
2 __license__ = "MIT"
|
|
3
|
|
4
|
|
5 def helper_get_G(lineentry):
|
|
6 if "G" in lineentry.upper():
|
|
7 splitline = lineentry.split()
|
|
8 for item in splitline:
|
|
9 if "G" in item:
|
|
10 return item
|
|
11 return None
|
|
12
|
|
13 def get_acceptor_keggids(entry):
|
|
14 """
|
|
15 :param entry. entry from glycogene db
|
|
16 :return: txt keggids
|
|
17 """
|
|
18 import StringIO
|
|
19 import xml.etree.cElementTree as ET
|
|
20 #handle = StringIO.StringIO(''.join(entry))
|
|
21 handle = StringIO.StringIO(entry)
|
|
22 tree = ET.parse(handle)
|
|
23 #print tree.findtext("acceptors")
|
|
24 root = tree.getroot()
|
|
25 print root, root.tag, root.attrib
|
|
26 for elem in root.findall('./gts/acceptors/acceptor_ref'):
|
|
27 print "acceptors ", elem.tag, elem.attrib
|
|
28 a=dict(elem.attrib)
|
|
29 for key in a.keys():
|
|
30 print key, a[key]
|
|
31
|
|
32
|
|
33 def get_entry_from_glycogene(gene):
|
|
34 """
|
|
35 :param gene. Gene name
|
|
36 :return: xml of entry information
|
|
37 """
|
|
38 import urllib2
|
|
39 #import xml.etree.cElementTree as ET
|
|
40
|
|
41
|
|
42 #tree = ET.parse()
|
|
43
|
|
44 uri = 'http://jcggdb.jp/rcmg/wsglycodb/ggdb/entry/'
|
|
45 #if inputstream is None or inputstream == []:
|
|
46 # raise IOError("empty input stream")
|
|
47 gene = "ST3GAL1"
|
|
48 try:
|
|
49 dbresponse = urllib2.urlopen(uri + gene).read()
|
|
50 except Exception as e:
|
|
51 raise urllib2.HTTPError(e.url, e.code, e.msg, e.hdrs, e.fp)
|
|
52 return dbresponse
|
|
53
|
|
54
|
|
55 if __name__ == "__main__":
|
|
56 from optparse import OptionParser
|
|
57
|
|
58 # usage = "usage: python %prog [options]\n"
|
|
59 # parser = OptionParser(usage=usage)
|
|
60 # parser.add_option("-i", action="store", type="string", dest="i", default="input",
|
|
61 # help="single or double column text file containing GL entries")
|
|
62 # parser.add_option("-k", action="store", type="string", dest="k", default="kcf.output",
|
|
63 # help="kcf output file name")
|
|
64 # parser.add_option("-d", action="store", type="string", dest="d", default="db.output",
|
|
65 # help="KEGG db entry in text format output file name")
|
|
66 # (options, args) = parser.parse_args()
|
|
67 # try:
|
|
68 # instream = file(options.i, 'r')
|
|
69 # except Exception as e:
|
|
70 # raise IOError(e, "the input file specified does not exist. Use -h flag for help")
|
|
71 entry = get_entry_from_glycogene("ST3GAL1")
|
|
72 print entry
|
|
73 #instream = file("xml.xml",'r')
|
|
74 #entry = instream.read()
|
|
75 #print entry
|
|
76 get_acceptor_keggids(entry)
|
|
77 #out = file("xml.xml",'w')
|
|
78 #out.write(entry)
|
|
79 #out.close()
|
|
80 # try:
|
|
81 # kcfout = file(options.k, 'w')
|
|
82 # dbout = file(options.d, 'w')
|
|
83 # except Exception as e:
|
|
84 # raise IOError(e, "cannot open output files. -h flag for help")
|
|
85 #
|
|
86 # kcfout.write("".join(kcf))
|
|
87 # dbout.write("".join(db))
|
|
88 # kcfout.close()
|
|
89 # dbout.close()
|
|
90
|