Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_floor_division(self):
a_int32 = hl.array([2, 4, 8, 16, hl.null(tint32)])
a_int64 = a_int32.map(lambda x: hl.int64(x))
a_float32 = a_int32.map(lambda x: hl.float32(x))
a_float64 = a_int32.map(lambda x: hl.float64(x))
int32_4s = hl.array([4, 4, 4, 4, hl.null(tint32)])
int32_3s = hl.array([3, 3, 3, 3, hl.null(tint32)])
int64_3 = hl.int64(3)
int64_3s = int32_3s.map(lambda x: hl.int64(x))
float32_3 = hl.float32(3)
float32_3s = int32_3s.map(lambda x: hl.float32(x))
float64_3 = hl.float64(3)
float64_3s = int32_3s.map(lambda x: hl.float64(x))
expected = [0, 1, 2, 5, None]
expected_inv = [1, 0, 0, 0, None]
self.check_expr(a_int32 // 3, expected, tarray(tint32))
>>> hl.eval(hl.or_missing(False, 5))
None
Parameters
----------
predicate : :class:`.BooleanExpression`
value : :class:`.Expression`
Value to return if `predicate` is ``True``.
Returns
-------
:class:`.Expression`
This expression has the same type as `b`.
"""
return hl.cond(predicate, value, hl.null(value.dtype))
'gene_pheno': hl.null('int32'),
'gene_symbol': 'NOC2L',
'gene_symbol_source': 'HGNC',
'hgnc_id': '24517',
'hgvs_offset': hl.null('int32'),
'hgvsc': 'ENST00000483767.1:n.523C>T',
'hgvsp': hl.null('str'),
'impact': 'MODIFIER',
'intron': hl.null('str'),
'lof': hl.null('str'),
'lof_filter': hl.null('str'),
'lof_flags': hl.null('str'),
'lof_info': hl.null('str'),
'minimised': 1,
'polyphen_prediction': hl.null('str'),
'polyphen_score': hl.null('float64'),
'protein_end': hl.null('int32'),
'protein_id': hl.null('str'),
'protein_start': hl.null('int32'),
'sift_prediction': hl.null('str'),
'sift_score': hl.null('float64'),
'strand': -1,
'swissprot': hl.null('str'),
'transcript_id': 'ENST00000483767',
'trembl': hl.null('str'),
'uniparc': hl.null('str'),
'variant_allele': 'A'}),
hl.struct(**{'allele_num': 1,
'amino_acids': hl.null('str'),
'biotype': 'processed_transcript',
'canonical': hl.null('int32'),
'ccds': hl.null('str'),
def pull_out_worst_from_tx_annotate(mt):
csq_order = []
for loftee_filter in ["HC", "LC"]:
for no_flag in [True, False]:
for consequence in CSQ_CODING_HIGH_IMPACT:
csq_order.append((loftee_filter, no_flag, consequence))
# prioritization of mis and syn variant on protein coding transcripts
csq_order.extend([(hl.null(hl.tstr), True, x) for x in
CSQ_CODING_MEDIUM_IMPACT + CSQ_CODING_LOW_IMPACT])
# Any variant on a non protein coding transcript (ie. where LOF = None)
csq_order.extend([(hl.null(hl.tstr), True, x) for x in
CSQ_CODING_HIGH_IMPACT + CSQ_CODING_MEDIUM_IMPACT + CSQ_CODING_LOW_IMPACT])
csq_order = hl.literal({(x): i for i, x in enumerate(csq_order)})
mt = mt.annotate_rows(**hl.sorted(mt.tx_annotation, key=lambda x: csq_order[
(x.lof, hl.or_else(hl.is_missing(x.lof_flag), False), x.csq)])[0])
return mt
def _genotype_fields(self):
# Convert the mt genotype entries into num_alt, gq, ab, dp, and sample_id.
is_called = hl.is_defined(self.mt.GT)
return {
'num_alt': hl.cond(is_called, self.mt.GT.n_alt_alleles(), -1),
'gq': hl.cond(is_called, self.mt.GQ, hl.null(hl.tint)),
'ab': hl.bind(
lambda total: hl.cond((is_called) & (total != 0) & (hl.len(self.mt.AD) > 1),
hl.float(self.mt.AD[1] / total),
hl.null(hl.tfloat)),
hl.sum(self.mt.AD)
),
'dp': hl.cond(is_called, hl.int(hl.min(self.mt.DP, 32000)), hl.null(hl.tfloat)),
'sample_id': self.mt.s
}
def nullify_nan(value):
return hl.cond(hl.is_nan(value), hl.null(value.dtype), value)
lambda e:
hl.struct(
DP=e.DP,
END=row.info.END,
GQ=e.GQ,
LA=hl.range(0, alleles_len - hl.cond(has_non_ref, 1, 0)),
LAD=hl.cond(has_non_ref, e.AD[:-1], e.AD),
LGT=e.GT,
LPGT=e.PGT,
LPL=hl.cond(has_non_ref,
hl.cond(alleles_len > 2,
e.PL[:-alleles_len],
hl.null(e.PL.dtype)),
hl.cond(alleles_len > 1,
e.PL,
hl.null(e.PL.dtype))),
MIN_DP=e.MIN_DP,
PID=e.PID,
RGQ=hl.cond(
has_non_ref,
e.PL[hl.call(0, alleles_len - 1).unphased_diploid_gt_index()],
hl.null(e.PL.dtype.element_type)),
SB=e.SB,
gvcf_info=hl.case()
.when(hl.is_missing(row.info.END),
hl.struct(**(
parse_as_fields(
row.info.select(*info_to_keep),
has_non_ref)
)))
lambda c: c.select(
*selected_annotations,
consequence_terms=c.consequence_terms.filter(lambda t: ~omit_consequence_terms.contains(t)),
domains=c.domains.map(lambda domain: domain.db + ":" + domain.name),
major_consequence=hl.cond(
c.consequence_terms.size() > 0,
hl.sorted(c.consequence_terms, key=lambda t: CONSEQUENCE_TERM_RANK_LOOKUP.get(t))[0],
hl.null(hl.tstr),
)
min_callrate,
min_inbreeding_coeff_threshold,
min_hardy_weinberg_threshold,
apply_hard_filters,
)
if ld_r2 is not None:
qc_mt = qc_mt.persist()
unfiltered_qc_mt = qc_mt.unfilter_entries()
pruned_ht = hl.ld_prune(unfiltered_qc_mt.GT, r2=ld_r2)
qc_mt = qc_mt.filter_rows(hl.is_defined(pruned_ht[qc_mt.row_key]))
qc_mt = qc_mt.annotate_globals(
qc_mt_params=hl.struct(
adj_only=adj_only,
min_af=min_af if min_af is not None else hl.null(hl.tfloat32),
min_callrate=min_callrate
if min_callrate is not None
else hl.null(hl.tfloat32),
inbreeding_coeff_threshold=min_inbreeding_coeff_threshold
if min_inbreeding_coeff_threshold is not None
else hl.null(hl.tfloat32),
min_hardy_weinberg_threshold=min_hardy_weinberg_threshold
if min_hardy_weinberg_threshold is not None
else hl.null(hl.tfloat32),
apply_hard_filters=apply_hard_filters,
ld_r2=ld_r2 if ld_r2 is not None else hl.null(hl.tfloat32),
filter_exome_low_coverage_regions=filter_exome_low_coverage_regions,
high_conf_regions=high_conf_regions
if high_conf_regions is not None
else hl.null(hl.tarray(hl.tstr)),
)