##################################
#                                #
# Last modified 09/04/2013       # 
#                                #
# Georgi Marinov                 #
#                                # 
##################################

import sys
import os

try:
	import psyco
	psyco.full()
except:
	pass

def run():

    if len(sys.argv) < 1:
        print 'usage: python %s <inputfilename>' % sys.argv[0]
        print '\tUse - to specify standard input, the script will print to stdout by default'
        print '\tThe script can read compressed files as long as they have the correct suffix - .bz2 or .gz'
        print '\tThe script will take a FASTQ file that has the two ends mixed and will resort them properly into two separate FASTQ files for each end'
        sys.exit(1)

    inputfilename = sys.argv[1]

    doStdIn = False
    if inputfilename != '-':
        if inputfilename.endswith('.bz2'):
            cmd = 'bzip2 -cd ' + inputfilename
        elif inputfilename.endswith('.gz'):
            cmd = 'gunzip -c ' + inputfilename
        else:
            cmd = 'cat ' + inputfilename
        p = os.popen(cmd, "r")
    else:
        doStdIn = True

    line = 'line'

    i=1
    while line != '':
        if doStdIn:
            line = sys.stdin.readline()
        else:
            line = p.readline()
        if line.strip() == '--':
            continue
        else:
            print line.strip()

run()

