1 /* @source aaindexextract application
2 **
3 ** Extracts amino acid indices from AAINDEX
4 ** @author Copyright (C) Peter Rice (peter.rice@uk.lionbioscience.com)
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 #include <stdlib.h>
25 #include <string.h>
26 #include <ctype.h>
27 #include <limits.h>
28
29
30
31
32 /* @prog aaindexextract *******************************************************
33 **
34 ** Extract data from AAINDEX.
35 **
36 ** Each amino acid index is written as a separate file to the standard
37 ** EMBOSS data directory.
38 **
39 ******************************************************************************/
40
main(int argc,char ** argv)41 int main(int argc, char **argv)
42 {
43 AjPFile inf = NULL;
44 AjPFile outf = NULL;
45
46 AjPStr line;
47 AjPStr outdir = NULL;
48 AjPStr outfname = NULL;
49 AjPStr id = NULL;
50 AjBool done;
51
52 AjPRegexp idexp = NULL;
53 AjPRegexp endexp = NULL;
54
55 idexp = ajRegCompC("^H ([^ \n\r\t]+)$");
56 endexp = ajRegCompC("^//$");
57 ajStrAssignC(&outdir, "AAINDEX");
58
59 embInit("aaindexextract",argc,argv);
60
61 inf = ajAcdGetInfile("infile");
62
63
64 line = ajStrNew();
65
66 done = ajTrue;
67 while(ajReadlineTrim(inf, &line))
68 {
69 /* process the ID for a new index */
70 if(ajRegExec(idexp, line))
71 {
72 if(!done)
73 ajFatal("bad aaindex1 format new ID at: %S", line);
74 ajRegSubI(idexp, 1, &id);
75 ajStrFmtLower(&id);
76 ajFmtPrintS(&outfname, "%S/%S", outdir, id);
77 outf = ajDatafileNewOutNameS(outfname);
78 done = ajFalse;
79 }
80 else
81 {
82 if(done)
83 ajFatal("bad aaindex1 format expected ID at: %S", line);
84 done = ajFalse;
85 }
86
87 /* write the current line */
88 ajFmtPrintF(outf, "%S\n", line);
89
90 /* close the file at end of index */
91 if(ajRegExec(endexp, line))
92 {
93 done = ajTrue;
94 ajFileClose (&outf);
95 }
96 }
97 ajFileClose (&inf);
98
99 ajStrDel(&id);
100 ajStrDel(&line);
101 ajStrDel(&outdir);
102 ajStrDel(&outfname);
103
104 ajRegFree(&idexp);
105 ajRegFree(&endexp);
106
107 embExit();
108
109 return 0;
110 }
111