Skip to content

Commit 20b15d3

Browse files
committed
Calculate rules on a VariantCalls collection.
1 parent 1d5fd5d commit 20b15d3

File tree

2 files changed

+27
-34
lines changed

2 files changed

+27
-34
lines changed

pyvdrm/asi2.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,10 @@ def __repr__(self):
219219
return "AsiMutations(args={!r})".format(str(self.mutations))
220220

221221
def __call__(self, env):
222-
intersection = set(env) & self.mutations.mutations
223-
if len(intersection) > 0:
224-
return Score(True, intersection)
222+
for mutation_set in env:
223+
intersection = mutation_set.mutations & self.mutations.mutations
224+
if len(intersection) > 0:
225+
return Score(True, intersection)
225226
return None
226227

227228

pyvdrm/tests/test_asi2.py

+23-31
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
import unittest
2-
from functools import reduce
32
from pyvdrm.asi2 import ASI2, AsiMutations, Score
4-
from pyvdrm.vcf import Mutation, MutationSet
5-
6-
7-
def mus(mutations):
8-
if mutations == '':
9-
return set([])
10-
return reduce(lambda x, y: x.union(y),
11-
map(lambda x: set(MutationSet(x)), mutations.split()))
3+
from pyvdrm.vcf import Mutation, MutationSet, VariantCalls
124

135

146
# noinspection SqlNoDataSourceInspection,SqlDialectInspection
@@ -19,9 +11,9 @@ def test_stanford_ex1(self):
1911

2012
def test_stanford_ex2(self):
2113
rule = ASI2("SELECT ATLEAST 2 FROM (41L, 67N, 70R, 210W, 215F, 219Q)")
22-
m1 = Mutation('41L')
23-
m2 = Mutation('67N')
24-
m3 = Mutation('70N')
14+
m1 = MutationSet('41L')
15+
m2 = MutationSet('67N')
16+
m3 = MutationSet('70N')
2517
self.assertTrue(rule([m1, m2]))
2618
self.assertFalse(rule([m1, m3]))
2719

@@ -58,41 +50,41 @@ class TestRuleSemantics(unittest.TestCase):
5850

5951
def test_score_from(self):
6052
rule = ASI2("SCORE FROM ( 100G => 10, 101D => 20 )")
61-
self.assertEqual(rule(mus("100G 102G")), 10)
53+
self.assertEqual(rule(VariantCalls("100G 102G")), 10)
6254

6355
def test_score_from_max(self):
6456
rule = ASI2("SCORE FROM (MAX (100G => 10, 101D => 20, 102D => 30))")
65-
self.assertEqual(rule(mus("100G 101D")), 20)
66-
self.assertEqual(rule(mus("10G 11D")), False)
57+
self.assertEqual(rule(VariantCalls("100G 101D")), 20)
58+
self.assertEqual(rule(VariantCalls("10G 11D")), False)
6759

6860
def test_score_from_max_neg(self):
6961
rule = ASI2("SCORE FROM (MAX (100G => -10, 101D => -20, 102D => 30))")
70-
self.assertEqual(rule(mus("100G 101D")), -10)
71-
self.assertEqual(rule(mus("10G 11D")), False)
62+
self.assertEqual(rule(VariantCalls("100G 101D")), -10)
63+
self.assertEqual(rule(VariantCalls("10G 11D")), False)
7264

7365
def test_bool_and(self):
7466
rule = ASI2("1G AND (2T AND 7Y)")
75-
self.assertEqual(rule(mus("2T 7Y 1G")), True)
76-
self.assertEqual(rule(mus("2T 1Y 1G")), False)
77-
self.assertEqual(rule(mus("7Y 1G 2T")), True)
67+
self.assertEqual(rule(VariantCalls("2T 7Y 1G")), True)
68+
self.assertEqual(rule(VariantCalls("2T 3Y 1G")), False)
69+
self.assertEqual(rule(VariantCalls("7Y 1G 2T")), True)
7870
self.assertEqual(rule([]), False)
7971

8072
def test_bool_or(self):
8173
rule = ASI2("1G OR (2T OR 7Y)")
82-
self.assertTrue(rule(mus("2T")))
83-
self.assertFalse(rule(mus("3T")))
84-
self.assertTrue(rule(mus("1G")))
74+
self.assertTrue(rule(VariantCalls("2T")))
75+
self.assertFalse(rule(VariantCalls("3T")))
76+
self.assertTrue(rule(VariantCalls("1G")))
8577
self.assertFalse(rule([]))
8678

8779
def test_select_from_atleast(self):
8880
rule = ASI2("SELECT ATLEAST 2 FROM (2T, 7Y, 3G)")
89-
self.assertTrue(rule(mus("2T 7Y 1G")))
90-
self.assertFalse(rule(mus("2T 0Y 0G")))
91-
self.assertTrue(rule(mus("3G 9Y 2T")))
81+
self.assertTrue(rule(VariantCalls("2T 7Y 1G")))
82+
self.assertFalse(rule(VariantCalls("2T 4Y 5G")))
83+
self.assertTrue(rule(VariantCalls("3G 9Y 2T")))
9284

9385
def test_score_from_exactly(self):
9486
rule = ASI2("SELECT EXACTLY 1 FROM (2T, 7Y)")
95-
score = rule(mus("2T 7Y 1G"))
87+
score = rule(VariantCalls("2T 7Y 1G"))
9688
self.assertEqual(0, score)
9789

9890

@@ -122,10 +114,10 @@ def test_chained_and(self):
122114
215FY) => 10), MAX ((41L AND 215ACDEILNSV) => 5, (41L AND 215FY) =>
123115
15))
124116
""")
125-
self.assertEqual(rule(mus("40F 41L 210W 215Y")), 65)
126-
self.assertEqual(rule(mus("41L 210W 215F")), 60)
127-
self.assertEqual(rule(mus("40F 210W 215Y")), 25)
128-
self.assertEqual(rule(mus("40F 67G 215Y")), 15)
117+
self.assertEqual(rule(VariantCalls("40F 41L 210W 215Y")), 65)
118+
self.assertEqual(rule(VariantCalls("41L 210W 215F")), 60)
119+
self.assertEqual(rule(VariantCalls("40F 210W 215Y")), 25)
120+
self.assertEqual(rule(VariantCalls("40F 67G 215Y")), 15)
129121

130122

131123
class TestAsiMutations(unittest.TestCase):

0 commit comments

Comments
 (0)