Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
entries_sym: hl.map(lambda i:
hl.bind(lambda t: hl.struct(proband_entry=mt[entries_sym][t.id],
father_entry=mt[entries_sym][t.pat_id],
mother_entry=mt[entries_sym][t.mat_id]),
mt[trios_sym][i]),
hl.range(0, n_trios))})
def make_struct(i):
def error_on_moved(v):
return (hl.case()
.when(v.locus == old_row.locus, new_struct(v, i))
.or_error("Found non-left-aligned variant in SplitMulti"))
return hl.bind(error_on_moved,
hl.min_rep(old_row.locus, [old_row.alleles[0], old_row.alleles[i]]))
return split_rows(hl.sorted(kept_alleles.map(make_struct)), False)
lambda alleles:
hl.struct(
locus=row.locus,
alleles=alleles.globl,
rsid=hl.find(hl.is_defined, row.data.map(lambda d: d.rsid)),
__entries=hl.bind(
lambda combined_allele_index:
hl.range(0, hl.len(row.data)).flatmap(
lambda i:
hl.cond(hl.is_missing(row.data[i].__entries),
hl.range(0, hl.len(gbl.g[i].__cols))
.map(lambda _: hl.null(row.data[i].__entries.dtype.element_type)),
hl.bind(
lambda old_to_new: row.data[i].__entries.map(
lambda e: renumber_entry(e, old_to_new)),
hl.range(0, hl.len(alleles.local[i])).map(
lambda j: combined_allele_index[alleles.local[i][j]])))),
hl.dict(hl.range(0, hl.len(alleles.globl)).map(
lambda j: hl.tuple([alleles.globl[j], j])))))),
ts.row.dtype, ts.globals.dtype)
>>> hl.eval(hl.rand_dirichlet([1, 1, 1])) # doctest: +NOTEST
[0.20851948405364765,0.7873859423649898,0.004094573581362475]
Parameters
----------
a : :obj:`list` of float or :class:`.ArrayExpression` of type :py:data:`.tfloat64`
Array of non-negative concentration parameters.
seed : :obj:`int`, optional
Random seed.
Returns
-------
:class:`.Float64Expression`
"""
return hl.bind(lambda x: x / hl.sum(x),
a.map(lambda p:
hl.cond(p == 0.0,
0.0,
hl.rand_gamma(p, 1, seed=seed))))
def make_struct(i, cond):
def struct_or_empty(v):
return (hl.case()
.when(cond(v.locus), hl.array([new_struct(v, i)]))
.or_missing())
return hl.bind(struct_or_empty,
hl.min_rep(old_row.locus, [old_row.alleles[0], old_row.alleles[i]]))
:class:`.MatrixTable`
"""
if mt.entry.dtype != hl.hts_entry_schema:
raise FatalError("'filter_alleles_hts': entry schema must be the HTS entry schema:\n"
" found: {}\n"
" expected: {}\n"
" Use 'hl.filter_alleles' to split entries with non-HTS entry fields.".format(
mt.entry.dtype, hl.hts_entry_schema
))
mt = filter_alleles(mt, f)
if subset:
newPL = hl.cond(
hl.is_defined(mt.PL),
hl.bind(
lambda unnorm: unnorm - hl.min(unnorm),
hl.range(0, hl.triangle(mt.alleles.length())).map(
lambda newi: hl.bind(
lambda newc: mt.PL[hl.call(mt.new_to_old[newc[0]],
mt.new_to_old[newc[1]]).unphased_diploid_gt_index()],
hl.unphased_diploid_gt_index_call(newi)))),
hl.null(tarray(tint32)))
return mt.annotate_entries(
GT=hl.unphased_diploid_gt_index_call(hl.argmin(newPL, unique=True)),
AD=hl.cond(
hl.is_defined(mt.AD),
hl.range(0, mt.alleles.length()).map(
lambda newi: mt.AD[mt.new_to_old[newi]]),
hl.null(tarray(tint32))),
# DP unchanged
GQ=hl.gq_from_pl(newPL),
def get_expr_for_contig_number(
locus: hl.expr.LocusExpression
) -> hl.expr.Int32Expression:
"""Convert contig name to contig number"""
return hl.bind(
lambda contig: (
hl.case()
.when(contig == "X", 23)
.when(contig == "Y", 24)
.when(contig[0] == "M", 25)
.default(hl.int(contig))
),
get_expr_for_contig(locus),
)
def sum_mcnv_ac_or_af(alts, values):
return hl.bind(
lambda cn2_index: hl.bind(
lambda values_to_sum: values_to_sum.fold(lambda acc, n: acc + n, 0),
hl.cond(hl.is_defined(cn2_index), values[0:cn2_index].extend(values[cn2_index + 1 :]), values),
),
hl.zip_with_index(alts).find(lambda t: t[1] == "")[0],
)
1
>>> hl.eval(names.index('Beth'))
None
>>> hl.eval(names.index(lambda x: x.endswith('e')))
0
>>> hl.eval(names.index(lambda x: x.endswith('h')))
None
"""
if callable(x):
f = lambda elt, x: x(elt)
else:
f = lambda elt, x: elt == x
return hl.bind(lambda a: hl.range(0, a.length()).filter(lambda i: f(a[i], x)).head(), self)
lambda aggs: hl.bind(
lambda mean: hl.struct(
mean=mean,
stdev=hl.sqrt(hl.float64(
aggs.sumsq - (2 * mean * aggs.sum) + (aggs.n_def * mean ** 2)) / aggs.n_def),
min=hl.float64(aggs.min),
max=hl.float64(aggs.max),
n=aggs.n_def,
sum=hl.float64(aggs.sum)
), hl.float64(aggs.sum) / aggs.n_def),
hl.struct(n_def=count_where(hl.is_defined(expr)),