#!/usr/bin/env python3
import argparse
import pickle
import os.path
import sys

from frea.simulation import *

parser = argparse.ArgumentParser('frea-sample-events', description='First pass sampler for simulation')
parser.add_argument('seed', help='Random seed (integer)')
parser.add_argument('n', help='Target number of samples (integer)')
parser.add_argument('legend_file', help='1KG legend (single chromosome)')
parser.add_argument('haps_file', help='1KG reference haplotypes (single chromosome)')
parser.add_argument('sample_file', help='1KG sample file')
parser.add_argument('hotspot_file', help='deCODE recombination hotspots (single chromosome)')
parser.add_argument('output_file', help='Output file name')
parser.add_argument('--p-causal', help='Probability of LD block being causal', default=0.5)
parser.add_argument('--n-per-window', help='Number of causal variants within LD block', default=1)
args = parser.parse_args()

seed = int(args.seed)
y, events = sample_events(seed=seed, n=int(args.n),
                          legend_file=args.legend_file,
                          haps_file=args.haps_file,
                          sample_file=args.sample_file,
                          hotspot_file=args.hotspot_file,
                          p_causal=float(args.p_causal),
                          n_per_window=int(args.n_per_window))
with open(args.output_file, 'wb') as f:
    A = os.path.abspath
    result = {'seed': seed,
              'y': y,
              'events': events,
              'legend_file': A(args.legend_file),
              'haps_file': A(args.haps_file),
              'sample_file': A(args.sample_file),
              'hotspot_file': A(args.hotspot_file)}
    pickle.dump(result, f)
