class_docstr: BaseClass for variant callers.
class_docstr_tok: ["BaseClass","for","variant","callers","."]
docstr: Primary interface function for computing gVCF confidence at a site.
  
  Looks at the counts in the provided list of AlleleCountSummary protos and
  returns properly-formatted Variant protos containing gVCF reference
  blocks for all sites in allele_count_summaries. The returned Variant has
  reference_name, start, end are set and contains a single VariantCall in the
  calls field with call_set_name of options.sample_name, genotypes set to 0/0
  (diploid reference), a GQ value bound in the info field appropriate to the
  data in allele_count, and a MIN_DP value which is the minimum read coverage
  seen in the block.
  
  The provided allele count must have either a canonical DNA sequence base (
  A, C, G, T) or be "N".
  
  Args:
    allele_count_summaries: iterable of AlleleCountSummary protos in
      coordinate-sorted order. Each proto is used to get the read counts for
      reference and alternate alleles, the reference position, and reference
      base.
    include_med_dp: boolean. If True, in the gVCF records, we will include
      MED_DP.
  
  Yields:
    third_party.nucleus.protos.Variant proto in
    coordinate-sorted order containing gVCF records.
docstr_tok: ["Primary","interface","function","for","computing","gVCF","confidence","at","a","site",".","Looks","at","the","counts","in","the","provided","list","of","AlleleCountSummary","protos","and","returns","properly-formatted","Variant","protos","containing","gVCF","reference","blocks","for","all","sites","in","allele_count_summaries",".","The","returned","Variant","has","reference_name",",","start",",","end","are","set","and","contains","a","single","VariantCall","in","the","calls","field","with","call_set_name","of","options.sample_name",",","genotypes","set","to","0\/0","(","diploid","reference",")",",","a","GQ","value","bound","in","the","info","field","appropriate","to","the","data","in","allele_count",",","and","a","MIN_DP","value","which","is","the","minimum","read","coverage","seen","in","the","block",".","The","provided","allele","count","must","have","either","a","canonical","DNA","sequence","base","(","A",",","C",",","G",",","T",")","or","be","``","N","''",".","Args",":","allele_count_summaries",":","iterable","of","AlleleCountSummary","protos","in","coordinate-sorted","order",".","Each","proto","is","used","to","get","the","read","counts","for","reference","and","alternate","alleles",",","the","reference","position",",","and","reference","base",".","include_med_dp",":","boolean",".","If","True",",","in","the","gVCF","records",",","we","will","include","MED_DP",".","Yields",":","third_party.nucleus.protos.Variant","proto","in","coordinate-sorted","order","containing","gVCF","records","."]
code: def make_gvcfs(self, allele_count_summaries, include_med_dp=False):
      """Primary interface function for computing gVCF confidence at a site.
  
      Looks at the counts in the provided list of AlleleCountSummary protos and
      returns properly-formatted Variant protos containing gVCF reference
      blocks for all sites in allele_count_summaries. The returned Variant has
      reference_name, start, end are set and contains a single VariantCall in the
      calls field with call_set_name of options.sample_name, genotypes set to 0/0
      (diploid reference), a GQ value bound in the info field appropriate to the
      data in allele_count, and a MIN_DP value which is the minimum read coverage
      seen in the block.
  
      The provided allele count must have either a canonical DNA sequence base (
      A, C, G, T) or be "N".
  
      Args:
        allele_count_summaries: iterable of AlleleCountSummary protos in
          coordinate-sorted order. Each proto is used to get the read counts for
          reference and alternate alleles, the reference position, and reference
          base.
        include_med_dp: boolean. If True, in the gVCF records, we will include
          MED_DP.
  
      Yields:
        third_party.nucleus.protos.Variant proto in
        coordinate-sorted order containing gVCF records.
      """
  
      def with_gq_and_likelihoods(summary_counts):
          """Returns summary_counts along with GQ and genotype likelihoods.
  
          If the reference base is not in CANONICAL_DNA_BASES, both GQ and genotype
          likelihoods are set to None.
  
          Args:
            summary_counts: A single AlleleCountSummary.
  
          Returns:
            A tuple of summary_counts, quantized GQ, raw GQ, and genotype
            likelihoods for summary_counts where raw GQ and genotype_likelihood are
            calculated by self.reference_confidence.
  
          Raises:
            ValueError: The reference base is not a valid DNA or IUPAC base.
          """
          if summary_counts.ref_base not in CANONICAL_DNA_BASES:
              if summary_counts.ref_base in EXTENDED_IUPAC_CODES:
                  # Skip calculating gq and likelihoods, since this is an ambiguous
                  # reference base.
                  quantized_gq, raw_gq, likelihoods = None, None, None
                  has_valid_gl = True
                  n_total = summary_counts.total_read_count
              else:
                  raise ValueError(
                      "Invalid reference base={} found during gvcf calculation".format(
                          summary_counts.ref_base
                      )
                  )
          else:
              n_ref = summary_counts.ref_supporting_read_count
              n_total = summary_counts.total_read_count
              raw_gq, likelihoods = self.reference_confidence(
                  n_ref, n_total
              )
              quantized_gq = _quantize_gq(
                  raw_gq, self.options.gq_resolution
              )
              has_valid_gl = np.amax(likelihoods) == likelihoods[0]
          return _GVCF(
              summary_counts=summary_counts,
              quantized_gq=quantized_gq,
              raw_gq=raw_gq,
              likelihoods=likelihoods,
              read_depth=n_total,
              has_valid_gl=has_valid_gl,
          )
  
      # Combines contiguous, compatible single-bp blocks into larger gVCF blocks,
      # respecting non-reference variants interspersed among them. Yields each
      # combined gVCF Variant proto, in order. Compatible right now means that the
      # blocks to be merged have the same non-None GQ value.
      for key, combinable in itertools.groupby(
          (
              with_gq_and_likelihoods(sc)
              for sc in allele_count_summaries
          ),
          key=operator.attrgetter("quantized_gq", "has_valid_gl"),
      ):
          quantized_gq_val, gl_is_valid = key
          if quantized_gq_val is None:
              # A None key indicates that a non-DNA reference base was encountered, so
              # skip this group.
              continue
  
          if gl_is_valid:
              combinable = list(combinable)
              min_gq = min(elt.raw_gq for elt in combinable)
              min_dp = min(elt.read_depth for elt in combinable)
              med_dp = int(
                  statistics.median(
                      elt.read_depth for elt in combinable
                  )
              )
              first_record, last_record = combinable[0], combinable[-1]
              call = variants_pb2.VariantCall(
                  call_set_name=self.options.sample_name,
                  genotype=[0, 0],
                  genotype_likelihood=first_record.likelihoods,
              )
              variantcall_utils.set_gq(call, min_gq)
              variantcall_utils.set_min_dp(call, min_dp)
              if include_med_dp:
                  variantcall_utils.set_med_dp(call, med_dp)
              yield variants_pb2.Variant(
                  reference_name=first_record.summary_counts.reference_name,
                  reference_bases=first_record.summary_counts.ref_base,
                  alternate_bases=[vcf_constants.GVCF_ALT_ALLELE],
                  start=first_record.summary_counts.position,
                  end=last_record.summary_counts.position + 1,
                  calls=[call],
              )
          else:
              # After evaluating the effect of including sites with contradictory GL
              # (where the value for hom_ref is not maximal), we concluded that
              # un-calling these sites (by setting its genotype "./.") is better
              # for cohort merging.
              # See internal for detail.
              for elt in combinable:
                  uncalled_gt = [-1, -1]
                  call = variants_pb2.VariantCall(
                      call_set_name=self.options.sample_name,
                      genotype=uncalled_gt,
                      genotype_likelihood=elt.likelihoods,
                  )
                  variantcall_utils.set_gq(call, elt.raw_gq)
                  variantcall_utils.set_min_dp(call, elt.read_depth)
                  if include_med_dp:
                      variantcall_utils.set_med_dp(call, elt.read_depth)
                  yield variants_pb2.Variant(
                      reference_name=elt.summary_counts.reference_name,
                      reference_bases=elt.summary_counts.ref_base,
                      alternate_bases=[vcf_constants.GVCF_ALT_ALLELE],
                      start=elt.summary_counts.position,
                      end=elt.summary_counts.position + 1,
                      calls=[call],
                  )
  
imports: import abc
  import collections
  import itertools
  import math
  import operator
  import statistics
  from typing import Dict, Sequence, Tuple
  import numpy
  from deepvariant.protos import deepvariant_pb2
  from deepvariant.python import allelecounter
  from deepvariant.python import variant_calling
  from deepvariant.python import variant_calling_multisample
  from third_party.nucleus.protos import variants_pb2
  from third_party.nucleus.util import genomics_math
  from third_party.nucleus.util import variantcall_utils
  from third_party.nucleus.util import vcf_constants
label_desc: Use image node_id 4 for calling the VariantCaller obj's underlying member method code with example usage: obj.make_gvcfs(allele_count_summaries, include_med_dp) and returns: _GVCF