1 /* @source inforesidue application
2 **
3 ** Return information on amino acid residues
4 ** @author Copyright (C) Jon Ison (jison@ebi.ac.uk)
5 ** @@
6 **
7 ** This program is free software; you can redistribute it and/or
8 ** modify it under the terms of the GNU General Public License
9 ** as published by the Free Software Foundation; either version 2
10 ** of the License, or (at your option) any later version.
11 **
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; if not, write to the Free Software
19 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 ******************************************************************************/
21 
22 #include "emboss.h"
23 #include <math.h>
24 
25 #define DAYHOFF_FILE "Edayhoff.freq"
26 
27 
28 
29 
30 /* @prog inforesidue ***********************************************************
31 **
32 ** Return information on amino acid residues
33 **
34 ******************************************************************************/
35 
36 
37 
main(int argc,char ** argv)38 int main(int argc, char **argv)
39 {
40     /* Variable Declarations */
41     AjPStr code = NULL;
42     AjPFile mfptr = NULL;
43     AjPFile wfptr = NULL;
44     AjPFile outf = NULL;
45 
46     EmbPPropMolwt *mwdata;
47     EmbPPropAmino *aadata;
48 
49     float *dhstat = NULL;
50 
51     char    code1;
52     AjPStr  code3 = NULL;
53     ajint idx    = 0;
54     ajuint i;
55     ajuint iend;
56     AjPStr  propstr = NULL;
57     float charge;
58     char csign;
59 
60     /* ACD File Processing */
61     embInit("inforesidue", argc, argv);
62     code = ajAcdGetString("code");
63     mfptr   = ajAcdGetDatafile("aadata");
64     wfptr   = ajAcdGetDatafile("mwdata");
65     outf = ajAcdGetOutfile("outfile");
66 
67     aadata = embPropEaminoRead(mfptr);
68     mwdata = embPropEmolwtRead(wfptr);
69     if(!embReadAminoDataFloatC(DAYHOFF_FILE,&dhstat,(float)0.001))
70 	ajFatal("Set the EMBOSS_DATA environment variable");
71 
72 
73     /* Application logic */
74 
75     ajStrFmtUpper(&code);
76     iend = ajStrGetLen(code);
77     ajFmtPrintF(outf, "%-4s %-5s %-20s %6s %9s %-30s %s\n",
78                 "Code", "Short", "Mnemonic",
79                 "Charge", "MolWt",
80                 "Properties", "Ambiguity");
81     for(i=0;i<iend;i++)
82     {
83         code1=ajStrGetCharPos(code,i);
84         if(ajResidueExistsChar(code1))
85         {
86             idx = ajBasecodeToInt(code1);
87             ajResidueToTriplet(code1, &code3);
88             ajStrFmtTitle(&code3);
89 
90             if(!embPropGetProperties(aadata[idx], &propstr))
91                 ajStrAssignC(&propstr, "(none)");
92 
93             charge = embPropGetCharge(aadata[idx]);
94             if(charge > 0.0)
95                 csign = '+';
96             else if(charge < 0.0)
97                 csign = '-';
98             else
99                 csign = ' ';
100 
101             ajFmtPrintF(outf, "%-4c %-5S %-20S %3c%3.1f %9.4f %-30S %S\n",
102                         code1, code3, ajResidueGetMnemonic(code1),
103                         csign, fabs(charge),
104                         embPropMolwtGetMolwt(mwdata[idx]),
105                         propstr, ajResidueGetCodes(code1));
106         }
107         else
108         {
109             ajFmtPrintF(outf, "%-4c %-5s %-20s %6s %9s %-30s %s\n",
110                         code1, ".", "invalid", ".", ".", ".", ".");
111 
112         }
113 
114     }
115 
116 
117 
118     /* Memory management and exit */
119     ajStrDel(&code);
120     ajStrDel(&code3);
121     ajStrDel(&propstr);
122     ajFileClose(&outf);
123     ajFileClose(&mfptr);
124     ajFileClose(&wfptr);
125     ajFileClose(&outf);
126     embPropAminoDel(&aadata);
127     embPropMolwtDel(&mwdata);
128     AJFREE(dhstat);
129 
130     embExit();
131 
132     return 0;
133 }
134 
135