def _order_refalt_lexicographically(self, variants):
# Also assert that chrom and pos are in order
cp_groups = itertools.groupby(variants, key=lambda v:(v['chrom'], v['pos']))
prev_chrom_index, prev_pos = -1, -1
for cp, tied_variants in cp_groups:
chrom_index = self._get_chrom_index(cp[0])
if chrom_index < prev_chrom_index:
raise PheWebError(
"The chromosomes in your file appear to be in the wrong order.\n" +
"The required order is: {!r}\n".format(chrom_order_list) +
"But in your file, the chromosome {!r} came after the chromosome {!r}\n".format(
cp[0], chrom_order_list[prev_chrom_index]))
if chrom_index == prev_chrom_index and cp[1] < prev_pos:
raise PheWebError(
"The positions in your file appear to be in the wrong order.\n" +
"In your file, the position {!r} came after the position {!r} on chromsome {!r}\n".format(
cp[1], prev_pos, cp[0]))
prev_chrom_index, prev_pos = chrom_index, cp[1]
for v in sorted(tied_variants, key=lambda v:(v['ref'], v['alt'])):
yield v
评论列表
文章目录