1 /* parsingviterbi_test.c
2 * Wed Mar 4 15:07:37 1998
3 * cp trace_test.c ../src/testdriver.c; cd ../src; make testdriver
5 * Test driver for P7ParsingViterbi(); alignment in linear memory.
7 * CVS $Id: parsingviterbi_test.c,v 1.1.1.1 2005/03/22 08:34:47 cmzmasek Exp $
19 static char banner[] = "\
20 parsingviterbi_test : testing of Plan7 linear memory alignment code";
22 static char usage[] = "\
23 Usage: parsingviterbi_test [-options]\n\
24 Available options are:\n\
25 -h : help; display this usage info\n\
29 static char experts[] = "\
32 static struct opt_s OPTIONS[] = {
33 { "-h", TRUE, sqdARG_NONE },
34 { "-v", TRUE, sqdARG_NONE },
36 #define NOPTIONS (sizeof(OPTIONS) / sizeof(struct opt_s))
39 main(int argc, char **argv)
41 char *hmmfile; /* file to read HMM(s) from */
42 HMMFILE *hmmfp; /* opened hmmfile for reading */
43 char *seqfile; /* file to read target sequence(s) from */
44 SQFILE *sqfp; /* opened seqfile for reading */
45 char *seq; /* target sequence */
46 SQINFO sqinfo; /* optional info for seq */
47 char *dsq; /* digitized target sequence */
48 struct plan7_s *hmm; /* HMM to search with */
49 struct p7trace_s *tr1; /* traceback from P7Viterbi() */
50 struct p7trace_s *tr2; /* traceback from P7ParsingViterbi() */
52 float sc1, sc2; /* scores from Viterbi, ParsingViterbi() */
54 struct p7trace_s **tarr; /* array of decomposed Viterbi traces */
55 int ntr; /* number of traces */
56 int i1,i2,k1,k2; /* starts, stops in seq, model for Viterbi */
57 int idx; /* index of a decomposed trace */
61 char *optname; /* name of option found by Getopt() */
62 char *optarg; /* argument found by Getopt() */
63 int optind; /* index in argv[] */
65 /***********************************************
67 ***********************************************/
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, "-h") == 0) {
75 Banner(stdout, banner);
81 if (argc - optind != 0)
82 Die("Incorrect number of arguments.\n%s\n", usage);
87 /***********************************************
88 * Open test sequence file
89 ***********************************************/
91 if ((sqfp = SeqfileOpen(seqfile, SQFILE_UNKNOWN, "BLASTDB")) == NULL)
92 Die("Failed to open sequence database file %s\n%s\n", seqfile, usage);
94 /***********************************************
96 * Read a single HMM from it. (Config HMM, if necessary).
97 ***********************************************/
99 if ((hmmfp = HMMFileOpen(hmmfile, NULL)) == NULL)
100 Die("Failed to open HMM file %s\n%s", hmmfile, usage);
101 if (!HMMFileRead(hmmfp, &hmm))
102 Die("Failed to read any HMMs from %s\n", hmmfile);
104 Die("HMM file %s corrupt or in incorrect format? Parse failed", hmmfile);
105 P7Logoddsify(hmm, TRUE);
107 /***********************************************
108 * Search HMM against each sequence, using both
109 * normal Viterbi and P7ParsingViterbi.
110 ***********************************************/
113 while (ReadSeq(sqfp, sqfp->format, &seq, &sqinfo))
116 dsq = DigitizeSequence(seq, sqinfo.len);
118 sc1 = P7Viterbi(dsq, sqinfo.len, hmm, &tr1);
119 sc2 = P7ParsingViterbi(dsq, sqinfo.len, hmm, &tr2);
123 printf("test sequence %d: %s %s\n",
125 sqinfo.flags & SQINFO_DESC ? sqinfo.desc : "");
126 for (idx = 0; idx < tr2->tlen; idx++)
127 printf("%1s %d\n", Statetype(tr2->statetype[idx]), tr2->pos[idx]);
131 Die("Scores for the two Viterbi implementations are unequal (%d,%d)", sc1, sc2);
133 TraceDecompose(tr1, &tarr, &ntr);
135 Die("ntr == 0 can't happen");
136 if (ntr != (tr2->tlen/2) -1)
137 Die("# of domains for the two Viterbi implementations are unequal (%d, %d)",
138 ntr, (tr2->tlen/2) -1);
140 for (idx = 0; idx < ntr; idx++)
142 TraceSimpleBounds(tarr[idx], &i1, &i2, &k1, &k2);
144 if (i1 != tr2->pos[idx*2 + 1] + 1)
145 Die("Start positions %d and %d disagree for domain %d\n",
146 i1, tr2->pos[idx*2 + 1] + 1, idx);
147 if (i2 != tr2->pos[idx*2 + 2])
148 Die("End positions %d and %d disagree for domain %d\n",
149 i2, tr2->pos[idx*2 + 2], idx);
153 for (idx = 0; idx < ntr; idx++)
154 P7FreeTrace(tarr[idx]);
156 FreeSequence(seq, &sqinfo);