#!/usr/bin/env python

import os
import re
import sys
import argparse
import itertools
import logging as lg
import subprocess as sp

import vcf
lg.basicConfig(level=lg.DEBUG)

parser = argparse.ArgumentParser(description='Prepare the vcf for SNPEff')
parser.add_argument('vcf', type=str, default='-', nargs='?', 
                    help='vcf file input (needs nucleotide frequencies '+
                    'FORMAT:NF, - for stdin)')
parser.add_argument('-o', dest='out', help='vcf output', default='-')

args = parser.parse_args()


vcf = vcf.PSVCF(args.vcf)
if args.out == '-':
    F = sys.stdout
else:
    F = open(args.out, 'w')
    
for i, locus in enumerate(vcf):

    vrs = set()
    [vrs.update(set(list(x))) for x in locus.vars]
    vrs.discard(locus.ref)
    
    locus.vars=list(vrs)

    #print locus.vcf_line
    #print locus.build_vcf_line()
    #print
    F.write("%s\n" % locus.build_vcf_line())
    
    

