code: def _candidates_to_windows(config, candidate_pos, ref_name):
      """ "Process candidate positions to determine windows for local assembly.
  
      Windows are within range of
        [min(pos) - config.min_windows_distance,
         max(pos) + config.min_windows_distance)
  
      Args:
        config: learning.genomics.deepvariant.realigner.WindowSelectorOptions
          options determining the behavior of this window selector.
        candidate_pos: A list of ref_pos.
        ref_name: Reference name, used in setting the output
          genomics.range.reference_name value.
  
      Returns:
        A sorted list of nucleus.protos.Range protos for all windows in this region.
      """
      windows = []
  
      def _add_window(start_pos, end_pos):
          windows.append(
              ranges.make_range(
                  ref_name,
                  start_pos - config.min_windows_distance,
                  end_pos + config.min_windows_distance,
              )
          )
  
      start_pos, end_pos = None, None
      for pos in sorted(candidate_pos):
          if start_pos is None:
              start_pos = pos
              end_pos = pos
          # We need to check if the previous end_pos is within 2*window_distance as we
          # generate a window of radius window_distance around each position.
          #
          #   <-------end_pos------->
          #                          <-------pos------->
          # where window_distance = ------->
          #
          # If this is the case, we need to merge the two windows.
          elif pos > end_pos + 2 * config.min_windows_distance:
              _add_window(start_pos, end_pos)
              start_pos = pos
              end_pos = pos
          else:
              end_pos = pos
      if start_pos is not None:
          _add_window(start_pos, end_pos)
  
      return sorted(windows, key=ranges.as_tuple)
  
file_path: deepvariant/deepvariant/realigner/window_selector.py
imports: from third_party.nucleus.protos import reads_pb2
  from third_party.nucleus.util import ranges
  from deepvariant.protos import deepvariant_pb2
  from deepvariant.protos import realigner_pb2
  from deepvariant.python import allelecounter
  from deepvariant.realigner.python import window_selector
label_desc: Use image node_id 4 for calling a global function with example usage: _candidates_to_windows(config, candidate_pos, ref_name) and returns: sorted