##################################
#                                #
# Last modified 06/29/2011       # 
#                                #
# Georgi Marinov                 #
#                                # 
##################################

import sys
import string
import random
from sets import Set

def run():

    if len(sys.argv) < 3:
        print 'usage: python %s bed chr1[,chr2,...chrN] outfilename [-ERANGEwiggle]' % sys.argv[0]
        sys.exit(1)

    doERANGEwiggle=False
    if '-ERANGEwiggle' in sys.argv:
        doERANGEwiggle=True

    input = sys.argv[1]
    chrList = sys.argv[2].split(',')
    outfilename = sys.argv[3]

    chrDict={}
    for chr in chrList:
        chrDict[chr]={}

    outfile = open(outfilename, 'w')

    lineslist = open(input)
    i=0
    for line in lineslist:
        i+=1
        if doERANGEwiggle:
            fields = line.strip().split(' ')
        else:
            fields = line.strip().split('\t')
        if chrDict.has_key(fields[0]):
            continue
        else:
            outfile.write(line)

    outfile.close()

run()
