private static int [ ] getGenotypeReorderingMap ( int ploidy , int [ ] map ) { int [ ] gMap ; if ( ploidy == 1 ) { gMap = new int [ map . length + 1 ] ; gMap [ 0 ] = 0 ; for ( int i = 0 ; i < map . length ; i ++ ) { gMap [ i + 1 ] = map [ i ] + 1 ; } } else if ( ploidy == 2 ) { int l = map . length ; gMap = new int [ l * ( l + 1 ) / 2 + l + 1 ] ; for ( int i = 0 ; i < gMap . length ; i ++ ) { gMap [ i ] = - 1 ; } int pos = 0 ; for ( int a2 = 0 ; a2 <= map . length ; a2 ++ ) { int newA2 = remapAlleleReverse ( map , a2 ) ; if ( newA2 < 0 ) { continue ; } for ( int a1 = 0 ; a1 <= a2 ; a1 ++ ) { int newA1 = remapAlleleReverse ( map , a1 ) ; if ( newA1 < 0 ) { continue ; } // With P=2, given a genotype a/b, where a<b, its position is b(b+1)/2+a if ( newA2 > newA1 ) { gMap [ newA2 * ( newA2 + 1 ) / 2 + newA1 ] = pos ++ ; } else { gMap [ newA1 * ( newA1 + 1 ) / 2 + newA2 ] = pos ++ ; } } } } else { List < String > originalOrdering = getOrdering ( ploidy , map . length , null ) ; List < String > reorderedOrdering = getOrdering ( ploidy , map . length , map ) ; gMap = new int [ originalOrdering . size ( ) ] ; for ( int i = 0 ; i < reorderedOrdering . size ( ) ; i ++ ) { gMap [ i ] = originalOrdering . indexOf ( reorderedOrdering . get ( i ) ) ; } } return gMap ; }
Gets an array for reordering the positions of a format field with Number = G and ploidy = 2 .