# 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())))


import logging
import time
import pysam
from mitty.lib.bedfile import read_bed
  def __init__(self, pos, ref, alt, cigarop, oplen):
    self.pos = pos
    self.ref = ref
    self.alt = alt
    self.cigarop = cigarop
    self.oplen = oplen

  def tuple(self):
    return self.pos, self.ref, self.alt, self.cigarop, self.oplen

  def __repr__(self):
    return self.tuple().__repr__()


# Unphased variants always go into chrom copy 0|1
# We get results in the form of a ploid_bed
def load_variant_file(fname, sample, bed_fname):
  """Use pysam to read in a VCF file and convert it into a form suitable for use in Mitty

  :param fname:
  :param sample:
  :return: dict of numpy recarrays
  """
  mode = 'rb' if fname.endswith('bcf') else 'r'
  vcf_fp = pysam.VariantFile(fname, mode)
  vcf_fp.subset_samples([sample])
  return [
    split_copies(region,
                 [v for v in vcf_fp.fetch(contig=region[0], start=region[1], stop=region[2])],
                 sniff_ploidy(vcf_fp, region[0]))

# 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/vcfio.py
import logging
import time
import pysam
from mitty.lib.bedfile import read_bed

  def __init__(self, pos, ref, alt, cigarop, oplen):
    self.pos = pos
    self.ref = ref
    self.alt = alt
    self.cigarop = cigarop
    self.oplen = oplen

  def tuple(self):
    return self.pos, self.ref, self.alt, self.cigarop, self.oplen

  def __repr__(self):
    return self.tuple().__repr__()


# Unphased variants always go into chrom copy 0|1
# We get results in the form of a ploid_bed
def load_variant_file(fname, sample, bed_fname):
  """Use pysam to read in a VCF file and convert it into a form suitable for use in Mitty

  :param fname:
  :param sample:
  :return: dict of numpy recarrays
  """
  mode = 'rb' if fname.endswith('bcf') else 'r'
  vcf_fp = pysam.VariantFile(fname, mode)
  vcf_fp.subset_samples([sample])
  return [
    split_copies(region,
                 [v for v in vcf_fp.fetch(contig=region[0], start=region[1], stop=region[2])],
                 sniff_ploidy(vcf_fp, region[0]))

    for region in read_bed(bed_fname)