Example #1
0
def is_variant_call(variant,
                    require_non_ref_genotype=True,
                    no_calls_are_variant=False,
                    call_indices=None):
  """Is variant a non-reference call?

  A Variant proto doesn't always imply that there's a variant present in the
  genome. The call may not have alternate bases, may be filtered, may a have
  hom-ref genotype, etc. This function looks for all of those configurations
  and returns true iff the variant is asserting that a mutation is present
  in the same.

  Note that this code allows a variant without a calls field to be variant,
  but one with a genotype call must have a non-reference genotype to be
  considered variant (if require_non_ref_genotype is True, the default). If
  False, a variant that passes all of the site-level requirements for being
  a variant_call will return a True value, regardless of the genotypes, which
  means that we'll consider a site with a sample with a hom-ref or no-call site
  a variant call.

  Args:
    variant: nucleus.genomics.v1.Variant.
    require_non_ref_genotype: Should we require a site with a genotype call to
      have a non-reference (het, hom-var) genotype for the site to be considered
      a variant call?
    no_calls_are_variant: If a site has genotypes, should we consider no_call
      genotypes as being variant or not?
    call_indices: A list of 0-based indices. If specified, only the calls
      at the given indices will be considered. The function will return
      True if any of those calls are variant.

  Returns:
    True if variant is really a mutation call.
  """
  if not variant.alternate_bases:
    return False
  elif is_filtered(variant):
    return False
  elif not variant.calls or not require_non_ref_genotype:
    return True
  # All tests after this point should only look at genotype-based fields, as
  # we may have aborted out in the prev. line due to require_non_ref_genotype.
  else:
    if call_indices is None:
      call_indices = range(len(variant.calls))
    return any(
        any(g > 0
            for g in variant.calls[i].genotype) or
        (no_calls_are_variant and
         not variantcall_utils.has_genotypes(variant.calls[i]))
        for i in call_indices)
Example #2
0
 def test_has_genotypes(self, genotype, expected):
     call = variants_pb2.VariantCall(genotype=genotype)
     actual = variantcall_utils.has_genotypes(call)
     self.assertEqual(actual, expected)