import pandas as pd
import argparse

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

args = parser.parse_args()

df = pd.read_csv(args.maf_file,sep='\t')

# this step is to remove vars where major is different from ref. Should not be necessary if I give angsd correct minorMajor argument
df = df[df['major'] == df['ref']].copy()

df[['chromo','position']].to_csv(args.output_name+'.tsv',index=False, header=False,sep='\t')

df['id'] = 'rs' + df.index.astype(str)

df['null'] = 0

df[['id','chromo','null','position','ref','minor']].to_csv(args.output_name+'.snp',index=False, header=False,sep='\t')
