##################################
#                                #
# Last modified 2019/08/11       # 
#                                #
# Georgi Marinov                 #
#                                # 
##################################

import sys
import os
import random
import string

def run():

    if len(sys.argv) < 2:
        print 'usage: python %s file outprefix' % sys.argv[0]
        sys.exit(1)

    input = sys.argv[1]
    outprefix = sys.argv[2]

    outfile1 = open(outprefix + '.pseudoRep1', 'w')
    outfile2 = open(outprefix + '.pseudoRep2', 'w')

    if input.endswith('.bz2'):
        cmd = 'bzip2 -cd ' + input
    elif input.endswith('.gz') or input.endswith('.bgz'):
        cmd = 'zcat ' + input
    else:
        cmd = 'cat ' + input
    p = os.popen(cmd, "r")
    line = 'line'
    while line != '':
        line = p.readline().strip()
        if line == '':
            break
        fields = line.strip().split('\t')
        if fields[2] == '*':
            continue
        if random.random() >= 0.5:
            outfile1.write(line.strip() + '\n')
        else:
            outfile2.write(line.strip() + '\n')

    outfile1.close()
    outfile2.close()

run()

