Esempio n. 1
0
def age_hists_expr(
    adj_expr: hl.expr.BooleanExpression,
    gt_expr: hl.expr.CallExpression,
    age_expr: hl.expr.NumericExpression,
    lowest_boundary: int = 30,
    highest_boundary: int = 80,
    n_bins: int = 10,
) -> hl.expr.StructExpression:
    """
    Returns a StructExpression with the age histograms for hets and homs.

    :param adj_expr: Entry expression containing whether a genotype is high quality (adj) or not
    :param gt_expr: Entry expression containing the genotype
    :param age_expr: Col expression containing the sample's age
    :param lowest_boundary: Lowest bin boundary (any younger sample will be binned in n_smaller)
    :param highest_boundary: Highest bin boundary (any older sample will be binned in n_larger)
    :param n_bins: Total number of bins
    :return: A struct with `age_hist_het` and `age_hist_hom`
    """
    return hl.struct(
        age_hist_het=hl.agg.filter(
            adj_expr & gt_expr.is_het(),
            hl.agg.hist(age_expr, lowest_boundary, highest_boundary, n_bins),
        ),
        age_hist_hom=hl.agg.filter(
            adj_expr & gt_expr.is_hom_var(),
            hl.agg.hist(age_expr, lowest_boundary, highest_boundary, n_bins),
        ),
    )
Esempio n. 2
0
 def _is_dnm(
     proband_gt: hl.expr.CallExpression,
     father_gt: hl.expr.CallExpression,
     mother_gt: hl.expr.CallExpression,
     locus: hl.expr.LocusExpression,
     proband_is_female: Optional[hl.expr.BooleanExpression],
 ) -> hl.expr.BooleanExpression:
     """
     Helper method to get whether a given genotype combination is a DNM at a given locus with a given proband sex.
     """
     if proband_is_female is None:
         logger.warning(
             "Since no proband sex expression was given to generate_trio_stats_expr, only DNMs in autosomes will be counted."
         )
         return hl.or_missing(
             locus.in_autosome(),
             proband_gt.is_het() & father_gt.is_hom_ref()
             & mother_gt.is_hom_ref(),
         )
     return hl.cond(
         locus.in_autosome_or_par() |
         (proband_is_female & locus.in_x_nonpar()),
         proband_gt.is_het() & father_gt.is_hom_ref()
         & mother_gt.is_hom_ref(),
         hl.or_missing(~proband_is_female,
                       proband_gt.is_hom_var() & father_gt.is_hom_ref()),
     )