# How "alleles" filed in a key generated

**URL:** <https://discuss.hail.is/t/how-alleles-filed-in-a-key-generated/1962>\
**Category:** Hail Query & hailctl\
**Created:** [March 16, 2021, 3:51am UTC](https://discuss.hail.is/t/how-alleles-filed-in-a-key-generated/1962 "2021-03-16T03:51:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SimonLi5601](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/simonli5601/32/553_2.png) [@SimonLi5601](https://discuss.hail.is/u/SimonLi5601)\
**Post date:** [March 16, 2021, 3:51am UTC](https://discuss.hail.is/t/how-alleles-filed-in-a-key-generated/1962/1 "2021-03-16T03:51:50Z")

</div>

> is.hail.utils.HailException: RVD error! Keys found out of order:  
> Current key: { locus: { contig: chr1, position: 38046636 }, alleles: [2; GGCC, G] }  
> Previous key: { locus: { contig: chr1, position: 38046636 }, alleles: [2; GGCCGCC, G] }  
> This error can occur after a split\_multi if the dataset  
> contains both multiallelic variants and duplicated loci.

I read through two previous relevant posts and there might be a solution. However, my question is how this issue happens in the first place if we have variants look like below, specifically  
I don’t understand how keys are generated from a vcf, I couldn’t find what alleles are formatted in Hail documents.  
Could anyone help to explain a little bit more? Thanks!

> [2; GGCCGCC, G]  
> [2; GGCC, G]

Variants in vcf:

> chr1 38046636 . GGCCGCC G  
> chr1 38046636 . GGCCGCC GGCC  
> chr1 38046636 . GGCCGCC GGCCGCCGCC  
> chr1 38046640 . G A  
> chr1 38046640. G \*

---

<div class="post-metadata">

**Author:** ![tpoterba](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/tpoterba/32/61_2.png) [@tpoterba](https://discuss.hail.is/u/tpoterba)\
**Post date:** [March 16, 2021, 1:36pm UTC](https://discuss.hail.is/t/how-alleles-filed-in-a-key-generated/1962/2 "2021-03-16T13:36:37Z")

</div>

`split_multi` involves computing the minimal representation of a variant, which transforms `GGCCGCC/GGCC` into `GGCC/G`. That’s what you’re seeing in the error.

The core problem here is that split\_multi doesn’t really play nicely with data that’s already been split (particular by another tool). It looks like your input has already split multiallelics into biallelics, so do you need to split at all?

---

<div class="post-metadata">

**Author:** ![NLSVTN](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/nlsvtn/32/339_2.png) [@NLSVTN](https://discuss.hail.is/u/NLSVTN)\
**Post date:** [March 16, 2021, 1:52pm UTC](https://discuss.hail.is/t/how-alleles-filed-in-a-key-generated/1962/3 "2021-03-16T13:52:54Z")

</div>

Can we test in Hail if we need to run split\_multi before running it, so that not to get an error? We would then just do if-else and omit split\_multi when necessary.

---

<div class="post-metadata">

**Author:** ![tpoterba](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/tpoterba/32/61_2.png) [@tpoterba](https://discuss.hail.is/u/tpoterba)\
**Post date:** [March 16, 2021, 2:02pm UTC](https://discuss.hail.is/t/how-alleles-filed-in-a-key-generated/1962/4 "2021-03-16T14:02:17Z")

</div>

Yes, definitely:

```auto
contains_multiallelics = mt.aggregate_rows(hl.agg.max(hl.len(mt.alleles)) > 2)

```
