Skip to content

Commit 3d17e97

Browse files
committed
ignore non-primary reads in target BAM when replacing reads
1 parent 32b3fae commit 3d17e97

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

bamsurgeon/replacereads.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,12 @@ def replaceReads(targetbam, donorbam, outputbam, nameprefix=None, excludefile=No
138138
recount = 0 # number of replaced reads
139139
used = {}
140140
prog = 0
141+
ignored_target = 0 # number of supplemental / secondary reads in original
141142

142143
for read in targetbam.fetch(until_eof=True):
144+
if read.is_secondary or read.is_supplementary:
145+
ignored_target += 1
146+
continue
143147

144148
prog += 1
145149
if progress and prog % 10000000 == 0:
@@ -192,6 +196,7 @@ def replaceReads(targetbam, donorbam, outputbam, nameprefix=None, excludefile=No
192196
sys.stdout.write("replaced " + str(recount) + " reads (" + str(excount) + " excluded )\n")
193197
sys.stdout.write("kept " + str(sum([len(v) for k,v in secondary.iteritems()])) + " secondary reads.\n")
194198
sys.stdout.write("kept " + str(sum([len(v) for k,v in supplementary.iteritems()])) + " supplementary reads.\n")
199+
sys.stdout.write("ignored %d non-primary reads in target BAM.\n" % ignored_target)
195200

196201
nadded = 0
197202
# dump the unused reads from the donor if requested with --all

0 commit comments

Comments
 (0)