code: def shared_flags_to_options(
      add_flags,
      flags_obj,
      samples_in_order,
      sample_role_to_train,
      main_sample_index,
  ) -> deepvariant_pb2.MakeExamplesOptions:
      """Creates options from flags that are shared, along with given samples."""
      read_reqs = reads_pb2.ReadRequirements(
          keep_duplicates=flags_obj.keep_duplicates,
          keep_supplementary_alignments=flags_obj.keep_supplementary_alignments,
          keep_secondary_alignments=flags_obj.keep_secondary_alignments,
          min_base_quality=flags_obj.min_base_quality,
          min_mapping_quality=flags_obj.min_mapping_quality,
          min_base_quality_mode=reads_pb2.ReadRequirements.ENFORCED_BY_CLIENT,
      )
  
      logging.vlog(3, "ReadRequirements are: %s", read_reqs)
  
      pic_options = pileup_image.default_options(
          read_requirements=read_reqs
      )
  
      allele_counter_options = deepvariant_pb2.AlleleCounterOptions(
          partition_size=flags_obj.partition_size,
          read_requirements=read_reqs,
          track_ref_reads=flags_obj.track_ref_reads,
          normalize_reads=flags_obj.normalize_reads,
          keep_legacy_behavior=flags_obj.keep_legacy_allele_counter_behavior,
      )
  
      options = deepvariant_pb2.MakeExamplesOptions(
          exclude_contigs=exclude_contigs.EXCLUDED_HUMAN_CONTIGS,
          # Fixed random seed produced with 'od -vAn -N4 -tu4 < /dev/urandom'.
          random_seed=609314161,
          # # Not specified by default: calling_regions = 3;
          read_requirements=read_reqs,
          allele_counter_options=allele_counter_options,
          pic_options=pic_options,
          n_cores=1,
          task_id=0,
          num_shards=0,
          min_shared_contigs_basepairs=0.9,
          sample_options=samples_in_order,
          main_sample_index=main_sample_index,
          sample_role_to_train=sample_role_to_train,
          output_sitelist=_OUTPUT_SITELIST.value,
      )
  
      if add_flags:
          options.mode = make_examples_core.parse_proto_enum_flag(
              deepvariant_pb2.MakeExamplesOptions.Mode,
              flags_obj.mode.upper(),
          )
  
          options.labeler_algorithm = (
              make_examples_core.parse_proto_enum_flag(
                  deepvariant_pb2.MakeExamplesOptions.LabelerAlgorithm,
                  flags_obj.labeler_algorithm.upper(),
              )
          )
  
          options.variant_caller = (
              make_examples_core.parse_proto_enum_flag(
                  deepvariant_pb2.MakeExamplesOptions.VariantCaller,
                  flags_obj.variant_caller.upper(),
              )
          )
  
          if flags_obj.ref:
              options.reference_filename = flags_obj.ref
          if flags_obj.confident_regions:
              options.confident_regions_filename = (
                  flags_obj.confident_regions
              )
          if flags_obj.denovo_regions:
              options.denovo_regions_filename = _DENOVO_REGIONS.value
          if flags_obj.truth_variants:
              options.truth_variants_filename = flags_obj.truth_variants
          if flags_obj.sequencing_type:
              options.pic_options.sequencing_type = (
                  make_examples_core.parse_proto_enum_flag(
                      deepvariant_pb2.PileupImageOptions.SequencingType,
                      flags_obj.sequencing_type,
                  )
              )
  
          if flags_obj.channels:
              channel_set = re.split("[, ]+", flags_obj.channels)
              for channel in channel_set:
                  if (
                      channel
                      and channel not in dv_constants.OPT_CHANNELS
                  ):
                      err_msg = 'Channel "{}" is not one of the available opt channels: {}'.format(
                          channel, ", ".join(dv_constants.OPT_CHANNELS)
                      )
                      errors.log_and_raise(
                          err_msg, errors.CommandLineError
                      )
              options.pic_options.channels[:] = channel_set
              options.pic_options.num_channels += len(channel_set)
  
          if flags_obj.multi_allelic_mode:
              multi_allelic_enum = {
                  "include_het_alt_images": (
                      deepvariant_pb2.PileupImageOptions.ADD_HET_ALT_IMAGES
                  ),
                  "exclude_het_alt_images": (
                      deepvariant_pb2.PileupImageOptions.NO_HET_ALT_IMAGES
                  ),
              }[flags_obj.multi_allelic_mode]
              options.pic_options.multi_allelic_mode = (
                  multi_allelic_enum
              )
  
          if flags_obj.pileup_image_width:
              options.pic_options.width = flags_obj.pileup_image_width
  
          # DirectPhasing related flags.
          if flags_obj.phase_reads:
              options.phase_reads = flags_obj.phase_reads
          phase_region_padding = (
              dv_constants.PHASE_READS_REGION_PADDING_PCT
          )
          if phase_region_padding:
              options.phase_reads_region_padding_pct = (
                  phase_region_padding
              )
          if flags_obj.phase_max_candidates:
              options.phase_max_candidates = (
                  flags_obj.phase_max_candidates
              )
  
          options.pic_options.alt_aligned_pileup = (
              flags_obj.alt_aligned_pileup
          )
          options.pic_options.types_to_alt_align = (
              flags_obj.types_to_alt_align
          )
  
          if flags_obj.add_supporting_other_alt_color:
              options.pic_options.other_allele_supporting_read_alpha = (
                  0.3
              )
  
          if flags_obj.select_variant_types:
              options.select_variant_types[
                  :
              ] = flags_obj.select_variant_types.split()
              for svt in options.select_variant_types:
                  if (
                      svt
                      not in make_examples_core.VARIANT_TYPE_SELECTORS
                  ):
                      errors.log_and_raise(
                          "Select variant type {} not recognized. Allowed values are {}".format(
                              svt,
                              ", ".join(
                                  make_examples_core.VARIANT_TYPE_SELECTORS
                              ),
                          ),
                          errors.CommandLineError,
                      )
  
          (
              num_shards,
              examples,
              candidates,
              gvcf,
              runtime_by_region,
              read_phases_output,
          ) = sharded_file_utils.resolve_filespecs(
              flags_obj.task,
              flags_obj.examples or "",
              flags_obj.candidates or "",
              flags_obj.gvcf or "",
              flags_obj.runtime_by_region or "",
              flags_obj.output_local_read_phasing or "",
          )
          options.examples_filename = examples
          options.candidates_filename = candidates
          options.gvcf_filename = gvcf
          options.include_med_dp = flags_obj.include_med_dp
          options.task_id = flags_obj.task
          options.num_shards = num_shards
          options.runtime_by_region = runtime_by_region
          options.read_phases_output = read_phases_output
  
          options.parse_sam_aux_fields = (
              make_examples_core.resolve_sam_aux_fields(
                  flags_obj=flags_obj
              )
          )
          if flags_obj.aux_fields_to_keep:
              options.aux_fields_to_keep[
                  :
              ] = flags_obj.aux_fields_to_keep.split(",")
          else:
              options.aux_fields_to_keep = None
          options.use_original_quality_scores = (
              flags_obj.use_original_quality_scores
          )
  
          if flags_obj.add_hp_channel:
              options.pic_options.num_channels += 1
              options.pic_options.add_hp_channel = True
  
          if flags_obj.hp_tag_for_assembly_polishing < 0:
              errors.log_and_raise(
                  "--hp_tag_for_assembly_polishing has to be set to a positive int.",
                  errors.CommandLineError,
              )
          if (
              flags_obj.hp_tag_for_assembly_polishing > 0
              and not flags_obj.sort_by_haplotypes
          ):
              errors.log_and_raise(
                  (
                      "--hp_tag_for_assembly_polishing requires --sort_by_haplotypes to"
                      " be set "
                  ),
                  errors.CommandLineError,
              )
  
          options.pic_options.sort_by_haplotypes = (
              flags_obj.sort_by_haplotypes
          )
          options.pic_options.reverse_haplotypes = (
              flags_obj.reverse_haplotypes
          )
          options.pic_options.hp_tag_for_assembly_polishing = (
              flags_obj.hp_tag_for_assembly_polishing
          )
  
          if flags_obj.write_run_info:
              options.run_info_filename = (
                  examples + _RUN_INFO_FILE_EXTENSION
              )
  
          options.calling_regions.extend(
              make_examples_core.parse_regions_flag(flags_obj.regions)
          )
          options.exclude_calling_regions.extend(
              make_examples_core.parse_regions_flag(
                  flags_obj.exclude_regions
              )
          )
  
          options.realigner_enabled = flags_obj.realign_reads
          options.joint_realignment = _ENABLE_JOINT_REALIGNMENT.value
          options.realigner_options.CopyFrom(
              realigner.realigner_config(flags_obj)
          )
  
          if (
              options.mode
              == deepvariant_pb2.MakeExamplesOptions.TRAINING
              and flags_obj.training_random_emit_ref_sites
              != NO_RANDOM_REF
          ):
              options.sample_options[
                  main_sample_index
              ].variant_caller_options.fraction_reference_sites_to_emit = (
                  flags_obj.training_random_emit_ref_sites
              )
  
          if (
              flags_obj.use_allele_frequency
              and not flags_obj.population_vcfs
          ):
              errors.log_and_raise(
                  (
                      "If use_allele_frequency is set then population_vcfs "
                      "must be provided."
                  ),
                  errors.CommandLineError,
              )
          if flags_obj.use_allele_frequency:
              options.use_allele_frequency = (
                  flags_obj.use_allele_frequency
              )
              options.pic_options.num_channels += 1
              options.pic_options.use_allele_frequency = True
          if flags_obj.population_vcfs:
              for path in re.split(",| ", flags_obj.population_vcfs):
                  options.population_vcf_filenames.extend(
                      gfile.Glob(path)
                  )
          options.max_reads_per_partition = (
              flags_obj.max_reads_per_partition
          )
          options.max_reads_for_dynamic_bases_per_region = (
              _MAX_READS_FOR_DYNAMIC_BASES_PER_REGION.value
          )
          options.use_ref_for_cram = flags_obj.use_ref_for_cram
          options.hts_block_size = flags_obj.hts_block_size
          options.logging_every_n_candidates = (
              flags_obj.logging_every_n_candidates
          )
          options.customized_classes_labeler_classes_list = (
              flags_obj.customized_classes_labeler_classes_list
          )
          options.customized_classes_labeler_info_field_name = (
              flags_obj.customized_classes_labeler_info_field_name
          )
  
      options.discard_non_dna_regions = _DISCARD_NON_DNA_REGIONS.value
  
      return options
  
file_path: deepvariant/deepvariant/make_examples_options.py
imports: import re
  from absl import flags
  from absl import logging
  from deepvariant import dv_constants
  from deepvariant import exclude_contigs
  from deepvariant import make_examples_core
  from deepvariant import pileup_image
  from deepvariant.protos import deepvariant_pb2
  from deepvariant.realigner import realigner
  from tensorflow.python.platform import gfile
  from third_party.nucleus.io import sharded_file_utils
  from third_party.nucleus.io.python import hts_verbose
  from third_party.nucleus.protos import reads_pb2
  from third_party.nucleus.util import errors
label_desc: Use image node_id 1 for calling a global function with example usage: shared_flags_to_options(add_flags, flags_obj, samples_in_order, sample_role_to_train, main_sample_index) and returns: options