# Path: mitty/lib/bedfile.py
# def read_bed(bed_fname):
#   return list(map(lambda x: (x[0], int(x[1]), int(x[2])), map(lambda x: x.split(), open(bed_fname, 'r').readlines())))
# 
# Path: mitty/lib/sanitizeseq.py
# def sanitize(seq):
#   return seq.translate(sanitable)


import time
import pysam
import numpy as np
import logging
from itertools import chain
from mitty.lib.bedfile import read_bed
from mitty.lib.sanitizeseq import sanitize




logger = logging.getLogger(__name__)


SEED_MAX = (1 << 32) - 1  # Used for seeding rng


def main(fp_out, fasta_fname, sample_name, bed_fname, seed, p_het, models):
  """

  :param fp_out: output file pointer
  :param fasta_fname:
  :param sample_name:
  :param bed_fname:
  :param seed:
  :param p_het:
  :param models:
  :return:
  """
  logger.debug('Starting variant simulation ...')
  t0 = time.time()
  v_cnt_tot = 0

  fp_out.write(generate_header(fasta_fname, sample_name))
  fasta = pysam.FastaFile(fasta_fname)
  rng = np.random.RandomState(seed=seed)

# Path: mitty/lib/bedfile.py
# def read_bed(bed_fname):
#   return list(map(lambda x: (x[0], int(x[1]), int(x[2])), map(lambda x: x.split(), open(bed_fname, 'r').readlines())))
# 
# Path: mitty/lib/sanitizeseq.py
# def sanitize(seq):
#   return seq.translate(sanitable)


# Path: mitty/simulation/genome/simulatevariants.py
import time
import pysam
import numpy as np
import logging
from itertools import chain
from mitty.lib.bedfile import read_bed
from mitty.lib.sanitizeseq import sanitize





logger = logging.getLogger(__name__)


SEED_MAX = (1 << 32) - 1  # Used for seeding rng


def main(fp_out, fasta_fname, sample_name, bed_fname, seed, p_het, models):
  """

  :param fp_out: output file pointer
  :param fasta_fname:
  :param sample_name:
  :param bed_fname:
  :param seed:
  :param p_het:
  :param models:
  :return:
  """
  logger.debug('Starting variant simulation ...')
  t0 = time.time()
  v_cnt_tot = 0

  fp_out.write(generate_header(fasta_fname, sample_name))
  fasta = pysam.FastaFile(fasta_fname)
  rng = np.random.RandomState(seed=seed)

  for region in read_bed(bed_fname):