From 582e0654675d0be5e6c803b85865d08cbec629c4 Mon Sep 17 00:00:00 2001 From: JeremyWesthead Date: Tue, 23 Jul 2024 22:39:09 +0100 Subject: [PATCH 1/6] fix: multiple filter values + only allow nulls on exclusively MIN_FRS --- gumpy/variantfile.py | 10 +++++----- tests/test-cases/TEST-DNA-2.vcf | 2 +- tests/test-cases/TEST-DNA.vcf | 2 +- tests/unit/test_functions.py | 32 ++++++++++++++++---------------- tests/unit/test_instantiation.py | 4 ++-- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/gumpy/variantfile.py b/gumpy/variantfile.py index 8a2b595..34bea53 100644 --- a/gumpy/variantfile.py +++ b/gumpy/variantfile.py @@ -85,9 +85,9 @@ def __init__( self.filter = None self.is_filter_pass = False else: - self.filter = str(record.filter.items()[0][0]) + self.filter = list(record.filter.keys()) self.is_filter_pass = ( - True if record.filter.items()[0][0] == "PASS" else False + True if len(self.filter) == 1 and record.filter.items()[0][0] == "PASS" else False ) # Get the info field @@ -157,8 +157,8 @@ def __init__( self.is_alt = False self.is_reference = False - if self.is_null: - # Override filter fails on nulls to enforce that they are detected + if self.is_null and self.filter == ["MIN_FRS"]: + # Override MIN_FRS filter fails on nulls to enforce that they are detected self.is_filter_pass = True def __repr__(self) -> str: @@ -178,7 +178,7 @@ def __repr__(self) -> str: if self.filter is None: s += ".\t" else: - s += self.filter + "\t" + s += ",".join(self.filter) + "\t" for val in self.values.keys(): if val == "POS": continue diff --git a/tests/test-cases/TEST-DNA-2.vcf b/tests/test-cases/TEST-DNA-2.vcf index a9fe325..488f5d4 100644 --- a/tests/test-cases/TEST-DNA-2.vcf +++ b/tests/test-cases/TEST-DNA-2.vcf @@ -10,7 +10,7 @@ ##contig= #CHROM POS ID REF ALT QUAL FILTER INFO FORMAT 03.vcf TEST_DNA 2 . A G . PASS KMER=15 GT:DP:COV:GT_CONF ./.:2:1,1:2.05 -TEST_DNA 4 . A G,T . MIN_GT KMER=15 GT:DP:COV:GT_CONF ./.:4:1,2,2:3.77 +TEST_DNA 4 . A G,T . MIN_FRS KMER=15 GT:DP:COV:GT_CONF ./.:4:1,2,2:3.77 TEST_DNA 6 . AAA GGT,GTA,ATA . PASS KMER=15 GT:DP:COV:GT_CONF ./.:4:1,1,1,1:2.76 TEST_DNA 12 . C T . PASS KMER=15 GT:DP:COV:GT_CONF 1/1:50:0,50:200.58 TEST_DNA 14 . C T,G . PASS KMER=15 GT:DP:COV:GT_CONF 2/2:45:0,2,43:155.58 diff --git a/tests/test-cases/TEST-DNA.vcf b/tests/test-cases/TEST-DNA.vcf index fa9c232..7a8d1a0 100644 --- a/tests/test-cases/TEST-DNA.vcf +++ b/tests/test-cases/TEST-DNA.vcf @@ -10,7 +10,7 @@ ##contig= #CHROM POS ID REF ALT QUAL FILTER INFO FORMAT 03.vcf TEST_DNA 2 . A G . PASS KMER=15 GT:DP:COV:GT_CONF ./.:2:1,1:2.05 -TEST_DNA 4 . A G,T . MIN_GT KMER=15 GT:DP:COV:GT_CONF ./.:4:1,2,1:3.77 +TEST_DNA 4 . A G,T . MIN_FRS KMER=15 GT:DP:COV:GT_CONF ./.:4:1,2,1:3.77 TEST_DNA 6 . AAA GGT,GTA,ATA . PASS KMER=15 GT:DP:COV:GT_CONF ./.:4:1,1,1,1:2.76 TEST_DNA 12 . C T . PASS KMER=15 GT:DP:COV:GT_CONF 1/1:50:0,50:200.58 TEST_DNA 14 . C T,G . PASS KMER=15 GT:DP:COV:GT_CONF 2/2:45:0,2,43:155.58 diff --git a/tests/unit/test_functions.py b/tests/unit/test_functions.py index 92b5ec0..6415e55 100644 --- a/tests/unit/test_functions.py +++ b/tests/unit/test_functions.py @@ -1407,22 +1407,22 @@ def test_vcf_to_df(): None, ], "FILTER": [ - "PASS", - "MIN_GT", - "PASS", - "PASS", - "PASS", - "PASS", - "PASS", - "PASS", - "PASS", - "PASS", - "PASS", - "PASS", - "PASS", - "PASS", - "PASS", - "PASS", + ["PASS"], + ["MIN_FRS"], + ["PASS"], + ["PASS"], + ["PASS"], + ["PASS"], + ["PASS"], + ["PASS"], + ["PASS"], + ["PASS"], + ["PASS"], + ["PASS"], + ["PASS"], + ["PASS"], + ["PASS"], + ["PASS"], ], "INFO": [ {"KMER": 15}, diff --git a/tests/unit/test_instantiation.py b/tests/unit/test_instantiation.py index 1765793..8b075db 100644 --- a/tests/unit/test_instantiation.py +++ b/tests/unit/test_instantiation.py @@ -2554,9 +2554,9 @@ def test_instanciate_vcf(): for i in range(15): if i == 1: - assert vcf.records[i].filter == "MIN_GT" + assert vcf.records[i].filter == ["MIN_FRS"] else: - assert vcf.records[i].filter == "PASS" + assert vcf.records[i].filter == ["PASS"] # GT gt = [record.values["GT"] for record in vcf.records] From 06ede918985f8d6d98a9adb6e68a454990a48e49 Mon Sep 17 00:00:00 2001 From: JeremyWesthead Date: Tue, 23 Jul 2024 22:39:16 +0100 Subject: [PATCH 2/6] style: appease pc --- gumpy/variantfile.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gumpy/variantfile.py b/gumpy/variantfile.py index 34bea53..c9466e3 100644 --- a/gumpy/variantfile.py +++ b/gumpy/variantfile.py @@ -87,7 +87,9 @@ def __init__( else: self.filter = list(record.filter.keys()) self.is_filter_pass = ( - True if len(self.filter) == 1 and record.filter.items()[0][0] == "PASS" else False + True + if len(self.filter) == 1 and record.filter.items()[0][0] == "PASS" + else False ) # Get the info field From d81ec757aeafd87379c958ff359624ee18e2a15f Mon Sep 17 00:00:00 2001 From: JeremyWesthead Date: Tue, 23 Jul 2024 22:44:52 +0100 Subject: [PATCH 3/6] style: appease mypy --- gumpy/variantfile.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gumpy/variantfile.py b/gumpy/variantfile.py index c9466e3..824aed1 100644 --- a/gumpy/variantfile.py +++ b/gumpy/variantfile.py @@ -80,12 +80,12 @@ def __init__( # Get the filter attribute value assert len(record.filter.items()) >= 0, "A record has more than 1 filter set!" - self.filter: str | None + self.filter: list[str] | None if len(record.filter.items()) == 0: self.filter = None self.is_filter_pass = False else: - self.filter = list(record.filter.keys()) + self.filter = [str(x) for x in record.filter.keys()] self.is_filter_pass = ( True if len(self.filter) == 1 and record.filter.items()[0][0] == "PASS" @@ -563,7 +563,7 @@ def __find_calls(self): not record.is_filter_pass ): # We only want to allow these through if the filter fail is MIN_FRS - if record.filter == "MIN_FRS": + if record.filter == ["MIN_FRS"]: # Allow MIN_FRS variant = record.ref variant_type = "ref" From de3630dc9d50f94b3e613c0595f37420d9b0cf82 Mon Sep 17 00:00:00 2001 From: JeremyWesthead Date: Tue, 23 Jul 2024 22:46:47 +0100 Subject: [PATCH 4/6] fix: compare to filter instead of record --- gumpy/variantfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gumpy/variantfile.py b/gumpy/variantfile.py index 824aed1..314dc6a 100644 --- a/gumpy/variantfile.py +++ b/gumpy/variantfile.py @@ -88,7 +88,7 @@ def __init__( self.filter = [str(x) for x in record.filter.keys()] self.is_filter_pass = ( True - if len(self.filter) == 1 and record.filter.items()[0][0] == "PASS" + if len(self.filter) == 1 and self.filter == ["PASS"] else False ) From 09bec387cd4dc1f117cdf509bc39c49baba61fcc Mon Sep 17 00:00:00 2001 From: JeremyWesthead Date: Tue, 23 Jul 2024 22:46:49 +0100 Subject: [PATCH 5/6] style: appease pc --- gumpy/variantfile.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gumpy/variantfile.py b/gumpy/variantfile.py index 314dc6a..a6773be 100644 --- a/gumpy/variantfile.py +++ b/gumpy/variantfile.py @@ -87,9 +87,7 @@ def __init__( else: self.filter = [str(x) for x in record.filter.keys()] self.is_filter_pass = ( - True - if len(self.filter) == 1 and self.filter == ["PASS"] - else False + True if len(self.filter) == 1 and self.filter == ["PASS"] else False ) # Get the info field From 6a9c22242773f6cd8afe4779f851c26471ac2da7 Mon Sep 17 00:00:00 2001 From: JeremyWesthead Date: Tue, 23 Jul 2024 22:50:24 +0100 Subject: [PATCH 6/6] bump: VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index e87b0da..4ca9206 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -1.3.4 +1.3.6