public static AFPChain replaceOptAln ( AFPChain afpChain , Atom [ ] ca1 , Atom [ ] ca2 , Map < Integer , Integer > alignment ) throws StructureException { // Determine block lengths // Sort ca1 indices, then start a new block whenever ca2 indices aren't // increasing monotonically. Integer [ ] res1 = alignment . keySet ( ) . toArray ( new Integer [ 0 ] ) ; Arrays . sort ( res1 ) ; List < Integer > blockLens = new ArrayList < Integer > ( 2 ) ; int optLength = 0 ; Integer lastRes = alignment . get ( res1 [ 0 ] ) ; int blkLen = lastRes == null ? 0 : 1 ; for ( int i = 1 ; i < res1 . length ; i ++ ) { Integer currRes = alignment . get ( res1 [ i ] ) ; //res2 index assert ( currRes != null ) ; // could be converted to if statement if assertion doesn't hold; just modify below as well. if ( lastRes < currRes ) { blkLen ++ ; } else { // CP! blockLens . add ( blkLen ) ; optLength += blkLen ; blkLen = 1 ; } lastRes = currRes ; } blockLens . add ( blkLen ) ; optLength += blkLen ; // Create array structure for alignment int [ ] [ ] [ ] optAln = new int [ blockLens . size ( ) ] [ ] [ ] ; int pos1 = 0 ; //index into res1 for ( int blk = 0 ; blk < blockLens . size ( ) ; blk ++ ) { optAln [ blk ] = new int [ 2 ] [ ] ; blkLen = blockLens . get ( blk ) ; optAln [ blk ] [ 0 ] = new int [ blkLen ] ; optAln [ blk ] [ 1 ] = new int [ blkLen ] ; int pos = 0 ; //index into optAln while ( pos < blkLen ) { optAln [ blk ] [ 0 ] [ pos ] = res1 [ pos1 ] ; Integer currRes = alignment . get ( res1 [ pos1 ] ) ; optAln [ blk ] [ 1 ] [ pos ] = currRes ; pos ++ ; pos1 ++ ; } } assert ( pos1 == optLength ) ; // Create length array int [ ] optLens = new int [ blockLens . size ( ) ] ; for ( int i = 0 ; i < blockLens . size ( ) ; i ++ ) { optLens [ i ] = blockLens . get ( i ) ; } return replaceOptAln ( afpChain , ca1 , ca2 , blockLens . size ( ) , optLens , optAln ) ; }
Takes an AFPChain and replaces the optimal alignment based on an alignment map