Skip to content

Commit 4130c47

Browse files
authored
Push segmented virus fixes (#166)
1 parent 103f94b commit 4130c47

File tree

3 files changed

+40
-44
lines changed

3 files changed

+40
-44
lines changed

artic/make_depth_mask.py

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -143,51 +143,49 @@ def intervals_extract(iterable):
143143
def go(args):
144144

145145
# open the reference sequence and collect the sequence header and sequence length of the first record
146-
record = list(SeqIO.parse(args.reference, "fasta"))[0]
147-
seqID = record.id
148-
seqLength = len(record.seq)
146+
records = [x for x in SeqIO.parse(args.reference, "fasta")]
147+
intervals = []
149148

150-
# collect the depths from the pileup, replacing any depth<minDepth with 0
151-
try:
149+
for record in records:
150+
seqID = record.id
151+
seqLength = len(record.seq)
152+
153+
# collect the depths from the pileup, replacing any depth<minDepth with 0
152154
depths, rgDepths = collect_depths(
153155
args.bamfile,
154156
seqID,
155157
args.depth,
156158
args.ignore_deletions,
157159
args.warn_rg_coverage,
158160
)
159-
except Exception as e:
160-
print(e)
161-
raise SystemExit(1)
162-
163-
# check the number of positions in the reported depths matches the reference sequence
164-
if len(depths) != seqLength:
165-
print("pileup length did not match expected reference sequence length")
166-
167-
# print the readgroup depths to individual files if requested
168-
if args.store_rg_depths:
169-
170-
# rg is the readgroup and rgd is the depths per position for this readgroup
171-
for rg, rgd in rgDepths.items():
172-
fh = open(args.outfile + "." + rg + ".depths", "w")
173-
for pos, depth in enumerate(rgd):
174-
fh.write("%s\t%s\t%d\t%d\n" % (seqID, rg, pos, depth))
175-
fh.close()
176-
177-
# create a mask_vector that records reference positions where depth < minDepth
178-
mask_vector = []
179-
for pos, depth in enumerate(depths):
180-
if depth == 0:
181-
mask_vector.append(pos)
182-
183-
# get the intervals from the mask_vector
184-
intervals = list(intervals_extract(mask_vector))
185-
186-
# create the mask outfile
187-
maskfh = open(args.outfile, "w")
188-
for i in intervals:
189-
maskfh.write("%s\t%s\t%s\n" % (seqID, i[0] + 1, i[1] + 1))
190-
maskfh.close()
161+
162+
# check the number of positions in the reported depths matches the reference sequence
163+
if len(depths) != seqLength:
164+
print("pileup length did not match expected reference sequence length")
165+
166+
# print the readgroup depths to individual files if requested
167+
if args.store_rg_depths:
168+
# rg is the readgroup and rgd is the depths per position for this readgroup
169+
for rg, rgd in rgDepths.items():
170+
fh = open(args.outfile + "." + rg + ".depths", "a")
171+
for pos, depth in enumerate(rgd):
172+
fh.write("%s\t%s\t%d\t%d\n" % (seqID, rg, pos, depth))
173+
fh.close()
174+
175+
# create a mask_vector that records reference positions where depth < minDepth
176+
mask_vector = []
177+
for pos, depth in enumerate(depths):
178+
if depth == 0:
179+
mask_vector.append(pos)
180+
181+
# get the intervals from the mask_vector
182+
intervals = list(intervals_extract(mask_vector))
183+
184+
# create the mask outfile
185+
maskfh = open(args.outfile, "a")
186+
for i in intervals:
187+
maskfh.write("%s\t%s\t%s\n" % (seqID, i[0] + 1, i[1] + 1))
188+
maskfh.close()
191189

192190

193191
def main():

artic/minion.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,11 @@ def run(parser, args):
138138
cmds.append(f"samtools index {args.sample}.sorted.bam")
139139

140140
# 4) trim the alignments to the primer start sites and normalise the coverage to save time
141-
if args.normalise:
142-
normalise_string = f"--normalise {args.normalise}"
143-
else:
144-
normalise_string = ""
141+
normalise_string = f"--normalise {args.normalise}" if args.normalise else ""
145142

146-
if not args.allow_mismatched_primers:
147-
incorrect_pairs_string = "--remove-incorrect-pairs"
143+
incorrect_pairs_string = (
144+
"--remove-incorrect-pairs" if not args.allow_mismatched_primers else ""
145+
)
148146

149147
cmds.append(
150148
f"align_trim {normalise_string} {bed} --primer-match-threshold {args.primer_match_threshold} {incorrect_pairs_string} --min-mapq {args.min_mapq} --report {args.sample}.alignreport.csv < {args.sample}.sorted.bam > {args.sample}.trimmed.rg.sam"

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = artic
3-
version = 1.6.5
3+
version = 1.7.0
44
author = Nick Loman
55
author_email = [email protected]
66
maintainer = Sam Wilkinson

0 commit comments

Comments
 (0)