Esempio n. 1
0
int main(int argc, char *argv[]){
  char sequence[MAXSIZE], structure[MAXSIZE];
  int i, j;
  
  if (argc == 9) {
    i = 1;
    while (i < argc) {
  	  if (!strcmp(argv[i], "-s")) {
        sequence[0] = '@';
        strncpy(sequence + 1, argv[i + 1], strlen(argv[i + 1])); // The sequence starts from index 1
        sequence[strlen(argv[i + 1]) + 1] = '\0';                // Remember to end the sequence
        i += 2;
      } else if (!strcmp(argv[i], "-r")) {
        strncpy(structure, argv[i + 1], strlen(argv[i + 1])); // The structure starts from index 0
        structure[strlen(argv[i + 1])] = '\0';                // Remember to end the structure
        i += 2;
      } else if (!strcmp(argv[i], "-c")) {
        SCALING_FACTOR = atof(argv[i + 1]);
        i += 2;
      } else if (!strcmp(argv[i], "-p")) {
        PRECISION = atoi(argv[i + 1]);
        i += 2;
      } else {
        printf("Error: Unrecognizable Flag!\n");
        printf("Usage:");
        printf("%s -s SEQUENCE -r STRUCTURE -c SCALING -p PRECISION\n", argv[0]);
        printf("SEQUENCE is the RNA sequence.\n");
        printf("STRUCTURE is the RNA structure.\n");
        printf("SCALING is used internally as the scaling factor for the recursions.\n");
        printf("PRECISION dictates the number of signigicant digits in the resulting distribution.\n");
        printf("The length of RNA sequence should be less than %d and larger than or equal to 5.\n", MAXSIZE);
        exit(1);
      }
  	}
    CheckSequenceAndStructure(sequence, structure);
    S0     = encode_seq(sequence + 1);
    seqlen = strlen(sequence) - 1;
    
    Initialize_Params();
    make_pair_matrix(); // Needed for pair matching.
    
    kT       = (temperature + K0) * GASCONST / 1000.0;
    ML_base  = (double)P -> MLbase / 100;
    ML_close = (double)P -> MLclosing / 100;
    std::complex<double>** McCaskillZ;
    
    McCaskillZ = runMcCaskill(sequence, structure);
  } else {
    printf("Usage:");
    printf("%s -s SEQUENCE -r STRUCTURE -c SCALING -p PRECISION\n", argv[0]);
    printf("SEQUENCE is the RNA sequence.\n");
    printf("STRUCTURE is the RNA structure.\n");
    printf("SCALING is used internally as the scaling factor for the recursions.\n");
    printf("PRECISION dictates the number of signigicant digits in the resulting distribution.\n");
    printf("The length of RNA sequence should be less than %d and larger than or equal to 5.\n", MAXSIZE);
    exit(1);
  }
  return 0;
}
Esempio n. 2
0
float fold(const char *string, char *structure) {
  int i, length, energy, bonus=0, bonus_cnt=0;

  circ = 0;
  length = (int) strlen(string);
  if (length>init_length) initialize_fold(length);
  if (fabs(P->temperature - temperature)>1e-6) update_fold_params();

  encode_seq(string);

  BP = (int *)space(sizeof(int)*(length+2));
  make_ptypes(S, structure);

  energy = fill_arrays(string);

  backtrack(string, 0);

#ifdef PAREN
  parenthesis_structure(structure, length);
#else
  letter_structure(structure, length);
#endif

  /* check constraints */
  for(i=1;i<=length;i++) {
    if((BP[i]<0)&&(BP[i]>-4)) {
      bonus_cnt++;
      if((BP[i]==-3)&&(structure[i-1]==')')) bonus++;
      if((BP[i]==-2)&&(structure[i-1]=='(')) bonus++;
      if((BP[i]==-1)&&(structure[i-1]!='.')) bonus++;
    }

    if(BP[i]>i) {
      int l;
      bonus_cnt++;
      for(l=1; l<=base_pair[0].i; l++)
	if((i==base_pair[l].i)&&(BP[i]==base_pair[l].j)) bonus++;
    }
  }

  if (bonus_cnt>bonus) fprintf(stderr,"\ncould not enforce all constraints\n");
  bonus*=BONUS;

  free(S); free(S1); free(BP);

  energy += bonus;      /*remove bonus energies from result */

  if (backtrack_type=='C')
    return (float) c[indx[length]+1]/100.;
  else if (backtrack_type=='M')
    return (float) fML[indx[length]+1]/100.;
  else
    return (float) energy/100.;
}
Esempio n. 3
0
duplexT duplexfold(const char *s1, const char *s2) {
  int i, j, l1, Emin=INF, i_min=0, j_min=0;
  char *struc;
  duplexT mfe;
  
  n1 = (int) strlen(s1);
  n2 = (int) strlen(s2);
  
  if ((!P) || (fabs(P->temperature - temperature)>1e-6)) {
    update_fold_params();  P = scale_parameters();
    make_pair_matrix();
  }
  
  c = (int **) space(sizeof(int *) * (n1+1));
  for (i=1; i<=n1; i++) c[i] = (int *) space(sizeof(int) * (n2+1));
  
  encode_seq(s1, s2);
  
  for (i=1; i<=n1; i++) {
    for (j=n2; j>0; j--) {
      int type, type2, E, k,l;
      type = pair[S1[i]][S2[j]];
      c[i][j] = type ? P->DuplexInit : INF;
      if (!type) continue;
      if (i>1)  c[i][j] += P->dangle5[type][SS1[i-1]];
      if (j<n2) c[i][j] += P->dangle3[type][SS2[j+1]];
      if (type>2) c[i][j] += P->TerminalAU;
      for (k=i-1; k>0 && k>i-MAXLOOP-2; k--) {
	for (l=j+1; l<=n2; l++) {
	  if (i-k+l-j-2>MAXLOOP) break;
	  type2 = pair[S1[k]][S2[l]];
	  if (!type2) continue;
	  E = LoopEnergy(i-k-1, l-j-1, type2, rtype[type],
			    SS1[k+1], SS2[l-1], SS1[i-1], SS2[j+1]);
	  c[i][j] = MIN2(c[i][j], c[k][l]+E);
	}
      }
      E = c[i][j]; 
      if (i<n1) E += P->dangle3[rtype[type]][SS1[i+1]];
      if (j>1) E += P->dangle5[rtype[type]][SS2[j-1]];
      if (type>2) E += P->TerminalAU;
      if (E<Emin) {
	Emin=E; i_min=i; j_min=j;
      } 
    }
  }
  
  struc = backtrack(i_min, j_min);
  if (i_min<n1) i_min++;
  if (j_min>1 ) j_min--;
  l1 = strchr(struc, '&')-struc;
  /*
    printf("%s %3d,%-3d : %3d,%-3d (%5.2f)\n", struc, i_min+1-l1, i_min, 
       j_min, j_min+strlen(struc)-l1-2, Emin*0.01);
  */
  mfe.i = i_min;
  mfe.j = j_min;
  mfe.energy = (float) Emin/100.;
  mfe.structure = struc;
  if (!delay_free) {
    for (i=1; i<=n1; i++) free(c[i]);
    free(c);
    free(S1); free(S2); free(SS1); free(SS2);
  }
  return mfe;
}