def test_transform_to_gvcf_add_allele(self, prior_alts, prior_gls, prior_vaf):
   variant = _create_variant(
       ref_name='chr1',
       start=10,
       ref_base='A',
       alt_bases=prior_alts,
       qual=40,
       filter_field='PASS',
       genotype=[0, 1],
       gq=None,
       likelihoods=prior_gls)
   prior_vaf_values = [struct_pb2.Value(number_value=v) for v in prior_vaf]
   variant.calls[0].info['VAF'].values.extend(prior_vaf_values)
   expected = _create_variant(
       ref_name='chr1',
       start=10,
       ref_base='A',
       alt_bases=prior_alts + [variantutils.GVCF_ALT_ALLELE],
       qual=40,
       filter_field='PASS',
       genotype=[0, 1],
       gq=None,
       likelihoods=prior_gls + ([postprocess_variants._GVCF_ALT_ALLELE_GL] *
                                (len(prior_alts) + 2)))
   expected.calls[0].info['VAF'].values.extend(
       prior_vaf_values + [struct_pb2.Value(number_value=0)])
   actual = postprocess_variants._transform_to_gvcf_record(variant)
   self.assertEqual(actual, expected)
Пример #2
0
def _transform_to_gvcf_record(variant):
    """Modifies a variant to include gVCF allele and associated likelihoods.

  Args:
    variant: third_party.nucleus.protos.Variant. The Variant
      to modify.

  Returns:
    The variant after applying the modification to its alleles and
    allele-related FORMAT fields.
  """
    if variantutils.GVCF_ALT_ALLELE not in variant.alternate_bases:
        variant.alternate_bases.append(variantutils.GVCF_ALT_ALLELE)
        # Add one new GL for het allele/gVCF for each of the other alleles, plus one
        # for the homozygous gVCF allele.
        num_new_gls = len(variant.alternate_bases) + 1
        variant.calls[0].genotype_likelihood.extend([_GVCF_ALT_ALLELE_GL] *
                                                    num_new_gls)
        if variant.calls[0].info and 'AD' in variant.calls[0].info:
            variant.calls[0].info['AD'].values.extend(
                [struct_pb2.Value(number_value=0)])
        if variant.calls[0].info and 'VAF' in variant.calls[0].info:
            variant.calls[0].info['VAF'].values.extend(
                [struct_pb2.Value(number_value=0)])

    return variant
Пример #3
0
 def format_one(value):
     if isinstance(value, str):
         return struct_pb2.Value(string_value=value)
     elif isinstance(value, (float, int)):
         return struct_pb2.Value(number_value=value)
     else:
         raise ValueError('Unsupported type ', value)
Пример #4
0
def _format_test_variant(alleles, call_infos):
  variant = test_utils.make_variant(chrom='20', start=0, alleles=alleles)
  for i, call_info in enumerate(call_infos):
    call = variant.calls.add(call_set_name='sample' + str(i))
    for key, value in call_info.iteritems():
      if not isinstance(value, (list, tuple)):
        value = [value]
      call.info[key].values.extend(
          [struct_pb2.Value(number_value=v) for v in value])
  return variant
 def test_transform_to_gvcf_no_allele_addition(self, alts, gls, vaf):
   variant = _create_variant(
       ref_name='chr1',
       start=10,
       ref_base='A',
       alt_bases=alts,
       qual=40,
       filter_field='PASS',
       genotype=[0, 1],
       gq=None,
       likelihoods=gls)
   vaf_values = [struct_pb2.Value(number_value=v) for v in vaf]
   variant.calls[0].info['VAF'].values.extend(vaf_values)
   expected = variants_pb2.Variant()
   expected.CopyFrom(variant)
   actual = postprocess_variants._transform_to_gvcf_record(variant)
   self.assertEqual(actual, expected)
Пример #6
0
def set_variantcall_gq(variant_call, gq):
    if 'GQ' in variant_call.info:
        del variant_call.info['GQ']
    variant_call.info['GQ'].values.extend([struct_pb2.Value(number_value=gq)])