def test_process_with_realigner(self):
        self.processor.options.mode = deepvariant_pb2.DeepVariantOptions.CALLING
        self.processor.options.realigner_options.CopyFrom(
            realigner_pb2.RealignerOptions())
        self.processor.realigner = mock.Mock()
        self.processor.realigner.realign_reads.return_value = [], []

        self.processor.sam_reader = mock.Mock()
        self.processor.sam_reader.query.return_value = []
        self.processor.in_memory_sam_reader = mock.Mock()

        c1, c2 = mock.Mock(), mock.Mock()
        e1, e2, e3 = mock.Mock(), mock.Mock(), mock.Mock()
        self.add_mock('candidates_in_region', retval=([c1, c2], []))
        mock_cpe = self.add_mock('create_pileup_examples',
                                 side_effect=[[e1], [e2, e3]])
        mock_lv = self.add_mock('label_variant')

        self.assertEqual(([c1, c2], [e1, e2, e3], []),
                         self.processor.process(self.region))
        self.processor.sam_reader.query.assert_called_once_with(self.region)
        self.processor.realigner.realign_reads.assert_called_once_with(
            [], self.region)
        self.processor.in_memory_sam_reader.replace_reads.assert_called_once_with(
            [])
        self.assertEqual([mock.call(c1), mock.call(c2)],
                         mock_cpe.call_args_list)
        test_utils.assert_not_called_workaround(mock_lv)
Esempio n. 2
0
def realigner_config(flags_obj):
    """Creates a RealignerOptions proto based on input and default settings.

  Args:
    flags_obj: configuration FLAGS.

  Returns:
    realigner_pb2.RealignerOptions protobuf.

  Raises:
    ValueError: If we observe invalid flag values.
  """
    ws_config = window_selector_config(flags_obj)

    dbg_config = realigner_pb2.DeBruijnGraphOptions(
        min_k=flags_obj.dbg_min_k,
        max_k=flags_obj.dbg_max_k,
        step_k=flags_obj.dbg_step_k,
        min_mapq=flags_obj.dbg_min_mapq,
        min_base_quality=flags_obj.dbg_min_base_quality,
        min_edge_weight=flags_obj.dbg_min_edge_weight,
        max_num_paths=flags_obj.dbg_max_num_paths)

    aln_config = realigner_pb2.AlignerOptions(
        match=flags_obj.aln_match,
        mismatch=flags_obj.aln_mismatch,
        gap_open=flags_obj.aln_gap_open,
        gap_extend=flags_obj.aln_gap_extend,
        k=flags_obj.aln_k,
        error_rate=flags_obj.aln_error_rate,
        max_num_of_mismatches=flags_obj.max_num_mismatches,
        realignment_similarity_threshold=flags_obj.
        realignment_similarity_threshold,
        kmer_size=flags_obj.kmer_size,
        force_alignment=False)

    diagnostics = realigner_pb2.Diagnostics(
        enabled=bool(flags_obj.realigner_diagnostics),
        output_root=flags_obj.realigner_diagnostics,
        emit_realigned_reads=flags_obj.emit_realigned_reads)

    # The normalize_reads flag could came from the `flags_obj` arg, passed in
    # from make_examples_options.py. It is already part of AlleleCounterOptions in
    # MakeExamplesOptions. Here, we need to set it in RealignerOptions as well
    # because an if statement in fast_pass_aligner.cc needs it to decide whether
    # to run a specific logic.
    # This is not ideal. If there's a way to improve this, please do.
    normalize_reads = False
    if 'normalize_reads' in flags_obj:
        normalize_reads = flags_obj.normalize_reads
    return realigner_pb2.RealignerOptions(
        ws_config=ws_config,
        dbg_config=dbg_config,
        aln_config=aln_config,
        diagnostics=diagnostics,
        split_skip_reads=flags_obj.split_skip_reads,
        normalize_reads=normalize_reads)
Esempio n. 3
0
def realigner_config(flags_obj):
  """Creates a RealignerOptions proto based on input and default settings.

  Args:
    flags_obj: configuration FLAGS.

  Returns:
    realigner_pb2.RealignerOptions protobuf.

  Raises:
    ValueError: If we observe invalid flag values.
  """
  ws_config = realigner_pb2.RealignerOptions.WindowSelectorOptions(
      min_num_supporting_reads=flags_obj.ws_min_num_supporting_reads,
      max_num_supporting_reads=flags_obj.ws_max_num_supporting_reads,
      min_mapq=flags_obj.ws_min_mapq,
      min_base_quality=flags_obj.ws_min_base_quality,
      min_windows_distance=flags_obj.ws_min_windows_distance,
      max_window_size=flags_obj.ws_max_window_size)

  dbg_config = realigner_pb2.RealignerOptions.DeBruijnGraphOptions(
      min_k=flags_obj.dbg_min_k,
      max_k=flags_obj.dbg_max_k,
      step_k=flags_obj.dbg_step_k,
      min_mapq=flags_obj.dbg_min_mapq,
      min_base_quality=flags_obj.dbg_min_base_quality,
      min_edge_weight=flags_obj.dbg_min_edge_weight,
      max_num_paths=flags_obj.dbg_max_num_paths)

  aln_config = realigner_pb2.RealignerOptions.AlignerOptions(
      match=flags_obj.aln_match,
      mismatch=flags_obj.aln_mismatch,
      gap_open=flags_obj.aln_gap_open,
      gap_extend=flags_obj.aln_gap_extend,
      k=flags_obj.aln_k,
      error_rate=flags_obj.aln_error_rate)

  diagnostics = realigner_pb2.RealignerOptions.Diagnostics(
      enabled=bool(flags_obj.realigner_diagnostics),
      output_root=flags_obj.realigner_diagnostics,
      emit_realigned_reads=flags_obj.emit_realigned_reads)

  return realigner_pb2.RealignerOptions(
      ws_config=ws_config,
      dbg_config=dbg_config,
      aln_config=aln_config,
      diagnostics=diagnostics)
Esempio n. 4
0
def realigner_config(flags_obj):
    """Creates a RealignerOptions proto based on input and default settings.

  Args:
    flags_obj: configuration FLAGS.

  Returns:
    realigner_pb2.RealignerOptions protobuf.

  Raises:
    ValueError: If we observe invalid flag values.
  """
    ws_config = window_selector_config(flags_obj)

    dbg_config = realigner_pb2.DeBruijnGraphOptions(
        min_k=flags_obj.dbg_min_k,
        max_k=flags_obj.dbg_max_k,
        step_k=flags_obj.dbg_step_k,
        min_mapq=flags_obj.dbg_min_mapq,
        min_base_quality=flags_obj.dbg_min_base_quality,
        min_edge_weight=flags_obj.dbg_min_edge_weight,
        max_num_paths=flags_obj.dbg_max_num_paths)

    aln_config = realigner_pb2.AlignerOptions(
        match=flags_obj.aln_match,
        mismatch=flags_obj.aln_mismatch,
        gap_open=flags_obj.aln_gap_open,
        gap_extend=flags_obj.aln_gap_extend,
        k=flags_obj.aln_k,
        error_rate=flags_obj.aln_error_rate,
        max_num_of_mismatches=flags_obj.max_num_mismatches,
        realignment_similarity_threshold=flags_obj.
        realignment_similarity_threshold,
        kmer_size=flags_obj.kmer_size,
        force_alignment=False)

    diagnostics = realigner_pb2.Diagnostics(
        enabled=bool(flags_obj.realigner_diagnostics),
        output_root=flags_obj.realigner_diagnostics,
        emit_realigned_reads=flags_obj.emit_realigned_reads)

    return realigner_pb2.RealignerOptions(ws_config=ws_config,
                                          dbg_config=dbg_config,
                                          aln_config=aln_config,
                                          diagnostics=diagnostics)
Esempio n. 5
0
    def test_process_with_realigner(self):
        self.processor.options.mode = deepvariant_pb2.MakeExamplesOptions.CALLING
        self.processor.options.realigner_enabled = True
        self.processor.options.realigner_options.CopyFrom(
            realigner_pb2.RealignerOptions())
        self.processor.realigner = mock.Mock()
        self.processor.realigner.realign_reads.return_value = [], []

        main_sample = self.processor.samples[0]
        main_sample.sam_readers = [mock.Mock()]
        main_sample.sam_readers[0].query.return_value = []

        c1, c2 = mock.Mock(), mock.Mock()
        e1, e2, e3 = mock.Mock(), mock.Mock(), mock.Mock()
        self.add_mock('candidates_in_region',
                      retval=({
                          'main_sample': [c1, c2]
                      }, {
                          'main_sample': []
                      }))
        mock_cpe = self.add_mock('create_pileup_examples',
                                 side_effect=[[e1], [e2, e3]])
        mock_lc = self.add_mock('label_candidates')

        candidates, examples, gvcfs, runtimes = self.processor.process(
            self.region)
        self.assertEqual(candidates['main_sample'], [c1, c2])
        self.assertEqual(examples['main_sample'], [e1, e2, e3])
        self.assertEmpty(gvcfs['main_sample'])
        self.assertIsInstance(runtimes, dict)
        main_sample.sam_readers[0].query.assert_called_once_with(self.region)
        self.processor.realigner.realign_reads.assert_called_once_with(
            [], self.region)
        main_sample.in_memory_sam_reader.replace_reads.assert_called_once_with(
            [])
        self.assertEqual(
            [mock.call(c1, sample_order=[0]),
             mock.call(c2, sample_order=[0])], mock_cpe.call_args_list)
        test_utils.assert_not_called_workaround(mock_lc)