1 /* @source patmattest.c
2 **
3 ** General test routine for pattern matching.
4 **
5 ** This program is free software; you can redistribute it and/or
6 ** modify it under the terms of the GNU General Public License
7 ** as published by the Free Software Foundation; either version 2
8 ** of the License, or (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 ******************************************************************************/
19 
20 #include "emboss.h"
21 
22 
23 
24 
25 static const char *testset[] =
26 {
27     "GAN","GAATTC","CCSGG","GANTC","GABNNNNNVTC","GA", "GANN","TC"
28 };
29 
30 
31 
32 
33 /* @prog patmattest ***********************************************************
34 **
35 ** Testing
36 **
37 ******************************************************************************/
38 
main(int argc,char ** argv)39 int main(int argc, char **argv)
40 {
41     AjPStr cut    = NULL;
42     AjPStr cutseq = NULL;
43     AjPStr new    = NULL;
44     AjPStr test   = NULL;
45     AjPStr regexp = NULL;
46     AjPFile outf  = NULL;
47     EmbPPatMatch results = NULL;
48     AjPSeq seq;
49     ajuint i;
50     ajuint j;
51 
52     embInit("patmattest", argc, argv);
53 
54     seq = ajAcdGetSeq("sequence1");
55 
56     cutseq = ajAcdGetString("expression");
57 
58     outf = ajAcdGetOutfile("outfile");
59 
60     ajStrAssignC(&test,"GAATTCCCGGAGATTCCGACTC");
61 
62 
63     for(i=0;i<8;i++)
64     {
65 	ajStrAssignC(&cut,testset[i]);
66 
67 	/* Create the regular expression from the plain text */
68 	regexp = embPatSeqCreateRegExp(cut,0);
69 
70 	/* find the matches */
71 	results = embPatMatchFind(regexp,test, ajFalse, ajFalse);
72 
73 
74 	ajFmtPrintF(outf,"01234567890123456789012345\n");
75 	ajFmtPrintF(outf,"%S\n",test);
76 	ajFmtPrintF(outf,"%S %S\n",cut,regexp);
77 	ajFmtPrintF(outf,"%d matches found\n",results->number);
78 	for(j=0;j<results->number;j++)
79 	    ajFmtPrintF(outf,"start = %d len = %d\n",
80 			results->start[j],results->len[j]);
81 	ajFmtPrintF(outf," \n");
82 	embPatMatchDel(&results);
83 	ajStrDel(&regexp);
84 	ajStrDel(&cut);
85     }
86     ajStrDel(&test);
87 
88     results = embPatSeqMatchFind(seq, cutseq);
89     ajFmtPrintF(outf,"%S\n",cutseq);
90     ajFmtPrintF(outf,"%d matches found\n",results->number);
91     for(j=0;j < embPatMatchGetNumber(results) ;j++)
92     {
93 	ajFmtPrintF(outf,"start = %d len = %d\n",
94 		    embPatMatchGetStart(results,j),
95 		    embPatMatchGetLen(results,j));
96 	/* get a copy of the string */
97 	new = ajStrNewRes(results->len[j]);
98 	ajStrAssignSubS(&new,ajSeqGetSeqS(seq),embPatMatchGetStart(results,j),
99 		    embPatMatchGetEnd(results,j));
100 	ajFmtPrintF(outf,"%S\n",new);
101 	ajStrDel(&new);
102     }
103 
104     ajFmtPrintF(outf," \n");
105     embPatMatchDel(&results);
106     ajStrDel(&cutseq);
107     ajSeqDel(&seq);
108 
109     ajFileClose(&outf);
110 
111     embExit();
112 
113     return 0;
114 }
115