2015-04-04 3 views
0

на getIndexes (int number , int size , int characters)Cant получить индекс строки в функции картографа

Я должен добавить преобразованное число в конце массива, как я должен применить отступы 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 

ответ

0
/ in string 
     // 2 -> index -> 0 
     // 3 -> index -> 1 
     // 1 -> index -> 2 
     //Array has indexes 0 to 7 
     // so to add paadd 
     // 2 have to be at 5th index 
     // 3 have to be at 6th index 
     // 1 have to be at 7th index 
     // size variable has total required length that is 8 
     // so i subtracted length of 231 from 8. 8-3 = 5 + i = 5+0 
     // now i have to place second at 6th... so 8-3 = 5 + i = 5 + 1 
     // for 7th index 8 - 3 = 5 + i = 5 + 7 
     // i concatinated "" to make the character into string and Integer.parse int converted them to integer 
     // so 5 6 7 indexes will be filled with 2 3 1 

результат [размер-indexes.length() + I] = Integer.parseInt (indexes.charAt (я) + "");

+0

так добавить последнюю строку из вас MESG – user4594525

+0

пояснит да основано на вас explination выше O является и 1 с разве, у вас есть только 4 буквы в качестве входных данных – khanos

+0

у вас есть только 8 длина, так что 5 6 7 ИПА будет заполнен 231 – khanos

0
String [] tokens = values.iterator().next().toString().split(","); 
    int minDistance = Integer.parseInt (tokens [ 0 ]) ; 
    String bestMatching = tokens[ 1 ] ; 
    int index = Integer.parseInt(tokens [ 2 ]) ; 

    int minimumDistance = minDistance ; 


    for (Text t : values) 
    { 
     tokens = t.toString().split(","); 
     int distance = Integer.parseInt(tokens [ 0 ]) ; 
     if (distance < minDistance) 
     { 
      minDistance = distance ; 
      bestMatching = tokens [ 1 ] ; 
      index = Integer.parseInt(tokens [ 2 ]) ; 
     } 
     minimumDistance = minimumDistance + distance ; 
+0

просто показать мне minDistance, bestMatching, индекс не нужно писать цикл for. в любом случае thanx для справки – user4594525

+0

он успешно работает, спасибо – user4594525

Смежные вопросы