Skip to content

Commit

Permalink
Improvement of consistency in selection of read2 alignments for outpu…
Browse files Browse the repository at this point in the history
…t with dedup and --paired as well as avoiding large memory footprint (CGATOxford#347).
  • Loading branch information
christianbioinf committed Jul 8, 2019
1 parent 26f71dc commit 78f457b
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions umi_tools/sam_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@ def __init__(self, infile, outfile, tags=False):
self.infile = infile
self.outfile = outfile
self.read1s = set()
self.read1s_done = set()
self.chrom = None

def write(self, read, unique_id=None, umi=None, unmapped=False):
Expand All @@ -590,9 +589,8 @@ def write(self, read, unique_id=None, umi=None, unmapped=False):
self.write_mates()
self.chrom = read.reference_name

key = read.query_name, read.next_reference_name, read.next_reference_start
if key not in self.read1s_done:
self.read1s.add(key)
key = read.query_name, read.next_reference_name, read.next_reference_start, read.reference_name, read.reference_start
self.read1s.add(key)

self.outfile.write(read)

Expand All @@ -607,11 +605,10 @@ def write_mates(self):
if any((read.is_unmapped, read.mate_is_unmapped, read.is_read1)):
continue

key = read.query_name, read.reference_name, read.reference_start
key = read.query_name, read.reference_name, read.reference_start, read.next_reference_name, read.next_reference_start
if key in self.read1s:
self.outfile.write(read)
self.read1s.remove(key)
self.read1s_done.add(key)

U.debug("%i mates remaining" % len(self.read1s))

Expand All @@ -629,7 +626,7 @@ def close(self):
if any((read.is_unmapped, read.mate_is_unmapped, read.is_read1)):
continue

key = read.query_name, read.reference_name, read.reference_start
key = read.query_name, read.reference_name, read.reference_start, read.next_reference_name, read.next_reference_start
if key in self.read1s:
self.outfile.write(read)
self.read1s.remove(key)
Expand Down

0 comments on commit 78f457b

Please sign in to comment.