public static void getHeterozygousGenotype(int index, int numAlternativeAlleles, Integer alleles[]) {
//        index++;
//        double value = (-3 + Math.sqrt(1 + 8 * index)) / 2;    // slower than the iterating version, right?
//        alleles[1] = new Double(Math.ceil(value)).intValue();
//        alleles[0] = alleles[1] - ((alleles[1] + 1) * (alleles[1] +2) / 2 - index);

        int cursor = 0;
        for (int i = 0; i < numAlternativeAlleles; i++) {
            for (int j = i+1; j < numAlternativeAlleles +1; j++) {
                if (i != j) {
                    if (cursor == index) {
                        alleles[0] = i;
                        alleles[1] = j;
                        return;
                    }
                    cursor++;
                }
            }
        }
    }
public static void getHeterozygousGenotype ( int index , int numAlternativeAlleles , Integer alleles [ ] ) { int cursor = 0 ; for ( int i = 0 ; i < numAlternativeAlleles ; i ++ ) { for ( int j = i + 1 ; j < numAlternativeAlleles + 1 ; j ++ ) { if ( i != j ) { if ( cursor == index ) { alleles [ 0 ] = i ; alleles [ 1 ] = j ; return ; } cursor ++ ; } } } }
returns in alleles[] the heterozygous genotype specified in index in the sequence (in this example for 3 ALT alleles):
0/1, 0/2, 0/3, 1/2, 1/3, 2/3
@param index in this sequence, starting in 0
@param numAlternativeAlleles note that this ordering requires knowing how many alleles there are
@param alleles returned genotype.