Skip to content

Instantly share code, notes, and snippets.

@walterst
Created November 5, 2013 21:21
Show Gist options
  • Save walterst/7326543 to your computer and use it in GitHub Desktop.
Save walterst/7326543 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from sys import argv
from itertools import izip
from cogent.parse.fastq import MinimalFastqParser
""" Usage
python merge_bcs_reads.py X Y Z
X: barcodes fastq file
Y: reads fastq file
Z: merged output file
Will write the barcodes at the beginning of the output file
"""
bcs = open(argv[1], "U")
reads = open(argv[2], "U")
combined_out = open(argv[3], "w")
header_index = 0
sequence_index = 1
quality_index = 2
for bc_data,read_data in izip(MinimalFastqParser(bcs,strict=False),
MinimalFastqParser(reads,strict=False)):
curr_label = bc_data[header_index].strip()
bc_read = bc_data[sequence_index]
bc_qual = bc_data[quality_index]
seq_read = read_data[sequence_index]
seq_qual = read_data[quality_index]
combined_out.write("@%s\n" % curr_label)
combined_out.write("%s\n" % (bc_read + seq_read))
combined_out.write("+\n")
combined_out.write("%s\n" % (bc_qual + seq_qual))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment