Exemplo n.º 1
0
void analyse(t_atoms *atoms,t_blocka *gb,char ***gn,bool bASK,bool bVerb)
{
  t_aa_names *aan;
  eRestp  *restp;
  char    *resnm;
  atom_id *aid;
  int     nra;
  int     i;
  size_t  j;

  if (bVerb)
    printf("Analysing residue names:\n");
  snew(restp,atoms->nres);
  aid=mk_aid(atoms,restp,etOther,&nra,TRUE);
  add_grp(gb,gn,nra,aid,"System"); 
  sfree(aid);

  aan = get_aa_names();
  for(i=0; (i<atoms->nres); i++) {
    resnm = *atoms->resinfo[i].name;
    if ((restp[i] == etOther) && is_protein(aan,resnm))
      restp[i] = etProt;
    if (restp[i] == etOther)
      for(j=0; (j<NDNA);  j++) {
	if (strcasecmp(Sugars[j],resnm) == 0)
	  restp[i] = etDNA;
      }
  }
  p_status(atoms->nres,restp,bVerb);
  done_aa_names(&aan);
  
  /* Protein */
  aid=mk_aid(atoms,restp,etProt,&nra,TRUE);
  if (nra > 0) 
    analyse_prot(restp,atoms,gb,gn,bASK,bVerb);
  
  sfree(aid);

  /* Non-Protein */
  aid=mk_aid(atoms,restp,etProt,&nra,FALSE);
  if ((nra > 0) && (nra < atoms->nr))
    add_grp(gb,gn,nra,aid,"Non-Protein"); 
  sfree(aid);

  /* DNA */
  aid=mk_aid(atoms,restp,etDNA,&nra,TRUE);
  if (nra > 0) {
    add_grp(gb,gn,nra,aid,"DNA"); 
    analyse_dna(restp,atoms,gb,gn,bASK,bVerb);
  }
  sfree(aid);

  /* Other */
  analyse_other(restp,atoms,gb,gn,bASK,bVerb);
  aid=mk_aid(atoms,restp,etOther,&nra,TRUE);
  if ((nra > 0) && (nra < atoms->nr))
    add_grp(gb,gn,nra,aid,"Other"); 
  sfree(aid);
  sfree(restp);
}
Exemplo n.º 2
0
/* ---------------- sub_mat_read ------------------------------
 */
struct sub_mat *
sub_mat_read (const char *fname)
{
#   ifndef BUFSIZ
#       error please define BUFSIZ to around 1024
#   endif
    fpos_t pos;
    struct sub_mat *smat = NULL;
    FILE *fp;
    char buf [BUFSIZ];
    char aanames [ MAX_AA + 3];
    const char *this_sub = "read_mat";
    const char comment = '#';
    if ((fp = mfopen (fname, "r", this_sub)) == NULL)
        return NULL;

    /* Portably initialise the fpos_t structure
     * because =0 is insufficient
     */
    if (fgetpos(fp, &pos)) {
        mperror (this_sub);
        goto broken;
    }


    smat = E_MALLOC ( sizeof (*smat));
    smat -> fname   = NULL;
    smat -> comment = NULL;
    smat->fname = save_str (fname);

    while (fgets (buf, BUFSIZ, fp) != NULL) {
        if ( buf[0] != comment) {
            if (fsetpos (fp, &pos)) {
                mperror (this_sub);
                goto broken;
            }
            break;
        }
        smat->comment = save_str_append (smat->comment, buf);
        if (fgetpos(fp, &pos)) {
            mperror (this_sub);
            goto broken;
        }
    }

    if (fgets (buf, BUFSIZ, fp) == NULL)
        goto broken;
    memset (aanames, BAD_AA, MAX_AA);
    if (get_aa_names (aanames, buf, BAD_AA) == EXIT_FAILURE)
        goto broken;
    {
        int n, m;
        for (n = 0; n < MAX_AA; n++)
            for ( m = 0; m < MAX_AA; m++)
                smat->data[n][m] = (mat_t) INVALID;
    }
    {
        int n = 0;
        for ( ;fgets(buf, BUFSIZ, fp) != NULL; n++) {
            if (aanames [n] == BAD_AA)
                continue;
            if (add_to_mat (smat, aanames, buf, n) == EXIT_FAILURE)
                err_printf (this_sub, "Ignoring matrix line\n");
        }
    }

    fclose (fp);
    return smat;
 broken:
    fclose (fp);
    free_if_not_null (smat->comment);
    free_if_not_null (smat->fname);
    free_if_not_null (smat);
    return NULL;
}