public static void getOrdering ( int p , int n , List < String > list , int [ ] gt , int pos , int [ ] map ) { for ( int a = 0 ; a <= n ; a ++ ) { if ( map == null ) { gt [ pos ] = a ; } else { // Remap allele gt [ pos ] = remapAllele ( map , a ) ; } if ( p == 1 ) { int prev = gt [ 0 ] ; int [ ] gtSorted = gt ; // Check if sorted for ( int g : gt ) { if ( prev > g ) { // Sort if needed. Do not modify original array gtSorted = Arrays . copyOf ( gt , gt . length ) ; Arrays . sort ( gtSorted ) ; break ; } } StringBuilder sb = new StringBuilder ( ) ; for ( int g : gtSorted ) { sb . append ( g ) ; } list . add ( sb . toString ( ) ) ; } else { getOrdering ( p - 1 , a , list , gt , pos - 1 , map ) ; } } }
Recursive genotype ordering algorithm as seen in VCF - spec .