コード例 #1
0
    def label_variant(self, example, variant):
        """Adds the truth variant and label for variant to example.

    This function uses VariantLabeler to find a match for variant and writes
    in the correspond truth variant and derived label to our example proto.

    Args:
      example: A tf.Example proto. We will write truth_variant and label into
        this proto.
      variant: A learning.genomics.v1.Variant proto.
        This is the variant we'll use
        to call our VariantLabeler.match to get our truth variant.

    Returns:
      True if the variant was in the confident region (meaning that it could be
        given a label) and False otherwise.
    """
        is_confident, truth_variant = self.labeler.match(variant)
        if not is_confident:
            return False
        alt_alleles = tf_utils.example_alt_alleles(example, variant=variant)
        if variantutils.is_ref(variant):
            label = 0
        else:
            label = self.labeler.match_to_alt_count(variant, truth_variant,
                                                    alt_alleles)
        tf_utils.example_set_label(example, label)
        tf_utils.example_set_truth_variant(example, truth_variant)
        return True
コード例 #2
0
  def add_label_to_example(self, example, label):
    """Adds label information about the assigned label to our example.

    Args:
      example: A tf.Example proto. We will write truth_variant and label into
        this proto.
      label: A variant_labeler.Label object containing the labeling information
        to add to our example.

    Returns:
      The example proto with label fields added.

    Raises:
      ValueError: if label isn't confident.
    """
    if not label.is_confident:
      raise ValueError('Cannot add a non-confident label to an example',
                       example, label)
    alt_alleles_indices = tf_utils.example_alt_alleles_indices(example)

    # Set the genotype of the candidate variant to the labeled value.
    candidate = label.variant
    _set_variant_genotype(candidate, label.genotype)
    tf_utils.example_set_variant(example, candidate)

    # Set the label of the example to the # alts given our alt_alleles_indices.
    tf_utils.example_set_label(example,
                               label.label_for_alt_alleles(alt_alleles_indices))
    return example
コード例 #3
0
  def testExampleSetLabel(self):
    example = tf_utils.make_example(self.variant, self.alts, self.encoded_image,
                                    self.default_shape, self.default_format)

    self.assertIsNotAFeature('label', example)
    for label in [0, 1, 2]:
      tf_utils.example_set_label(example, label)
      self.assertEqual(label, tf_utils.example_label(example))