def add_call_to_variant(variant, predictions, qual_filter=0, sample_name=None): """Fills in Variant record using the prediction probabilities. This functions sets the call[0].genotype, call[0].info['GQ'], call[0].genotype_probabilities, variant.filter, and variant.quality fields of variant based on the genotype likelihoods in predictions. Args: variant: third_party.nucleus.protos.Variant protobuf to be filled in with info derived from predictions. predictions: N element array-like. The real-space probabilities of each genotype state for this variant. qual_filter: float. If predictions implies that this isn't a reference call and the QUAL of the prediction isn't larger than qual_filter variant will be marked as FILTERed. sample_name: str. The name of the sample to assign to the Variant proto call_set_name field. Returns: A Variant record. Raises: ValueError: If variant doesn't have exactly one variant.call record. """ call = variant_utils.only_call(variant) n_alleles = len(variant.alternate_bases) + 1 index, genotype = most_likely_genotype(predictions, n_alleles=n_alleles) gq, variant.quality = compute_quals(predictions, index) call.call_set_name = sample_name variantcall_utils.set_gt(call, genotype) variantcall_utils.set_gq(call, gq) gls = [genomics_math.perror_to_bounded_log10_perror(gp) for gp in predictions] variantcall_utils.set_gl(call, gls) variant.filter[:] = compute_filter_fields(variant, qual_filter) return variant
def add_call_to_variant(variant, predictions, qual_filter=0, sample_name=None): """Fills in Variant record using the prediction probabilities. This functions sets the call[0].genotype, call[0].info['GQ'], call[0].genotype_probabilities, variant.filter, and variant.quality fields of variant based on the genotype likelihoods in predictions. Args: variant: third_party.nucleus.protos.Variant protobuf to be filled in with info derived from predictions. predictions: N element array-like. The real-space probabilities of each genotype state for this variant. qual_filter: float. If predictions implies that this isn't a reference call and the QUAL of the prediction isn't larger than qual_filter variant will be marked as FILTERed. sample_name: str. The name of the sample to assign to the Variant proto call_set_name field. Returns: A Variant record. Raises: ValueError: If variant doesn't have exactly one variant.call record. """ call = variant_utils.only_call(variant) n_alleles = len(variant.alternate_bases) + 1 index, genotype = most_likely_genotype(predictions, n_alleles=n_alleles) gq, variant.quality = compute_quals(predictions, index) call.call_set_name = sample_name variantcall_utils.set_gt(call, genotype) variantcall_utils.set_gq(call, gq) gls = [ genomics_math.perror_to_bounded_log10_perror(gp) for gp in predictions ] variantcall_utils.set_gl(call, gls) variant.filter[:] = compute_filter_fields(variant, qual_filter) uncall_homref_gt_if_lowqual(variant, FLAGS.cnn_homref_call_min_gq) return variant