Skip to content

Commit d5da55b

Browse files
committed
Replace message on ParseException.
Increment version number.
1 parent bc65b7d commit d5da55b

File tree

6 files changed

+74
-10
lines changed

6 files changed

+74
-10
lines changed

README.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,14 @@ The `vcf` module has basic helper functions for construction lists of mutation
9191
calls:
9292

9393
```
94-
from pyvdrm.vcf import call_mutations
94+
from pyvdrm.vcf import VariantCalls
9595
from pyvdrm.asi2 import ASI2
9696
97-
ref = "APITAYAQQTRGLLGCIITSLTGRD"
98-
sample = "APITAYAQQTRGLLTCIITSLTGRD"
97+
calls = VariantCalls(reference="APITAYAQQTRGLLGCIITSLTGRD",
98+
sample= "APITAYAQQTRGLLTCIITSLTGRD")
99+
# mutation G15T ------------------------------^
99100
100-
score = rule(call_mutations(ref, sample))
101+
rule = ASI2('SCORE FROM ( G15T => 5 )')
102+
score = rule(calls)
103+
print(score) # => 5
101104
```

pyvdrm/asi2.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from functools import reduce, total_ordering
66
from pyparsing import (Literal, nums, Word, Forward, Optional, Regex,
7-
infixNotation, delimitedList, opAssoc)
7+
infixNotation, delimitedList, opAssoc, ParseException)
88
from pyvdrm.drm import AsiExpr, AsiBinaryExpr, AsiUnaryExpr, DRMParser
99
from pyvdrm.vcf import MutationSet
1010

@@ -299,4 +299,8 @@ def parser(self, rule):
299299

300300
statement = booleancondition | scorecondition
301301

302-
return statement.parseString(rule)
302+
try:
303+
return statement.parseString(rule)
304+
except ParseException as ex:
305+
ex.msg = 'Error in ASI2: ' + ex.markInputline()
306+
raise

pyvdrm/hcvr.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from functools import reduce, total_ordering
66
from pyparsing import (Literal, nums, Word, Forward, Optional, Regex,
7-
infixNotation, delimitedList, opAssoc, alphas)
7+
infixNotation, delimitedList, opAssoc, alphas, ParseException)
88
from pyvdrm.drm import AsiExpr, AsiBinaryExpr, AsiUnaryExpr, DRMParser
99
from pyvdrm.vcf import MutationSet
1010

@@ -329,4 +329,8 @@ def parser(self, rule):
329329

330330
statement = booleancondition | scorecondition
331331

332-
return statement.parseString(rule)
332+
try:
333+
return statement.parseString(rule)
334+
except ParseException as ex:
335+
ex.msg = 'Error in HCVR: ' + ex.markInputline()
336+
raise

pyvdrm/tests/test_asi2.py

+26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import unittest
2+
3+
from pyparsing import ParseException
4+
25
from pyvdrm.asi2 import ASI2, AsiMutations, Score
36
from pyvdrm.vcf import Mutation, MutationSet, VariantCalls
47

@@ -99,6 +102,29 @@ def test_score_from_exactly(self):
99102
score = rule(VariantCalls("2T 7Y 1G"))
100103
self.assertEqual(0, score)
101104

105+
def test_parse_exception(self):
106+
expected_error_message = (
107+
"Error in ASI2: SCORE FROM ( 10R => 2>!<;0 ) (at char 21), (line:1, col:22)")
108+
109+
with self.assertRaises(ParseException) as context:
110+
ASI2("SCORE FROM ( 10R => 2;0 )")
111+
112+
self.assertEqual(expected_error_message, str(context.exception))
113+
114+
def test_parse_exception_multiline(self):
115+
rule = """\
116+
SCORE FROM (
117+
10R => 2;0
118+
)
119+
"""
120+
expected_error_message = (
121+
"Error in ASI2: 10R => 2>!<;0 (at char 25), (line:2, col:13)")
122+
123+
with self.assertRaises(ParseException) as context:
124+
ASI2(rule)
125+
126+
self.assertEqual(expected_error_message, str(context.exception))
127+
102128

103129
class TestActualRules(unittest.TestCase):
104130
def test_hivdb_rules_parse(self):

pyvdrm/tests/test_hcvr.py

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import sys
21
import unittest
2+
3+
from pyparsing import ParseException
4+
35
from pyvdrm.hcvr import HCVR, AsiMutations, Score
46
from pyvdrm.vcf import Mutation, MutationSet, VariantCalls
57

@@ -120,6 +122,30 @@ def test_score_comment(self):
120122
self.assertEqual(result.score, 3)
121123
self.assertTrue("flag1 with_space" in result.flags)
122124

125+
def test_parse_exception(self):
126+
expected_error_message = (
127+
"Error in HCVR: SCORE FROM ( 10R => 2>!<;0 ) (at char 21), (line:1, col:22)")
128+
129+
with self.assertRaises(ParseException) as context:
130+
HCVR("SCORE FROM ( 10R => 2;0 )")
131+
132+
self.assertEqual(expected_error_message, str(context.exception))
133+
134+
def test_parse_exception_multiline(self):
135+
rule = """\
136+
SCORE FROM (
137+
10R => 2;0
138+
)
139+
"""
140+
expected_error_message = (
141+
"Error in HCVR: 10R => 2>!<;0 (at char 25), (line:2, col:13)")
142+
143+
with self.assertRaises(ParseException) as context:
144+
HCVR(rule)
145+
146+
self.assertEqual(expected_error_message, str(context.exception))
147+
148+
123149
class TestActualRules(unittest.TestCase):
124150
def test_hivdb_rules_parse(self):
125151
for line in open("pyvdrm/tests/HIVDB.rules"):
@@ -210,5 +236,6 @@ def test_true_positive(self):
210236
expected_repr = "[Mutation('Q54H'), Mutation('444H')]"
211237
self.assertEqual(expected_repr, repr(sorted(dtree.residues)))
212238

239+
213240
if __name__ == '__main__':
214241
unittest.main()

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='pyvdrm',
5-
version='0.1.1',
5+
version='0.2.0',
66
description='',
77

88
url='',

0 commit comments

Comments
 (0)