public static String getMaxMatchFragment ( String seq1 , String seq2 , int minLength ) throws NotationException { if ( null == seq1 || null == seq2 ) { throw new NotationException ( "Both sequences must not be null " ) ; } if ( ! seq1 . equals ( seq1 . toUpperCase ( ) ) || ! seq2 . equals ( seq2 . toUpperCase ( ) ) ) { throw new NotationException ( "Both sequences must be natural nucleotide sequence in upper case " ) ; } String longSeq , shortSeq ; if ( seq1 . length ( ) > seq2 . length ( ) ) { longSeq = seq1 ; shortSeq = seq2 ; } else { longSeq = seq2 ; shortSeq = seq1 ; } // replace T with U longSeq = longSeq . replaceAll ( "T" , "U" ) ; shortSeq = shortSeq . replaceAll ( "T" , "U" ) ; int min = MINUMUM_MATCH_FRAGMENT_LENGTH ; if ( minLength > min ) { min = minLength ; } for ( int len = shortSeq . length ( ) ; len > min ; len -- ) { for ( int i = 0 ; i <= shortSeq . length ( ) - len ; i ++ ) { String tmp = shortSeq . substring ( i , i + len ) ; if ( longSeq . contains ( tmp ) ) { return tmp ; } } } return "" ; }
This method returns the largest matched fragment between two sequences replace T with U before match