private int [ ] getGenotypesReorderingMap ( int numAllele , int [ ] alleleMap ) { int numAlleles = alleleMap . length ; // int ploidy = 2; int key = numAllele * 100 + numAlleles ; int [ ] map = genotypeReorderMapCache . get ( key ) ; if ( map != null ) { return map ; } else { ArrayList < Integer > mapList = new ArrayList <> ( ) ; for ( int originalA2 = 0 ; originalA2 < alleleMap . length ; originalA2 ++ ) { int newA2 = ArrayUtils . indexOf ( alleleMap , originalA2 ) ; for ( int originalA1 = 0 ; originalA1 <= originalA2 ; originalA1 ++ ) { int newA1 = ArrayUtils . indexOf ( alleleMap , originalA1 ) ; if ( newA1 <= newA2 ) { mapList . add ( ( newA2 * ( newA2 + 1 ) / 2 + newA1 ) ) ; } else { mapList . add ( ( newA1 * ( newA1 + 1 ) / 2 + newA2 ) ) ; } } } map = new int [ mapList . size ( ) ] ; for ( int i = 0 ; i < mapList . size ( ) ; i ++ ) { map [ i ] = mapList . get ( i ) ; } genotypeReorderMapCache . put ( key , map ) ; return map ; } }
Gets an array for reordening the positions of a format field with Number = G and ploidy = 2 .