daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Dec 7th, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. char getSymb(int ind) {
  2.     return alphabet[ind];
  3. }
  4.  
  5. int distance(string s1, string s2) {
  6.     int result = 0;
  7.     for (int i = 0; i < s1.length(); i++)
  8.         if (s1[i] != s2[i]) result++;
  9.     return result;
  10. }
  11. int totalDisatance(string *DNA, string v, int t) {
  12.  
  13.     int result = 0;
  14.     int min = v.length() + 1;
  15.  
  16.     for (int i = 0; i < t; i++) {
  17.         for (int j = 0; j < DNA[0].length() - v.length() + 1; j++) {
  18.             if (distance(v, DNA[i].substr(j, v.length())) < min) {
  19.                 min = distance(v, DNA[i].substr(j, v.length()));
  20.             }
  21.         }
  22.         result += min;
  23.         min = v.length() + 1;
  24.  
  25.     }
  26.     return result;
  27. }
  28.  
  29. //getting median string
  30. void getMedianStr(string &median, string *DNA, int t, int l, int n) {
  31.     int bestDistance = INT32_MAX;
  32.     string  bestWord;
  33.     int i = 0;
  34.     while (i < l) {
  35.         bestWord += 'A';
  36.         i++;
  37.     }
  38.     cout << "bestDist = " << bestDistance << " bestWord = " << bestWord << endl;
  39.     //ind - is a l-mer word
  40.     int *ind = new int[l];
  41.     for (int i = 0; i < t; i++) ind[i] = 0;
  42.  
  43.     string wordL = "";
  44.     int k = 0;
  45.     int c = pow(4, l); // number of different positions
  46.     for (int i = 0; i < c; i++) {
  47.         k++;
  48.         //here we can work with words
  49.         for (int j = 0; j < l; j++) {
  50.             wordL += getSymb(ind[j]);
  51.         }
  52.         cout << "wordl = " << wordL << endl;
  53.         if (totalDisatance(DNA, wordL, t)) {
  54.         }
  55.         wordL = "";
  56.         //refresh indexes
  57.         for (int j = 0; j < l; j++) {
  58.             ind[j]++;
  59.             if (ind[j] < 4)
  60.                 break;
  61.             ind[j] = 0;
  62.         }
  63.     }
  64.     cout << "k =" << k << endl;
  65. }
RAW Paste Data
Top