initial commit
[jalview.git] / forester / archive / RIO / others / hmmer / testsuite / masks_test.c
1 /* masks_test.c
2  * SRE, Tue Nov 18 11:10:20 1997 [St. Louis]
3  * 
4  * Test driver for sequence masking routines in masks.c
5  * 
6  * CVS $Id: masks_test.c,v 1.1.1.1 2005/03/22 08:34:46 cmzmasek Exp $
7  */
8
9 #include <stdio.h>
10
11 #include "structs.h"
12 #include "funcs.h"
13 #include "globals.h"
14 #include "squid.h"
15
16 static char banner[] = "\
17 masks_test : testing of repeat masking code in masks.c";
18
19 static char usage[] = "\
20 Usage: testdriver [-options]\n\
21   Available options are:\n\
22   -h              : help; display this usage info\n\
23   -v              : verbose output\n\
24 ";
25
26 static char experts[] = "\
27   --xnu     <file>: apply xnu to seqs in <file>\n\
28 \n";
29
30 static struct opt_s OPTIONS[] = {
31   { "-h",       TRUE,  sqdARG_NONE  },
32   { "-v",       TRUE,  sqdARG_NONE  },
33   { "--xnu",    FALSE, sqdARG_STRING },
34 };
35 #define NOPTIONS (sizeof(OPTIONS) / sizeof(struct opt_s))
36
37 /* The test sequence and result from the XNU software distribution
38  */
39 static char *test1 = "\
40 ACDEFGHIKLMNPQRQRQRQRQRQRQRQRQRSTVWYACDEFGHIKLMNPQRQRQRQRQRQ\
41 RQRQRQRSTVWYACDEFGHIKLMNPQRQRQRQRQRQRQRQRQRSTVWYACDEFGHIKLMN\
42 PQRQRQRQRQRQRQRQRQRSTVWYACDEFGHIKLMNPQRQRQRQRQRQRQRQRQRSTVWY\
43 ACDEFGHIKLMNPQRQRQRQRQRQRQRQRQRSTVWY";
44
45 static char *answer1 = "\
46 ACDEFGHIKLMNPXXXXXXXXXXXXXXXXXXSTVWYACDEFGHIKLMNPXXXXXXXXXXX\
47 XXXXXXXSTVWYACDEFGHIKLMNPXXXXXXXXXXXXXXXXXXSTVWYACDEFGHIKLMN\
48 PXXXXXXXXXXXXXXXXXXSTVWYACDEFGHIKLMNPXXXXXXXXXXXXXXXXXXSTVWY\
49 ACDEFGHIKLMNPXXXXXXXXXXXXXXXXXXSTVWY";
50
51 int
52 main(int argc, char **argv)
53 {
54   char *seq;
55   char *dsq;
56   int   len;
57   int   i,j;
58   char *result;
59
60   char *optname;                /* name of option found by Getopt()         */
61   char *optarg;                 /* argument found by Getopt()               */
62   int   optind;                 /* index in argv[]                          */
63   int   be_verbose;
64   char *xnufile;                /* NULL, or file to run xnu on     */
65
66
67   /*********************************************** 
68    * Parse command line
69    ***********************************************/
70
71   be_verbose = FALSE;
72   xnufile    = NULL;
73
74   while (Getopt(argc, argv, OPTIONS, NOPTIONS, usage,
75                 &optind, &optname, &optarg))  {
76     if      (strcmp(optname, "-v")       == 0) { be_verbose = TRUE;   }
77     else if (strcmp(optname, "--xnu")    == 0) { xnufile    = optarg; }
78     else if (strcmp(optname, "-h")       == 0) {
79       Banner(stdout, banner);
80       puts(usage);
81       puts(experts);
82       exit(0);
83     }
84   }
85   if (argc - optind != 0)
86     Die("Incorrect number of arguments.\n%s\n", usage);
87
88   SetAlphabet(hmmAMINO);
89
90   /* XNU test
91    */
92   seq = test1;
93   len = (int) strlen(seq);
94   dsq = DigitizeSequence(seq, len);
95   XNU(dsq, len);
96   result = MallocOrDie(sizeof(char) * (len+1));
97   
98   for (i = 0; i < len; i++)
99     result[i] = Alphabet[(int) dsq[i+1]];
100   result[len] = '\0';
101   
102   if (be_verbose)
103     {
104       printf("XNU test:\n");
105       for (i = 1; i <= len; i+=60)
106         {
107           for (j = i; j < i+60 && j <= len; j++)
108             putc(Alphabet[(int) dsq[j]], stdout);
109           putc('\n', stdout);
110         }
111       if (strcmp(answer1, result) == 0)
112         printf("-- OK; Identical to expected\n");
113     }
114
115   if (strcmp(answer1, result) != 0)
116     Die("XNU test failed.");
117   free(result);
118   free(dsq);
119
120   /* On demand XNU test.
121    */
122   if (xnufile != NULL)
123     {
124       int     format;
125       SQFILE *sqfp;
126       SQINFO  sqinfo;
127       int     xnum;
128       
129       if ((sqfp = SeqfileOpen(xnufile, SQFILE_UNKNOWN, NULL)) == NULL)
130         Die("Failed to open sequence database file %s\n%s\n", xnufile, usage);
131       while (ReadSeq(sqfp, sqfp->format, &seq, &sqinfo)) 
132         {
133           dsq = DigitizeSequence(seq, sqinfo.len);
134           xnum = XNU(dsq, sqinfo.len);
135           result = DedigitizeSequence(dsq, sqinfo.len);
136
137           printf("%-20s\t%5d\n", sqinfo.name, xnum);
138           if (be_verbose)
139             WriteSeq(stdout, SQFILE_FASTA, result, &sqinfo);
140
141           free(dsq);
142           FreeSequence(seq, &sqinfo);
143           free(result);
144         }
145       SeqfileClose(sqfp);
146     }
147
148   return EXIT_SUCCESS;
149 }