public ArrayList < SameLengthMotifs > classifyMotifs ( double lengthThreshold , GrammarRules grammarRules ) { // reset vars ArrayList < SameLengthMotifs > allClassifiedMotifs = new ArrayList < SameLengthMotifs > ( ) ; // down to business ArrayList < SAXMotif > allMotifs = getAllMotifs ( grammarRules ) ; // is this one better? int currentIndex = 0 ; for ( SAXMotif tmpMotif : allMotifs ) { currentIndex ++ ; if ( tmpMotif . isClassified ( ) ) { // this breaks the loop flow, so it goes to //for (SAXMotif // tempMotif : allMotifs) { continue ; } SameLengthMotifs tmpSameLengthMotifs = new SameLengthMotifs ( ) ; int tmpMotifLen = tmpMotif . getPos ( ) . getEnd ( ) - tmpMotif . getPos ( ) . getStart ( ) + 1 ; int minLen = tmpMotifLen ; int maxLen = tmpMotifLen ; // TODO: assuming that this motif has not been processed, right? ArrayList < SAXMotif > newMotifClass = new ArrayList < SAXMotif > ( ) ; newMotifClass . add ( tmpMotif ) ; tmpMotif . setClassified ( true ) ; // TODO: this motif assumed to be the first one of it's class, // traverse the rest down for ( int i = currentIndex ; i < allMotifs . size ( ) ; i ++ ) { SAXMotif anotherMotif = allMotifs . get ( i ) ; // if the two motifs are similar or not. int anotherMotifLen = anotherMotif . getPos ( ) . getEnd ( ) - anotherMotif . getPos ( ) . getStart ( ) + 1 ; // if they have the similar length. if ( Math . abs ( anotherMotifLen - tmpMotifLen ) < ( tmpMotifLen * lengthThreshold ) ) { newMotifClass . add ( anotherMotif ) ; anotherMotif . setClassified ( true ) ; if ( anotherMotifLen > maxLen ) { maxLen = anotherMotifLen ; } else if ( anotherMotifLen < minLen ) { minLen = anotherMotifLen ; } } } tmpSameLengthMotifs . setSameLenMotifs ( newMotifClass ) ; tmpSameLengthMotifs . setMinMotifLen ( minLen ) ; tmpSameLengthMotifs . setMaxMotifLen ( maxLen ) ; allClassifiedMotifs . add ( tmpSameLengthMotifs ) ; } return allClassifiedMotifs ; // System.out.println(); }
Classify the motifs based on their length .