private List < Integer > collapseGT ( List < String > gtsStr ) { if ( gtsStr . isEmpty ( ) ) { return Collections . emptyList ( ) ; } if ( gtsStr . size ( ) == 1 ) { return Collections . singletonList ( 0 ) ; } List < Genotype > gts = gtsStr . stream ( ) . map ( Genotype :: new ) . collect ( Collectors . toList ( ) ) ; // only get GT with an ALT e.g 0/1 0/2 1/2 etc. (ignore ./. and 0/0 GT) Predicate < Genotype > findAlts = gt -> Arrays . stream ( gt . getAllelesIdx ( ) ) . anyMatch ( i -> i > 0 ) ; Predicate < Genotype > findHomRef = gt -> Arrays . stream ( gt . getAllelesIdx ( ) ) . allMatch ( i -> i == 0 ) ; Predicate < Genotype > findOneRef = gt -> Arrays . stream ( gt . getAllelesIdx ( ) ) . anyMatch ( i -> i == 0 ) ; Predicate < Genotype > findNoCalls = gt -> Arrays . stream ( gt . getAllelesIdx ( ) ) . anyMatch ( i -> i < 0 ) ; List < Integer > oneAltAllele = getMatchingPositions ( gts , findAlts ) ; if ( ! oneAltAllele . isEmpty ( ) ) { return oneAltAllele ; } List < Integer > reference = getMatchingPositions ( gts , findHomRef ) ; if ( ! reference . isEmpty ( ) ) { return reference ; } List < Integer > oneReferenceAllele = getMatchingPositions ( gts , findOneRef ) ; if ( ! oneReferenceAllele . isEmpty ( ) ) { return oneReferenceAllele ; } // only no-calls left -> try to collapse List < Integer > nocalls = getMatchingPositions ( gts , findNoCalls ) ; if ( nocalls . size ( ) == gtsStr . size ( ) ) { // all GT found return Collections . singletonList ( nocalls . get ( 0 ) ) ; } // don't know that could be left!!! if ( this . collapseDeletions ) { throw new IllegalStateException ( "Not able to resolve GT: " + StringUtils . join ( gtsStr , "," ) ) ; } return IntStream . range ( 0 , gtsStr . size ( ) - 1 ) . boxed ( ) . collect ( Collectors . toList ( ) ) ; }
Collapses a list of GT to a minimal set .