Beispiel #1
0
PUBLIC int
move_standard(char *seq,
              char *struc,
              enum MOVE_TYPE type,
              int verbosity_level,
              int shifts,
              int noLP){

  make_pair_matrix();

  short int *s0 = encode_sequence(seq, 0);
  short int *s1 = encode_sequence(seq, 1);
  short int *str = vrna_ptable(struc);

  int energy = 0;
  switch (type){
  case GRADIENT: energy = move_gradient(seq, str, s0, s1, verbosity_level, shifts, noLP); break;
  case FIRST: energy = move_first(seq, str, s0, s1, verbosity_level, shifts, noLP); break;
  case ADAPTIVE: energy = move_adaptive(seq, str, s0, s1, verbosity_level); break;
  }

  int i=1;
  for (; i<=str[0]; i++) {
    if (str[i]==0) struc[i-1]='.';
    else if (str[i]>str[str[i]]) struc[i-1]='(';
      else struc[i-1]=')';
  }

  free(s0);
  free(s1);
  free(str);

  return energy;
}
Beispiel #2
0
void DSU::FindNumbers(int begin, int end, path_pk *path, vector<int> &lm_numbers, bool shifts, bool noLP, bool debug, bool no_new)
{
  // first resolve small case:
  if (end-begin<4) {
    bool begins = true;
    for (int i=begin+1; i<end; i++) {

      // get the minimum
      short *tmp_str = allocopy(path[i].structure);
      int tmp_en;
      if (pknots) {
        Structure str(seq, tmp_str, s0, s1);
        tmp_en = move_gradient_pk(seq, &str, s0, s1, shifts, 0);
        copy_arr(tmp_str, str.str);
      } else {
        tmp_en = move_gradient(seq, tmp_str, s0, s1, 0, shifts, noLP);
      }
      // speedup
      if (lm_numbers[begin] != -1 && begins && tmp_en == LM[lm_numbers[begin]].energy && str_eq(LM[lm_numbers[begin]].structure, tmp_str)) {
        lm_numbers[i] = lm_numbers[begin];
      } else {
        begins = false;
        if (lm_numbers[end] != -1 && tmp_en == LM[lm_numbers[end]].energy && str_eq(LM[lm_numbers[end]].structure, tmp_str)) {
          lm_numbers[i] = lm_numbers[end];
        }
      }

      if (lm_numbers[i]==-1) {
        lm_numbers[i] = FindNum(tmp_en, tmp_str);

        // update UBlist
        if (lm_numbers[i]==-1 && !no_new) {
          if (gl_maxen < tmp_en) {
            //fprintf(stderr, "exceeds en.: %s %6.2f\n", pt_to_str(tmp_str).c_str(), tmp_en/100.0);
            lm_numbers[i] = AddLMtoTBD(tmp_str, tmp_en, EE_DSU, debug);

          } else {
            if (debug) fprintf(stderr, "cannot find: %s %6.2f\n", pt_to_str_pk(tmp_str).c_str(), tmp_en/100.0);
            // add to list of minima and count with them later...
            lm_numbers[i] = AddLMtoTBD(tmp_str, tmp_en, NORM_CF, debug);
          }
        }
      } else debug_c++;

      free(tmp_str);
    }
    return ;
  }

  // da middle one
  int pivot = (end+begin)/2;

  short *tmp_str = allocopy(path[pivot].structure);
  //fprintf(stderr, "%s\n", pt_to_str(tmp_str).c_str());
  int tmp_en;
  if (pknots) {
    Structure str(seq, tmp_str, s0, s1);
    tmp_en = move_gradient_pk(seq, &str, s0, s1, shifts, 0);
    copy_arr(tmp_str, str.str);
  } else {
    tmp_en = move_gradient(seq, tmp_str, s0, s1, 0, shifts, noLP);
  }
  //fprintf(stderr, "%s\n", pt_to_str(tmp_str).c_str());

  // speed up:
  if (lm_numbers[begin] != -1 && tmp_en == LM[lm_numbers[begin]].energy && str_eq(LM[lm_numbers[begin]].structure, tmp_str)) {
    lm_numbers[pivot] = lm_numbers[begin];
  } else {
    if (lm_numbers[end] != -1 && tmp_en == LM[lm_numbers[end]].energy && str_eq(LM[lm_numbers[end]].structure, tmp_str)) {
      lm_numbers[pivot] = lm_numbers[end];
    }
  }

  // normal behaviour
  if (lm_numbers[pivot]==-1) {
    lm_numbers[pivot] = FindNum(tmp_en, tmp_str);

    // update UBlist
    if (lm_numbers[pivot]==-1 && !no_new) {
      if (gl_maxen < tmp_en) {
        //fprintf(stderr, "exceeds en.: %s %6.2f\n", pt_to_str(tmp_str).c_str(), tmp_en/100.0);
        lm_numbers[pivot] = AddLMtoTBD(tmp_str, tmp_en, EE_DSU, debug);

      } else {
        if (debug) fprintf(stderr, "cannot find: %s %6.2f\n", pt_to_str_pk(tmp_str).c_str(), tmp_en/100.0);
        // add to list of minima and count with them later...
        lm_numbers[pivot] = AddLMtoTBD(tmp_str, tmp_en, NORM_CF, debug);
      }
    }
  } else debug_c++;

  free(tmp_str);

  // continue recursion:
  if ((lm_numbers[pivot]!=lm_numbers[begin] || lm_numbers[pivot]==-1) && pivot-begin>1) FindNumbers(begin, pivot, path, lm_numbers, shifts, noLP, debug, no_new);
  if ((lm_numbers[pivot]!=lm_numbers[end]   || lm_numbers[pivot]==-1)  && end-pivot>1) FindNumbers(pivot, end, path, lm_numbers, shifts, noLP, debug, no_new);

  // return maximal energy
  return ;
}