PUBLIC float vrna_pf_fold( const char *seq, char *structure, vrna_plist_t **pl){ float free_energy; double mfe; vrna_fold_compound_t *vc; vrna_md_t md; vrna_md_set_default(&md); /* no need to backtrack MFE structure */ md.backtrack = 0; if(!pl){ /* no need for pair probability computations if we do not store them somewhere */ md.compute_bpp = 0; } vc = vrna_fold_compound(seq, &md, 0); mfe = (double)vrna_pf(vc, NULL); vrna_exp_params_rescale(vc, &mfe); free_energy = vrna_pf(vc, structure); /* fill plist */ if(pl){ *pl = vrna_plist_from_probs(vc, /*cut_off:*/ 1e-6); } vrna_fold_compound_free(vc); return free_energy; }
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); }
void InteractionEnergyVrna:: computeES( const Accessibility & acc, InteractionEnergyVrna::EsMatrix & esToFill ) { // prepare container esToFill.resize( acc.getSequence().size(), acc.getSequence().size() ); // sequence length const int seqLength = (int)acc.getSequence().size(); const E_type RT = getRT(); // VRNA compatible data structures char * sequence = (char *) vrna_alloc(sizeof(char) * (seqLength + 1)); char * structureConstraint = (char *) vrna_alloc(sizeof(char) * (seqLength + 1)); for (int i=0; i<seqLength; i++) { // copy sequence sequence[i] = acc.getSequence().asString().at(i); // copy accessibility constraint if present structureConstraint[i] = acc.getAccConstraint().getVrnaDotBracket(i); } sequence[seqLength] = structureConstraint[seqLength] = '\0'; // prepare folding data vrna_md_t curModel; vrna_md_copy( &curModel, &foldModel ); // set maximal base pair span curModel.max_bp_span = acc.getAccConstraint().getMaxBpSpan(); if (curModel.max_bp_span >= (int)acc.getSequence().size()) { curModel.max_bp_span = -1; } // TODO check if VRNA_OPTION_WINDOW reasonable to speedup vrna_fold_compound_t * foldData = vrna_fold_compound( sequence, &foldModel, VRNA_OPTION_PF); // Adding hard constraints from pseudo dot-bracket unsigned int constraint_options = VRNA_CONSTRAINT_DB_DEFAULT; // enforce constraints constraint_options |= VRNA_CONSTRAINT_DB_ENFORCE_BP; vrna_constraints_add( foldData, (const char *)structureConstraint, constraint_options); // compute correct partition function scaling via mfe FLT_OR_DBL min_free_energy = vrna_mfe( foldData, NULL ); vrna_exp_params_rescale( foldData, &min_free_energy); // compute partition functions const float ensembleE = vrna_pf( foldData, NULL ); if (foldData->exp_matrices == NULL) { throw std::runtime_error("AccessibilityVrna::computeES() : partition functions after computation not available"); } if (foldData->exp_matrices->qm == NULL) { throw std::runtime_error("AccessibilityVrna::computeES() : partition functions Qm after computation not available"); } // copy ensemble energies of multi loop parts = ES values FLT_OR_DBL qm_val = 0.0; const int minLoopSubseqLength = foldModel.min_loop_size + 2; for (int i=0; i<seqLength; i++) { for (int j=i; j<seqLength; j++) { // check if too short to enable a base pair if (j-i+1 < minLoopSubseqLength) { // make unfavorable esToFill(i,j) = E_INF; } else { // get Qm value // indexing via iindx starts with 1 instead of 0 qm_val = foldData->exp_matrices->qm[foldData->iindx[i+1]-j+1]; if ( E_equal(qm_val, 0.) ) { esToFill(i,j) = E_INF; } else { // ES energy = -RT*log( Qm ) esToFill(i,j) = (E_type)( - RT*( std::log(qm_val) +((FLT_OR_DBL)(j-i+1))*std::log(foldData->exp_params->pf_scale))); } } } } // garbage collection vrna_fold_compound_free(foldData); free(structureConstraint); free(sequence); }