Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple filters #38

Merged
merged 7 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
1.3.5

1.3.6
14 changes: 7 additions & 7 deletions gumpy/variantfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ 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 = str(record.filter.items()[0][0])
self.filter = [str(x) for x in record.filter.keys()]
self.is_filter_pass = (
True if record.filter.items()[0][0] == "PASS" else False
True if len(self.filter) == 1 and self.filter == ["PASS"] else False
)

# Get the info field
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -561,7 +561,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"
Expand Down
2 changes: 1 addition & 1 deletion tests/test-cases/TEST-DNA-2.vcf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
##contig=<ID=TEST_DNA,length=99>
#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
Expand Down
2 changes: 1 addition & 1 deletion tests/test-cases/TEST-DNA.vcf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
##contig=<ID=TEST_DNA,length=99>
#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
Expand Down
32 changes: 16 additions & 16 deletions tests/unit/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_instantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading