public static < C extends Compound > List < SequenceView < C > > overlappingKmers ( Sequence < C > sequence , int kmer ) { List < SequenceView < C >> l = new ArrayList < SequenceView < C > > ( ) ; List < Iterator < SequenceView < C > > > windows = new ArrayList < Iterator < SequenceView < C > > > ( ) ; for ( int i = 1 ; i <= kmer ; i ++ ) { if ( i == 1 ) { windows . add ( new WindowedSequence < C > ( sequence , kmer ) . iterator ( ) ) ; } else { SequenceView < C > sv = sequence . getSubSequence ( i , sequence . getLength ( ) ) ; windows . add ( new WindowedSequence < C > ( sv , kmer ) . iterator ( ) ) ; } } OUTER : while ( true ) { for ( int i = 0 ; i < kmer ; i ++ ) { Iterator < SequenceView < C >> iterator = windows . get ( i ) ; boolean breakLoop = true ; if ( iterator . hasNext ( ) ) { l . add ( iterator . next ( ) ) ; breakLoop = false ; } if ( breakLoop ) { break OUTER ; } } } return l ; }
Used to generate overlapping k - mers such i . e . ATGTA will give rise to ATG TGT & GTA