Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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(
Parameters
----------
start : int or :class:`.Expression` of type :py:data:`.tint32`
Start of range.
stop : int or :class:`.Expression` of type :py:data:`.tint32`
End of range.
step : int or :class:`.Expression` of type :py:data:`.tint32`
Step of range.
Returns
-------
:class:`.NDArrayNumericExpression`
A 1-dimensional ndarray from `start` to `stop` by `step`.
"""
return array(hl.range(start, stop, step))
return hl.range(0, 5).map(lambda i: hl.range(0, 5).map(lambda j: counter.get(i + 5 * j, 0)))
lambda step1_idx, m_step1, entry: hl.rbind(
hl.map(
lambda j: hl.int(hl.floor(j * (m_step1 / n_blocks))),
hl.range(0, n_blocks + 1)),
lambda step1_separators: hl.rbind(
hl.set(step1_separators).contains(step1_idx),
hl.sum(
hl.map(
lambda s1: step1_idx >= s1,
step1_separators)) - 1,
lambda is_separator, step1_block: entry.annotate(
__step1_block=step1_block,
__step2_block=hl.cond(~entry.__in_step1 & is_separator,
step1_block - 1,
step1_block))))),
hl.range(0, hl.len(ht.__entries)))))
def get_lm_prediction_expr(metric: str):
lm_pred_expr = _sample_qc_ht.lms[metric].beta[0] + hl.sum(
hl.range(n_pcs).map(
lambda i: _sample_qc_ht.lms[metric].beta[i + 1]
* _sample_qc_ht.scores[i]
)
)
if use_pc_square:
lm_pred_expr = lm_pred_expr + hl.sum(
hl.range(n_pcs).map(
lambda i: _sample_qc_ht.lms[metric].beta[i + n_pcs + 1]
* _sample_qc_ht.scores[i]
* _sample_qc_ht.scores[i]
)
)
return lm_pred_expr
Computes the sites concordance 5x5 matrix from the `nr` annotations in the left and right columns
:param n_samples:
:param left:
:param right:
:return:
"""
conc_coords = (
hl.range(0, n_samples)
.map(lambda s: hl.tuple([left.get(s, 2), right.get(s, 2)]))
.group_by(lambda x: x)
.map_values(lambda x: hl.len(x))
)
return hl.range(0,5).map(lambda left: hl.range(0,5).map(lambda right: conc_coords.get(hl.tuple([left, right]), 0)))
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),
PL=newPL)
# otherwise downcode
else:
mt = mt.annotate_rows(__old_to_new_no_na = mt.old_to_new.map(lambda x: hl.or_else(x, 0)))
newPL = hl.cond(
hl.is_defined(mt.PL),
(hl.range(0, hl.triangle(hl.len(mt.alleles)))
.map(lambda newi: hl.min(hl.range(0, hl.triangle(hl.len(mt.old_alleles)))
.filter(lambda oldi: hl.bind(
lambda oldc: hl.call(mt.__old_to_new_no_na[oldc[0]],
mt.__old_to_new_no_na[oldc[1]]) == hl.unphased_diploid_gt_index_call(newi),
hl.unphased_diploid_gt_index_call(oldi)))
# This expression creates a counter DP -> number of samples for DP between 0 and max_coverage_bin
coverage_counter_expr = hl.agg.counter(
hl.or_else(hl.min(max_coverage_bin, mt.DP), 0)
)
# This expression aggregates the DP counter in reverse order of the coverage_over_x_bins
# and computes the cumulative sum over them.
# It needs to be in reverse order because we want the sum over samples covered by > X.
count_array_expr = hl.cumulative_sum(
hl.array(
[
hl.int32(coverage_counter_expr.get(max_coverage_bin, 0))
] # The coverage was already floored to the max_coverage_bin, so no more aggregation is needed for the max bin
).extend( # For each of the other bins, coverage needs to be summed between the boundaries
hl.range(hl.len(hl_coverage_over_x_bins) - 1, 0, step=-1).map(
lambda i: hl.sum(
hl.range(
hl_coverage_over_x_bins[i - 1], hl_coverage_over_x_bins[i]
).map(lambda j: hl.int32(coverage_counter_expr.get(j, 0)))
)
)
)
)
mean_expr = hl.agg.mean(mt.DP)
# Annotate rows now
return mt.select_rows(
mean=hl.cond(hl.is_nan(mean_expr), 0, mean_expr),
median=hl.or_else(hl.agg.approx_median(mt.DP), 0),
total_DP=hl.agg.sum(mt.DP),
**{