File: redata.c

package info (click to toggle)
emboss 6.6.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 571,248 kB
  • ctags: 39,971
  • sloc: ansic: 460,578; java: 29,439; perl: 13,573; sh: 12,740; makefile: 3,275; csh: 706; asm: 351; xml: 239; pascal: 237; modula3: 8
file content (320 lines) | stat: -rw-r--r-- 7,333 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/* @source redata application
**
** Reports isoschizomers, references and suppliers for restriction enzymes
** @author Copyright (C) Alan Bleasby (ableasby@hgmp.mrc.ac.uk)
** @@
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
******************************************************************************/

#include "emboss.h"

#define ENZDATA "REBASE/embossre.enz"
#define REFDATA "REBASE/embossre.ref"
#define SUPDATA "REBASE/embossre.sup"

#define SUPPGUESS 50	/* Estimate of number of suppliers. */




static AjPTable redata_supply_table(AjPFile inf);




/* @prog redata ***************************************************************
**
** Search REBASE for enzyme name, references, suppliers etc
**
******************************************************************************/

int main(int argc, char **argv)
{
    AjPStr enzyme = NULL;

    AjPFile outf = NULL;

    AjPFile enzfile = NULL;
    AjPFile reffile = NULL;
    AjPFile supfile = NULL;

    AjBool isoschizomers;
    AjBool references;
    AjBool suppliers;

    AjPTable t;
    AjPStr key   = NULL;
    const AjPStr value = NULL;

    AjPStr line    = NULL;
    AjPStr enzline = NULL;

    const char   *p;
    AjPStr str;
    AjPStr iso;

    AjPStr *ea;
    ajint  ne = 0;

    ajint len;
    ajint ncuts;
    AjBool blunt;
    ajint cut1;
    ajint cut2;
    ajint cut3;
    ajint cut4;

    ajint i;
    ajint n;

    embInit("redata", argc, argv);

    enzfile = ajDatafileNewInNameC(ENZDATA);
    reffile = ajDatafileNewInNameC(REFDATA);
    supfile = ajDatafileNewInNameC(SUPDATA);
    if(!enzfile || !reffile || !supfile)
	ajFatal("EMBOSS_DATA undefined or REBASEEXTRACT needs running");

    enzyme        = ajAcdGetString("enzyme");
    outf          = ajAcdGetOutfile("outfile");
    isoschizomers = ajAcdGetBoolean("isoschizomers");
    references    = ajAcdGetBoolean("references");
    suppliers     = ajAcdGetBoolean("suppliers");


    ajStrRemoveWhite(&enzyme);

    line    = ajStrNew();
    enzline = ajStrNew();
    str     = ajStrNew();
    key     = ajStrNewC(".");
    iso     = ajStrNew();



    /* Read in and close supplier file for later use */
    t=redata_supply_table(supfile);
    ajFileClose(&supfile);

    /* Read the enzyme line */
    while(ajReadlineTrim(enzfile,&enzline))
    {
	p=ajStrGetPtr(enzline);

	if(*p=='#' || *p=='\n' || *p=='!')
	    continue;
	p = ajSysFuncStrtok(p," \t\n");
	ajStrAssignC(&str,p);
/*	while(*p) ++p;
	*p = ' ';*/

	if(ajStrMatchCaseS(str,enzyme))
	    break;
    }

    /* Only do the rest if a matching enzyme was found */
    if(ajStrMatchCaseS(str,enzyme))
    {
	ajFmtPrintF(outf,"%S\n\n",str);
	while(ajStrMatchCaseS(str,enzyme))
	{
	    p = ajStrGetPtr(enzline);
	    p = ajSysFuncStrtok(p," \t\n");
	    ajStrAssignC(&str,p);
	    p = ajSysFuncStrtok(NULL," \t\n");
	    ajStrAssignC(&line,p);
	    p = ajSysFuncStrtok(NULL,"\n");
	    sscanf(p,"%d%d",&len,&ncuts);
	    if(ncuts==2)
		sscanf(p,"%d%d%d%d%d",&len,&ncuts,&blunt,&cut1,&cut2);
	    else
		sscanf(p,"%d%d%d%d%d%d%d",&len,&ncuts,&blunt,&cut1,&cut2,
		       &cut3,&cut4);
	    ajStrFmtUpper(&line);
	    ajFmtPrintF(outf,"Recognition site is %s leaving ",
			ajStrGetPtr(line));
	    if(blunt)
		ajFmtPrintF(outf,"blunt ends\n");
	    else
		ajFmtPrintF(outf,"sticky ends\n");

	    if(ncuts==2)
		ajFmtPrintF(outf,"  Cut positions 5':%d 3':%d\n",cut1,cut2);
	    else
		ajFmtPrintF(outf,"  Cut positions 5':%d 3':%d [5':%d 3':%d]\n",
			    cut1,cut2,cut3,cut4);

	    if(!ajReadlineTrim(enzfile,&enzline))
		break;

	    p = ajStrGetPtr(enzline);
	    p = ajSysFuncStrtok(p," \t\n");
	    ajStrAssignC(&str,p);
	}

	/* Read the reference file */
	while(ajReadlineTrim(reffile,&line))
	{
	    p = ajStrGetPtr(line);
	    if(*p=='#' || *p=='\n' || *p=='!')
		continue;

	    if(ajStrMatchCaseS(line,enzyme))
		break;

	    while(!ajStrMatchC(line,"//"))
		ajReadlineTrim(reffile,&line);
	}

	ajReadlineTrim(reffile,&line);
	ajFmtPrintF(outf,"Organism: %s\n",ajStrGetPtr(line));
	ajReadlineTrim(reffile,&iso);

	if(ajStrGetLen(iso))
	    ne = ajArrCommaList(iso,&ea);
	ajReadlineTrim(reffile,&line);

	if(ajStrGetLen(line))
	    ajFmtPrintF(outf,"Methylated: %s\n",ajStrGetPtr(line));
	ajReadlineTrim(reffile,&line);

	if(ajStrGetLen(line))
	    ajFmtPrintF(outf,"Source: %s\n",ajStrGetPtr(line));

	if(isoschizomers && ajStrGetLen(iso))
	{
	    ajFmtPrintF(outf,"\nIsoschizomers:\n");
	    n = 0;
	    ajFmtPrintF(outf,"   ");
	    for(i=0;i<ne;++i)
	    {
		ajFmtPrintF(outf,"%-12s",ajStrGetPtr(ea[i]));
		if(++n==6)
		{
		    ajFmtPrintF(outf,"\n   ");
		    n = 0;
		}
	    }
	    ajFmtPrintF(outf,"\n");
	}
	ajReadlineTrim(reffile,&line);

	if(suppliers && ajStrGetLen(line))
	{
	    ajFmtPrintF(outf,"\nSuppliers:\n");
	    p = ajStrGetPtr(line);
	    while(*p)
	    {
		ajStrAssignK(&key,*p);
		value = ajTableFetchS(t,key);
		if (value)
		    ajFmtPrintF(outf,"%S\n",value);
		else
		    ajFmtPrintF(outf,"'%S' not in suppliers file\n",key);
		++p;
	    }
	}
	ajReadlineTrim(reffile,&line);
	if(references && ajStrGetLen(line))
	{
	    p = ajStrGetPtr(line);
	    sscanf(p,"%d",&n);
	    ajFmtPrintF(outf,"\nReferences:\n");
	    for(i=0;i<n;++i)
	    {
		ajReadlineTrim(reffile,&line);
		ajFmtPrintF(outf,"%s\n",ajStrGetPtr(line));
	    }
	}

	if(ajStrGetLen(iso))
	{
	    for(i=0;i<ne;++i)
	        ajStrDel(&ea[i]);
	    AJFREE(ea);
        }
    }
    else
	ajFmtPrintF(outf,"Restriction enzyme %s not found\n",ajStrGetPtr(enzyme));

    ajStrDel(&str);
    ajStrDel(&iso);
    ajStrDel(&enzyme);
    ajStrDel(&line);
    ajStrDel(&enzline);
    ajStrDel(&key);
    ajTablestrFree(&t);
    ajFileClose(&enzfile);
    ajFileClose(&reffile);
    ajFileClose(&outf);

    embExit();

    return 0;
}




/* @funcstatic redata_supply_table ********************************************
**
** Read list of RE suppliers into table
**
** @param [u] inf [AjPFile] infile
** @return [AjPTable] Undocumented
** @@
******************************************************************************/

static AjPTable redata_supply_table(AjPFile inf)
{
    AjPTable t;

    AjPStr line;

    AjPStr key;
    AjPStr value;

    const char *p;
    const char *q;
    char c;

    t = ajTablestrNew(SUPPGUESS);
    line = ajStrNew();

    while(ajReadlineTrim(inf,&line))
    {
	p = ajStrGetPtr(line);
	q = p;

	if(!*p || *p=='#' || *p=='\n' || *p=='!')
	    continue;
	p = ajSysFuncStrtok(p," \t\n");
	key = ajStrNewC(p);
	q = strstr(q,p);

	while((c=*q)!=' ' && c!='\t' && c!='\n' && c)
	    ++q;

	while((c=*q)==' ' || c=='\t' || c=='\n')
	    ++q;
	value=ajStrNewC(q);
	ajTablePut(t,(void *)key, (void *)value);
    }

    ajStrDel(&line);

    return t;
}