Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
filter_expr.append((mt.hwe.p_value > min_hardy_weinberg_threshold))
if snv_only:
filter_expr.append(hl.is_snp(mt.alleles[0], mt.alleles[1]))
if bi_allelic_only:
filter_expr.append(bi_allelic_expr(mt))
if apply_hard_filters:
if 'info' in mt.row_value:
if 'QD' in mt.info:
filter_expr.append((mt.info.QD >= 2))
else:
logger.warn("Could not apply QD hard filter, as `info.QD` not found in schema.")
if 'FS' in mt.info:
filter_expr.append((mt.info.FS <= 60))
else:
logger.warn("Could not apply FS hard filter, as `info.FS` not found in schema.")
if 'MQ' in mt.info:
filter_expr.append((mt.info.MQ >= 30))
else:
logger.warn("Could not apply MQ hard filter, as `info.MQ` not found in schema.")
else:
logger.warn("Could not apply hard filters as `info` not found in schema.")
return mt.filter_rows(functools.reduce(operator.iand, filter_expr))
filter_expr.append(bi_allelic_expr(mt))
if apply_hard_filters:
if 'info' in mt.row_value:
if 'QD' in mt.info:
filter_expr.append((mt.info.QD >= 2))
else:
logger.warn("Could not apply QD hard filter, as `info.QD` not found in schema.")
if 'FS' in mt.info:
filter_expr.append((mt.info.FS <= 60))
else:
logger.warn("Could not apply FS hard filter, as `info.FS` not found in schema.")
if 'MQ' in mt.info:
filter_expr.append((mt.info.MQ >= 30))
else:
logger.warn("Could not apply MQ hard filter, as `info.MQ` not found in schema.")
else:
logger.warn("Could not apply hard filters as `info` not found in schema.")
return mt.filter_rows(functools.reduce(operator.iand, filter_expr))
if apply_hard_filters:
if 'info' in mt.row_value:
if 'QD' in mt.info:
filter_expr.append((mt.info.QD >= 2))
else:
logger.warn("Could not apply QD hard filter, as `info.QD` not found in schema.")
if 'FS' in mt.info:
filter_expr.append((mt.info.FS <= 60))
else:
logger.warn("Could not apply FS hard filter, as `info.FS` not found in schema.")
if 'MQ' in mt.info:
filter_expr.append((mt.info.MQ >= 30))
else:
logger.warn("Could not apply MQ hard filter, as `info.MQ` not found in schema.")
else:
logger.warn("Could not apply hard filters as `info` not found in schema.")
return mt.filter_rows(functools.reduce(operator.iand, filter_expr))
The input interval HT should have a key of type Interval.
The resulting table will have a key of the same type as the `intervals_ht` table and
contain an `interval_info` field containing all non-key fields of the `intervals_ht`.
:param mt: Input MT
:param intervals_ht: Table containing the intervals. This table has to be keyed by locus.
:param bi_allelic_only: If set, only bi-allelic sites are used for the computation
:param autosomes_only: If set, only autosomal intervals are used.
:param matches: If set, returns all intervals in intervals_ht that overlap the locus in the input MT.
:return: Callrate MT
"""
logger.info('Computing call rate MatrixTable')
if len(intervals_ht.key) != 1 or not isinstance(intervals_ht.key[0], hl.expr.IntervalExpression):
logger.warn(f'Call rate matrix computation expects `intervals_ht` with a key of type Interval. Found: {intervals_ht.key}')
if autosomes_only:
callrate_mt = filter_to_autosomes(mt)
if bi_allelic_only:
callrate_mt = callrate_mt.filter_rows(bi_allelic_expr(callrate_mt))
intervals_ht = intervals_ht.annotate(_interval_key=intervals_ht.key)
callrate_mt = callrate_mt.annotate_rows(_interval_key=intervals_ht.index(callrate_mt.locus, all_matches=match)._interval_key)
if match:
callrate_mt = callrate_mt.explode_rows('_interval_key')
callrate_mt = callrate_mt.filter_rows(hl.is_defined(callrate_mt._interval_key.interval))
callrate_mt = callrate_mt.select_entries(GT=hl.or_missing(hl.is_defined(callrate_mt.GT), hl.struct()))
callrate_mt = callrate_mt.group_rows_by(**callrate_mt._interval_key).aggregate(callrate=hl.agg.fraction(hl.is_defined(callrate_mt.GT)))