class_docstr: This class serves as an `input_fn` for the `tf.estimator` framework.
class_docstr_tok: ["This","class","serves","as","an","`","input_fn","`","for","the","`","tf.estimator","`","framework","."]
docstr: Parse a DeepVariant pileup tf.Example to features and labels.
  
  This potentially stores parsed strings as fixed length tensors of integers,
  as required by TPU.  They have to be handled properly by consumers.
  
  Args:
    tf_example: a serialized tf.Example for a DeepVariant "pileup".
  
  Returns:
    If (mode is EVAL or TRAIN) or debugging_true_label_mode:
      (features, label) ...
    If mode is PREDICT,
      features ...
docstr_tok: ["Parse","a","DeepVariant","pileup","tf.Example","to","features","and","labels",".","This","potentially","stores","parsed","strings","as","fixed","length","tensors","of","integers",",","as","required","by","TPU",".","They","have","to","be","handled","properly","by","consumers",".","Args",":","tf_example",":","a","serialized","tf.Example","for","a","DeepVariant","``","pileup","''",".","Returns",":","If","(","mode","is","EVAL","or","TRAIN",")","or","debugging_true_label_mode",":","(","features",",","label",")","...","If","mode","is","PREDICT",",","features","..."]
code: def parse_tfexample(self, tf_example):
      """Parse a DeepVariant pileup tf.Example to features and labels.
  
      This potentially stores parsed strings as fixed length tensors of integers,
      as required by TPU.  They have to be handled properly by consumers.
  
      Args:
        tf_example: a serialized tf.Example for a DeepVariant "pileup".
  
      Returns:
        If (mode is EVAL or TRAIN) or debugging_true_label_mode:
          (features, label) ...
        If mode is PREDICT,
          features ...
      """
      with tf.compat.v1.name_scope("input"):
          parsed = tf.io.parse_single_example(
              serialized=tf_example,
              features=self.feature_extraction_spec,
          )
          image = parsed["image/encoded"]
          if self.tensor_shape:
              # If the input is empty there won't be a tensor_shape.
              image = tf.reshape(
                  tf.io.decode_raw(image, tf.uint8), self.tensor_shape
              )
              if self.use_tpu:
                  # Cast to int32 for loading onto the TPU
                  image = tf.cast(image, tf.int32)
  
          variant = parsed["variant/encoded"]
          alt_allele_indices = parsed["alt_allele_indices/encoded"]
          if self.use_tpu:
              # Passing a string to a TPU draws this error: TypeError: <dtype:
              # 'string'> is not a supported TPU infeed type. Supported types are:
              # [tf.float32, tf.int32, tf.complex64, tf.int64, tf.bool, tf.bfloat16]
              # Thus, we must encode the string as a tensor of int.
              variant = dv_utils.string_to_int_tensor(variant)
              alt_allele_indices = dv_utils.string_to_int_tensor(
                  alt_allele_indices
              )
  
          features = {
              "image": image,
              "variant": variant,
              "alt_allele_indices": alt_allele_indices,
              "sequencing_type": parsed["sequencing_type"],
          }
  
          if (
              self.mode
              in (
                  tf_estimator.ModeKeys.TRAIN,
                  tf_estimator.ModeKeys.EVAL,
              )
              or self.debugging_true_label_mode
          ):
              if self.use_tpu:
                  features["locus"] = dv_utils.string_to_int_tensor(
                      parsed["locus"]
                  )
              else:
                  features["locus"] = parsed["locus"]
  
              # Add variant_type to our features if are in TRAIN or EVAL mode.
              features["variant_type"] = parsed["variant_type"]
  
              if self.mode in (
                  tf_estimator.ModeKeys.TRAIN,
                  tf_estimator.ModeKeys.EVAL,
              ):
                  label = parsed["label"]
                  return features, label
              features["label"] = parsed["label"]
  
          # For predict model, label is not present. So, returns features only.
          return features
  
imports: import itertools
  from typing import Callable, Optional, Tuple
  from absl import logging
  import ml_collections
  import tensorflow
  from tensorflow import estimator
  from deepvariant import dv_constants
  from deepvariant import dv_utils
  from deepvariant import keras_modeling
  from deepvariant.protos import deepvariant_pb2
  from google.protobuf import text_format
  from third_party.nucleus.io import sharded_file_utils
label_desc: Use image node_id 3 for calling the DeepVariantInput obj's underlying member method code with example usage: obj.parse_tfexample(tf_example) and returns: features, features,  label