Skip to content

Commit ada384d

Browse files
committed
Update vcf filtering and clair3 command
1 parent 40ec250 commit ada384d

File tree

3 files changed

+36
-46
lines changed

3 files changed

+36
-46
lines changed

artic/minion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def run(parser, args):
158158
cmds.append(f"samtools index {args.sample}.{p}.trimmed.rg.sorted.bam")
159159

160160
cmds.append(
161-
f"run_clair3.sh --enable_long_indel --chunk_size=10000 --no_phasing_for_fa --bam_fn='{args.sample}.{p}.trimmed.rg.sorted.bam' --ref_fn='{ref}' --output='{args.sample}_rg_{p}' --threads='{args.threads}' --platform='ont' --model_path='{full_model_path}' --include_all_ctgs --min_coverage='{args.min_depth}'"
161+
f"run_clair3.sh --enable_long_indel --chunk_size=10000 --haploid_precise --no_phasing_for_fa --bam_fn='{args.sample}.{p}.trimmed.rg.sorted.bam' --ref_fn='{ref}' --output='{args.sample}_rg_{p}' --threads='{args.threads}' --platform='ont' --model_path='{full_model_path}' --include_all_ctgs --min_coverage='{args.min_depth}'"
162162
)
163163

164164
cmds.append(
@@ -183,7 +183,7 @@ def run(parser, args):
183183
fs_str = "--no-frameshifts" if args.no_frameshifts else ""
184184
indel_str = "--no-indels" if args.no_indels else ""
185185
cmds.append(
186-
f"artic_vcf_filter {fs_str} {indel_str} --min-variant-quality {args.min_variant_quality} --min-depth {args.min_depth} {pre_filter_vcf}.gz {args.sample}.pass.vcf {args.sample}.fail.vcf"
186+
f"artic_vcf_filter {fs_str} {indel_str} --min-depth {args.min_depth} {pre_filter_vcf}.gz {args.sample}.pass.vcf {args.sample}.fail.vcf"
187187
)
188188

189189
# 9) get the depth of coverage for each readgroup, create a coverage mask and plots, and add failed variants to the coverage mask (artic_mask must be run before bcftools consensus)

artic/pipeline.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,6 @@ def init_pipeline_parser():
104104
default=20,
105105
help="Minimum depth required to call a variant (default: %(default)d)",
106106
)
107-
parser_minion.add_argument(
108-
"--min-variant-quality",
109-
type=int,
110-
default=15,
111-
help="Minimum quality required to call a variant (default: %(default)d)",
112-
)
113107
parser_minion.add_argument(
114108
"--threads",
115109
type=int,

artic/vcf_filter.py

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,62 +16,59 @@ def in_frame(v):
1616
return False
1717

1818

19-
class NanoporeFilter:
20-
def __init__(self, no_frameshifts):
19+
class Clair3Filter:
20+
def __init__(self, no_frameshifts, min_depth):
2121
self.no_frameshifts = no_frameshifts
22-
pass
22+
self.min_depth = min_depth
23+
self.min_variant_quality = 10
2324

2425
def check_filter(self, v):
25-
total_reads = float(v.INFO["TotalReads"])
2626
qual = v.QUAL
27-
# strandbias = float(v.INFO["StrandFisherTest"])
2827

29-
if qual / total_reads < 3:
28+
if qual < self.min_variant_quality:
3029
return False
3130

3231
if self.no_frameshifts and not in_frame(v):
3332
return False
3433

35-
if v.is_indel:
36-
strand_fraction_by_strand = v.INFO["SupportFractionByStrand"]
37-
if float(strand_fraction_by_strand[0]) < 0.5:
38-
return False
39-
40-
if float(strand_fraction_by_strand[1]) < 0.5:
41-
return False
34+
try:
35+
# We don't really care about the depth here, just skip it if it isn't there
36+
depth = v.INFO["DP"]
37+
except KeyError:
38+
depth = v.format("DP")[0][0]
4239

43-
if total_reads < 20:
40+
if depth < self.min_depth:
4441
return False
4542

4643
return True
4744

4845

49-
class MedakaFilter:
50-
def __init__(self, no_frameshifts, min_depth, min_variant_quality):
51-
self.no_frameshifts = no_frameshifts
52-
self.min_depth = min_depth
53-
self.min_variant_quality = min_variant_quality
46+
# class MedakaFilter:
47+
# def __init__(self, no_frameshifts, min_depth):
48+
# self.no_frameshifts = no_frameshifts
49+
# self.min_depth = min_depth
50+
# self.min_variant_quality = 20
5451

55-
def check_filter(self, v, min_depth):
56-
try:
57-
# We don't really care about the depth here, just skip it if it isn't there
58-
depth = v.INFO["DP"]
59-
except KeyError:
60-
depth = v.format("DP")[0][0]
52+
# def check_filter(self, v, min_depth):
53+
# try:
54+
# # We don't really care about the depth here, just skip it if it isn't there
55+
# depth = v.INFO["DP"]
56+
# except KeyError:
57+
# depth = v.format("DP")[0][0]
6158

62-
if depth < min_depth:
63-
return False
59+
# if depth < min_depth:
60+
# return False
6461

65-
if self.no_frameshifts and not in_frame(v):
66-
return False
62+
# if self.no_frameshifts and not in_frame(v):
63+
# return False
6764

68-
if v.num_het:
69-
return False
65+
# if v.num_het:
66+
# return False
7067

71-
if v.QUAL < self.min_variant_quality:
72-
return False
68+
# if v.QUAL < self.min_variant_quality:
69+
# return False
7370

74-
return True
71+
# return True
7572

7673

7774
def go(args):
@@ -80,7 +77,7 @@ def go(args):
8077
vcf_writer.write_header()
8178
vcf_writer_filtered = Writer(args.output_fail_vcf, vcf_reader, "w")
8279
vcf_writer_filtered.write_header()
83-
filter = MedakaFilter(args.no_frameshifts)
80+
filter = Clair3Filter(args.no_frameshifts, args.min_depth)
8481

8582
variants = [v for v in vcf_reader]
8683

@@ -101,15 +98,15 @@ def go(args):
10198
pass
10299

103100
# now apply the filter to send variants to PASS or FAIL file
104-
if filter.check_filter(v, args.min_depth):
101+
if filter.check_filter(v):
105102
vcf_writer.write_record(v)
106103
else:
107104
variant_passes = False
108105

109106
indx = "%s-%s" % (v.CHROM, v.POS)
110107
if len(group_variants[indx]) > 1:
111108
for check_variant in group_variants[indx]:
112-
if filter.check_filter(check_variant, args.min_depth):
109+
if filter.check_filter(check_variant):
113110
variant_passes = True
114111

115112
if not variant_passes:
@@ -124,7 +121,6 @@ def main():
124121

125122
parser = argparse.ArgumentParser()
126123
parser.add_argument("--no-frameshifts", action="store_true")
127-
parser.add_argument("--min-variant-quality", type=int)
128124
parser.add_argument("--min-depth", type=int)
129125
parser.add_argument("inputvcf")
130126
parser.add_argument("output_pass_vcf")

0 commit comments

Comments
 (0)