2 * Mon Feb 2 07:57:47 1998
3 * cp trace_test.c ../src/testdriver.c; cd ../src; make testdriver
5 * Test driver for Viterbi tracebacks.
7 * RCS $Id: trace_test.c,v 1.1.1.1 2005/03/22 08:34:47 cmzmasek Exp $
20 static char banner[] = "\
21 trace_test : testing of Plan7 Viterbi traceback code";
23 static char usage[] = "\
24 Usage: testdriver [-options]\n\
25 Available options are:\n\
26 -h : help; display this usage info\n\
30 static char experts[] = "\
31 --hmm <f> : use HMM in file <f>\n\
32 --seq <f> : use seq(s) in file <f>\n\
33 --small : run P7SmallViterbi()\n\
36 static struct opt_s OPTIONS[] = {
37 { "-h", TRUE, sqdARG_NONE },
38 { "-v", TRUE, sqdARG_NONE },
39 { "--hmm", FALSE, sqdARG_STRING },
40 { "--seq", FALSE, sqdARG_STRING },
41 { "--small", FALSE, sqdARG_NONE },
43 #define NOPTIONS (sizeof(OPTIONS) / sizeof(struct opt_s))
46 main(int argc, char **argv)
48 char *hmmfile; /* file to read HMM(s) from */
49 HMMFILE *hmmfp; /* opened hmmfile for reading */
50 char *seqfile; /* file to read target sequence(s) from */
51 SQFILE *sqfp; /* opened seqfile for reading */
52 char *seq; /* target sequence */
53 SQINFO sqinfo; /* optional info for seq */
54 char *dsq; /* digitized target sequence */
55 struct plan7_s *hmm; /* HMM to search with */
56 struct p7trace_s *tr; /* traceback */
61 int do_small; /* TRUE to invoke P7SmallViterbi */
63 char *optname; /* name of option found by Getopt() */
64 char *optarg; /* argument found by Getopt() */
65 int optind; /* index in argv[] */
67 /***********************************************
69 ***********************************************/
72 hmmfile = "trace_test.hmm";
73 seqfile = "trace_test.seq";
76 while (Getopt(argc, argv, OPTIONS, NOPTIONS, usage,
77 &optind, &optname, &optarg)) {
78 if (strcmp(optname, "-v") == 0) be_verbose = TRUE;
79 else if (strcmp(optname, "--hmm") == 0) hmmfile = optarg;
80 else if (strcmp(optname, "--seq") == 0) seqfile = optarg;
81 else if (strcmp(optname, "--small") == 0) do_small = TRUE;
82 else if (strcmp(optname, "-h") == 0) {
83 Banner(stdout, banner);
89 if (argc - optind != 0)
90 Die("Incorrect number of arguments.\n%s\n", usage);
92 /***********************************************
93 * Open test sequence file
94 ***********************************************/
96 if ((sqfp = SeqfileOpen(seqfile, SQFILE_UNKNOWN, "BLASTDB")) == NULL)
97 Die("Failed to open sequence database file %s\n%s\n", seqfile, usage);
99 /***********************************************
101 * Read a single HMM from it. (Config HMM, if necessary).
102 ***********************************************/
104 if ((hmmfp = HMMFileOpen(hmmfile, NULL)) == NULL)
105 Die("Failed to open HMM file %s\n%s", hmmfile, usage);
106 if (!HMMFileRead(hmmfp, &hmm))
107 Die("Failed to read any HMMs from %s\n", hmmfile);
109 Die("HMM file %s corrupt or in incorrect format? Parse failed", hmmfile);
110 P7Logoddsify(hmm, TRUE);
112 /***********************************************
113 * Search HMM against each sequence
114 ***********************************************/
117 while (ReadSeq(sqfp, sqfp->format, &seq, &sqinfo))
120 dsq = DigitizeSequence(seq, sqinfo.len);
122 if (do_small) sc = P7SmallViterbi(dsq, sqinfo.len, hmm, &tr);
123 else sc = P7Viterbi(dsq, sqinfo.len, hmm, &tr);
127 printf("test sequence %d: score %.1f : %s %s\n",
128 nseq, sc, sqinfo.name,
129 sqinfo.flags & SQINFO_DESC ? sqinfo.desc : "");
130 P7PrintTrace(stdout, tr, hmm, dsq);
133 if (! TraceVerify(tr, hmm->M, sqinfo.len))
134 Die("Trace verify failed on seq #%d, %s\n", nseq, sqinfo.name);
136 FreeSequence(seq, &sqinfo);