|
79 | 79 | import sys |
80 | 80 | import collections |
81 | 81 | import os |
| 82 | +import itertools |
82 | 83 |
|
83 | 84 | # required to make iteritems python2 and python3 compatible |
84 | 85 | from builtins import dict |
@@ -182,7 +183,7 @@ def main(argv=None): |
182 | 183 | if options.tsv: |
183 | 184 | mapping_outfile = U.openFile(options.tsv, "w") |
184 | 185 | 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", |
186 | 187 | "final_umi", "final_umi_count", "unique_id"])) |
187 | 188 |
|
188 | 189 | nInput, nOutput, unique_id, input_reads, output_reads = 0, 0, 0, 0, 0 |
@@ -253,22 +254,32 @@ def main(argv=None): |
253 | 254 |
|
254 | 255 | for umi in umi_group: |
255 | 256 | 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): |
257 | 259 | if outfile: |
258 | 260 | # Add the 'UG' tag to the read |
259 | 261 | read.tags += [('UG', unique_id)] |
260 | 262 | read.tags += [(options.umi_group_tag, top_umi)] |
261 | 263 | 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) |
262 | 268 |
|
263 | 269 | if options.tsv: |
264 | 270 | if options.per_gene: |
| 271 | + # XXX: What if the two reads disagree? |
265 | 272 | gene = read.get_tag(gene_tag) |
266 | 273 | else: |
267 | 274 | 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 "" |
268 | 279 | mapping_outfile.write("%s\n" % "\t".join(map(str, ( |
269 | 280 | read.query_name, read.reference_name, |
270 | | - umi_methods.get_read_position( |
271 | | - read, options.soft_clip_threshold)[1], |
| 281 | + pos, |
| 282 | + pos2, |
272 | 283 | gene, |
273 | 284 | umi.decode(), |
274 | 285 | counts[umi], |
|
0 commit comments