Minor modification to the above script, to allow for the case where @ is the first character on the quality line:
import sys
inFile = open(sys.argv[1],'rU')
header = ''
data = ''
outFile = {}
for i,line in enumerate(inFile):
if (line[0] == "@" and i % 4 == 0):
if header != '':
barcode = header.split('#')[-1].split('/')[0]
if not outFile.has_key(barcode):
outFile[barcode] = open(barcode + ".fastq",'a')
outFile[barcode].write(header + "\n" + data)
header = line.strip()
data = ''
else:
data += line
barcode = header.split('#')[-1].split('/')[0]
if not outFile.has_key(barcode):
outFile[barcode] = open(barcode + ".fastq",'a')
outFile[barcode].write(header + "\n" + data)
Are the barcodes and read names delimited by something? It looks like the "_" character separates the barcoding and read names?
The barcode in the above mentioned example is AGTTCC, always after the number sign (#) and before the slash, although in some other datasets it comes as the six last characters of the identifier line