1 /*
2   Copyright (c) 2003 by Stefan Kurtz and The Institute for
3   Genomic Research.  This is OSI Certified Open Source Software.
4   Please see the file LICENSE for licensing information and
5   the file ACKNOWLEDGEMENTS for names of contributors to the
6   code base.
7 */
8 
9 //\IgnoreLatex{
10 
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include "types.h"
15 #include "debugdef.h"
16 #include "errordef.h"
17 #include "protodef.h"
18 #include "spacedef.h"
19 #include "megabytes.h"
20 #include "maxmatdef.h"
21 
22 #ifdef DEBUG
23 
24 #define SHOWBOOLEANVALUE(CC)\
25         fprintf(stderr,"# %s=%s\n",#CC,SHOWBOOL(mmcallinfo->CC));
26 
showmaxmatflags(char * program,MMcallinfo * mmcallinfo)27 static void showmaxmatflags (char *program,
28                              MMcallinfo *mmcallinfo)
29 {
30   Uint i;
31 
32   fprintf (stderr,"# %s called with the following flags\n", program);
33   SHOWBOOLEANVALUE (showstring);
34   SHOWBOOLEANVALUE (reversecomplement);
35   SHOWBOOLEANVALUE (forward);
36   SHOWBOOLEANVALUE (showreversepositions);
37   SHOWBOOLEANVALUE (showsequencelengths);
38   SHOWBOOLEANVALUE (matchnucleotidesonly);
39   SHOWBOOLEANVALUE (cmumcand);
40   SHOWBOOLEANVALUE (cmum);
41   fprintf (stderr,"# minmatchlength=%lu\n",
42 	   (Showuint) mmcallinfo->minmatchlength);
43   fprintf (stderr,"# subject-file=\"%s\"\n", &mmcallinfo->subjectfile[0]);
44   for(i=0; i< mmcallinfo->numofqueryfiles; i++)
45   {
46     fprintf (stderr,"# query-file=\"%s\"\n", &mmcallinfo->queryfilelist[i][0]);
47   }
48 }
49 #endif
50 
51 //}
52 
53 /*EE
54   This module contains the main function of maxmatch3. It calls
55   the following three functions in an appropriate order and with
56   proper arguments.
57 */
58 
59 /*EE
60   The following function is imported form \texttt{maxmatopt.c}.
61 */
62 
63 Sint parsemaxmatoptions (MMcallinfo *maxmatcallinfo,
64                          Argctype argc,
65                          char **argv);
66 
67 /*EE
68   The following function is imported form \texttt{maxmatinp.c}.
69 */
70 
71 Sint getmaxmatinput (Multiseq *subjectmultiseq,
72                      BOOL matchnucleotidesonly,
73                      char *subjectfile);
74 
75 /*EE
76   The following function is imported form \texttt{procmaxmat.c}.
77 */
78 
79 Sint procmaxmatches(MMcallinfo *mmcallinfo,
80                     Multiseq *subjectmultiseq);
81 
82 //\IgnoreLatex{
83 
84 /*
85   This is the main function.
86 */
87 
88 MAINFUNCTION
89 {
90   Sint retcode;
91   MMcallinfo mmcallinfo;
92   Multiseq subjectmultiseq;
93 
94   DEBUGLEVELSET;
95   initclock();
96   retcode = parsemaxmatoptions (&mmcallinfo, argc, argv);
97   if (retcode < 0)
98   {
99     STANDARDMESSAGE;  // return error code and show message
100   }
101   if (retcode == 1)   // program was called with option -help
102   {
103     checkspaceleak ();
104     mmcheckspaceleak ();
105     return EXIT_SUCCESS;
106   }
107   DEBUGCODE(1,showmaxmatflags (argv[0], &mmcallinfo));
108   if (getmaxmatinput (&subjectmultiseq,
109                       mmcallinfo.matchnucleotidesonly,
110                       &mmcallinfo.subjectfile[0]) != 0)
111   {
112     STANDARDMESSAGE;
113   }
114   if(procmaxmatches(&mmcallinfo,&subjectmultiseq) != 0)
115   {
116     STANDARDMESSAGE;
117   }
118   freemultiseq (&subjectmultiseq);
119   checkspaceleak ();
120   mmcheckspaceleak ();
121   fprintf(stderr,"# COMPLETETIME %s %s %.2f\n",
122          argv[0],&mmcallinfo.subjectfile[0],
123          getruntime());
124   fprintf(stderr,"# SPACE %s %s %.2f\n",argv[0],
125          &mmcallinfo.subjectfile[0],
126          MEGABYTES(getspacepeak()+mmgetspacepeak()));
127   return EXIT_SUCCESS;
128 }
129 
130 //}
131