Skip to content

Commit

Permalink
implement MIN operator complement MAX
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-k committed Feb 21, 2018
1 parent ce92d45 commit 5839279
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pyvdrm/hcvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,16 @@ def __call__(self, mutations):


class ScoreList(AsiExpr):
"""Lists of scores are either summed or maxed"""
"""Lists of scores are either SUMed, MAXed, or MINed"""

def __call__(self, mutations):
operation, *rest = self.children
if operation == 'MAX':
terms = rest
func = max
elif operation == 'MIN':
terms = rest
func = min
else:
# the default operation is sum
terms = self.children
Expand Down Expand Up @@ -262,10 +265,10 @@ def parser(self, rule):
from_ = Literal('FROM').suppress()

max_ = Literal('MAX')
min_ = Literal('MIN')

and_ = Literal('AND').suppress()
or_ = Literal('OR').suppress()
# min_ = Literal('MIN')

notmorethan = Literal('NOTMORETHAN')
l_par = Literal('(').suppress()
Expand All @@ -283,6 +286,7 @@ def parser(self, rule):
excludestatement = except_ + residue

quantifier = exactly | atleast | notmorethan
tropical = max_ | min_
inequality = quantifier + integer
inequality.setParseAction(EqualityExpr)

Expand All @@ -309,7 +313,7 @@ def parser(self, rule):
score = Optional(Literal('-')) + integer | quote + Regex(r'[a-zA-Z0-9 _]+') + quote
scoreitem = booleancondition + mapper + score
scoreitem.setParseAction(ScoreExpr)
scorelist = max_ + l_par + delimitedList(scoreitem) + r_par |\
scorelist = tropical + l_par + delimitedList(scoreitem) + r_par |\
delimitedList(scoreitem)
scorelist.setParseAction(ScoreList)

Expand Down
10 changes: 10 additions & 0 deletions pyvdrm/tests/test_hcvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ def test_score_from_max_neg(self):
rule = HCVR("SCORE FROM (MAX (100G => -10, 101D => -20, 102D => 30))")
self.assertEqual(-10, rule(VariantCalls("100G 101D 102d")))

def test_score_from_min(self):
rule = HCVR("SCORE FROM (MIN (100G => 10, 101D => 20, 102D => 30))")
self.assertEqual(rule(VariantCalls("100G 101D 102d")), 10)

def test_score_from_min_neg(self):
rule = HCVR("SCORE FROM (MIN (100G => -10, 101D => -20, 102D => 30))")
self.assertEqual(-20, rule(VariantCalls("100G 101D 102d")))



def test_bool_and(self):
rule = HCVR("1G AND (2T AND 7Y)")
self.assertEqual(rule(VariantCalls("2T 7Y 1G")), True)
Expand Down

0 comments on commit 5839279

Please sign in to comment.