#!/usr/bin/env python 

################################################################################
### COPYRIGHT ##################################################################

# New York Genome Center

# SOFTWARE COPYRIGHT NOTICE AGREEMENT
# This software and its documentation are copyright (2014) by the New York
# Genome Center. All rights are reserved. This software is supplied without
# any warranty or guaranteed support whatsoever. The New York Genome Center
# cannot be responsible for its use, misuse, or functionality.

# Version: 0.2
# Author: Andre Corvelo

################################################################# /COPYRIGHT ###
################################################################################



################################################################################
### MODULES ####################################################################

from optparse import OptionParser
import sys
from itertools import islice


################################################################### /MODULES ###
################################################################################



################################################################################
### FUNCTIONS ##################################################################

################################################################# /FUNCTIONS ###
################################################################################



################################################################################
### ARGUMENTS,OPTIONS ##########################################################

parser = OptionParser(usage="\n%prog [options]", version="%prog v0.2")

parser.add_option(
	"-i",
	metavar = "FILE",
	type = "string",
	dest = "input_file",
	default = 'stdin',
	help = "Input FASTQ file (default = 'stdin')"
	)

(opt, args) = parser.parse_args()

######################################################### /ARGUMENTS,OPTIONS ###
################################################################################



################################################################################
### CONSTANTS ##################################################################

################################################################# /CONSTANTS ###
################################################################################



################################################################################
### MAIN #######################################################################

if __name__ == "__main__":
	if opt.input_file != 'stdin':
		fq = open(opt.input_file, 'r')
	else:
		fq = sys.stdin

	r0 = None
	rid0 = None
	while True:
		r = [line for line in islice(fq, 4)]
		if not r:
			break
		rid = r[0].replace(' ', '/').split('/')[0]
		if rid == rid0:
			sys.stdout.write(''.join(r0 + r))
		else:
			rid0 = rid
			r0 = r

	if opt.input_file != 'stdin':
		fq.close()
	
###################################################################### /MAIN ###
################################################################################
