在 getIndexes (int number , int size , int characters )
我必须在数组末尾加上转换后的数字,因为我必须应用填充0,假设它是231。。。
这意味着我必须在开头加6个零,然后加20。
//Input characters and Lenght of Motif
char [] inputChars = {'a','c','g','t'} ;
int lengthOfMotif = 8 ;
public void map(Object key, Text value, Context context) throws IOException, InterruptedException
{
/*
* To generate all the combinations of lengthOfMotif i used formula or probability to count of all possible strings that will be power of ( inputChars length , elements in motif )
*
* Then i called my getIndexes method to get int[] of length lengthOfMotif representing an index from inputChars
*
* I generated a motif and made it key of Mapper and called minDistance returning minDistance,bestMatchingString,indexOfBestMatchingString and made it value for key motif
*
*
*/
for (int i = 0 ; i < Math.pow(inputChars.length, lengthOfMotif) ; i ++ )
{
String motif = "" ; // initialize the empty motif string
for ( int j : getIndexes ( i , lengthOfMotif , inputChars.length ) ) //loop on array returned by getIndexes() with indexes to select from inputChar Array to build the string
{
motif = motif+inputChars[j] ;
}
context.write(new Text(motif), new Text ( minDistance(motif,value.toString() ) ) ) ;
}
}
// It takes a number , length of resultant indexes , number of unique characters
/*
* I convert the number to base of unique characters so the max index that can be generated will be less than the power
* then place the number at end of indexes array which will keep the starting indexes to be 0
*
* As our length is 8 and characters are 4 so
* if my number is 0
* i converted it to base 4 so it will remain 0
* i placed it at end of indexes array so my array will be like
* 0 0 0 0 0 0 0 0
* which in our case if considered as index of inputChars it will return
* a a a a a a a a
* The max number will be 8 ^ 4 = 65536 as we are starting from 0 our max number will be 65536
* in base 4 65536 is 3 3 3 3 3 3 3 3 which if we consider indexes will become
* t t t t t t t t
* So every number from 0 to 65536 will be covered and each combination will be passed as key of mapper
*
*/
int[] getIndexes (int number , int size , int characters )
{
//init new result array
int[] result = new int[size] ;
// I stuck here
}
return result ;
}
//return concatinated string in format minDistance,bestMatching,index
2条答案
按热度按时间sxpgvts31#
result[size indexes.length()+i]=integer.parseint(indexes.charat(i)+“”);
pvcm50d12#