comparison get_data/kegg_glycan/linkKEGG.py @ 1:0a5e0df17054 draft default tip

Uploaded
author chrisb
date Fri, 06 May 2016 08:05:48 -0400
parents 89592faa2875
children
comparison
equal deleted inserted replaced
0:89592faa2875 1:0a5e0df17054
1 __author__ = 'cbarnett' 1 __author__ = 'cbarnett'
2 __license__ = "MIT" 2 __license__ = "MIT"
3 __version = "0.3" 3 __version = "0.3.1"
4 # http://www.kegg.jp/kegg/rest/keggapi.html 4 # http://www.kegg.jp/kegg/rest/keggapi.html
5 5
6 6
7 def linked_entries_from_kegg(targetdb="glycan", sourcedb="pathway"): 7 def linked_entries_from_kegg(targetdb="glycan", sourcedb="pathway"):
8 """ 8 """
11 :return: string of linked entries 11 :return: string of linked entries
12 """ 12 """
13 import urllib2 13 import urllib2
14 14
15 uri = 'http://rest.kegg.jp/link/' 15 uri = 'http://rest.kegg.jp/link/'
16
17 import re
18 p = re.compile(' *\+ *') # ensure no unneccessary space in an AND query
19 sdbfix = p.subn('+', sourcedb)
20 sourcedb=sdbfix[0]
21
22 if ' ' in sourcedb:
23 sourcedb = sourcedb.replace(' ', '%20') # previous behaviour was ignoring text after a space, rather convert to '%20' and pass on to KEGG REST service
24
16 fulluri = uri + targetdb + "/" + sourcedb 25 fulluri = uri + targetdb + "/" + sourcedb
17 try: 26 try:
18 response = urllib2.urlopen(fulluri).read() 27 response = urllib2.urlopen(fulluri).read()
19 except Exception as e: 28 except Exception as e:
20 raise urllib2.HTTPError(e.url, e.code, e.msg, e.hdrs, e.fp) 29 raise urllib2.HTTPError(e.url, e.code, e.msg, e.hdrs, e.fp)