1 /* General routines used throughout HMMER.
2 *
3 * Contents:
4 * 1. Miscellaneous functions for H3
5 * 2. Unit tests
6 * 3. Test driver
7 *
8 * SRE, Fri Jan 12 13:19:38 2007 [Janelia] [Franz Ferdinand, eponymous]
9 */
10
11 #include "p7_config.h"
12
13 #include <math.h>
14 #include <float.h>
15
16 #include "easel.h"
17 #include "esl_getopts.h"
18 #include "hmmer.h"
19
20 /*****************************************************************
21 * 1. Miscellaneous functions for H3
22 *****************************************************************/
23
24 /* Function: p7_banner()
25 * Synopsis: print standard HMMER application output header
26 * Incept: SRE, Wed May 23 10:45:53 2007 [Janelia]
27 *
28 * Purpose: Print the standard HMMER command line application banner
29 * to <fp>, constructing it from <progname> (the name of the
30 * program) and a short one-line description <banner>.
31 * For example,
32 * <p7_banner(stdout, "hmmsim", "collect profile HMM score distributions");>
33 * might result in:
34 *
35 * \begin{cchunk}
36 * # hmmsim :: collect profile HMM score distributions
37 * # HMMER 3.0 (May 2007)
38 * # Copyright (C) 2004-2007 HHMI Janelia Farm Research Campus
39 * # Freely licensed under the Janelia Software License.
40 * # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41 * \end{cchunk}
42 *
43 * <progname> would typically be an application's
44 * <argv[0]>, rather than a fixed string. This allows the
45 * program to be renamed, or called under different names
46 * via symlinks. Any path in the <progname> is discarded;
47 * for instance, if <progname> is "/usr/local/bin/hmmsim",
48 * "hmmsim" is used as the program name.
49 *
50 * Note:
51 * Needs to pick up preprocessor #define's from p7_config.h,
52 * as set by ./configure:
53 *
54 * symbol example
55 * ------ ----------------
56 * HMMER_VERSION "3.0"
57 * HMMER_DATE "May 2007"
58 * HMMER_COPYRIGHT "Copyright (C) 2004-2007 HHMI Janelia Farm Research Campus"
59 * HMMER_LICENSE "Freely licensed under the Janelia Software License."
60 *
61 * Returns: (void)
62 */
63 void
p7_banner(FILE * fp,const char * progname,char * banner)64 p7_banner(FILE *fp, const char *progname, char *banner)
65 {
66 char *appname = NULL;
67
68 if (esl_FileTail(progname, FALSE, &appname) != eslOK) esl_strdup(progname, -1, &appname);
69
70 fprintf(fp, "# %s :: %s\n", appname, banner);
71 fprintf(fp, "# HMMER %s (%s); %s\n", HMMER_VERSION, HMMER_DATE, HMMER_URL);
72 fprintf(fp, "# %s\n", HMMER_COPYRIGHT);
73 fprintf(fp, "# %s\n", HMMER_LICENSE);
74 fprintf(fp, "# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
75
76 if (appname) free(appname);
77 return;
78 }
79
80
81 /* Function: p7_CreateDefaultApp()
82 * Synopsis: Initialize a small/simple/standard HMMER application
83 * Incept: SRE, Thu Oct 28 15:03:21 2010 [Janelia]
84 *
85 * Purpose: Identical to <esl_getopts_CreateDefaultApp()>, but
86 * specialized for HMMER. See documentation in
87 * <easel/esl_getopts.c>.
88 *
89 * Args: options - array of <ESL_OPTIONS> structures for getopts
90 * nargs - number of cmd line arguments expected (excl. of cmdname)
91 * argc - <argc> from main()
92 * argv - <argv> from main()
93 * banner - optional one-line description of program (or NULL)
94 * usage - optional one-line usage hint (or NULL)
95 *
96 * Returns: ptr to new <ESL_GETOPTS> object.
97 *
98 * On command line errors, this routine prints an error
99 * message to <stderr> then calls <exit(1)> to halt
100 * execution with abnormal (1) status.
101 *
102 * If the standard <-h> option is seen, the routine prints
103 * the help page (using the data in the <options> structure),
104 * then calls <exit(0)> to exit with normal (0) status.
105 *
106 * Xref: J7/3
107 *
108 * Note: The only difference between this and esl_getopts_CreateDefaultApp()
109 * is to call p7_banner() instead of esl_banner(), to get HMMER
110 * versioning info into the header. There ought to be a better way
111 * (perhaps using PACKAGE_* define's instead of HMMER_* vs. EASEL_*
112 * define's in esl_banner(), thus removing the need for p7_banner).
113 */
114 ESL_GETOPTS *
p7_CreateDefaultApp(ESL_OPTIONS * options,int nargs,int argc,char ** argv,char * banner,char * usage)115 p7_CreateDefaultApp(ESL_OPTIONS *options, int nargs, int argc, char **argv, char *banner, char *usage)
116 {
117 ESL_GETOPTS *go = NULL;
118
119 go = esl_getopts_Create(options);
120 if (esl_opt_ProcessCmdline(go, argc, argv) != eslOK ||
121 esl_opt_VerifyConfig(go) != eslOK)
122 {
123 printf("Failed to parse command line: %s\n", go->errbuf);
124 if (usage != NULL) esl_usage(stdout, argv[0], usage);
125 printf("\nTo see more help on available options, do %s -h\n\n", argv[0]);
126 exit(1);
127 }
128 if (esl_opt_GetBoolean(go, "-h") == TRUE)
129 {
130 if (banner != NULL) p7_banner(stdout, argv[0], banner);
131 if (usage != NULL) esl_usage (stdout, argv[0], usage);
132 puts("\nOptions:");
133 esl_opt_DisplayHelp(stdout, go, 0, 2, 80);
134 exit(0);
135 }
136 if (esl_opt_ArgNumber(go) != nargs)
137 {
138 puts("Incorrect number of command line arguments.");
139 esl_usage(stdout, argv[0], usage);
140 printf("\nTo see more help on available options, do %s -h\n\n", argv[0]);
141 exit(1);
142 }
143 return go;
144 }
145
146
147 /* Function: p7_AminoFrequencies()
148 * Incept: SRE, Fri Jan 12 13:46:41 2007 [Janelia]
149 *
150 * Purpose: Fills a vector <f> with amino acid background frequencies,
151 * in [A..Y] alphabetic order, same order that Easel digital
152 * alphabet uses. Caller must provide <f> allocated for at
153 * least 20 floats.
154 *
155 * These were updated 4 Sept 2007, from Swiss-Prot 50.8,
156 * (Oct 2006), counting over 85956127 (86.0M) residues.
157 *
158 * Returns: <eslOK> on success.
159 */
160 int
p7_AminoFrequencies(float * f)161 p7_AminoFrequencies(float *f)
162 {
163 f[0] = 0.0787945; /* A */
164 f[1] = 0.0151600; /* C */
165 f[2] = 0.0535222; /* D */
166 f[3] = 0.0668298; /* E */
167 f[4] = 0.0397062; /* F */
168 f[5] = 0.0695071; /* G */
169 f[6] = 0.0229198; /* H */
170 f[7] = 0.0590092; /* I */
171 f[8] = 0.0594422; /* K */
172 f[9] = 0.0963728; /* L */
173 f[10]= 0.0237718; /* M */
174 f[11]= 0.0414386; /* N */
175 f[12]= 0.0482904; /* P */
176 f[13]= 0.0395639; /* Q */
177 f[14]= 0.0540978; /* R */
178 f[15]= 0.0683364; /* S */
179 f[16]= 0.0540687; /* T */
180 f[17]= 0.0673417; /* V */
181 f[18]= 0.0114135; /* W */
182 f[19]= 0.0304133; /* Y */
183 return eslOK;
184 }
185
186 /*****************************************************************
187 * 2. Unit tests
188 *****************************************************************/
189 #ifdef p7HMMER_TESTDRIVE
190
191 static void
utest_alphabet_config(int alphatype)192 utest_alphabet_config(int alphatype)
193 {
194 char *msg = "HMMER alphabet config unit test failed";
195 ESL_ALPHABET *abc = NULL;
196
197 if ((abc = esl_alphabet_Create(alphatype)) == NULL) esl_fatal(msg);
198 if (abc->K > p7_MAXABET) esl_fatal(msg);
199 if (abc->Kp > p7_MAXCODE) esl_fatal(msg);
200 esl_alphabet_Destroy(abc);
201 }
202 #endif /*p7HMMER_TESTDRIVE*/
203
204
205
206 /*****************************************************************
207 * 3. Test driver
208 *****************************************************************/
209 #ifdef p7HMMER_TESTDRIVE
210
211 /* gcc -o hmmer_utest -g -Wall -I../easel -L../easel -I. -L. -Dp7HMMER_TESTDRIVE hmmer.c -lhmmer -leasel -lm
212 * ./hmmer_utest
213 */
214 #include "esl_getopts.h"
215
216 static ESL_OPTIONS options[] = {
217 /* name type default env range toggles reqs incomp help docgroup*/
218 { "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 },
219 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
220 };
221 static char usage[] = "[-options]";
222 static char banner[] = "test driver for hmmer.c";
223
224 int
main(int argc,char ** argv)225 main(int argc, char **argv)
226 {
227 ESL_GETOPTS *go = p7_CreateDefaultApp(options, 0, argc, argv, banner, usage);
228
229 utest_alphabet_config(eslAMINO);
230 utest_alphabet_config(eslDNA);
231 utest_alphabet_config(eslRNA);
232 utest_alphabet_config(eslCOINS);
233 utest_alphabet_config(eslDICE);
234
235 esl_getopts_Destroy(go);
236 return 0;
237 }
238 #endif /*p7HMMER_TESTDRIVE*/
239
240
241
242
243