private static List < Integer > initializeEligible ( Map < Integer , Integer > alignment , Map < Integer , Double > scores , List < Integer > eligible , int k , NavigableSet < Integer > forwardLoops , NavigableSet < Integer > backwardLoops ) { // Eligible if: // 1. score(x)>0 // 2. f^K-1(x) is defined // 3. score(f^K-1(x))>0 // 4. For all y, score(y)==0 implies sign(f^K-1(x)-y) == sign(x-f(y) ) // 5. Not in a loop of length less than k // Assume all residues are eligible to start if ( eligible == null ) { eligible = new LinkedList < Integer > ( alignment . keySet ( ) ) ; } // Precalculate f^K-1(x) // Map<Integer, Integer> alignK1 = AlignmentTools.applyAlignment(alignment, k-1); Map < Integer , Integer > alignK1 = applyAlignmentAndCheckCycles ( alignment , k - 1 , eligible ) ; // Remove ineligible residues Iterator < Integer > eligibleIt = eligible . iterator ( ) ; while ( eligibleIt . hasNext ( ) ) { Integer res = eligibleIt . next ( ) ; // 2. f^K-1(x) is defined if ( ! alignK1 . containsKey ( res ) ) { eligibleIt . remove ( ) ; continue ; } Integer k1 = alignK1 . get ( res ) ; if ( k1 == null ) { eligibleIt . remove ( ) ; continue ; } // 1. score(x)>0 Double score = scores . get ( res ) ; if ( score == null || score <= 0.0 ) { eligibleIt . remove ( ) ; // res is in a loop. Add it to the proper set if ( res <= alignment . get ( res ) ) { //forward forwardLoops . add ( res ) ; } else { //backward backwardLoops . add ( res ) ; } continue ; } // 3. score(f^K-1(x))>0 Double scoreK1 = scores . get ( k1 ) ; if ( scoreK1 == null || scoreK1 <= 0.0 ) { eligibleIt . remove ( ) ; continue ; } } // Now that loops are up-to-date, check for loop crossings eligibleIt = eligible . iterator ( ) ; while ( eligibleIt . hasNext ( ) ) { Integer res = eligibleIt . next ( ) ; //4. For all y, score(y)==0 implies sign(f^K-1(x)-y) == sign(x-f(y) ) //Test equivalent: All loop edges should be properly ordered wrt edge f^k-1(x) -> x Integer src = alignK1 . get ( res ) ; if ( src < res ) { //forward // get interval [a,b) containing res Integer a = forwardLoops . floor ( src ) ; Integer b = forwardLoops . higher ( src ) ; // Ineligible unless f(a) < res < f(b) if ( a != null && alignment . get ( a ) > res ) { eligibleIt . remove ( ) ; continue ; } if ( b != null && alignment . get ( b ) < res ) { eligibleIt . remove ( ) ; continue ; } } } return eligible ; }
Helper method to initialize eligible residues .