Пример #1
0
PRIVATE float
wrap_pf_fold( const char *sequence,
              char *structure,
              vrna_exp_param_t *parameters,
              int calculate_bppm,
              int is_constrained,
              int is_circular){

  vrna_fold_compound_t  *vc;
  vrna_md_t             md;

  vc = NULL;

  /* we need vrna_exp_param_t datastructure to correctly init default hard constraints */
  if(parameters)
    md = parameters->model_details;
  else{
    set_model_details(&md); /* get global default parameters */
  }
  md.circ         = is_circular;
  md.compute_bpp  = calculate_bppm;

  vc = vrna_fold_compound(sequence, &md, VRNA_OPTION_DEFAULT);

  /* prepare exp_params and set global pf_scale */
  vc->exp_params = vrna_exp_params(&md);
  vc->exp_params->pf_scale = pf_scale;

  if(is_constrained && structure){
    unsigned int constraint_options = 0;
    constraint_options |= VRNA_CONSTRAINT_DB
                          | VRNA_CONSTRAINT_DB_PIPE
                          | VRNA_CONSTRAINT_DB_DOT
                          | VRNA_CONSTRAINT_DB_X
                          | VRNA_CONSTRAINT_DB_ANG_BRACK
                          | VRNA_CONSTRAINT_DB_RND_BRACK;

    vrna_constraints_add(vc, (const char *)structure, constraint_options);
  }

  if(backward_compat_compound && backward_compat)
    vrna_fold_compound_free(backward_compat_compound);

  backward_compat_compound  = vc;
  backward_compat           = 1;
  iindx = backward_compat_compound->iindx;

  return vrna_pf(vc, structure);
}
Пример #2
0
PRIVATE void
add_params( vrna_fold_compound_t *vc,
            vrna_md_t *md_p,
            unsigned int options){

  /* ALWAYS add regular energy parameters */
  vc->params = vrna_params(md_p);

  if(options & VRNA_OPTION_PF){
    vc->exp_params  = (vc->type == VRNA_VC_TYPE_SINGLE) ? \
                        vrna_exp_params(md_p) : \
                        vrna_exp_params_comparative(vc->n_seq, md_p);
  }

}
Пример #3
0
PUBLIC int
vrna_fold_compound_prepare( vrna_fold_compound_t *vc,
                            unsigned int options){
  int ret = 1; /* success */

  if(options & VRNA_OPTION_MFE){   /* prepare for MFE computation */
    switch(vc->type){
      case VRNA_VC_TYPE_SINGLE:     if(!vc->ptype)
                                      vc->ptype = vrna_ptypes(vc->sequence_encoding2,
                                                              &(vc->params->model_details));
                                    break;
      case VRNA_VC_TYPE_ALIGNMENT:  break;
      default:                      break;
    }

    if(options & VRNA_OPTION_WINDOW){ /* Windowing approach, a.k.a. locally optimal */
      /*  check whether we have the correct DP matrices attached, and if there is
          enough memory allocated
      */
      if(!vc->matrices || (vc->matrices->type != VRNA_MX_WINDOW) || (vc->matrices->length < vc->length)){
        /* here we simply pass '0' as options, since we call mx_mfe_add() explicitely */
        vrna_mx_mfe_add(vc, VRNA_MX_WINDOW, options);
      }
    } else { /* default is regular MFE */
      /*  check whether we have the correct DP matrices attached, and if there is
          enough memory allocated
      */
      if(!vc->matrices || (vc->matrices->type != VRNA_MX_DEFAULT) || (vc->matrices->length < vc->length)){
        vrna_mx_mfe_add(vc, VRNA_MX_DEFAULT, options);
      }
    }
  }

  if(options & VRNA_OPTION_PF){   /* prepare for partition function computation */

    switch(vc->type){
      case VRNA_VC_TYPE_SINGLE:     /* get pre-computed Boltzmann factors if not present*/
                                    if(!vc->exp_params)
                                      vc->exp_params      = vrna_exp_params(&(vc->params->model_details));

                                    if(!vc->ptype)
                                      vc->ptype           = vrna_ptypes(vc->sequence_encoding2, &(vc->exp_params->model_details));
#ifdef VRNA_BACKWARD_COMPAT
                                    /* backward compatibility ptypes */
                                    if(!vc->ptype_pf_compat)
                                      vc->ptype_pf_compat = get_ptypes(vc->sequence_encoding2, &(vc->exp_params->model_details), 1);
#endif
                                    /* get precomputed Boltzmann factors for soft-constraints (if any) */
                                    if(vc->sc){
                                      if(!vc->sc->exp_energy_up)
                                        vrna_sc_add_up(vc, NULL, VRNA_OPTION_PF);
                                      if(!vc->sc->exp_energy_bp)
                                        vrna_sc_add_bp(vc, NULL, VRNA_OPTION_PF);
                                      if(!vc->sc->exp_energy_stack)
                                        vrna_sc_add_SHAPE_deigan(vc, NULL, 0, 0, VRNA_OPTION_PF);
                                    }

                                    break;

      case VRNA_VC_TYPE_ALIGNMENT:  /* get pre-computed Boltzmann factors if not present*/
                                    if(!vc->exp_params)
                                      vc->exp_params  = vrna_exp_params_comparative(vc->n_seq, &(vc->params->model_details));
                                    break;

      default:                      break;
    }

    /*  Add DP matrices, if not they are not present */
    if(!vc->exp_matrices || (vc->exp_matrices->type != VRNA_MX_DEFAULT) || (vc->exp_matrices->length < vc->length)){
      vrna_mx_pf_add(vc, VRNA_MX_DEFAULT, options);
    }
  }

  return ret;
}
Пример #4
0
int main(int argc, char *argv[]){
  struct  ct2db_args_info args_info;

  char          *line       = NULL;

  int           pkfree      = 0;
  int           verbose     = 0;

  char          *seq        = NULL;
  char          *structure  = NULL;
  plist         *pairs      = NULL;
  int           num_pairs   = 0;
  unsigned int  seq_pos     = 0;
  unsigned int  length      = 0;

  /*
  #############################################
  # check the command line prameters
  #############################################
  */
  if(ct2db_cmdline_parser (argc, argv, &args_info) != 0) exit(1);
  /* remove Pseudknots? */
  if(args_info.removePK_given)
    pkfree = 1;
  /* be verbose ? */
  if(args_info.verbose_given)
    verbose = 1;

  /* free allocated memory of command line data structure */
  ct2db_cmdline_parser_free (&args_info);

  do{
    if ((line = get_line(stdin))==NULL) break;
    /* skip comment lines */
    while ((*line=='*')||(*line=='\0')||(*line=='>')||(*line=='#')) {
      free(line);
      if ((line = get_line(stdin))==NULL) break;
    }

    if ((line ==NULL) || (strcmp(line, "@") == 0)) break;

    if(length != 0){
      if(!seq){
        /*
        printf("sequence length: %u\n", length);
        */
        seq   = (char *)vrna_alloc(sizeof(char) * (length + 1));
        pairs = (plist *)vrna_alloc(sizeof(plist) * (2*length));
      }
    }

    char      *ptr, c;
    int       row       = 0;
    long int  curr_int  = -1;
    long int  last_int  = -1;
    int       i         = -1;
    int       j         = -1;

    ptr = strtok(line, " \t");

    while(ptr != NULL){
/*
      printf("%d. %s\n", row, ptr);
*/

      char* end;
      curr_int          = strtol(ptr, &end, 10);
      if(*end) curr_int = -1; /* not read an int */

      switch(row){
        
        case 0:   if( curr_int != -1)
                    i = (int) curr_int;
                  break;
        case 4:   if( curr_int != -1 )
                    if((i != -1) && (curr_int > i)){
                      j = curr_int;
                      pairs[num_pairs].i      = i;
                      pairs[num_pairs].j      = j;
                      pairs[num_pairs].p      = 1.;
                      pairs[num_pairs++].type = 0;
                    }
                  break;
        case 1:   if(sscanf(ptr, "%c", &c)){
                    switch(c){
                      case 'E': if(!strcmp("ENERGY", ptr)){
                                  if(last_int != -1)
                                  length = (unsigned int)last_int;
                                }
                                break;
                      case 'A':
                      case 'U':
                      case 'T':
                      case 'C':
                      case 'G': if(seq_pos < length){
                                  seq[seq_pos++] = c;
                                }
                                break;
                      default:  break;
                    }
                  }
                  break;
        default:  break;
      }
      ptr = strtok(NULL, " \t");
      if(curr_int != -1)
        last_int = curr_int;
      row++;
    }

    free(line);

  } while(1);

  if(seq){
    pairs = vrna_realloc(pairs, sizeof(plist) * (num_pairs+1));
    pairs[num_pairs].i    = 0;
    pairs[num_pairs].j    = 0;
    pairs[num_pairs].p    = 0.;
    pairs[num_pairs].type = 0;


/*
    plist *p = pairs;
    for(p = pairs; (*p).i; p++)
      printf("pair (%d,%d)\n", (*p).i, (*p).j);
*/

    if(pkfree){
      float mea, MEAgamma;
      MEAgamma = 2.0;
      vrna_exp_param_t *params = vrna_exp_params(NULL);

      structure = (char *)vrna_alloc(sizeof(char) * (length + 1));
      strcpy(structure, seq);

      mea = MEA_seq(pairs, seq, structure, MEAgamma, params);

      char *structure_tmp = vrna_db_from_plist(pairs, length);
      int d =  vrna_bp_distance((const char *)structure, (const char *)structure_tmp);
      if(verbose && (d > 0))
        fprintf(stderr, "removed %d pairs from pseudoknotted structure\n", d);

      free(structure_tmp);
      free(params);
    } else {
      structure = vrna_db_from_plist(pairs, length);
    }

    printf("%s\n%s\n", seq, structure);
    free(pairs);
    free(seq);
  }

  return(EXIT_SUCCESS);
}