PRIVATE char * wrap_get_ptypes(const short *S, vrna_md_t *md){ char *ptype; int n,i,j,k,l,*idx; n = S[0]; ptype = (char *)vrna_alloc(sizeof(char)*((n*(n+1))/2+2)); idx = vrna_idx_row_wise(n); int min_loop_size = md->min_loop_size; for (k=1; k<n-min_loop_size; k++) for (l=1; l<=2; l++) { int type,ntype=0,otype=0; i=k; j = i+min_loop_size+l; if (j>n) continue; type = md->pair[S[i]][S[j]]; while ((i>=1)&&(j<=n)) { if ((i>1)&&(j<n)) ntype = md->pair[S[i-1]][S[j+1]]; if (md->noLP && (!otype) && (!ntype)) type = 0; /* i.j can only form isolated pairs */ ptype[idx[i]-j] = (char) type; otype = type; type = ntype; i--; j++; } } free(idx); return ptype; }
PUBLIC double mean_bp_distance_pr(int length, FLT_OR_DBL *p){ double d=0; int *index = vrna_idx_row_wise((unsigned int) length); if (p==NULL) vrna_message_error("p==NULL. You need to supply a valid probability matrix for mean_bp_distance_pr()"); d = wrap_mean_bp_distance(p, length, index, TURN); free(index); return d; }
PUBLIC float *Make_bp_profile_bppm(FLT_OR_DBL *bppm, int length){ int i,j; int L=3; float *P; /* P[i*3+0] unpaired, P[i*3+1] upstream, P[i*3+2] downstream p */ int *index = vrna_idx_row_wise((unsigned) length); P = (float *) vrna_alloc((length+1)*3*sizeof(float)); /* indices start at 1 use first entries to store length and dimension */ P[0] = (float) length; P[1] = (float) L; for( i=1; i<length; i++) for( j=i+1; j<=length; j++ ) { P[i*L+1] += bppm[index[i]-j]; P[j*L+2] += bppm[index[i]-j]; } for( i=1; i<=length; i++) P[i*3+0] = 1 - P[i*3+1] - P[i*3+2]; free(index); return (float *) P; }
PUBLIC double mean_bp_dist(int length) { /* compute the mean base pair distance in the thermodynamic ensemble */ /* <d> = \sum_{a,b} p_a p_b d(S_a,S_b) this can be computed from the pair probs p_ij as <d> = \sum_{ij} p_{ij}(1-p_{ij}) */ int i, j, *my_iindx; double d = 0; if (pr==NULL) vrna_message_error("pr==NULL. You need to call pf_fold() before mean_bp_dist()"); my_iindx = vrna_idx_row_wise(length); for (i=1; i<=length; i++) for (j=i+TURN+1; j<=length; j++) d += pr[my_iindx[i]-j] * (1-pr[my_iindx[i]-j]); free(my_iindx); return 2*d; }
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 * get_iindx(unsigned int length){ return vrna_idx_row_wise(length); }