From 24ba63907539eaf05dca26e9f1cc7c78a918654c Mon Sep 17 00:00:00 2001 From: pbashyal-nmdp Date: Wed, 16 Aug 2023 09:53:03 -0500 Subject: [PATCH 1/2] Add `is_null` method to ARD --- pyard/ard.py | 9 +++++++++ tests/test_pyard.py | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/pyard/ard.py b/pyard/ard.py index c7e2ce1..49b16dd 100644 --- a/pyard/ard.py +++ b/pyard/ard.py @@ -529,6 +529,15 @@ def is_shortnull(self, allele): """ return allele in self.shortnulls and self._config["reduce_shortnull"] + def is_null(self, allele): + """ + Check if allele is a null allele. + + @param allele: Allele to check for null + @return: boolean indicating whether allele is null or not + """ + return allele.endswith("N") and not self.is_mac(allele) + def is_exp_allele(self, allele): """ Test if allele is valid as a shortening (WHO rules) diff --git a/tests/test_pyard.py b/tests/test_pyard.py index d7adaee..13821fb 100644 --- a/tests/test_pyard.py +++ b/tests/test_pyard.py @@ -186,3 +186,17 @@ def test_cache_info(self): another_ard._redux_allele.cache_info().maxsize, higher_cache_size ) self.assertEqual(another_ard.redux.cache_info().maxsize, higher_cache_size) + + def test_is_null(self): + # a null allele + allele = "A*01:01N" + self.assertTrue(self.ard.is_null(allele)) + # not null allele + allele = "A*01:01" + self.assertFalse(self.ard.is_null(allele)) + # MACs ending with N shouldn't be called as Nulls + allele = "A*01:MN" + self.assertFalse(self.ard.is_null(allele)) + # MACs shouldn't be called as Nulls + allele = "A*01:AB" + self.assertFalse(self.ard.is_null(allele)) From 606404b5b000f27c7788dafee38da8edf09e0397 Mon Sep 17 00:00:00 2001 From: pbashyal-nmdp Date: Wed, 16 Aug 2023 15:55:08 -0500 Subject: [PATCH 2/2] Added msg to test validation --- tests/test_pyard.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/test_pyard.py b/tests/test_pyard.py index 13821fb..0dcf87a 100644 --- a/tests/test_pyard.py +++ b/tests/test_pyard.py @@ -190,13 +190,18 @@ def test_cache_info(self): def test_is_null(self): # a null allele allele = "A*01:01N" - self.assertTrue(self.ard.is_null(allele)) + self.assertTrue(self.ard.is_null(allele), msg="A Null Allele") # not null allele allele = "A*01:01" - self.assertFalse(self.ard.is_null(allele)) + self.assertFalse(self.ard.is_null(allele), msg="not null allele") # MACs ending with N shouldn't be called as Nulls allele = "A*01:MN" - self.assertFalse(self.ard.is_null(allele)) + self.assertFalse( + self.ard.is_null(allele), + msg="MACs ending with N shouldn't be called as Nulls", + ) # MACs shouldn't be called as Nulls allele = "A*01:AB" - self.assertFalse(self.ard.is_null(allele)) + self.assertFalse( + self.ard.is_null(allele), msg="MACs shouldn't be called as Nulls" + )