Skip to content

Commit

Permalink
Fix for multiple reported alignments from bwa
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlees committed Sep 9, 2019
1 parent 565c363 commit bfb40bf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pyseer/kmer_mapping/bwa.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def bwa_iter(reference, fasta, algorithm):
raise ValueError(algorithm)

bwa_p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True, universal_newlines=True)
prev_record = None

# read sam file from bwa mem
if algorithm == "mem":
for sam_line in bwa_p.stdout:
Expand All @@ -51,6 +53,16 @@ def bwa_iter(reference, fasta, algorithm):
if sam_fields[0][0] == "@":
continue

# ignore supplementary alignments
if int(sam_fields[1]) & 2048 == 2048:
continue

if sam_fields[0] == prev_record:
sys.stderr.write("WARNING: Found same k-mer line multiple times in SAM file")
continue
else:
prev_record = sam_fields[0]

positions = []
if int(sam_fields[1]) & 4 == 4:
mapped = False
Expand Down

0 comments on commit bfb40bf

Please sign in to comment.