Example #1
0
LVAL xlc_seq_copy(void)
{
    seq_type arg1 = getseq(xlgaseq());
    seq_type result;

    xllastarg();
    result = seq_copy(arg1);
    return cvseq(result);
}
Example #2
0
/*-------------------- coord_rmsd ------------------------------------------
 * Takes a pairset and two structures and moves coord1 on top of coord2 so 
 * that the RMSD is minimized. The superimposed structures are returned as
 * c1_new and c2_new. If sub_flag is set, the returned structures contain only
 * the subset of residues specified by the pairset.
 */
int
coord_rmsd(struct pair_set *const pairset, struct coord *source,
           struct coord *target, const int sub_flag, float *rmsd,
           struct coord **c1_new, struct coord **c2_new)
{
    float rmat[3][3];
    size_t tmp_idx = 0;
    size_t size, i;
    int r, a, b;
    struct RPoint translation1, translation2;
    int **pairs = pairset->indices;
    struct coord *temp_struct_1 =
        coord_template(source, coord_size(source));
    struct coord *temp_struct_2 =
        coord_template(target, coord_size(target));
    const char *this_sub = "coord_rmsd";
    /* Create temporary structures to hold the aligned parts of the two structures */
    temp_struct_1->seq = seq_copy(source->seq);
    temp_struct_2->seq = seq_copy(target->seq);
    coord_nm_2_a(temp_struct_1);
    coord_nm_2_a(temp_struct_2);
    if(sub_flag > 4){
                for (i = 0; i < pairset->n; i++) {
                   a = pairs[i][0];
                   b = pairs[i][1];
                   if (a != GAP_INDEX && b != GAP_INDEX) {
                           copy_coord_elem(temp_struct_1, source, tmp_idx, pairs[i][1]);
                           copy_coord_elem(temp_struct_2, target, tmp_idx, pairs[i][0]);
                           tmp_idx++;
                   }
                }
        }
        else{
                for (i = 0; i < pairset->n; i++) {
                    a = pairs[i][0];
                    b = pairs[i][1];
                    if (a != GAP_INDEX && b != GAP_INDEX) {
                            copy_coord_elem(temp_struct_1, source, tmp_idx, pairs[i][0]);
                            copy_coord_elem(temp_struct_2, target, tmp_idx, pairs[i][1]);
                            tmp_idx++;
                    }
                }
        }
    size = tmp_idx;
    coord_trim(temp_struct_1, size);
    coord_trim(temp_struct_2, size);
/* Determine the center of mass of the two structures and move the CoMs to the 
 * coordinate origin.
 */
    translation1 = calc_CM(size, temp_struct_1->rp_ca);
    translation2 = calc_CM(size, temp_struct_2->rp_ca);
    coord_trans(&translation1, temp_struct_1, size);
    coord_trans(&translation2, temp_struct_2, size);

/* Determine the rotation matrix and apply the rotation to structure 2.
 * Then calculate the RMSD
 */

    r = lsq_fit(tmp_idx, temp_struct_1->rp_ca, temp_struct_2->rp_ca,
                rmat);
    if (r == EXIT_FAILURE) {
            err_printf(this_sub, "lsq_fit fail\n");
            *rmsd = -1;
            goto escape;
    }
    apply_rot(rmat, temp_struct_1);
    *rmsd = calc_RMSD(size, temp_struct_1->rp_ca, temp_struct_2->rp_ca);

/* Move the structures' CoMs back to the original CoM of structure 2.*/
    translation2.x *= -1;
    translation2.y *= -1;
    translation2.z *= -1;
/* If only the aligned subset of the structures is needed, translate and
 *  return the temporary structures.
 */
    if (sub_flag%2) {
           coord_trans(&translation2, temp_struct_1, size);
           coord_trans(&translation2, temp_struct_2, size);
           *c1_new = temp_struct_1;
           *c2_new = temp_struct_2;
    }
/* Otherwise create a copy of the original structures, apply translation
 * and rotation to the copies and return those.
 */
    else {
           coord_destroy(temp_struct_1);
           coord_destroy(temp_struct_2);
           *c1_new = coord_template(source, coord_size(source));
           *c2_new = coord_template(target, coord_size(target));
           (*c1_new)->seq = seq_copy(source->seq);
           (*c2_new)->seq = seq_copy(target->seq);
           for (i = 0; i < coord_size(source); i++) {
               copy_coord_elem(*c1_new, source, i, i);
           }
           for (i = 0; i < coord_size(target); i++) {
               copy_coord_elem(*c2_new, target, i, i);
           }
           coord_trans(&translation1, *c1_new, (*c1_new)->size);
           apply_rot(rmat, *c1_new);
           coord_trans(&translation2, *c1_new, (*c1_new)->size);
    }

    return (EXIT_SUCCESS);
  escape:
    return (EXIT_FAILURE);
}
/* ---------------- seq_strct_2_prob_vec  -----------------------
 * This calculates probabilities for using combinations of
 * sequence and structure, sequence profile and structure,
 * sequence only, sequence profile only, and structure only.
 */
static struct prob_vec *
seq_strct_2_prob_vec (struct coord *structure, const struct seq *seq,
                      const struct seqprof *sp, const size_t size,
                      const struct aa_strct_clssfcn *cmodel,
                      const enum yes_no norm)
{
    size_t i, j, compnd_len;
    float *fragment;
    struct prob_vec *pvec;
    float **aa_prob;
    struct aa_clssfcn *aa_class;
    const size_t n_pvec = size - cmodel->n_att + 1;

    if ((pvec = new_pvec (cmodel->n_att, size,n_pvec,
                          cmodel->strct->n_class))!= NULL) {
        for (i = 0; i < n_pvec; i++)                   /* Initialize mship */
            for (j = 0; j < cmodel->strct->n_class; j++)
                pvec->mship[i][j] = cmodel->strct->class_weight[j];

        if (structure) {                           /* Structure membership */
            for (i = 0; i < n_pvec; i++) {         /* for every fragment...*/
                fragment = getFragment (i, cmodel->n_att, structure);
                if (computeMembershipStrct(pvec->mship[i], fragment,
                                           cmodel->strct) == NULL) {
                    prob_vec_destroy (pvec);
                    return NULL;
                }
            }
            free_if_not_null (fragment);
        }

        if (sp || seq) {                /* Sequence or profile membership */
            aa_prob = f_matrix (n_pvec,  cmodel->strct->n_class);
            aa_class = E_MALLOC (sizeof (struct aa_clssfcn));
            aa_class->n_class = cmodel->strct->n_class;
            aa_class->n_att = cmodel->n_att;
            aa_class->log_pp = cmodel->log_pp;
            aa_class->class_wt = cmodel->strct->class_weight;
            if (seq){
                struct seq *s = seq_copy (seq);
                if (computeMembershipAA (aa_prob, s, aa_class)
                    == EXIT_FAILURE) {
                    prob_vec_destroy (pvec);
                    return NULL;
                }
                seq_destroy (s);
            } else if (sp) {
                if (computeMembershipAAProf (aa_prob, sp, aa_class)
                    == EXIT_FAILURE) {
                    prob_vec_destroy (pvec);
                    return NULL;
                }
            }
            free (aa_class);
            for (i = 0; i < n_pvec; i++)
                for (j = 0; j < cmodel->strct->n_class; j++)
                    pvec->mship[i][j] *= aa_prob[i][j];
            kill_f_matrix (aa_prob);
        }
        if (norm == YES) {
            for (i = 0; i < n_pvec; i++){
                double sum = 0.0;
                for (j = 0; j < cmodel->strct->n_class; j++)
                    sum += pvec->mship[i][j];
                for (j = 0; j < cmodel->strct->n_class; j++)
                    pvec->mship[i][j] /= sum;
            }
            pvec->norm_type = PVEC_TRUE_PROB;
        }
    }


    /*shoffmann*/
	compnd_len = structure->compnd_len;
    /*finally read compound*/ 
    if(compnd_len > 0){
    	pvec->compnd = E_MALLOC(compnd_len*sizeof(char));
	pvec->compnd = memmove(pvec->compnd, structure->compnd, compnd_len);
    }
    pvec->compnd_len = compnd_len;
    return pvec;		 

}