diff options
author | Zachary Sloan | 2012-10-05 18:14:00 -0500 |
---|---|---|
committer | Zachary Sloan | 2012-10-05 18:14:00 -0500 |
commit | 779d6736f8fdc15c1df4695410e9c952847143d8 (patch) | |
tree | ab24e867389369d8a4a1fe06fcf90b51e8e785d5 /wqflask | |
parent | ff6feb27253811571e4009e8f7048c3374bdf4a7 (diff) | |
download | genenetwork2-779d6736f8fdc15c1df4695410e9c952847143d8.tar.gz |
Parsing code can now split input into key (GO, LRS, etc), seperator (=, :)
and value (the numbers, etc to the right of the = or :
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/parser.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/wqflask/wqflask/parser.py b/wqflask/wqflask/parser.py index b58b6c0b..16eff609 100644 --- a/wqflask/wqflask/parser.py +++ b/wqflask/wqflask/parser.py @@ -2,13 +2,38 @@ from __future__ import print_function, division import re +from pprint import pformat as pf def parse(pstring): pstring = re.split(r"""(?:(\w+\s*=\s*\([^)]*\))|(\w+\s*[=:]\w+))""", pstring) pstring = [item.strip() for item in pstring if item and item.strip()] print(pstring) + + items = [] + for item in pstring: + if ":" in item: + key, seperator, value = item.partition(':') + elif "=" in item: + key, seperator, value = item.partition('=') + else: + seperator = None + if seperator: + if '(' in value: + assert value.startswith("("), "Invalid token" + assert value.endswith(")"), "Invalid token" + value = value[1:-1] # Get rid of the parenthesis + values = re.split(r"""\s+|,""", value) + value = [value.strip() for value in values] + term = dict(key=key, + seperator=seperator, + value=value) + else: + term = dict(search_term = item) + + items.append(term) + print(pf(items)) parse("foo=(3 2 1)") parse("LRS=(9 99 Chr4 122 155) cisLRS=(9 999 10)") |