diff --git a/umi_tools/sam_methods.py b/umi_tools/sam_methods.py index 724e1f96..e040d00d 100644 --- a/umi_tools/sam_methods.py +++ b/umi_tools/sam_methods.py @@ -589,7 +589,7 @@ 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 + 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) @@ -605,7 +605,7 @@ 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) @@ -623,10 +623,10 @@ def close(self): found = 0 for read in self.infile.fetch(until_eof=True, multiple_iterators=True): - if read.is_unmapped: + 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)