def merge_conditions_array(conds):
"""If there are multiple affected samples sharing the same parents,
the conditions can be redundant. Simplify the conditions array so that
there is at most one for each genotype/sample. If there are several constraints
for the same genotype, check that they are compatible and take the strongest
(lowest bit value).
:param conds: an array of couples [sample_index, genotype_bit]
:rtype: same as input
"""
merged = []
if not conds:
return merged
# Group by sample index, and get a single common bit for all conds on that sample
conds.sort(key=itemgetter(0))
for idx,group in itertools.groupby(conds, itemgetter(0)):
genbits = [x[1] for x in group] # only the genotype bit
common_bits = reduce(__and__, genbits)
merged.append((idx, common_bits))
return merged
评论列表
文章目录