Beispiel #1
0
double score_seq( int s, char* seq, int ip )
{
    double score = 0.0;
    if( !is_legal( seq ) ) return score;

    int length = strlen( seq );
    int* ix = get_iindx( length );

    double betaScale = 1.0;
    double kT = ( betaScale*( ( temperature+K0 )*GASCONST ) )/1000.; /* in Kcal */
    model_detailsT md;
    set_model_details( &md );

    char* secstr = strdup( seq );
    secstr[0] = 0;
    fold_constrained = 0;
    paramT* params = get_scaled_parameters( temperature, md );
    double min_en = fold_par( seq, secstr, params, fold_constrained, 0 );
    if( strncmp( secstr + ip,
                 cnf->hairpin_ss, strlen( cnf->hairpin_ss ) ) != 0
        || strcmp( secstr + length - strlen( cnf->tail3p_ss ),
                   cnf->tail3p_ss ) != 0 ) {
        free( params );
        free( secstr );
        free( ix );
        return score;
    }
    if( !is_legal_pair_content( seq, secstr, ip ) ) {
        free( params );
        free( secstr );
        free( ix );
        return score;
    }
    #pragma omp atomic update
    num_scored++;

    double pf_scale = exp( -( 1.07*min_en )/kT/length );
    pf_paramT* pf_params = get_boltzmann_factors( temperature, betaScale, md, pf_scale );
    // Either patch fold_vars.h by inserting following at line 166
    //
    // #ifdef _OPENMP
    // #pragma omp threadprivate(iindx)
    // #endif
    //
    // or uncomment this pragma below
    //
    // #pragma omp critical(pf_fold)
    double e = pf_fold_par( seq, NULL, pf_params, 1, fold_constrained, 0 );
    FLT_OR_DBL* ppm = export_bppm();

#define pr_ij(i,j) (i == j? 0.0 : (i < j ? ppm[ix[i]-j] : ppm[ix[j]-i]))

    score = cnf->s_max;
    int i, o;
    for( i = 1; i <= length; i++ ) {
        for( o = 1; o <= strlen( cnf->hairpin_ss ); o++ ) {
            int j = ip + o;
            double v = pr_ij( i, j );
            score -= v * ( 1.0 - v );
        }
    }
    score *= cnf->s_scale;

    free( pf_params );
    free( params );
    free( secstr );
    free( ix );
    return score;
}
Beispiel #2
0
void main()
{
   char *seq1="CGCAGGGAUACCCGCG", *seq2="GCGCCCAUAGGGACGC",
        *struct1,* struct2,* xstruc;
   float e1, e2, tree_dist, string_dist, profile_dist, kT;
   Tree *T1, *T2;
   swString *S1, *S2;
   float *pf1, *pf2;
   FLT_OR_DBL *bppm;
   /* fold at 30C instead of the default 37C */
   temperature = 30.;      /* must be set *before* initializing  */

   /* allocate memory for structure and fold */
   struct1 = (char* ) space(sizeof(char)*(strlen(seq1)+1));
   e1 =  fold(seq1, struct1);

   struct2 = (char* ) space(sizeof(char)*(strlen(seq2)+1));
   e2 =  fold(seq2, struct2);

   free_arrays();     /* free arrays used in fold() */

   /* produce tree and string representations for comparison */
   xstruc = expand_Full(struct1);
   T1 = make_tree(xstruc);
   S1 = Make_swString(xstruc);
   free(xstruc);

   xstruc = expand_Full(struct2);
   T2 = make_tree(xstruc);
   S2 = Make_swString(xstruc);
   free(xstruc);

   /* calculate tree edit distance and aligned structures with gaps */
   edit_backtrack = 1;
   tree_dist = tree_edit_distance(T1, T2);
   free_tree(T1); free_tree(T2);
   unexpand_aligned_F(aligned_line);
   printf("%s\n%s  %3.2f\n", aligned_line[0], aligned_line[1], tree_dist);

   /* same thing using string edit (alignment) distance */
   string_dist = string_edit_distance(S1, S2);
   free(S1); free(S2);
   printf("%s  mfe=%5.2f\n%s  mfe=%5.2f  dist=%3.2f\n",
          aligned_line[0], e1, aligned_line[1], e2, string_dist);

   /* for longer sequences one should also set a scaling factor for
      partition function folding, e.g: */
   kT = (temperature+273.15)*1.98717/1000.;  /* kT in kcal/mol */
   pf_scale = exp(-e1/kT/strlen(seq1));

   /* calculate partition function and base pair probabilities */
   e1 = pf_fold(seq1, struct1);
   /* get the base pair probability matrix for the previous run of pf_fold() */
   bppm = export_bppm();
   pf1 = Make_bp_profile_bppm(bppm, strlen(seq1));

   e2 = pf_fold(seq2, struct2);
   /* get the base pair probability matrix for the previous run of pf_fold() */
   bppm = export_bppm();
   pf2 = Make_bp_profile_bppm(bppm, strlen(seq2));

   free_pf_arrays();  /* free space allocated for pf_fold() */

   profile_dist = profile_edit_distance(pf1, pf2);
   printf("%s  free energy=%5.2f\n%s  free energy=%5.2f  dist=%3.2f\n",
          aligned_line[0], e1, aligned_line[1], e2, profile_dist);

   free_profile(pf1); free_profile(pf2);
}