# Path: mitty/benchmarking/alignmentscore.py
# def is_simple_case(cigar1, cigar2):
# def find_first_common_reference_matching_base_positions(r1, r2):
# def score_alignment_error(r, ri, max_d=200, strict=False):
# def correct_tlen(ri1, ri2, r):
# def tag_alignment(r, ri, max_d=200, strict=False):


import time
import logging
import os
import pysam
from mitty.benchmarking.alignmentscore import score_alignment_error, load_qname_sidecar, parse_qname

  :param bam_fname:
  :param sidecar_fname:
  :param out_fname:
  :param d_range:
  :param reject_d_range:
  :param v_range:
  :param reject_v_range:
  :param reject_reads_with_variants:
  :param reject_reference_reads:
  :param strict_scoring:
  :param do_not_index:
  :param processes:
  :return:
  """
  def _filter_pass(_r):
    """

    :param _r:
    :return: T/F, d_err
    """
    ri = parse_qname(_r.qname, long_qname_table=long_qname_table)[1 if _r.is_read2 else 0]

    is_ref_read = len(ri.v_list) == 0
    if is_ref_read and reject_reference_reads:
      return False, 0

    if not is_ref_read and reject_reads_with_variants:
      return False, 0


# Path: mitty/benchmarking/alignmentscore.py
# def is_simple_case(cigar1, cigar2):
# def find_first_common_reference_matching_base_positions(r1, r2):
# def score_alignment_error(r, ri, max_d=200, strict=False):
# def correct_tlen(ri1, ri2, r):
# def tag_alignment(r, ri, max_d=200, strict=False):


# Path: mitty/benchmarking/subsetbam.py
import time
import logging
import os
import pysam
from mitty.benchmarking.alignmentscore import score_alignment_error, load_qname_sidecar, parse_qname


  :param bam_fname:
  :param sidecar_fname:
  :param out_fname:
  :param d_range:
  :param reject_d_range:
  :param v_range:
  :param reject_v_range:
  :param reject_reads_with_variants:
  :param reject_reference_reads:
  :param strict_scoring:
  :param do_not_index:
  :param processes:
  :return:
  """
  def _filter_pass(_r):
    """

    :param _r:
    :return: T/F, d_err
    """
    ri = parse_qname(_r.qname, long_qname_table=long_qname_table)[1 if _r.is_read2 else 0]

    is_ref_read = len(ri.v_list) == 0
    if is_ref_read and reject_reference_reads:
      return False, 0

    if not is_ref_read and reject_reads_with_variants:
      return False, 0


    _d_err = score_alignment_error(_r, ri=ri, max_d=max_d, strict=strict_scoring)