1 /* @source dreg application
2 **
3 ** DNA regular expressions (perl style)
4 **
5 ** @author Copyright (C) Peter Rice
6 ** @@
7 **
8 ** This program is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License
10 ** as published by the Free Software Foundation; either version 2
11 ** of the License, or (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with this program; if not, write to the Free Software
20 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 ******************************************************************************/
22 
23 #include "emboss.h"
24 
25 
26 
27 
28 /* @prog dreg *****************************************************************
29 **
30 ** regular expression search of a nucleotide sequence
31 **
32 ******************************************************************************/
33 
main(int argc,char ** argv)34 int main(int argc, char **argv)
35 {
36 
37     AjPSeqall seqall;
38     AjPRegexp patexp = NULL;
39     AjPPatlistRegex plist = NULL;
40     AjPReport report=NULL;
41     AjPFeattable feat=NULL;
42     AjPSeq seq = NULL;
43     AjPStr str = NULL;
44     AjPStr tmpstr = NULL;
45     AjPStr substr = NULL;
46     ajint adj;
47 
48     embInit("dreg", argc, argv);
49 
50     report = ajAcdGetReport ("outfile");
51     seqall = ajAcdGetSeqall("sequence");
52     plist  = ajAcdGetRegexp("pattern");
53 
54     ajFmtPrintAppS (&tmpstr, "Pattern: %S\n", ajAcdGetValue("pattern"));
55     ajReportSetHeaderS(report, tmpstr);
56 
57     while(ajSeqallNext(seqall, &seq))
58     {
59 	if(ajSeqIsReversed(seq))
60 	    adj = ajSeqGetLen(seq) - ajSeqGetOffend(seq);
61 	else
62 	    adj = ajSeqGetOffset(seq);
63 	ajDebug("begin:%d end:%d len:%d offset:%d offend:%d "
64 		"rev:%B nuc:%B adj:%d\n",
65 	       ajSeqGetBegin(seq), ajSeqGetEnd(seq), ajSeqGetLen(seq),
66 	       ajSeqGetOffset(seq), ajSeqGetOffend(seq),
67 	       ajSeqIsReversed(seq), ajSeqIsNuc(seq), adj);
68 
69 	ajStrAssignS(&str, ajSeqGetSeqS(seq));
70 	ajStrFmtUpper(&str);
71 	ajDebug("Testing '%s' len: %d %d regex %x\n",
72 		ajSeqGetNameC(seq), ajSeqGetLen(seq), ajStrGetLen(str),
73 		patexp);
74 	feat = ajFeattableNewSeq(seq);
75 	embPatlistRegexSearchAll(feat, seq, plist, ajFalse);
76 	if(ajFeattableGetSize(feat))
77 	    (void) ajReportWrite (report,feat,seq);
78 
79         ajFeattableDel(&feat);
80     }
81     ajReportSetSeqstats(report, seqall);
82 
83     ajReportClose(report);
84     ajReportDel(&report);
85 
86     ajSeqallDel(&seqall);
87     ajSeqDel(&seq);
88 
89     ajStrDel(&tmpstr);
90     ajStrDel(&substr);
91     ajStrDel(&str);
92     ajPatlistRegexDel(&plist);
93 
94     embExit();
95 
96     return 0;
97 }
98