class_docstr: Realign reads in regions to assembled haplotypes.
  
  This class helps us to realign reads in regions by:
  
  (1) Create smaller windows in which to operate over the region. These windows
  are created by finding evidence of genetic variation surrounded by stretches
  of reference-matching seqence.
  
  (2) Build a de-Bruijn assembly graph of the window. Edges are pruned if they
  don't meet the required weight threshold. Every remaining haplotype is listed
  by traversing the graph.
  
  (3) Realign reads using a Smith-Waterman algorithm to the best candidate
  haplotype and then realign that haplotype to the reference sequence to modify
  the read's alignment.
class_docstr_tok: ["Realign","reads","in","regions","to","assembled","haplotypes",".","This","class","helps","us","to","realign","reads","in","regions","by",":","(","1",")","Create","smaller","windows","in","which","to","operate","over","the","region",".","These","windows","are","created","by","finding","evidence","of","genetic","variation","surrounded","by","stretches","of","reference-matching","seqence",".","(","2",")","Build","a","de-Bruijn","assembly","graph","of","the","window",".","Edges","are","pruned","if","they","do","n't","meet","the","required","weight","threshold",".","Every","remaining","haplotype","is","listed","by","traversing","the","graph",".","(","3",")","Realign","reads","using","a","Smith-Waterman","algorithm","to","the","best","candidate","haplotype","and","then","realign","that","haplotype","to","the","reference","sequence","to","modify","the","read","'s","alignment","."]
docstr: Helper function to call fast pass aligner module.
docstr_tok: ["Helper","function","to","call","fast","pass","aligner","module","."]
code: def call_fast_pass_aligner(self, assembled_region):
      """Helper function to call fast pass aligner module."""
      if not assembled_region.reads:
          return []
  
      contig = assembled_region.region.reference_name
      ref_start = max(
          0,
          min(
              assembled_region.read_span.start,
              assembled_region.region.start,
          )
          - _REF_ALIGN_MARGIN,
      )
      ref_end = min(
          self.ref_reader.contig(contig).n_bases,
          max(
              assembled_region.read_span.end,
              assembled_region.region.end,
          )
          + _REF_ALIGN_MARGIN,
      )
  
      ref_prefix = self.ref_reader.query(
          ranges.make_range(
              contig, ref_start, assembled_region.region.start
          )
      )
      ref = self.ref_reader.query(assembled_region.region)
  
      # If we can't create the ref suffix then return the original alignments.
      if ref_end <= assembled_region.region.end:
          return assembled_region.reads
      else:
          ref_suffix = self.ref_reader.query(
              ranges.make_range(
                  contig, assembled_region.region.end, ref_end
              )
          )
  
      ref_seq = ref_prefix + ref + ref_suffix
  
      fast_pass_realigner = fast_pass_aligner.FastPassAligner()
      # Read sizes may vary. We need this for realigner initialization and sanity
      # checks.
      self.config.aln_config.read_size = len(
          assembled_region.reads[0].aligned_sequence
      )
      self.config.aln_config.force_alignment = False
      fast_pass_realigner.set_normalize_reads(
          self.config.normalize_reads
      )
      fast_pass_realigner.set_options(self.config.aln_config)
      fast_pass_realigner.set_reference(ref_seq)
      fast_pass_realigner.set_ref_start(contig, ref_start)
      fast_pass_realigner.set_ref_prefix_len(len(ref_prefix))
      fast_pass_realigner.set_ref_suffix_len(len(ref_suffix))
      fast_pass_realigner.set_haplotypes(
          [
              ref_prefix + target + ref_suffix
              for target in assembled_region.haplotypes
          ]
      )
      return fast_pass_realigner.realign_reads(assembled_region.reads)
  
imports: import csv
  import os
  import os.path
  from absl import flags
  from etils import epath
  from deepvariant.protos import realigner_pb2
  from deepvariant.realigner import window_selector
  from deepvariant.realigner.python import debruijn_graph
  from deepvariant.realigner.python import fast_pass_aligner
  from deepvariant.vendor import timer
  from google.protobuf import text_format
  from third_party.nucleus.io import sam
  from third_party.nucleus.protos import cigar_pb2
  from third_party.nucleus.protos import reads_pb2
  from third_party.nucleus.util import cigar
  from third_party.nucleus.util import ranges
  from third_party.nucleus.util import utils
  from third_party.nucleus.util.cigar import READ_ADVANCING_OPS
  from third_party.nucleus.util.cigar import REF_ADVANCING_OPS
label_desc: Use image node_id 3 for calling the Realigner obj's underlying member method code with example usage: obj.call_fast_pass_aligner(assembled_region) and returns: fast_pass_realigner, list, assembled_region