Skip to content

Commit 4cce2bb

Browse files
committed
The "group" tool now reports the position of the 2nd mate of proper mate pairs
in a new column "position2". The uses the previously introduced mate pair support in bundle_iterator
1 parent 9ab1fd7 commit 4cce2bb

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

umi_tools/group.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
import sys
8080
import collections
8181
import os
82+
import itertools
8283

8384
# required to make iteritems python2 and python3 compatible
8485
from builtins import dict
@@ -182,7 +183,7 @@ def main(argv=None):
182183
if options.tsv:
183184
mapping_outfile = U.openFile(options.tsv, "w")
184185
mapping_outfile.write("%s\n" % "\t".join(
185-
["read_id", "contig", "position", "gene", "umi", "umi_count",
186+
["read_id", "contig", "position", "position2", "gene", "umi", "umi_count",
186187
"final_umi", "final_umi_count", "unique_id"]))
187188

188189
nInput, nOutput, unique_id, input_reads, output_reads = 0, 0, 0, 0, 0
@@ -253,22 +254,32 @@ def main(argv=None):
253254

254255
for umi in umi_group:
255256
reads = bundle[umi]['read']
256-
for read in reads:
257+
reads2 = bundle[umi]['read2'] if options.paired else [None]
258+
for read, read2 in itertools.izip(reads, reads2):
257259
if outfile:
258260
# Add the 'UG' tag to the read
259261
read.tags += [('UG', unique_id)]
260262
read.tags += [(options.umi_group_tag, top_umi)]
261263
outfile.write(read)
264+
if read2 is not None:
265+
read2.tags += [('UG', unique_id)]
266+
read2.tags += [(options.umi_group_tag, top_umi)]
267+
outfile.write(read2)
262268

263269
if options.tsv:
264270
if options.per_gene:
271+
# XXX: What if the two reads disagree?
265272
gene = read.get_tag(gene_tag)
266273
else:
267274
gene = "NA"
275+
pos = umi_methods.get_read_position(
276+
read, options.soft_clip_threshold)[1]
277+
pos2 = umi_methods.get_read_position(
278+
read2, options.soft_clip_threshold)[1] if read2 is not None else ""
268279
mapping_outfile.write("%s\n" % "\t".join(map(str, (
269280
read.query_name, read.reference_name,
270-
umi_methods.get_read_position(
271-
read, options.soft_clip_threshold)[1],
281+
pos,
282+
pos2,
272283
gene,
273284
umi.decode(),
274285
counts[umi],

0 commit comments

Comments
 (0)