# This scripts converts vcfs to bed files for input to Gunther et al scripts

from cyvcf2 import VCF
import pandas as pd
import argparse

parser = argparse.ArgumentParser(description='Convert vcf file to mpileup and eigenstrat format', usage="maf.gz_file output_name")
parser.add_argument('vcf_file', type=str, help='path to vcf.gz or vcf file')
parser.add_argument('output_name', type=str, help='root name of output file')

args = parser.parse_args()

todf = []

vcf = VCF(args.vcf_file,gts012=True)
for var in vcf:

    # to make this easy, let's just put this all into one big dataframe and go from there.
    todf.append([var.CHROM, var.POS, var.REF, var.ALT[0]])

df = pd.DataFrame(todf,columns=['chrom','pos','ref','alt'])

df[['chrom','pos','pos']].to_csv(args.output_name+'.bed',index=False,header=False,sep='\t')

df[['chrom','pos','ref','alt']].to_csv(args.output_name+'.tsv',index=False,header=False,sep='\t')
