Skip to content

Commit 09d2ba6

Browse files
committed
add option to keep tags, default to dropping existing comments
1 parent de803e1 commit 09d2ba6

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

harpy/bin/inline_to_haplotag.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
exit_on_error = False
1717
)
1818
parser.add_argument("-p", "--prefix", required = True, type = str, help = "Prefix for outfile files (e.g. <prefix>.R1.fq.gz)")
19+
parser.add_argument("-k", "--keep-tags", action='store_true', help = "Keep the existing tags/comments in the FASTQ header")
1920
parser.add_argument("-b", "--barcodes", required = True, type=str, help="Barcode conversion key file with format: ATCG<tab>ACBD")
2021
parser.add_argument("forward", type = str, help = "Forward reads of paired-end FASTQ file pair")
2122
parser.add_argument("reverse", type = str, help = "Reverse reads of paired-end FASTQ file pair")
@@ -58,20 +59,29 @@ def process_record(fw_rec, rv_rec, barcode_database, bc_len):
5859
if fw_rec and len(fw_rec.sequence) > bc_len:
5960
bc_inline = fw_rec.sequence[:bc_len]
6061
bc_hap = get_value_by_key(barcode_database, bc_inline)
61-
fw_rec.comment = fw_rec.comment.split()[0] + f"\tOX:Z:{bc_inline}\tBX:Z:{bc_hap}"
62+
if args.keep_tags:
63+
fw_rec.comment += f"\tOX:Z:{bc_inline}\tBX:Z:{bc_hap}"
64+
else:
65+
fw_rec.comment = f"OX:Z:{bc_inline}\tBX:Z:{bc_hap}"
6266
fw_rec.sequence = fw_rec.sequence[bc_len:]
6367
fw_rec.quality = fw_rec.quality[bc_len:]
6468
_new_fw = str(fw_rec) + "\n"
6569
if rv_rec:
66-
rv_rec.comment = rv_rec.comment.split()[0] + f"\tOX:Z:{bc_inline}\tBX:Z:{bc_hap}"
70+
if args.keep_tags:
71+
rv_rec.comment += f"\tOX:Z:{bc_inline}\tBX:Z:{bc_hap}"
72+
else:
73+
rv_rec.comment = f"OX:Z:{bc_inline}\tBX:Z:{bc_hap}"
6774
_new_rv = str(rv_rec) + "\n"
6875
else:
6976
_new_rv = None
7077
else:
7178
_new_fw = None
7279
# no forward read, therefore no barcode to search for
7380
if rv_rec:
74-
rv_rec.comment = rv_rec.comment.split()[0] + "\tBX:Z:A00C00B00D00"
81+
if args.keep_tags:
82+
rv_rec.comment += "\tBX:Z:A00C00B00D00"
83+
else:
84+
rv_rec.comment = "BX:Z:A00C00B00D00"
7585
_new_rv = str(rv_rec) + "\n"
7686
else:
7787
_new_rv = None

0 commit comments

Comments
 (0)