-
Notifications
You must be signed in to change notification settings - Fork 3
/
glycan_only.py
68 lines (56 loc) · 2.56 KB
/
glycan_only.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""Handles Glycan Reader & Modeler options for glycan-only systems"""
import re
from cgui_browser_process import CGUIBrowserProcess
_BROWSER_PROCESS = 'GlycanOnlyBrowserProcess'
class GlycanOnlyBrowserProcess(CGUIBrowserProcess):
"""Implements Glycan Only front page options for Glycan Reader & Modeler"""
def __init__(self, *args, **kwargs):
self.module_title = "Glycan Reader & Modeler"
self.module_url = "?doc=input/glycan&step=0"
super().__init__(*args, **kwargs)
def set_glycan(self):
"""Builds glycan from GRS sequence"""
glycan = self.test_case.get('glycan')
if not glycan:
raise ValueError("Missing glycan options")
_d = re.compile('- ')
chemod_init = False
nchem = 0
for i,residue in enumerate(glycan['grs'].split('\n')):
if not residue.strip():
continue
depth = len(_d.findall(residue))
linkage, resname = residue.split('- ')[-1].split()
chemod = None
idx = resname.find('_') #... chemical modification
if idx > 0:
chemod = resname[idx+1:].split('_')
resname = resname[:idx]
if i > 0:
self.browser.find_by_id(str(depth)).find_by_css('.add').first.click()
self.browser.select(f"sequence[{i+1}][linkage]", linkage[1])
self.browser.select(f"sequence[{i+1}][type]", resname[0])
self.browser.select(f"sequence[{i+1}][name]", resname[1:])
if chemod:
for chm in chemod:
if not chemod_init:
self.browser.find_by_id("chem_checked").first.click()
chemod_init = True
else:
self.browser.execute_script("add_chem()")
match = re.match('[0-9]+', chm)
site = match.group()
patch = chm[match.end():]
self.browser.select("chem[%d][resid]" % nchem, i+1)
self.browser.select("chem[%d][patch]" % nchem, patch)
self.browser.select("chem[%d][site]" % nchem, site)
nchem += 1
self.go_next(self.test_case['steps'][0]['wait_text'])
def init_system(self, **kwargs):
url = self.base_url + self.module_url
browser = self.browser
if not kwargs.get('resume'):
browser.visit(url)
self.browser.click_link_by_text("Glycan Only System")
self.set_glycan()
self.get_jobid()