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

    in_d_err_range = d_range[0] <= _d_err <= d_range[1]
    if in_d_err_range == reject_d_range:
      return False, 0

    if not is_ref_read:
      # All variants are inside/outside v_range and we want to/do not want to reject the range
      if all((v_range[0] <= v <= v_range[1]) == reject_v_range for v in ri.v_list):
        return False, 0

    return True, _d_err

  se_bam = is_single_end_bam(bam_fname)
  bam_fp = pysam.AlignmentFile(bam_fname)

# 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

  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)

    in_d_err_range = d_range[0] <= _d_err <= d_range[1]
    if in_d_err_range == reject_d_range:
      return False, 0

    if not is_ref_read:
      # All variants are inside/outside v_range and we want to/do not want to reject the range
      if all((v_range[0] <= v <= v_range[1]) == reject_v_range for v in ri.v_list):
        return False, 0

    return True, _d_err

  se_bam = is_single_end_bam(bam_fname)
  bam_fp = pysam.AlignmentFile(bam_fname)

  long_qname_table = load_qname_sidecar(sidecar_fname)