PUBLIC char * get_ptypes( const short *S, vrna_md_t *md, unsigned int idx_type){ if(S){ if((unsigned int)S[0] > vrna_sequence_length_max(VRNA_OPTION_DEFAULT)){ vrna_message_warning("[email protected]: sequence length of %d exceeds addressable range", (int)S[0]); return NULL; } if(idx_type) return wrap_get_ptypes(S, md); else return vrna_ptypes(S, md); } else { return NULL; } }
PRIVATE void set_fold_compound(vrna_fold_compound_t *vc, vrna_md_t *md_p, unsigned int options, unsigned int aux){ char *sequence, **sequences; unsigned int length, s; int cp; /* cut point for cofold */ char *seq, *seq2; sequence = NULL; sequences = NULL; cp = -1; /* some default init values */ vc->params = NULL; vc->exp_params = NULL; vc->matrices = NULL; vc->exp_matrices = NULL; vc->hc = NULL; vc->auxdata = NULL; vc->free_auxdata = NULL; switch(vc->type){ case VRNA_VC_TYPE_SINGLE: sequence = vc->sequence; seq2 = strdup(sequence); seq = vrna_cut_point_remove(seq2, &cp); /* splice out the '&' if concatenated sequences and reset cp... this should also be safe for single sequences */ vc->cutpoint = cp; if((cp > 0) && (md_p->min_loop_size == TURN)) md_p->min_loop_size = 0; /* is it safe to set this here? */ free(vc->sequence); vc->sequence = seq; vc->length = length = strlen(seq); vc->sequence_encoding = vrna_seq_encode(seq, md_p); vc->sequence_encoding2 = vrna_seq_encode_simple(seq, md_p); if(!(options & VRNA_OPTION_EVAL_ONLY)){ vc->ptype = (aux & WITH_PTYPE) ? vrna_ptypes(vc->sequence_encoding2, md_p) : NULL; /* backward compatibility ptypes */ vc->ptype_pf_compat = (aux & WITH_PTYPE_COMPAT) ? get_ptypes(vc->sequence_encoding2, md_p, 1) : NULL; } else { vc->ptype = NULL; vc->ptype_pf_compat = NULL; } vc->sc = NULL; free(seq2); break; case VRNA_VC_TYPE_ALIGNMENT: sequences = vc->sequences; vc->length = length = vc->length; vc->cons_seq = consensus((const char **)sequences); vc->S_cons = vrna_seq_encode_simple(vc->cons_seq, md_p); vc->pscore = vrna_alloc(sizeof(int)*((length*(length+1))/2+2)); /* backward compatibility ptypes */ vc->pscore_pf_compat = (aux & WITH_PTYPE_COMPAT) ? vrna_alloc(sizeof(int)*((length*(length+1))/2+2)) : NULL; oldAliEn = vc->oldAliEn = md_p->oldAliEn; vc->S = vrna_alloc((vc->n_seq+1) * sizeof(short *)); vc->S5 = vrna_alloc((vc->n_seq+1) * sizeof(short *)); vc->S3 = vrna_alloc((vc->n_seq+1) * sizeof(short *)); vc->a2s = vrna_alloc((vc->n_seq+1) * sizeof(unsigned short *)); vc->Ss = vrna_alloc((vc->n_seq+1) * sizeof(char *)); for (s = 0; s < vc->n_seq; s++) { vrna_aln_encode(vc->sequences[s], &(vc->S[s]), &(vc->S5[s]), &(vc->S3[s]), &(vc->Ss[s]), &(vc->a2s[s]), md_p); } vc->S5[vc->n_seq] = NULL; vc->S3[vc->n_seq] = NULL; vc->a2s[vc->n_seq] = NULL; vc->Ss[vc->n_seq] = NULL; vc->S[vc->n_seq] = NULL; vc->scs = NULL; break; default: /* do nothing ? */ break; } vc->iindx = vrna_idx_row_wise(vc->length); vc->jindx = vrna_idx_col_wise(vc->length); /* now come the energy parameters */ add_params(vc, md_p, options); }
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; }