2 * Wed Mar 4 17:30:39 1998
4 * Test driver for Myers/Miller/Hirschberg linear memory Viterbi tracebacks.
6 * RCS $Id: weeviterbi_test.c,v 1.1.1.1 2005/03/22 08:34:47 cmzmasek Exp $
18 static char banner[] = "\
19 weeviterbi_test : testing of Plan7 Myers/Miller/Hirschberg Viterbi traceback code";
21 static char usage[] = "\
22 Usage: testdriver [-options]\n\
23 Available options are:\n\
24 -h : help; display this usage info\n\
28 static char experts[] = "\
29 --hmm <f> : use HMM in file <f>\n\
30 --seq <f> : use seq(s) in file <f>\n\
33 static struct opt_s OPTIONS[] = {
34 { "-h", TRUE, sqdARG_NONE },
35 { "-v", TRUE, sqdARG_NONE },
36 { "--hmm", FALSE, sqdARG_STRING },
37 { "--seq", FALSE, sqdARG_STRING },
39 #define NOPTIONS (sizeof(OPTIONS) / sizeof(struct opt_s))
42 main(int argc, char **argv)
44 char *hmmfile; /* file to read HMM(s) from */
45 HMMFILE *hmmfp; /* opened hmmfile for reading */
46 char *seqfile; /* file to read target sequence(s) from */
47 SQFILE *sqfp; /* opened seqfile for reading */
48 char *seq; /* target sequence */
49 SQINFO sqinfo; /* optional info for seq */
50 char *dsq; /* digitized target sequence */
51 struct plan7_s *hmm; /* HMM to search with */
52 struct p7trace_s *t1; /* standard Viterbi traceback */
53 struct p7trace_s *t2; /* WeeViterbi traceback */
55 float sc1,sc2; /* scores from Viterbi, WeeViterbi */
59 char *optname; /* name of option found by Getopt() */
60 char *optarg; /* argument found by Getopt() */
61 int optind; /* index in argv[] */
63 /***********************************************
65 ***********************************************/
68 hmmfile = "weeviterbi_test.hmm";
69 seqfile = "weeviterbi_test.seq";
71 while (Getopt(argc, argv, OPTIONS, NOPTIONS, usage,
72 &optind, &optname, &optarg)) {
73 if (strcmp(optname, "-v") == 0) be_verbose = TRUE;
74 else if (strcmp(optname, "--hmm") == 0) hmmfile = optarg;
75 else if (strcmp(optname, "--seq") == 0) seqfile = optarg;
76 else if (strcmp(optname, "-h") == 0) {
77 Banner(stdout, banner);
83 if (argc - optind != 0)
84 Die("Incorrect number of arguments.\n%s\n", usage);
86 /***********************************************
87 * Open test sequence file
88 ***********************************************/
90 if ((sqfp = SeqfileOpen(seqfile, SQFILE_UNKNOWN, "BLASTDB")) == NULL)
91 Die("Failed to open sequence database file %s\n%s\n", seqfile, usage);
93 /***********************************************
95 * Read a single HMM from it. (Config HMM, if necessary).
96 ***********************************************/
98 if ((hmmfp = HMMFileOpen(hmmfile, NULL)) == NULL)
99 Die("Failed to open HMM file %s\n%s", hmmfile, usage);
100 if (!HMMFileRead(hmmfp, &hmm))
101 Die("Failed to read any HMMs from %s\n", hmmfile);
103 Die("HMM file %s corrupt or in incorrect format? Parse failed", hmmfile);
104 P7Logoddsify(hmm, TRUE);
106 /***********************************************
107 * Search HMM against each sequence
108 ***********************************************/
111 while (ReadSeq(sqfp, sqfp->format, &seq, &sqinfo))
114 dsq = DigitizeSequence(seq, sqinfo.len);
116 sc1 = P7Viterbi(dsq, sqinfo.len, hmm, &t1);
117 sc2 = P7WeeViterbi(dsq, sqinfo.len, hmm, &t2);
121 printf("test sequence %d: %s %s\n",
123 sqinfo.flags & SQINFO_DESC ? sqinfo.desc : "");
124 printf("** P7Viterbi trace:\n");
125 P7PrintTrace(stdout, t1, hmm, dsq);
126 printf("** P7WeeViterbi trace:\n");
127 P7PrintTrace(stdout, t2, hmm, dsq);
130 if (! TraceVerify(t1, hmm->M, sqinfo.len))
131 Die("Trace verify failed on Viterbi for seq #%d, %s\n", nseq, sqinfo.name);
132 if (! TraceVerify(t2, hmm->M, sqinfo.len))
133 Die("Trace verify failed on WeeViterbi for seq #%d, %s\n", nseq, sqinfo.name);
135 Die("Scores for the two Viterbi implementations are unequal (%.1f,%.1f)", sc1, sc2);
136 if (! TraceCompare(t1, t2))
137 Die("WeeViterbi() trace is not identical to Viterbi() trace");
139 FreeSequence(seq, &sqinfo);