1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include "convert.h" |
---|
4 | #include "global.h" |
---|
5 | |
---|
6 | extern int warning_out; |
---|
7 | |
---|
8 | /* ---------------------------------------------------------- |
---|
9 | * Function init_pm_data(). |
---|
10 | * Init macke and embl data. |
---|
11 | */ |
---|
12 | void |
---|
13 | init_em_data() { |
---|
14 | /* void init_macke(), init_embl(); */ |
---|
15 | |
---|
16 | init_macke(); |
---|
17 | init_embl(); |
---|
18 | } |
---|
19 | /* ------------------------------------------------------------ |
---|
20 | * Function init_embl(). |
---|
21 | * Initialize embl entry. |
---|
22 | */ |
---|
23 | void |
---|
24 | init_embl() { |
---|
25 | |
---|
26 | int indi; |
---|
27 | /* void Freespace(); */ |
---|
28 | /* char *Dupstr(); */ |
---|
29 | |
---|
30 | /* initialize embl format */ |
---|
31 | Freespace(&(data.embl.id)); |
---|
32 | Freespace(&(data.embl.dateu)); |
---|
33 | Freespace(&(data.embl.datec)); |
---|
34 | Freespace(&(data.embl.description)); |
---|
35 | Freespace(&(data.embl.os)); |
---|
36 | Freespace(&(data.embl.accession)); |
---|
37 | Freespace(&(data.embl.keywords)); |
---|
38 | |
---|
39 | for(indi=0; indi<data.embl.numofref; indi++) { |
---|
40 | Freespace(&(data.embl.reference[indi].author)); |
---|
41 | Freespace(&(data.embl.reference[indi].title)); |
---|
42 | Freespace(&(data.embl.reference[indi].journal)); |
---|
43 | Freespace(&(data.embl.reference[indi].processing)); |
---|
44 | } |
---|
45 | Freespace(&(data.embl.reference)); |
---|
46 | Freespace(&(data.embl.dr)); |
---|
47 | Freespace(&(data.embl.comments.orginf.source)); |
---|
48 | Freespace(&(data.embl.comments.orginf.cc)); |
---|
49 | Freespace(&(data.embl.comments.orginf.formname)); |
---|
50 | Freespace(&(data.embl.comments.orginf.nickname)); |
---|
51 | Freespace(&(data.embl.comments.orginf.commname)); |
---|
52 | Freespace(&(data.embl.comments.orginf.hostorg)); |
---|
53 | Freespace(&(data.embl.comments.seqinf.RDPid)); |
---|
54 | Freespace(&(data.embl.comments.seqinf.gbkentry)); |
---|
55 | Freespace(&(data.embl.comments.seqinf.methods)); |
---|
56 | Freespace(&(data.embl.comments.others)); |
---|
57 | |
---|
58 | data.embl.id=Dupstr("\n"); |
---|
59 | data.embl.dateu=Dupstr("\n"); |
---|
60 | data.embl.datec=Dupstr("\n"); |
---|
61 | data.embl.description=Dupstr("\n"); |
---|
62 | data.embl.os=Dupstr("\n"); |
---|
63 | data.embl.accession=Dupstr("\n"); |
---|
64 | data.embl.keywords=Dupstr("\n"); |
---|
65 | data.embl.dr=Dupstr("\n"); |
---|
66 | data.embl.numofref=0; |
---|
67 | data.embl.reference=NULL; |
---|
68 | data.embl.comments.orginf.exist=0; |
---|
69 | data.embl.comments.orginf.source=Dupstr("\n"); |
---|
70 | data.embl.comments.orginf.cc=Dupstr("\n"); |
---|
71 | data.embl.comments.orginf.formname=Dupstr("\n"); |
---|
72 | data.embl.comments.orginf.nickname=Dupstr("\n"); |
---|
73 | data.embl.comments.orginf.commname=Dupstr("\n"); |
---|
74 | data.embl.comments.orginf.hostorg=Dupstr("\n"); |
---|
75 | data.embl.comments.seqinf.exist=0; |
---|
76 | data.embl.comments.seqinf.RDPid=Dupstr("\n"); |
---|
77 | data.embl.comments.seqinf.gbkentry=Dupstr("\n"); |
---|
78 | data.embl.comments.seqinf.methods=Dupstr("\n"); |
---|
79 | data.embl.comments.others=NULL; |
---|
80 | data.embl.comments.seqinf.comp5=' '; |
---|
81 | data.embl.comments.seqinf.comp3=' '; |
---|
82 | } |
---|
83 | /* --------------------------------------------------------------- |
---|
84 | * Function embl_in(). |
---|
85 | * Read in one embl entry. |
---|
86 | */ |
---|
87 | char |
---|
88 | embl_in(fp) |
---|
89 | FILE_BUFFER fp; |
---|
90 | { |
---|
91 | char line[LINENUM], key[TOKENNUM]; |
---|
92 | char *eof, eoen; |
---|
93 | /* char *embl_date(); */ |
---|
94 | /* char *embl_version(); */ |
---|
95 | /* char *embl_comments(), *embl_origin(); */ |
---|
96 | /* char *embl_skip_unidentified(); */ |
---|
97 | /* char *Dupstr(), *temp; */ |
---|
98 | /* void embl_key_word(), warning(), error(), Append_char(); */ |
---|
99 | /* void replace_entry(), embl_verify_title(); */ |
---|
100 | int refnum; |
---|
101 | |
---|
102 | eoen=' '; /* end-of-entry, set to be 'y' after '//' is read */ |
---|
103 | |
---|
104 | for(eof=Fgetline(line, LINENUM, fp); eof!=NULL&&eoen!='y'; ) { |
---|
105 | if(Lenstr(line)<=1) { |
---|
106 | eof=Fgetline(line, LINENUM, fp); |
---|
107 | continue; /* empty line, skip */ |
---|
108 | } |
---|
109 | |
---|
110 | embl_key_word(line, 0, key, TOKENNUM); |
---|
111 | eoen='n'; |
---|
112 | |
---|
113 | if((Cmpstr(key, "ID"))==EQ) { |
---|
114 | eof = embl_one_entry(line, fp, |
---|
115 | &(data.embl.id), key); |
---|
116 | |
---|
117 | } else if((Cmpstr(key, "DT"))==EQ) { |
---|
118 | eof = embl_date(line, fp); |
---|
119 | |
---|
120 | } else if((Cmpstr(key, "DE"))==EQ) { |
---|
121 | eof = embl_one_entry(line, fp, |
---|
122 | &(data.embl.description), key); |
---|
123 | |
---|
124 | } else if((Cmpstr(key, "OS"))==EQ) { |
---|
125 | eof = embl_one_entry(line, fp, |
---|
126 | &(data.embl.os), key); |
---|
127 | |
---|
128 | } else if((Cmpstr(key, "AC"))==EQ) { |
---|
129 | eof = embl_one_entry(line, fp, |
---|
130 | &(data.embl.accession), key); |
---|
131 | |
---|
132 | } else if((Cmpstr(key, "KW"))==EQ) { |
---|
133 | eof = embl_one_entry(line, fp, |
---|
134 | &(data.embl.keywords), key); |
---|
135 | |
---|
136 | /* correct missing '.' */ |
---|
137 | if(Lenstr(data.embl.keywords)<=1) { |
---|
138 | replace_entry(&(data.embl.keywords), ".\n"); |
---|
139 | } else Append_char(&(data.embl.keywords), '.'); |
---|
140 | |
---|
141 | } else if((Cmpstr(key, "DR"))==EQ) { |
---|
142 | eof = embl_one_entry(line, fp, |
---|
143 | &(data.embl.dr), key); |
---|
144 | |
---|
145 | } else if((Cmpstr(key, "RA"))==EQ) { |
---|
146 | |
---|
147 | refnum = data.embl.numofref-1; |
---|
148 | eof = embl_one_entry(line, fp, |
---|
149 | &(data.embl.reference[refnum].author), key); |
---|
150 | Append_char |
---|
151 | (&(data.embl.reference[refnum].author), ';'); |
---|
152 | |
---|
153 | } else if((Cmpstr(key, "RT"))==EQ) { |
---|
154 | |
---|
155 | refnum = data.embl.numofref-1; |
---|
156 | eof = embl_one_entry(line, fp, |
---|
157 | &(data.embl.reference[refnum].title), key); |
---|
158 | |
---|
159 | /* Check missing '"' at the both ends */ |
---|
160 | embl_verify_title(refnum); |
---|
161 | |
---|
162 | } else if((Cmpstr(key, "RL"))==EQ) { |
---|
163 | |
---|
164 | refnum = data.embl.numofref-1; |
---|
165 | eof = embl_one_entry(line, fp, |
---|
166 | &(data.embl.reference[refnum].journal), key); |
---|
167 | Append_char |
---|
168 | (&(data.embl.reference[refnum].journal), '.'); |
---|
169 | |
---|
170 | } else if((Cmpstr(key, "RP"))==EQ) { |
---|
171 | |
---|
172 | refnum = data.embl.numofref-1; |
---|
173 | eof = embl_one_entry(line, fp, |
---|
174 | &(data.embl.reference[refnum].processing), key); |
---|
175 | |
---|
176 | } else if((Cmpstr(key, "RN"))==EQ) { |
---|
177 | |
---|
178 | eof = embl_version(line, fp); |
---|
179 | |
---|
180 | } else if((Cmpstr(key, "CC"))==EQ) { |
---|
181 | |
---|
182 | eof = embl_comments(line, fp); |
---|
183 | |
---|
184 | } else if((Cmpstr(key, "SQ"))==EQ) { |
---|
185 | |
---|
186 | eof = embl_origin(line, fp); |
---|
187 | eoen = 'y'; |
---|
188 | |
---|
189 | } else { /* unidentified key word */ |
---|
190 | eof = embl_skip_unidentified(key, line, fp); |
---|
191 | } |
---|
192 | /* except "ORIGIN", at the end of all the other cases, |
---|
193 | * a new line has already read in, so no further read |
---|
194 | * is necessary */ |
---|
195 | |
---|
196 | } /* for loop to read an entry line by line */ |
---|
197 | |
---|
198 | if(eoen=='n') |
---|
199 | error(83, "Reach EOF before one entry is read, Exit"); |
---|
200 | |
---|
201 | if(eof==NULL) return(EOF); |
---|
202 | else return(EOF+1); |
---|
203 | |
---|
204 | } |
---|
205 | /* --------------------------------------------------------------- |
---|
206 | * Function embl_in_id(). |
---|
207 | * Read in one embl entry. |
---|
208 | */ |
---|
209 | char |
---|
210 | embl_in_id(fp) |
---|
211 | FILE_BUFFER fp; |
---|
212 | { |
---|
213 | char line[LINENUM], key[TOKENNUM]; |
---|
214 | char *eof, eoen; |
---|
215 | /* char *embl_one_entry(), *embl_origin(); */ |
---|
216 | /* char *embl_skip_unidentified(); */ |
---|
217 | /* void embl_key_word(), warning(), error(); */ |
---|
218 | /* int Lenstr(); */ |
---|
219 | |
---|
220 | eoen=' '; |
---|
221 | /* end-of-entry, set to be 'y' after '//' is read */ |
---|
222 | |
---|
223 | for(eof=Fgetline(line, LINENUM, fp); eof!=NULL&&eoen!='y'; ) |
---|
224 | { |
---|
225 | if(Lenstr(line)<=1) { |
---|
226 | eof=Fgetline(line, LINENUM, fp); |
---|
227 | continue; /* empty line, skip */ |
---|
228 | } |
---|
229 | |
---|
230 | embl_key_word(line, 0, key, TOKENNUM); |
---|
231 | eoen='n'; |
---|
232 | |
---|
233 | if((Cmpstr(key, "ID"))==EQ) { |
---|
234 | eof = embl_one_entry(line, fp, |
---|
235 | &(data.embl.id), key); |
---|
236 | } else if((Cmpstr(key, "SQ"))==EQ) { |
---|
237 | eof = embl_origin(line, fp); |
---|
238 | eoen = 'y'; |
---|
239 | } else { /* unidentified key word */ |
---|
240 | eof = embl_skip_unidentified(key, line, fp); |
---|
241 | } |
---|
242 | /* except "ORIGIN", at the end of all the other cases, |
---|
243 | a new line has already read in, so no further read |
---|
244 | is necessary */ |
---|
245 | |
---|
246 | } /* for loop to read an entry line by line */ |
---|
247 | |
---|
248 | if(eoen=='n') |
---|
249 | error(84, "Reach EOF before one entry is read, Exit"); |
---|
250 | |
---|
251 | if(eof==NULL) return(EOF); |
---|
252 | else return(EOF+1); |
---|
253 | |
---|
254 | } |
---|
255 | /* ---------------------------------------------------------------- |
---|
256 | * Function embl_key_word(). |
---|
257 | * Get the key_word from line beginning at index. |
---|
258 | */ |
---|
259 | void |
---|
260 | embl_key_word(line, index, key, length) |
---|
261 | char *line; |
---|
262 | int index; |
---|
263 | char *key; |
---|
264 | int length; /* max size of key word */ |
---|
265 | { |
---|
266 | int indi, indj; |
---|
267 | |
---|
268 | if(line==NULL) { key[0]='\0'; return; } |
---|
269 | for(indi=index, indj=0; (index-indi)<length&&line[indi]!=' ' |
---|
270 | &&line[indi]!='\t'&&line[indi]!='\n'&&line[indi]!='\0'; |
---|
271 | indi++, indj++) |
---|
272 | key[indj] = line[indi]; |
---|
273 | key[indj] = '\0'; |
---|
274 | } |
---|
275 | /* ------------------------------------------------------------ |
---|
276 | * Function embl_check_blanks(). |
---|
277 | * Check if there is (numb) blanks at beginning of line. |
---|
278 | */ |
---|
279 | int |
---|
280 | embl_check_blanks(line, numb) |
---|
281 | char *line; |
---|
282 | int numb; |
---|
283 | { |
---|
284 | int blank=1, indi, indk; |
---|
285 | |
---|
286 | for(indi=0; blank&&indi<numb; indi++) { |
---|
287 | if(line[indi]!=' '&&line[indi]!='\t') blank=0; |
---|
288 | if(line[indi]=='\t') { |
---|
289 | indk=indi/8+1; indi=8*indk+1; |
---|
290 | } |
---|
291 | } |
---|
292 | |
---|
293 | return(blank); |
---|
294 | } |
---|
295 | /* ---------------------------------------------------------------- |
---|
296 | * Function embl_continue_line(). |
---|
297 | * if there are (numb) blanks at the beginning of line, |
---|
298 | * it is a continue line of the current command. |
---|
299 | */ |
---|
300 | char |
---|
301 | *embl_continue_line(pattern, string, line, fp) |
---|
302 | char *pattern, **string, *line; |
---|
303 | FILE_BUFFER fp; |
---|
304 | { |
---|
305 | int ind; |
---|
306 | /* int embl_check_blanks(), Skip_white_space(); */ |
---|
307 | char key[TOKENNUM], *eof, temp[LINENUM]; |
---|
308 | /* void Cpystr(), embl_key_word(), Append_rp_eoln(); */ |
---|
309 | |
---|
310 | /* check continue lines */ |
---|
311 | for(eof=Fgetline(line, LINENUM, fp); |
---|
312 | eof!=NULL; eof=Fgetline(line, LINENUM, fp)) { |
---|
313 | |
---|
314 | if(Lenstr(line)<=1) continue; |
---|
315 | |
---|
316 | embl_key_word(line, 0, key, TOKENNUM); |
---|
317 | |
---|
318 | if(Cmpstr(pattern, key)!=EQ) break; |
---|
319 | |
---|
320 | /* remove end-of-line, if there is any */ |
---|
321 | ind=Skip_white_space(line, p_nonkey_start); |
---|
322 | Cpystr(temp, (line+ind)); |
---|
323 | Append_rp_eoln(string, temp); |
---|
324 | |
---|
325 | } /* end of continue line checking */ |
---|
326 | |
---|
327 | return(eof); |
---|
328 | } |
---|
329 | /* -------------------------------------------------------------- |
---|
330 | * Function embl_one_entry(). |
---|
331 | * Read in one embl entry lines. |
---|
332 | */ |
---|
333 | char |
---|
334 | *embl_one_entry(line, fp, entry, key) |
---|
335 | char *line; |
---|
336 | FILE_BUFFER fp; |
---|
337 | char **entry, *key; |
---|
338 | { |
---|
339 | int index; |
---|
340 | char *eof; |
---|
341 | /* void error(), replace_entry(); */ |
---|
342 | |
---|
343 | index = Skip_white_space(line, p_nonkey_start); |
---|
344 | replace_entry(entry, line+index); |
---|
345 | eof = (char*)embl_continue_line(key, entry, line, fp); |
---|
346 | |
---|
347 | return(eof); |
---|
348 | } |
---|
349 | /* --------------------------------------------------------------- |
---|
350 | * Function embl_verify_title(). |
---|
351 | * Verify title. |
---|
352 | */ |
---|
353 | void |
---|
354 | embl_verify_title(refnum) |
---|
355 | int refnum; |
---|
356 | { |
---|
357 | int len; |
---|
358 | char *temp; |
---|
359 | /* void Append(), Append_char(), replace_entry(); */ |
---|
360 | |
---|
361 | Append_char(&(data.embl.reference[refnum].title), ';'); |
---|
362 | |
---|
363 | len=Lenstr(data.embl.reference[refnum].title); |
---|
364 | if(len>2&&(data.embl.reference[refnum].title[0]!='"' |
---|
365 | ||data.embl.reference[refnum].title[len-3]!='"')) { |
---|
366 | if(data.embl.reference[refnum].title[0]!='"') |
---|
367 | temp=(char*)Dupstr("\""); |
---|
368 | else temp=(char*)Dupstr(""); |
---|
369 | Append(&temp, data.embl.reference[refnum].title); |
---|
370 | if((len>2&&data.embl.reference[refnum].title[len-3] |
---|
371 | !='"')) |
---|
372 | { |
---|
373 | len=Lenstr(temp); |
---|
374 | temp[len-2]='"'; |
---|
375 | Append_char(&temp, ';'); |
---|
376 | } |
---|
377 | replace_entry(&(data.embl.reference[refnum].title), |
---|
378 | temp); |
---|
379 | } |
---|
380 | } |
---|
381 | /* -------------------------------------------------------------- |
---|
382 | * Function embl_date(). |
---|
383 | * Read in embl DATE lines. |
---|
384 | */ |
---|
385 | char |
---|
386 | *embl_date(line, fp) |
---|
387 | char *line; |
---|
388 | FILE_BUFFER fp; |
---|
389 | { |
---|
390 | int index; |
---|
391 | char *eof, key[TOKENNUM]; |
---|
392 | /* void error(), embl_key_word(), replace_entry(); */ |
---|
393 | /* void warning(); */ |
---|
394 | |
---|
395 | index = Skip_white_space(line, p_nonkey_start); |
---|
396 | replace_entry(&(data.embl.dateu), line+index); |
---|
397 | |
---|
398 | eof = Fgetline(line, LINENUM, fp); |
---|
399 | embl_key_word(line, 0, key, TOKENNUM); |
---|
400 | if((Cmpstr(key, "DT"))==EQ) { |
---|
401 | index = Skip_white_space(line, p_nonkey_start); |
---|
402 | replace_entry(&(data.embl.datec), line+index); |
---|
403 | /* skip the rest of DT lines */ |
---|
404 | do { |
---|
405 | eof = Fgetline(line, LINENUM, fp); |
---|
406 | embl_key_word(line, 0, key, TOKENNUM); |
---|
407 | } while(eof!=NULL&&Cmpstr(key, "DT")==EQ); |
---|
408 | return(eof); |
---|
409 | } else { |
---|
410 | /* always expect more than two DT lines */ |
---|
411 | warning(33, "one DT line is missing"); |
---|
412 | return(eof); |
---|
413 | } |
---|
414 | } |
---|
415 | /* -------------------------------------------------------------- |
---|
416 | * Function embl_version(). |
---|
417 | * Read in embl RN lines. |
---|
418 | */ |
---|
419 | char |
---|
420 | *embl_version(line, fp) |
---|
421 | char *line; |
---|
422 | FILE_BUFFER fp; |
---|
423 | { |
---|
424 | int index; |
---|
425 | char *eof; |
---|
426 | /* char *Reallocspace(), *Fgetline(); */ |
---|
427 | |
---|
428 | index = Skip_white_space(line, p_nonkey_start); |
---|
429 | if(data.embl.numofref==0) { |
---|
430 | data.embl.numofref = 1; |
---|
431 | data.embl.reference = (Emblref*)calloc(1,sizeof(Emblref)*1); |
---|
432 | data.embl.reference[0].author = Dupstr(""); |
---|
433 | data.embl.reference[0].title = Dupstr(""); |
---|
434 | data.embl.reference[0].journal = Dupstr(""); |
---|
435 | data.embl.reference[0].processing = Dupstr(""); |
---|
436 | } else { |
---|
437 | data.embl.numofref++; |
---|
438 | data.embl.reference = (Emblref*)Reallocspace(data.embl.reference, sizeof(Emblref)*(data.embl.numofref)); |
---|
439 | data.embl.reference[data.embl.numofref-1].author = Dupstr(""); |
---|
440 | data.embl.reference[data.embl.numofref-1].title = Dupstr(""); |
---|
441 | data.embl.reference[data.embl.numofref-1].journal = Dupstr(""); |
---|
442 | data.embl.reference[data.embl.numofref-1].processing = Dupstr(""); |
---|
443 | } |
---|
444 | eof = Fgetline(line, LINENUM, fp); |
---|
445 | return(eof); |
---|
446 | } |
---|
447 | /* -------------------------------------------------------------- |
---|
448 | * Function embl_comments(). |
---|
449 | * Read in embl comment lines. |
---|
450 | */ |
---|
451 | char |
---|
452 | *embl_comments(line, fp) |
---|
453 | char *line; |
---|
454 | FILE_BUFFER fp; |
---|
455 | { |
---|
456 | int index, offset; |
---|
457 | /* int Skip_white_space(); */ |
---|
458 | char *eof; |
---|
459 | char key[TOKENNUM]; |
---|
460 | /* char *Dupstr(); */ |
---|
461 | /* void Append(); */ |
---|
462 | |
---|
463 | for(;line[0]=='C'&&line[1]=='C';) { |
---|
464 | |
---|
465 | index = Skip_white_space(line, 5); |
---|
466 | offset = embl_comment_key(line+index, key); |
---|
467 | index = Skip_white_space(line, index+offset); |
---|
468 | if(Cmpstr(key, "Source of strain:")==EQ) { |
---|
469 | eof = embl_one_comment_entry |
---|
470 | (fp, &(data.embl.comments.orginf.source), |
---|
471 | line, index); |
---|
472 | |
---|
473 | } else if(Cmpstr(key, "Culture collection:")==EQ) { |
---|
474 | |
---|
475 | eof = embl_one_comment_entry |
---|
476 | (fp, &(data.embl.comments.orginf.cc), |
---|
477 | line, index); |
---|
478 | |
---|
479 | } else if(Cmpstr(key, "Former name:")==EQ) { |
---|
480 | |
---|
481 | eof = embl_one_comment_entry |
---|
482 | (fp, &(data.embl.comments.orginf.formname), |
---|
483 | line, index); |
---|
484 | |
---|
485 | } else if(Cmpstr(key, "Alternate name:")==EQ) { |
---|
486 | |
---|
487 | eof = embl_one_comment_entry |
---|
488 | (fp, &(data.embl.comments.orginf.nickname), |
---|
489 | line, index); |
---|
490 | |
---|
491 | } else if(Cmpstr(key, "Common name:")==EQ) { |
---|
492 | |
---|
493 | eof = embl_one_comment_entry |
---|
494 | (fp, &(data.embl.comments.orginf.commname), |
---|
495 | line, index); |
---|
496 | |
---|
497 | } else if(Cmpstr(key, "Host organism:")==EQ) { |
---|
498 | |
---|
499 | eof = embl_one_comment_entry |
---|
500 | (fp, &(data.embl.comments.orginf.hostorg), |
---|
501 | line, index); |
---|
502 | |
---|
503 | } else if(Cmpstr(key, "RDP ID:")==EQ) { |
---|
504 | eof = embl_one_comment_entry |
---|
505 | (fp, &(data.embl.comments.seqinf.RDPid), |
---|
506 | line, index); |
---|
507 | |
---|
508 | } else if(Cmpstr(key, |
---|
509 | "Corresponding GenBank entry:")==EQ) { |
---|
510 | |
---|
511 | eof = embl_one_comment_entry |
---|
512 | (fp, &(data.embl.comments.seqinf.gbkentry), |
---|
513 | line, index); |
---|
514 | |
---|
515 | } else if(Cmpstr(key, "Sequencing methods:")==EQ) { |
---|
516 | |
---|
517 | eof = embl_one_comment_entry |
---|
518 | (fp, &(data.embl.comments.seqinf.methods), |
---|
519 | line, index); |
---|
520 | |
---|
521 | } else if(Cmpstr(key, "5' end complete:")==EQ) { |
---|
522 | |
---|
523 | sscanf(line+index, "%s", key); |
---|
524 | if(key[0]=='Y') |
---|
525 | data.embl.comments.seqinf.comp5 = 'y'; |
---|
526 | else data.embl.comments.seqinf.comp5 = 'n'; |
---|
527 | |
---|
528 | eof=Fgetline(line, LINENUM, fp); |
---|
529 | |
---|
530 | } else if(Cmpstr(key, "3' end complete:")==EQ) { |
---|
531 | |
---|
532 | sscanf(line+index, "%s", key); |
---|
533 | if(key[0]=='Y') |
---|
534 | data.embl.comments.seqinf.comp3 = 'y'; |
---|
535 | else data.embl.comments.seqinf.comp3 = 'n'; |
---|
536 | |
---|
537 | eof=Fgetline(line, LINENUM, fp); |
---|
538 | |
---|
539 | } else if(Cmpstr(key, |
---|
540 | "Sequence information ")==EQ) { |
---|
541 | |
---|
542 | /* do nothing */ |
---|
543 | data.embl.comments.seqinf.exist = 1; |
---|
544 | |
---|
545 | eof=Fgetline(line, LINENUM, fp); |
---|
546 | |
---|
547 | } else if(Cmpstr(key, "Organism information")==EQ) { |
---|
548 | |
---|
549 | /* do nothing */ |
---|
550 | data.embl.comments.orginf.exist = 1; |
---|
551 | |
---|
552 | eof=Fgetline(line, LINENUM, fp); |
---|
553 | |
---|
554 | } else { /* other comments */ |
---|
555 | |
---|
556 | if(data.embl.comments.others == NULL) { |
---|
557 | data.embl.comments.others |
---|
558 | =(char*)Dupstr(line+5); |
---|
559 | |
---|
560 | } else Append(&(data.embl.comments.others), |
---|
561 | line+5); |
---|
562 | eof=Fgetline(line, LINENUM, fp); |
---|
563 | |
---|
564 | } |
---|
565 | } |
---|
566 | return(eof); |
---|
567 | } |
---|
568 | /* ---------------------------------------------------------------- |
---|
569 | * Function embl_skip_unidentified(). |
---|
570 | * if there are (numb) blanks at the beginning of line, |
---|
571 | * it is a continue line of the current command. |
---|
572 | */ |
---|
573 | char |
---|
574 | *embl_skip_unidentified(pattern, line, fp) |
---|
575 | char *pattern, *line; |
---|
576 | FILE_BUFFER fp; |
---|
577 | { |
---|
578 | /* int Lenstr(), Cmpstr(); */ |
---|
579 | char *eof; |
---|
580 | char key[TOKENNUM]; |
---|
581 | /* void embl_key_word(); */ |
---|
582 | |
---|
583 | /* check continue lines */ |
---|
584 | for(eof=Fgetline(line, LINENUM, fp); |
---|
585 | eof!=NULL; eof=Fgetline(line, LINENUM, fp)) { |
---|
586 | embl_key_word(line, 0, key, TOKENNUM); |
---|
587 | if(Cmpstr(key, pattern)!=EQ) break; |
---|
588 | } /* end of continue line checking */ |
---|
589 | return(eof); |
---|
590 | } |
---|
591 | /* ------------------------------------------------------------- |
---|
592 | * Function embl_comment_key(). |
---|
593 | * Get the subkey_word in comment lines beginning |
---|
594 | * at index. |
---|
595 | */ |
---|
596 | int |
---|
597 | embl_comment_key(line, key) |
---|
598 | char *line; |
---|
599 | char *key; |
---|
600 | { |
---|
601 | int indi, indj; |
---|
602 | |
---|
603 | if(line==NULL) { key[0]='\0'; return(0); } |
---|
604 | |
---|
605 | for(indi=indj=0; |
---|
606 | line[indi]!=':'&&line[indi]!='\t'&&line[indi]!='\n' |
---|
607 | &&line[indi]!='\0'&&line[indi]!='('; indi++, indj++) |
---|
608 | key[indj] = line[indi]; |
---|
609 | |
---|
610 | if(line[indi]==':') key[indj++] = ':'; |
---|
611 | |
---|
612 | key[indj] = '\0'; |
---|
613 | |
---|
614 | return(indi+1); |
---|
615 | } |
---|
616 | /* ------------------------------------------------------------ |
---|
617 | * Function embl_one_comment_entry(). |
---|
618 | * Read in one embl sub-entry in comments lines. |
---|
619 | * If not RDP defined comment, should not call |
---|
620 | * this function. |
---|
621 | */ |
---|
622 | char *embl_one_comment_entry(fp, datastring, line, start_index) |
---|
623 | FILE_BUFFER fp; |
---|
624 | char **datastring, *line; |
---|
625 | int start_index; |
---|
626 | { |
---|
627 | int index; |
---|
628 | /* int Skip_white_space(), Lenstr(), Blank_num(); */ |
---|
629 | char *eof, temp[LINENUM]; |
---|
630 | /* char *eof, *Fgetline(), *Dupstr(), temp[LINENUM]; */ |
---|
631 | /* void replace_entry(), Cpystr(), Append_rp_eoln(); */ |
---|
632 | |
---|
633 | index = Skip_white_space(line, start_index); |
---|
634 | replace_entry(datastring, line+index); |
---|
635 | |
---|
636 | /* check continue lines */ |
---|
637 | for(eof=Fgetline(line, LINENUM, fp); |
---|
638 | eof!=NULL&&line[0]=='C'&&line[1]=='C' |
---|
639 | &&Blank_num(line+2)>=COMMCNINDENT+COMMSKINDENT; |
---|
640 | eof=Fgetline(line, LINENUM, fp)) { |
---|
641 | |
---|
642 | /* remove end-of-line, if there is any */ |
---|
643 | index=Skip_white_space(line, p_nonkey_start+COMMSKINDENT+COMMCNINDENT); |
---|
644 | Cpystr(temp, (line+index)); |
---|
645 | Append_rp_eoln(datastring, temp); |
---|
646 | |
---|
647 | } /* end of continue line checking */ |
---|
648 | |
---|
649 | return eof; |
---|
650 | } |
---|
651 | /* -------------------------------------------------------------- |
---|
652 | * Function embl_origin(). |
---|
653 | * Read in embl sequence data. |
---|
654 | */ |
---|
655 | char |
---|
656 | *embl_origin(line, fp) |
---|
657 | char *line; |
---|
658 | FILE_BUFFER fp; |
---|
659 | { |
---|
660 | char *eof; |
---|
661 | int index; |
---|
662 | |
---|
663 | data.seq_length = 0; |
---|
664 | /* read in whole sequence data */ |
---|
665 | for(eof=Fgetline(line, LINENUM, fp); |
---|
666 | eof!=NULL&&line[0]!='/'&&line[1]!='/'; |
---|
667 | eof=Fgetline(line, LINENUM, fp)) |
---|
668 | { |
---|
669 | for(index=5; line[index]!='\n'&&line[index]!='\0'; |
---|
670 | index++) { |
---|
671 | if(line[index]!=' ' |
---|
672 | &&data.seq_length>=data.max) { |
---|
673 | data.max += 100; |
---|
674 | data.sequence = (char*) |
---|
675 | Reallocspace(data.sequence, |
---|
676 | (unsigned)(sizeof(char)*data.max)); |
---|
677 | } |
---|
678 | if(line[index]!=' ') |
---|
679 | data.sequence[data.seq_length++] |
---|
680 | = line[index]; |
---|
681 | } |
---|
682 | data.sequence[data.seq_length] = '\0'; |
---|
683 | } |
---|
684 | |
---|
685 | return(eof); |
---|
686 | } |
---|
687 | /* ---------------------------------------------------------------- |
---|
688 | * Function embl_out(). |
---|
689 | * Output EMBL data. |
---|
690 | */ |
---|
691 | void embl_out(fp) |
---|
692 | FILE *fp; |
---|
693 | { |
---|
694 | /* int Lenstr(); */ |
---|
695 | /* int base_a, base_t, base_g, base_c, base_other; */ |
---|
696 | int indi /*, indj, indk, len*/; |
---|
697 | /* void embl_print_lines(), embl_out_comments(); */ |
---|
698 | /* void embl_out_origin(); */ |
---|
699 | |
---|
700 | if(Lenstr(data.embl.id)>1) |
---|
701 | fprintf(fp, "ID %sXX\n", data.embl.id); |
---|
702 | if(Lenstr(data.embl.accession)>1) { |
---|
703 | embl_print_lines(fp, "AC", data.embl.accession, SEPNODEFINED, ""); |
---|
704 | fprintf(fp, "XX\n"); |
---|
705 | } |
---|
706 | |
---|
707 | /* Date */ |
---|
708 | if(Lenstr(data.embl.dateu)>1) |
---|
709 | fprintf(fp, "DT %s", data.embl.dateu); |
---|
710 | if(Lenstr(data.embl.datec)>1) |
---|
711 | fprintf(fp, "DT %sXX\n", data.embl.datec); |
---|
712 | if(Lenstr(data.embl.description)>1) { |
---|
713 | embl_print_lines(fp, "DE", data.embl.description, SEPNODEFINED, ""); |
---|
714 | fprintf(fp, "XX\n"); |
---|
715 | } |
---|
716 | |
---|
717 | if(Lenstr(data.embl.keywords)>1) { |
---|
718 | embl_print_lines(fp, "KW", data.embl.keywords, SEPDEFINED, ";"); |
---|
719 | fprintf(fp, "XX\n"); |
---|
720 | } |
---|
721 | |
---|
722 | if(Lenstr(data.embl.os)>1) { |
---|
723 | embl_print_lines(fp, "OS", data.embl.os, SEPNODEFINED, ""); |
---|
724 | fprintf(fp, "OC No information.\n"); |
---|
725 | fprintf(fp, "XX\n"); |
---|
726 | } |
---|
727 | |
---|
728 | /* Reference */ |
---|
729 | for(indi=0; indi<data.embl.numofref; indi++) { |
---|
730 | fprintf(fp, "RN [%d]\n", indi+1); |
---|
731 | if(Lenstr(data.embl.reference[indi].processing)>1) |
---|
732 | fprintf(fp, "RP %s", |
---|
733 | data.embl.reference[indi].processing); |
---|
734 | if(Lenstr(data.embl.reference[indi].author)>1) |
---|
735 | embl_print_lines(fp, "RA", data.embl.reference[indi].author, SEPDEFINED, ","); |
---|
736 | if(Lenstr(data.embl.reference[indi].title)>1) |
---|
737 | embl_print_lines(fp, "RT", data.embl.reference[indi].title, SEPNODEFINED, ""); |
---|
738 | else fprintf(fp, "RT ;\n"); |
---|
739 | if(Lenstr(data.embl.reference[indi].journal)>1) |
---|
740 | embl_print_lines(fp, "RL", data.embl.reference[indi].journal, SEPNODEFINED, ""); |
---|
741 | fprintf(fp, "XX\n"); |
---|
742 | } |
---|
743 | |
---|
744 | if(Lenstr(data.embl.dr)>1) { |
---|
745 | embl_print_lines(fp, "DR", data.embl.dr, SEPNODEFINED, ""); |
---|
746 | fprintf(fp, "XX\n"); |
---|
747 | } |
---|
748 | |
---|
749 | embl_out_comments(fp); |
---|
750 | embl_out_origin(fp); |
---|
751 | } |
---|
752 | /* ---------------------------------------------------------------- |
---|
753 | * Function embl_print_lines(). |
---|
754 | * Print EMBL entry and wrap around if line over |
---|
755 | * EMBLMAXCHAR. |
---|
756 | */ |
---|
757 | void embl_print_lines(fp, key, Data, flag, separators) |
---|
758 | FILE *fp; |
---|
759 | const char *key; |
---|
760 | char *Data; |
---|
761 | int flag; |
---|
762 | const char *separators; |
---|
763 | { |
---|
764 | int indi, indj, indk, len; |
---|
765 | int ibuf; |
---|
766 | |
---|
767 | len = Lenstr(Data)-1; |
---|
768 | /* indi: first char of the line */ |
---|
769 | /* indj: num of char, excluding the first char, of the line */ |
---|
770 | for(indi=0; indi<len; indi+=(indj+1)) { |
---|
771 | indj=EMBLMAXCHAR; |
---|
772 | if((Lenstr(Data+indi))>EMBLMAXCHAR) { |
---|
773 | |
---|
774 | ibuf = indj; |
---|
775 | |
---|
776 | /* searching for proper termination of a line */ |
---|
777 | for(;indj>0 |
---|
778 | &&((!flag&&!last_word(Data[indi+indj])) |
---|
779 | ||(flag&&!is_separator |
---|
780 | (Data[indi+indj], separators))); |
---|
781 | indj--) ; |
---|
782 | |
---|
783 | if(indj==0) indj=ibuf; |
---|
784 | else if(Data[indi+indj+1]==' ') indj++; |
---|
785 | |
---|
786 | fprintf(fp, "%s ", key); |
---|
787 | |
---|
788 | for(indk=0; indk<indj; indk++) |
---|
789 | fprintf(fp, "%c", Data[indi+indk]); |
---|
790 | |
---|
791 | /* leave out the last space, if there is any */ |
---|
792 | if(Data[indi+indj]!=' ') |
---|
793 | fprintf(fp, "%c", Data[indi+indj]); |
---|
794 | |
---|
795 | fprintf(fp, "\n"); |
---|
796 | |
---|
797 | } else fprintf(fp, "%s %s", key, Data+indi); |
---|
798 | } |
---|
799 | } |
---|
800 | /* ------------------------------------------------------- |
---|
801 | * Function embl_out_comments(). |
---|
802 | * Print out the comments part of EMBL format. |
---|
803 | */ |
---|
804 | void |
---|
805 | embl_out_comments(fp) |
---|
806 | FILE *fp; |
---|
807 | { |
---|
808 | int indi, len; |
---|
809 | /* void embl_print_comment(); */ |
---|
810 | |
---|
811 | if(data.embl.comments.orginf.exist==1) { |
---|
812 | fprintf(fp, "CC Organism information\n"); |
---|
813 | |
---|
814 | if(Lenstr(data.embl.comments.orginf.source)>1) |
---|
815 | embl_print_comment(fp, "Source of strain: ", data.embl.comments.orginf.source, COMMSKINDENT, COMMCNINDENT); |
---|
816 | |
---|
817 | if(Lenstr(data.embl.comments.orginf.cc)>1) |
---|
818 | embl_print_comment(fp, "Culture collection: ", data.embl.comments.orginf.cc, COMMSKINDENT, COMMCNINDENT); |
---|
819 | |
---|
820 | if(Lenstr(data.embl.comments.orginf.formname)>1) |
---|
821 | embl_print_comment(fp, "Former name: ", data.embl.comments.orginf.formname, COMMSKINDENT, COMMCNINDENT); |
---|
822 | |
---|
823 | if(Lenstr(data.embl.comments.orginf.nickname)>1) |
---|
824 | embl_print_comment(fp, "Alternate name: ", data.embl.comments.orginf.nickname, COMMSKINDENT, COMMCNINDENT); |
---|
825 | |
---|
826 | if(Lenstr(data.embl.comments.orginf.commname)>1) |
---|
827 | embl_print_comment(fp, "Common name: ", data.embl.comments.orginf.commname, COMMSKINDENT, COMMCNINDENT); |
---|
828 | |
---|
829 | if(Lenstr(data.embl.comments.orginf.hostorg)>1) |
---|
830 | embl_print_comment(fp, "Host organism: ", data.embl.comments.orginf.hostorg, COMMSKINDENT, COMMCNINDENT); |
---|
831 | |
---|
832 | } /* organism information */ |
---|
833 | |
---|
834 | if(data.embl.comments.seqinf.exist==1) { |
---|
835 | |
---|
836 | fprintf(fp, |
---|
837 | "CC Sequence information (bases 1 to %d)\n", |
---|
838 | data.seq_length); |
---|
839 | |
---|
840 | if(Lenstr(data.embl.comments.seqinf.RDPid)>1) |
---|
841 | embl_print_comment(fp, "RDP ID: ", |
---|
842 | data.embl.comments.seqinf.RDPid, |
---|
843 | COMMSKINDENT, COMMCNINDENT); |
---|
844 | |
---|
845 | if(Lenstr(data.embl.comments.seqinf.gbkentry)>1) |
---|
846 | embl_print_comment(fp, "Corresponding GenBank entry: ", |
---|
847 | data.embl.comments.seqinf.gbkentry, |
---|
848 | COMMSKINDENT, COMMCNINDENT); |
---|
849 | |
---|
850 | if(Lenstr(data.embl.comments.seqinf.methods)>1) |
---|
851 | embl_print_comment(fp, "Sequencing methods: ", |
---|
852 | data.embl.comments.seqinf.methods, |
---|
853 | COMMSKINDENT, COMMCNINDENT); |
---|
854 | |
---|
855 | if(data.embl.comments.seqinf.comp5=='n') |
---|
856 | fprintf(fp, |
---|
857 | "CC 5' end complete: No\n"); |
---|
858 | |
---|
859 | else if(data.embl.comments.seqinf.comp5=='y') |
---|
860 | fprintf(fp, |
---|
861 | "CC 5' end complete: Yes\n"); |
---|
862 | |
---|
863 | if(data.embl.comments.seqinf.comp3=='n') |
---|
864 | fprintf(fp, |
---|
865 | "CC 3' end complete: No\n"); |
---|
866 | |
---|
867 | else if(data.embl.comments.seqinf.comp3=='y') |
---|
868 | fprintf(fp, |
---|
869 | "CC 3' end complete: Yes\n"); |
---|
870 | |
---|
871 | } /* sequence information */ |
---|
872 | |
---|
873 | if(Lenstr(data.embl.comments.others)>1) { |
---|
874 | for(indi=0, len=Lenstr(data.embl.comments.others); |
---|
875 | indi<len; indi++){ |
---|
876 | if((indi>0&&data.embl.comments.others[indi-1]=='\n') |
---|
877 | ||indi==0) |
---|
878 | fprintf(fp, "CC "); |
---|
879 | fprintf(fp, "%c", |
---|
880 | data.embl.comments.others[indi]); |
---|
881 | } |
---|
882 | fprintf(fp, "XX\n"); |
---|
883 | } |
---|
884 | } |
---|
885 | /* -------------------------------------------------------------- |
---|
886 | * Fucntion embl_print_comment(). |
---|
887 | * Print one embl comment line, wrap around if over |
---|
888 | * column 80. |
---|
889 | */ |
---|
890 | void embl_print_comment(fp, key, string, offset, indent) |
---|
891 | FILE *fp; |
---|
892 | const char *key; |
---|
893 | char *string; |
---|
894 | int offset, indent; |
---|
895 | { |
---|
896 | int first_time=1, indi, indj, indk, indl; |
---|
897 | int len; |
---|
898 | |
---|
899 | len = Lenstr(string)-1; |
---|
900 | for(indi=0; indi<len; indi+=(indj+1)) { |
---|
901 | |
---|
902 | if(first_time) |
---|
903 | indj=EMBLMAXCHAR-offset-Lenstr(key)-1; |
---|
904 | else indj=EMBLMAXCHAR-offset-indent-1; |
---|
905 | |
---|
906 | fprintf(fp, "CC "); |
---|
907 | |
---|
908 | if(!first_time) { |
---|
909 | for(indl=0; indl<(offset+indent); indl++) |
---|
910 | fprintf(fp, " "); |
---|
911 | } else { |
---|
912 | for(indl=0; indl<offset; indl++) |
---|
913 | fprintf(fp, " "); |
---|
914 | fprintf(fp, "%s", key); |
---|
915 | first_time = 0; |
---|
916 | } |
---|
917 | if(Lenstr(string+indi)>indj) { |
---|
918 | |
---|
919 | /* search for proper termination of a line */ |
---|
920 | for(; indj>=0&&!last_word(string[indj+indi]); |
---|
921 | indj--) ; |
---|
922 | |
---|
923 | /* print left margine */ |
---|
924 | if(string[indi]==' ') indk = 1; |
---|
925 | else indk = 0; |
---|
926 | |
---|
927 | for(; indk<indj; indk++) |
---|
928 | fprintf(fp, "%c", string[indi+indk]); |
---|
929 | |
---|
930 | /* leave out the last space, if there is any */ |
---|
931 | if(string[indi+indj]!=' ') |
---|
932 | fprintf(fp, "%c", string[indi+indj]); |
---|
933 | fprintf(fp, "\n"); |
---|
934 | |
---|
935 | } else fprintf(fp, "%s", string+indi); |
---|
936 | |
---|
937 | } /* for each char */ |
---|
938 | } |
---|
939 | /* ----------------------------------------------------- |
---|
940 | * Function embl_out_origin(). |
---|
941 | * Print out the sequence data of EMBL format. |
---|
942 | */ |
---|
943 | void |
---|
944 | embl_out_origin(fp) |
---|
945 | FILE *fp; |
---|
946 | { |
---|
947 | int base_a, base_c, base_t, base_g, base_other; |
---|
948 | int indi, indj, indk; |
---|
949 | /* void count_base(); */ |
---|
950 | |
---|
951 | /* print seq data */ |
---|
952 | count_base(&base_a, &base_t, &base_g, &base_c, &base_other); |
---|
953 | |
---|
954 | fprintf(fp, |
---|
955 | "SQ Sequence %d BP; %d A; %d C; %d G; %d T; %d other;\n", |
---|
956 | data.seq_length, base_a, base_c, base_g, base_t, base_other); |
---|
957 | |
---|
958 | for(indi=0, indj=0, indk=1; indi<data.seq_length; indi++) |
---|
959 | { |
---|
960 | if((indk % 60)==1) fprintf(fp, " "); |
---|
961 | fprintf(fp, "%c", data.sequence[indi]); |
---|
962 | indj++; |
---|
963 | if((indk % 60)==0) { fprintf(fp, "\n"); indj=0; } |
---|
964 | else if(indj==10&&indi!=(data.seq_length-1)) |
---|
965 | { fprintf(fp, " "); indj=0; } |
---|
966 | indk++; |
---|
967 | } |
---|
968 | if((indk % 60)==1) fprintf(fp, "//\n"); |
---|
969 | else fprintf(fp, "\n//\n"); |
---|
970 | } |
---|
971 | /* ---------------------------------------------------------- |
---|
972 | * Function embl_to_macke(). |
---|
973 | * Convert from Embl format to Macke format. |
---|
974 | */ |
---|
975 | void |
---|
976 | embl_to_macke(inf, outf, format) |
---|
977 | char *inf, *outf; |
---|
978 | int format; |
---|
979 | { |
---|
980 | FILE *IFP, *ofp; |
---|
981 | FILE_BUFFER ifp; |
---|
982 | char temp[TOKENNUM]; |
---|
983 | int indi, total_num; |
---|
984 | |
---|
985 | if((IFP=fopen(inf, "r"))==NULL) { |
---|
986 | sprintf(temp, |
---|
987 | "Cannot open input file %s, exit\n", inf); |
---|
988 | error(98, temp); |
---|
989 | } |
---|
990 | ifp = create_FILE_BUFFER(inf, IFP); |
---|
991 | if(Lenstr(outf) <= 0) ofp = stdout; |
---|
992 | else if((ofp=fopen(outf, "w"))==NULL) { |
---|
993 | sprintf(temp, |
---|
994 | "Cannot open output file %s, exit\n", outf); |
---|
995 | error(97, temp); |
---|
996 | } |
---|
997 | |
---|
998 | init(); |
---|
999 | /* macke format seq irelenvant header */ |
---|
1000 | macke_out_header(ofp); |
---|
1001 | for(indi=0; indi<3; indi++) { |
---|
1002 | FILE_BUFFER_rewind(ifp); |
---|
1003 | init_seq_data(); |
---|
1004 | init_em_data(); |
---|
1005 | while(embl_in(ifp)!=EOF) { |
---|
1006 | data.numofseq++; |
---|
1007 | if(etom()) { |
---|
1008 | /* convert from embl form to macke form */ |
---|
1009 | switch(indi) { |
---|
1010 | case 0: |
---|
1011 | /* output seq display format */ |
---|
1012 | macke_out0(ofp, format); |
---|
1013 | break; |
---|
1014 | case 1: |
---|
1015 | /* output seq information */ |
---|
1016 | macke_out1(ofp); |
---|
1017 | break; |
---|
1018 | case 2: |
---|
1019 | /* output seq data */ |
---|
1020 | macke_out2(ofp); |
---|
1021 | break; |
---|
1022 | default: ; |
---|
1023 | } |
---|
1024 | } else error(4, |
---|
1025 | "Conversion from embl to macke fails, Exit"); |
---|
1026 | init_em_data(); |
---|
1027 | } |
---|
1028 | total_num = data.numofseq; |
---|
1029 | if(indi==0) { |
---|
1030 | fprintf(ofp, "#-\n"); |
---|
1031 | /* no warning messages for next loop */ |
---|
1032 | warning_out = 0; |
---|
1033 | } |
---|
1034 | } /* for each seq; loop */ |
---|
1035 | |
---|
1036 | warning_out = 1; |
---|
1037 | |
---|
1038 | #ifdef log |
---|
1039 | fprintf(stderr, "Total %d sequences have been processed\n", |
---|
1040 | total_num); |
---|
1041 | #endif |
---|
1042 | } |
---|
1043 | /* ------------------------------------------------------------ |
---|
1044 | * Function etom(). |
---|
1045 | * Convert from embl format to Macke format. |
---|
1046 | */ |
---|
1047 | int etom() { |
---|
1048 | /* void init_genbank(); */ |
---|
1049 | /* int etog(), gtom(); */ |
---|
1050 | |
---|
1051 | init_genbank(); |
---|
1052 | if (etog()) return gtom(); |
---|
1053 | return 0; |
---|
1054 | } |
---|
1055 | /* ------------------------------------------------------------- |
---|
1056 | * Function embl_to_embl(). |
---|
1057 | * Print out EMBL data. |
---|
1058 | */ |
---|
1059 | void |
---|
1060 | embl_to_embl(inf, outf) |
---|
1061 | char *inf, *outf; |
---|
1062 | { |
---|
1063 | FILE *IFP, *ofp; |
---|
1064 | FILE_BUFFER ifp; |
---|
1065 | char temp[TOKENNUM]; |
---|
1066 | |
---|
1067 | if((IFP=fopen(inf, "r"))==NULL) { |
---|
1068 | sprintf(temp, |
---|
1069 | "Cannot open input file %s\n", inf); |
---|
1070 | error(27, temp); |
---|
1071 | } |
---|
1072 | ifp = create_FILE_BUFFER(inf, IFP); |
---|
1073 | if(Lenstr(outf) <= 0) ofp = stdout; |
---|
1074 | else if((ofp=fopen(outf, "w"))==NULL) { |
---|
1075 | sprintf(temp, |
---|
1076 | "Cannot open output file %s\n", outf); |
---|
1077 | error(28, temp); |
---|
1078 | } |
---|
1079 | init(); |
---|
1080 | init_seq_data(); |
---|
1081 | init_embl(); |
---|
1082 | |
---|
1083 | #ifdef log |
---|
1084 | fprintf(stderr, "Start converting...\n"); |
---|
1085 | #endif |
---|
1086 | |
---|
1087 | while(embl_in(ifp)!=EOF) { |
---|
1088 | data.numofseq++; |
---|
1089 | embl_out(ofp); |
---|
1090 | init_embl(); |
---|
1091 | } |
---|
1092 | |
---|
1093 | #ifdef log |
---|
1094 | fprintf(stderr, |
---|
1095 | "Total %d sequences have been processed\n", |
---|
1096 | data.numofseq); |
---|
1097 | #endif |
---|
1098 | |
---|
1099 | } |
---|
1100 | /* ------------------------------------------------------------- |
---|
1101 | * Function embl_to_genbank(). |
---|
1102 | * Convert from EMBL format to genbank format. |
---|
1103 | */ |
---|
1104 | void |
---|
1105 | embl_to_genbank(inf, outf) |
---|
1106 | char *inf, *outf; |
---|
1107 | { |
---|
1108 | FILE *IFP, *ofp; |
---|
1109 | FILE_BUFFER ifp; |
---|
1110 | char temp[TOKENNUM]; |
---|
1111 | |
---|
1112 | if((IFP=fopen(inf, "r"))==NULL) { |
---|
1113 | sprintf(temp, "Cannot open input file %s\n", inf); |
---|
1114 | error(30, temp); |
---|
1115 | } |
---|
1116 | ifp = create_FILE_BUFFER(inf, IFP); |
---|
1117 | if(Lenstr(outf) <= 0) ofp = stdout; |
---|
1118 | else if((ofp=fopen(outf, "w"))==NULL) { |
---|
1119 | sprintf(temp, "Cannot open output file %s\n", outf); |
---|
1120 | error(31, temp); |
---|
1121 | } |
---|
1122 | init(); |
---|
1123 | init_seq_data(); |
---|
1124 | init_genbank(); |
---|
1125 | init_embl(); |
---|
1126 | |
---|
1127 | #ifdef log |
---|
1128 | fprintf(stderr, "Start converting...\n"); |
---|
1129 | #endif |
---|
1130 | |
---|
1131 | while(embl_in(ifp)!=EOF) { |
---|
1132 | data.numofseq++; |
---|
1133 | if(etog()) genbank_out(ofp); |
---|
1134 | else error(32, |
---|
1135 | "Conversion from macke to genbank fails, Exit"); |
---|
1136 | init_genbank(); |
---|
1137 | init_embl(); |
---|
1138 | #ifdef log |
---|
1139 | if((data.numofseq % 50)==0) |
---|
1140 | fprintf(stderr, "%d sequences are converted...\n", |
---|
1141 | data.numofseq); |
---|
1142 | #endif |
---|
1143 | |
---|
1144 | } |
---|
1145 | |
---|
1146 | #ifdef log |
---|
1147 | fprintf(stderr, |
---|
1148 | "Total %d sequences have been processed\n", data.numofseq); |
---|
1149 | #endif |
---|
1150 | } |
---|
1151 | /* ------------------------------------------------------------- |
---|
1152 | * Function etog() |
---|
1153 | * Convert from embl to genbank format. |
---|
1154 | */ |
---|
1155 | int |
---|
1156 | etog() { |
---|
1157 | |
---|
1158 | int indi; |
---|
1159 | char key[TOKENNUM], temp[LONGTEXT]; |
---|
1160 | char t1[TOKENNUM], t2[TOKENNUM], t3[TOKENNUM]; |
---|
1161 | /* char *Dupstr(), *genbank_date(); */ |
---|
1162 | /* void embl_key_word(), Cpystr(); */ |
---|
1163 | /* void etog_comments(), etog_reference(), Append_char(); */ |
---|
1164 | /* void replace_entry(); */ |
---|
1165 | |
---|
1166 | embl_key_word(data.embl.id, 0, key, TOKENNUM); |
---|
1167 | if(Lenstr(data.embl.dr)>1) { |
---|
1168 | /* get short_id from DR line if there is RDP def. */ |
---|
1169 | Cpystr(t3, "dummy"); |
---|
1170 | sscanf(data.embl.dr, "%s %s %s", t1, t2, t3); |
---|
1171 | if(Cmpstr(t1, "RDP;")==EQ) { |
---|
1172 | if(Cmpstr(t3, "dummy")!=EQ) { |
---|
1173 | Cpystr(key, t3); |
---|
1174 | } else Cpystr(key, t2); |
---|
1175 | key[Lenstr(key)-1]='\0'; /* remove '.' */ |
---|
1176 | } |
---|
1177 | } |
---|
1178 | Cpystr(temp, key); |
---|
1179 | |
---|
1180 | /* LOCUS */ |
---|
1181 | for(indi=Lenstr(temp); indi<13; temp[indi++]=' ') ; |
---|
1182 | if(Lenstr(data.embl.dateu)>1) { |
---|
1183 | sprintf((temp+10), |
---|
1184 | "%7d bp RNA RNA %s\n", |
---|
1185 | data.seq_length, genbank_date(data.embl.dateu)); |
---|
1186 | } else sprintf((temp+10), |
---|
1187 | "7%d bp RNA RNA %s\n", |
---|
1188 | data.seq_length, genbank_date(today_date())); |
---|
1189 | replace_entry(&(data.gbk.locus), temp); |
---|
1190 | |
---|
1191 | /* DEFINITION */ |
---|
1192 | if(Lenstr(data.embl.description)>1) { |
---|
1193 | |
---|
1194 | replace_entry(&(data.gbk.definition), |
---|
1195 | data.embl.description); |
---|
1196 | |
---|
1197 | /* must have a period at the end */ |
---|
1198 | Append_char(&(data.gbk.definition), '.'); |
---|
1199 | } |
---|
1200 | |
---|
1201 | /* SOURCE and DEFINITION if not yet defined */ |
---|
1202 | if(Lenstr(data.embl.os)>1) { |
---|
1203 | replace_entry(&(data.gbk.source), |
---|
1204 | data.embl.os); |
---|
1205 | |
---|
1206 | replace_entry(&(data.gbk.organism), |
---|
1207 | data.embl.os); |
---|
1208 | |
---|
1209 | if(Lenstr(data.embl.description)<=1) { |
---|
1210 | replace_entry(&(data.gbk.definition), |
---|
1211 | data.embl.os); |
---|
1212 | } |
---|
1213 | } |
---|
1214 | |
---|
1215 | /* COMMENT GenBank entry */ |
---|
1216 | if(Lenstr(data.embl.accession)>1) |
---|
1217 | replace_entry(&(data.gbk.accession), |
---|
1218 | data.embl.accession); |
---|
1219 | |
---|
1220 | if(Lenstr(data.embl.keywords)>1&&data.embl.keywords[0]!='.') |
---|
1221 | replace_entry(&(data.gbk.keywords), |
---|
1222 | data.embl.keywords); |
---|
1223 | |
---|
1224 | /* convert reference */ |
---|
1225 | etog_reference(); |
---|
1226 | |
---|
1227 | /* convert comments */ |
---|
1228 | etog_comments(); |
---|
1229 | |
---|
1230 | return(1); |
---|
1231 | } |
---|
1232 | /* --------------------------------------------------------------------- |
---|
1233 | * Function etog_reference(). |
---|
1234 | * Convert reference from EMBL to GenBank format. |
---|
1235 | */ |
---|
1236 | void |
---|
1237 | etog_reference() { |
---|
1238 | |
---|
1239 | int indi, len, start, end; |
---|
1240 | char temp[LONGTEXT]; |
---|
1241 | /* char *etog_author(), *etog_journal(); */ |
---|
1242 | |
---|
1243 | data.gbk.numofref = data.embl.numofref; |
---|
1244 | |
---|
1245 | data.gbk.reference |
---|
1246 | = (Reference*)calloc(1,sizeof(Reference)*data.embl.numofref); |
---|
1247 | |
---|
1248 | for(indi=0; indi<data.embl.numofref; indi++) { |
---|
1249 | |
---|
1250 | if(Lenstr(data.embl.reference[indi].processing)>1) { |
---|
1251 | sscanf(data.embl.reference[indi].processing, |
---|
1252 | "%d %d", &start, &end); |
---|
1253 | end *= -1; /* will get negative from sscanf */ |
---|
1254 | sprintf(temp, "%d (bases %d to %d)\n", (indi+1), start, end); |
---|
1255 | data.gbk.reference[indi].ref |
---|
1256 | = (char*)Dupstr(temp); |
---|
1257 | } else { |
---|
1258 | sprintf(temp, "%d\n", (indi+1)); |
---|
1259 | data.gbk.reference[indi].ref = (char*)Dupstr(temp); |
---|
1260 | } |
---|
1261 | |
---|
1262 | if(Lenstr(data.embl.reference[indi].title)>1 |
---|
1263 | &&data.embl.reference[indi].title[0]!=';') { |
---|
1264 | |
---|
1265 | /* remove '"' and ';', if there is any */ |
---|
1266 | len = Lenstr(data.embl.reference[indi].title); |
---|
1267 | if(len>2&&data.embl.reference[indi].title[0]=='"' |
---|
1268 | &&data.embl.reference[indi].title[len-2]==';' |
---|
1269 | &&data.embl.reference[indi].title[len-3]=='"') { |
---|
1270 | data.embl.reference[indi].title[len-3]='\n'; |
---|
1271 | data.embl.reference[indi].title[len-2]='\0'; |
---|
1272 | data.gbk.reference[indi].title = (char*) |
---|
1273 | Dupstr(data.embl.reference[indi].title+1); |
---|
1274 | data.embl.reference[indi].title[len-3]='"'; |
---|
1275 | data.embl.reference[indi].title[len-2]=';'; |
---|
1276 | } else data.gbk.reference[indi].title = (char*) |
---|
1277 | Dupstr(data.embl.reference[indi].title); |
---|
1278 | |
---|
1279 | } else data.gbk.reference[indi].title |
---|
1280 | = (char*)Dupstr("\n"); |
---|
1281 | |
---|
1282 | /* GenBank AUTHOR */ |
---|
1283 | if(Lenstr(data.embl.reference[indi].author)>1) |
---|
1284 | |
---|
1285 | data.gbk.reference[indi].author |
---|
1286 | = etog_author(data.embl.reference[indi].author); |
---|
1287 | |
---|
1288 | else data.gbk.reference[indi].author |
---|
1289 | = (char*)Dupstr("\n"); |
---|
1290 | |
---|
1291 | if(Lenstr(data.embl.reference[indi].journal)>1) |
---|
1292 | |
---|
1293 | data.gbk.reference[indi].journal |
---|
1294 | = (char*)etog_journal(data.embl.reference[indi].journal); |
---|
1295 | |
---|
1296 | else data.gbk.reference[indi].journal |
---|
1297 | = (char*)Dupstr("\n"); |
---|
1298 | |
---|
1299 | data.gbk.reference[indi].standard |
---|
1300 | = (char*)Dupstr("\n"); |
---|
1301 | } |
---|
1302 | } |
---|
1303 | /* ----------------------------------------------------------------- |
---|
1304 | * Function etog_author(). |
---|
1305 | * Convert EMBL author format to Genbank author format. |
---|
1306 | */ |
---|
1307 | char |
---|
1308 | *etog_author(string) |
---|
1309 | char *string; |
---|
1310 | { |
---|
1311 | int indi, /*indj,*/ indk, len, index; |
---|
1312 | char token[TOKENNUM], *author; |
---|
1313 | /* void Append(); */ |
---|
1314 | |
---|
1315 | author=(char*)Dupstr(""); |
---|
1316 | for(indi=index=0,len=Lenstr(string)-1; indi<len; indi++, index++) { |
---|
1317 | if(string[indi]==','||string[indi]==';') { |
---|
1318 | token[index--]='\0'; |
---|
1319 | if(string[indi]==',') { |
---|
1320 | if(Lenstr(author)>0) Append(&(author), ","); |
---|
1321 | } |
---|
1322 | else if(Lenstr(author)>0) { |
---|
1323 | Append(&(author), " and"); |
---|
1324 | } |
---|
1325 | /* search backward to find the first blank and replace the blank by ',' */ |
---|
1326 | for(indk=0; index>0&&indk==0; index--) |
---|
1327 | if(token[index]==' ') { |
---|
1328 | token[index]=','; |
---|
1329 | indk=1; |
---|
1330 | } |
---|
1331 | Append(&(author), token); |
---|
1332 | index = (-1); |
---|
1333 | } else token[index]=string[indi]; |
---|
1334 | } |
---|
1335 | Append(&(author), "\n"); |
---|
1336 | return(author); |
---|
1337 | } |
---|
1338 | /* ------------------------------------------------------------ |
---|
1339 | * Function etog_journal(). |
---|
1340 | * Convert jpurnal part from EMBL to GenBank format. |
---|
1341 | */ |
---|
1342 | char |
---|
1343 | *etog_journal(string) |
---|
1344 | char *string; |
---|
1345 | { |
---|
1346 | int indi, len, index; |
---|
1347 | char *journal, *new_journal; |
---|
1348 | char token[TOKENNUM]; |
---|
1349 | /* void Freespace(), Append(); */ |
---|
1350 | |
---|
1351 | sscanf(string, "%s", token); |
---|
1352 | if(Cmpstr(token, "(in)")==EQ||Cmpstr(token, "Submitted")==EQ |
---|
1353 | ||Cmpstr(token, "Unpublished")==EQ) { |
---|
1354 | /* remove '.' */ |
---|
1355 | string[Lenstr(string)-2]='\n'; |
---|
1356 | string[Lenstr(string)-1]='\0'; |
---|
1357 | new_journal = (char*)Dupstr(string); |
---|
1358 | string[Lenstr(string)-1]='.'; |
---|
1359 | string[Lenstr(string)]='\n'; |
---|
1360 | return(new_journal); |
---|
1361 | } |
---|
1362 | journal=(char*)Dupstr(string); |
---|
1363 | for(indi=0, len=Lenstr(journal); indi<len; indi++) { |
---|
1364 | if(journal[indi]==':') { |
---|
1365 | journal[indi]='\0'; |
---|
1366 | new_journal=(char*)Dupstr(journal); |
---|
1367 | journal[indi]=':'; |
---|
1368 | Append(&new_journal, ", "); |
---|
1369 | index=indi+1; |
---|
1370 | } |
---|
1371 | if(journal[indi]=='(') { |
---|
1372 | journal[indi]='\0'; |
---|
1373 | Append(&new_journal, journal+index); |
---|
1374 | Append(&new_journal, " "); |
---|
1375 | journal[indi]='('; |
---|
1376 | index=indi; |
---|
1377 | } |
---|
1378 | if(journal[indi]=='.') { |
---|
1379 | journal[indi]='\0'; |
---|
1380 | Append(&new_journal, journal+index); |
---|
1381 | journal[indi]='.'; |
---|
1382 | } |
---|
1383 | } |
---|
1384 | Freespace(&journal); |
---|
1385 | Append(&new_journal, "\n"); |
---|
1386 | return(new_journal); |
---|
1387 | } |
---|
1388 | /* --------------------------------------------------------------- |
---|
1389 | * Function etog_comments(). |
---|
1390 | * Convert comment part from EMBL to GenBank. |
---|
1391 | */ |
---|
1392 | void |
---|
1393 | etog_comments() { |
---|
1394 | |
---|
1395 | /* int Lenstr(); */ |
---|
1396 | /* void replace_entry(); */ |
---|
1397 | /* char *Dupsstr(); */ |
---|
1398 | |
---|
1399 | /* RDP defined Organism Information comments */ |
---|
1400 | data.gbk.comments.orginf.exist = data.embl.comments.orginf.exist; |
---|
1401 | |
---|
1402 | if(Lenstr(data.embl.comments.orginf.source)>1) |
---|
1403 | replace_entry(&(data.gbk.comments.orginf.source), |
---|
1404 | data.embl.comments.orginf.source); |
---|
1405 | |
---|
1406 | if(Lenstr(data.embl.comments.orginf.cc)>1) |
---|
1407 | replace_entry(&(data.gbk.comments.orginf.cc), |
---|
1408 | data.embl.comments.orginf.cc); |
---|
1409 | |
---|
1410 | if(Lenstr(data.embl.comments.orginf.formname)>1) |
---|
1411 | replace_entry(&(data.gbk.comments.orginf.formname), |
---|
1412 | data.embl.comments.orginf.formname); |
---|
1413 | |
---|
1414 | if(Lenstr(data.embl.comments.orginf.nickname)>1) |
---|
1415 | replace_entry(&(data.gbk.comments.orginf.nickname), |
---|
1416 | data.embl.comments.orginf.nickname); |
---|
1417 | |
---|
1418 | if(Lenstr(data.embl.comments.orginf.commname)>1) |
---|
1419 | replace_entry(&(data.gbk.comments.orginf.commname), |
---|
1420 | data.embl.comments.orginf.commname); |
---|
1421 | |
---|
1422 | if(Lenstr(data.embl.comments.orginf.hostorg)>1) |
---|
1423 | replace_entry(&(data.gbk.comments.orginf.hostorg), |
---|
1424 | data.embl.comments.orginf.hostorg); |
---|
1425 | |
---|
1426 | /* RDP defined Sequence Information comments */ |
---|
1427 | data.gbk.comments.seqinf.exist = data.embl.comments.seqinf.exist; |
---|
1428 | |
---|
1429 | if(Lenstr(data.embl.comments.seqinf.RDPid)>1) |
---|
1430 | replace_entry(&(data.gbk.comments.seqinf.RDPid), |
---|
1431 | data.embl.comments.seqinf.RDPid); |
---|
1432 | |
---|
1433 | if(Lenstr(data.embl.comments.seqinf.gbkentry)>1) |
---|
1434 | replace_entry(&(data.gbk.comments.seqinf.gbkentry), |
---|
1435 | data.embl.comments.seqinf.gbkentry); |
---|
1436 | |
---|
1437 | if(Lenstr(data.embl.comments.seqinf.methods)>1) |
---|
1438 | replace_entry(&(data.gbk.comments.seqinf.methods), |
---|
1439 | data.embl.comments.seqinf.methods); |
---|
1440 | |
---|
1441 | data.gbk.comments.seqinf.comp5 = data.embl.comments.seqinf.comp5; |
---|
1442 | |
---|
1443 | data.gbk.comments.seqinf.comp3 = data.embl.comments.seqinf.comp3; |
---|
1444 | |
---|
1445 | /* other comments */ |
---|
1446 | if(Lenstr(data.embl.comments.others)>1) |
---|
1447 | replace_entry(&(data.gbk.comments.others), |
---|
1448 | data.embl.comments.others); |
---|
1449 | } |
---|
1450 | /* ---------------------------------------------------------------- |
---|
1451 | * Function genbank_to_embl(). |
---|
1452 | * Convert from genbank to EMBL. |
---|
1453 | */ |
---|
1454 | void |
---|
1455 | genbank_to_embl(inf, outf) |
---|
1456 | char *inf, *outf; |
---|
1457 | { |
---|
1458 | FILE *IFP, *ofp; |
---|
1459 | FILE_BUFFER ifp; |
---|
1460 | char temp[TOKENNUM]; |
---|
1461 | |
---|
1462 | if((IFP=fopen(inf, "r"))==NULL) { |
---|
1463 | sprintf(temp, |
---|
1464 | "Cannot open input file %s, exit\n", inf); |
---|
1465 | error(132, temp); |
---|
1466 | } |
---|
1467 | ifp = create_FILE_BUFFER(inf, IFP); |
---|
1468 | if((ofp=fopen(outf, "w"))==NULL) { |
---|
1469 | sprintf(temp, |
---|
1470 | "Cannot open output file %s, exit\n", outf); |
---|
1471 | error(133, temp); |
---|
1472 | } |
---|
1473 | init(); |
---|
1474 | init_genbank(); |
---|
1475 | init_embl(); |
---|
1476 | /* rewind(ifp); */ |
---|
1477 | while(genbank_in(ifp)!=EOF) { |
---|
1478 | data.numofseq++; |
---|
1479 | if(gtoe()) embl_out(ofp); |
---|
1480 | init_genbank(); |
---|
1481 | init_embl(); |
---|
1482 | } |
---|
1483 | |
---|
1484 | #ifdef log |
---|
1485 | fprintf(stderr, |
---|
1486 | "Total %d sequences have been processed\n", |
---|
1487 | data.numofseq); |
---|
1488 | #endif |
---|
1489 | |
---|
1490 | destroy_FILE_BUFFER(ifp); fclose(ofp); |
---|
1491 | } |
---|
1492 | /* ------------------------------------------------------------ |
---|
1493 | * Function gtoe(). |
---|
1494 | * Genbank to EMBL. |
---|
1495 | */ |
---|
1496 | int |
---|
1497 | gtoe() { |
---|
1498 | /* void genbank_key_word(), replace_entry(); */ |
---|
1499 | /* void Cpystr(), Upper_case(); */ |
---|
1500 | /* void genbank_key_word(), Append(), Append_char(); */ |
---|
1501 | /* void gtoe_comments(), gtoe_reference(); */ |
---|
1502 | char token[TOKENNUM], temp[LONGTEXT], rdpid[TOKENNUM]; |
---|
1503 | /* char *Dupstr(), *today_date(), *genbank_date(); */ |
---|
1504 | int indi /*,length*/; |
---|
1505 | |
---|
1506 | genbank_key_word(data.gbk.locus, 0, token, TOKENNUM); |
---|
1507 | Cpystr(temp, token); |
---|
1508 | /* Adjust short-id, EMBL short_id always upper case */ |
---|
1509 | Upper_case(temp); |
---|
1510 | if(Lenstr(token)>9) indi=9; else indi=Lenstr(token); |
---|
1511 | for(; indi<10; indi++) temp[indi]=' '; |
---|
1512 | sprintf(temp+10, "preliminary; RNA; UNA; %d BP.\n", |
---|
1513 | data.seq_length); |
---|
1514 | replace_entry(&(data.embl.id), temp); |
---|
1515 | |
---|
1516 | /* accession number */ |
---|
1517 | if(Lenstr(data.gbk.accession)>1) |
---|
1518 | /* take just the accession num, no version num. */ |
---|
1519 | replace_entry(&(data.embl.accession), |
---|
1520 | data.gbk.accession); |
---|
1521 | |
---|
1522 | /* date */ |
---|
1523 | if(Lenstr(data.gbk.locus)<61) { |
---|
1524 | Cpystr(token, genbank_date(today_date())); |
---|
1525 | } else { |
---|
1526 | for(indi=0; indi<11; indi++) |
---|
1527 | token[indi]=data.gbk.locus[indi+50]; |
---|
1528 | token[11]='\0'; |
---|
1529 | } |
---|
1530 | sprintf(temp, |
---|
1531 | "%s (Rel. 1, Last updated, Version 1)\n", token); |
---|
1532 | replace_entry(&(data.embl.dateu), temp); |
---|
1533 | sprintf(temp, "%s (Rel. 1, Created)\n", token); |
---|
1534 | replace_entry(&(data.embl.datec), temp); |
---|
1535 | |
---|
1536 | /* description */ |
---|
1537 | if(Lenstr(data.gbk.definition)>1) |
---|
1538 | replace_entry(&(data.embl.description), |
---|
1539 | data.gbk.definition); |
---|
1540 | |
---|
1541 | /* EMBL KW line */ |
---|
1542 | if(Lenstr(data.gbk.keywords)>1) { |
---|
1543 | |
---|
1544 | replace_entry(&(data.embl.keywords), |
---|
1545 | data.gbk.keywords); |
---|
1546 | Append_char(&(data.embl.keywords), '.'); |
---|
1547 | |
---|
1548 | } else replace_entry(&(data.embl.keywords), ".\n"); |
---|
1549 | |
---|
1550 | /* EMBL OS line */ |
---|
1551 | if(Lenstr(data.gbk.organism)>1) |
---|
1552 | replace_entry(&(data.embl.os), |
---|
1553 | data.gbk.organism); |
---|
1554 | |
---|
1555 | /* reference */ |
---|
1556 | gtoe_reference(); |
---|
1557 | |
---|
1558 | /* EMBL DR line */ |
---|
1559 | sscanf(data.gbk.locus, "%s", token); /* short_id */ |
---|
1560 | if(Lenstr(data.gbk.comments.seqinf.RDPid)>1) { |
---|
1561 | sscanf(data.gbk.comments.seqinf.RDPid, "%s", rdpid); |
---|
1562 | sprintf(temp, "RDP; %s; %s.\n", rdpid, token); |
---|
1563 | } else sprintf(temp, "RDP; %s.\n", token); |
---|
1564 | replace_entry(&(data.embl.dr), temp); |
---|
1565 | |
---|
1566 | gtoe_comments(); |
---|
1567 | |
---|
1568 | return(1); |
---|
1569 | } |
---|
1570 | /* ------------------------------------------------------------------ |
---|
1571 | * Function gtoe_reference(). |
---|
1572 | * Convert references from GenBank to EMBL. |
---|
1573 | */ |
---|
1574 | void |
---|
1575 | gtoe_reference() { |
---|
1576 | |
---|
1577 | int indi, start, end, refnum; |
---|
1578 | char token[TOKENNUM]; |
---|
1579 | char t1[TOKENNUM], t2[TOKENNUM], t3[TOKENNUM]; |
---|
1580 | /* char *gtoe_author(), *gtoe_journal(); */ |
---|
1581 | /* void embl_verify_title(), Append_char(); */ |
---|
1582 | |
---|
1583 | data.embl.numofref=data.gbk.numofref; |
---|
1584 | |
---|
1585 | if(data.gbk.numofref>0) { |
---|
1586 | data.embl.reference = (Emblref*)malloc |
---|
1587 | (sizeof(Emblref)*data.gbk.numofref); |
---|
1588 | } |
---|
1589 | |
---|
1590 | for(indi=0; indi<data.gbk.numofref; indi++) { |
---|
1591 | |
---|
1592 | data.embl.reference[indi].title |
---|
1593 | = (char*)Dupstr |
---|
1594 | (data.gbk.reference[indi].title); |
---|
1595 | |
---|
1596 | embl_verify_title(indi); |
---|
1597 | |
---|
1598 | data.embl.reference[indi].journal |
---|
1599 | = (char*)gtoe_journal |
---|
1600 | (data.gbk.reference[indi].journal); |
---|
1601 | |
---|
1602 | /* append a '.' if there is not any. */ |
---|
1603 | Append_char(&(data.embl.reference[indi].journal), '.'); |
---|
1604 | |
---|
1605 | data.embl.reference[indi].author |
---|
1606 | = gtoe_author(data.gbk.reference[indi].author); |
---|
1607 | |
---|
1608 | /* append a ';' if there is not any. */ |
---|
1609 | Append_char(&(data.embl.reference[indi].author), ';'); |
---|
1610 | |
---|
1611 | /* create processing information */ |
---|
1612 | start=end=0; |
---|
1613 | if (data.gbk.reference[indi].ref) { |
---|
1614 | sscanf(data.gbk.reference[indi].ref, |
---|
1615 | "%d %s %d %s %d %s", |
---|
1616 | &refnum, t1, &start, t2, &end, t3); |
---|
1617 | }else{ |
---|
1618 | start = 0; end = 0; |
---|
1619 | } |
---|
1620 | |
---|
1621 | if(start!=0||end!=0) |
---|
1622 | { |
---|
1623 | sprintf(token, "%d-%d\n", |
---|
1624 | start, end); |
---|
1625 | data.embl.reference[indi].processing |
---|
1626 | = (char*)Dupstr(token); |
---|
1627 | } else /* else change nothing about RP */ |
---|
1628 | data.embl.reference[indi].processing |
---|
1629 | = (char*)Dupstr("\n"); |
---|
1630 | |
---|
1631 | } /* for each reference */ |
---|
1632 | } |
---|
1633 | /* ---------------------------------------------------------------- |
---|
1634 | * Function gtoe_author(). |
---|
1635 | * Convert GenBank author to EMBL author. |
---|
1636 | */ |
---|
1637 | char |
---|
1638 | *gtoe_author(author) |
---|
1639 | char *author; |
---|
1640 | { |
---|
1641 | int indi, len, index, odd; |
---|
1642 | char *auth, *string; |
---|
1643 | /* void Append(), Freespace(); */ |
---|
1644 | |
---|
1645 | /* replace " and " by ", " */ |
---|
1646 | auth = (char*)Dupstr(author); |
---|
1647 | if((index=find_pattern(auth, " and "))>0) { |
---|
1648 | auth[index]='\0'; |
---|
1649 | string=(char*)Dupstr(auth); |
---|
1650 | auth[index]=' '; /* remove '\0' for free space later */ |
---|
1651 | Append(&(string), ","); |
---|
1652 | Append(&(string), auth+index+4); |
---|
1653 | } else string=(char*)Dupstr(author); |
---|
1654 | |
---|
1655 | for(indi=0,len=Lenstr(string), odd=1; indi<len; indi++) { |
---|
1656 | if(string[indi]==',') { |
---|
1657 | if (odd) { |
---|
1658 | string[indi] = ' '; |
---|
1659 | odd=0; |
---|
1660 | } |
---|
1661 | else { |
---|
1662 | odd=1; |
---|
1663 | } |
---|
1664 | } |
---|
1665 | } |
---|
1666 | |
---|
1667 | Freespace(&auth); |
---|
1668 | return(string); |
---|
1669 | |
---|
1670 | } |
---|
1671 | /* ------------------------------------------------------------ |
---|
1672 | * Function gtoe_journal(). |
---|
1673 | * Convert GenBank journal to EMBL journal. |
---|
1674 | */ |
---|
1675 | char |
---|
1676 | *gtoe_journal(string) |
---|
1677 | char *string; |
---|
1678 | { |
---|
1679 | char token[TOKENNUM], *journal; |
---|
1680 | int indi, indj, index, len; |
---|
1681 | /* void Append_char(); */ |
---|
1682 | |
---|
1683 | sscanf(string, "%s", token); |
---|
1684 | if(Cmpstr(token, "(in)")==EQ||Cmpstr(token, "Unpublished")==EQ |
---|
1685 | ||Cmpstr(token, "Submitted")==EQ) { |
---|
1686 | journal=(char*)Dupstr(string); |
---|
1687 | Append_char(&journal, '.'); |
---|
1688 | return(journal); |
---|
1689 | } |
---|
1690 | |
---|
1691 | journal=(char*)Dupstr(string); |
---|
1692 | for(indi=indj=index=0, len=Lenstr(journal); indi<len; indi++, indj++) { |
---|
1693 | if(journal[indi]==',') { |
---|
1694 | journal[indi]=':'; |
---|
1695 | indi++; /* skip blank after ',' */ |
---|
1696 | index=1; |
---|
1697 | } else if(journal[indi]==' '&&index) { |
---|
1698 | indj--; |
---|
1699 | } else journal[indj]=journal[indi]; |
---|
1700 | } |
---|
1701 | |
---|
1702 | journal[indj]='\0'; |
---|
1703 | Append_char(&journal, '.'); |
---|
1704 | return(journal); |
---|
1705 | } |
---|
1706 | /* --------------------------------------------------------------- |
---|
1707 | * Function gtoe_comments(). |
---|
1708 | * Convert comment part from GenBank to EMBL. |
---|
1709 | */ |
---|
1710 | void |
---|
1711 | gtoe_comments() { |
---|
1712 | /* int Lenstr(); */ |
---|
1713 | /* void replace_entry(); */ |
---|
1714 | /* char *Dupsstr(); */ |
---|
1715 | |
---|
1716 | /* RDP defined Organism Information comments */ |
---|
1717 | data.embl.comments.orginf.exist = data.gbk.comments.orginf.exist; |
---|
1718 | |
---|
1719 | if(Lenstr(data.gbk.comments.orginf.source)>1) |
---|
1720 | replace_entry(&(data.embl.comments.orginf.source), |
---|
1721 | data.gbk.comments.orginf.source); |
---|
1722 | |
---|
1723 | if(Lenstr(data.gbk.comments.orginf.cc)>1) |
---|
1724 | replace_entry(&(data.embl.comments.orginf.cc), |
---|
1725 | data.gbk.comments.orginf.cc); |
---|
1726 | |
---|
1727 | if(Lenstr(data.gbk.comments.orginf.formname)>1) |
---|
1728 | replace_entry(&(data.embl.comments.orginf.formname), |
---|
1729 | data.gbk.comments.orginf.formname); |
---|
1730 | |
---|
1731 | if(Lenstr(data.gbk.comments.orginf.nickname)>1) |
---|
1732 | replace_entry(&(data.embl.comments.orginf.nickname), |
---|
1733 | data.gbk.comments.orginf.nickname); |
---|
1734 | |
---|
1735 | if(Lenstr(data.gbk.comments.orginf.commname)>1) |
---|
1736 | replace_entry(&(data.embl.comments.orginf.commname), |
---|
1737 | data.gbk.comments.orginf.commname); |
---|
1738 | |
---|
1739 | if(Lenstr(data.gbk.comments.orginf.hostorg)>1) |
---|
1740 | replace_entry(&(data.embl.comments.orginf.hostorg), |
---|
1741 | data.gbk.comments.orginf.hostorg); |
---|
1742 | |
---|
1743 | /* RDP defined Sequence Information comments */ |
---|
1744 | data.embl.comments.seqinf.exist = data.gbk.comments.seqinf.exist; |
---|
1745 | |
---|
1746 | if(Lenstr(data.gbk.comments.seqinf.RDPid)>1) |
---|
1747 | replace_entry(&(data.embl.comments.seqinf.RDPid), |
---|
1748 | data.gbk.comments.seqinf.RDPid); |
---|
1749 | |
---|
1750 | if(Lenstr(data.gbk.comments.seqinf.gbkentry)>1) |
---|
1751 | replace_entry(&(data.embl.comments.seqinf.gbkentry), |
---|
1752 | data.gbk.comments.seqinf.gbkentry); |
---|
1753 | |
---|
1754 | if(Lenstr(data.gbk.comments.seqinf.methods)>1) |
---|
1755 | replace_entry(&(data.embl.comments.seqinf.methods), |
---|
1756 | data.gbk.comments.seqinf.methods); |
---|
1757 | |
---|
1758 | data.embl.comments.seqinf.comp5 = data.gbk.comments.seqinf.comp5; |
---|
1759 | |
---|
1760 | data.embl.comments.seqinf.comp3 = data.gbk.comments.seqinf.comp3; |
---|
1761 | |
---|
1762 | /* other comments */ |
---|
1763 | if(Lenstr(data.gbk.comments.others)>1) |
---|
1764 | replace_entry(&(data.embl.comments.others), |
---|
1765 | data.gbk.comments.others); |
---|
1766 | } |
---|
1767 | /* --------------------------------------------------------------- |
---|
1768 | * Function macke_to_embl(). |
---|
1769 | * Convert from macke to EMBL. |
---|
1770 | */ |
---|
1771 | void |
---|
1772 | macke_to_embl(inf, outf) |
---|
1773 | char *inf, *outf; |
---|
1774 | { |
---|
1775 | FILE *IFP1, *IFP2, *IFP3, *ofp; |
---|
1776 | FILE_BUFFER ifp1, ifp2, ifp3; |
---|
1777 | char temp[TOKENNUM]; |
---|
1778 | |
---|
1779 | if ((IFP1=fopen(inf, "r"))==NULL || |
---|
1780 | (IFP2=fopen(inf, "r"))==NULL || |
---|
1781 | (IFP3=fopen(inf, "r"))==NULL) |
---|
1782 | { |
---|
1783 | sprintf(temp, "Cannot open input file %s\n", inf); |
---|
1784 | error(99, temp); |
---|
1785 | } |
---|
1786 | |
---|
1787 | ifp1 = create_FILE_BUFFER(inf, IFP1); |
---|
1788 | ifp2 = create_FILE_BUFFER(inf, IFP2); |
---|
1789 | ifp3 = create_FILE_BUFFER(inf, IFP3); |
---|
1790 | |
---|
1791 | if(Lenstr(outf)<=0) ofp = stdout; |
---|
1792 | else if((ofp=fopen(outf, "w"))==NULL) { |
---|
1793 | sprintf(temp, "Cannot open output file %s\n", outf); |
---|
1794 | error(43, temp); |
---|
1795 | } |
---|
1796 | init(); |
---|
1797 | init_seq_data(); |
---|
1798 | init_genbank(); |
---|
1799 | init_macke(); |
---|
1800 | init_embl(); |
---|
1801 | |
---|
1802 | #ifdef log |
---|
1803 | fprintf(stderr, "Start converting...\n"); |
---|
1804 | #endif |
---|
1805 | |
---|
1806 | while(macke_in(ifp1, ifp2, ifp3)!=EOF) { |
---|
1807 | |
---|
1808 | data.numofseq++; |
---|
1809 | |
---|
1810 | /* partial_mtoe() is particularly handling |
---|
1811 | * subspecies information, not converting whole |
---|
1812 | * macke format to embl */ |
---|
1813 | |
---|
1814 | if(mtog()&>oe()&&partial_mtoe()) embl_out(ofp); |
---|
1815 | else error(14, |
---|
1816 | "Conversion from macke to embl fails, Exit"); |
---|
1817 | |
---|
1818 | init_genbank(); |
---|
1819 | init_embl(); |
---|
1820 | init_macke(); |
---|
1821 | |
---|
1822 | #ifdef log |
---|
1823 | if((data.numofseq % 50)==0) |
---|
1824 | fprintf(stderr, "%d sequences are converted...\n", |
---|
1825 | data.numofseq); |
---|
1826 | #endif |
---|
1827 | |
---|
1828 | } |
---|
1829 | |
---|
1830 | #ifdef log |
---|
1831 | fprintf(stderr, |
---|
1832 | "Total %d sequences have been processed\n", data.numofseq); |
---|
1833 | #endif |
---|
1834 | |
---|
1835 | } |
---|
1836 | /* -------------------------------------------------------------- |
---|
1837 | * Function partial_mtoe(). |
---|
1838 | * Handle subspecies information when converting from |
---|
1839 | * Macke to EMBL. |
---|
1840 | */ |
---|
1841 | int partial_mtoe() { |
---|
1842 | |
---|
1843 | int indj, indk; |
---|
1844 | /* int not_ending_mark(); */ |
---|
1845 | /* void Freespace(), Append(), Append_rm_eoln(); */ |
---|
1846 | |
---|
1847 | if(Lenstr(data.macke.strain)>1) { |
---|
1848 | if((indj=find_pattern(data.embl.comments.others, "*source:"))>=0 && |
---|
1849 | (indk=find_pattern (data.embl.comments.others+indj, "strain="))>=0) |
---|
1850 | { |
---|
1851 | ; /* do nothing */ |
---|
1852 | } |
---|
1853 | else { |
---|
1854 | if(Lenstr(data.embl.comments.others)<=1) Freespace(&(data.embl.comments.others)); |
---|
1855 | Append(&(data.embl.comments.others), "*source: strain="); |
---|
1856 | Append(&(data.embl.comments.others), data.macke.strain); |
---|
1857 | if (not_ending_mark(data.embl.comments.others[Lenstr(data.embl.comments.others)-2])) { |
---|
1858 | Append_rm_eoln (&(data.embl.comments.others), ";\n"); |
---|
1859 | } |
---|
1860 | } |
---|
1861 | } |
---|
1862 | |
---|
1863 | if(Lenstr(data.macke.subspecies)>1) { |
---|
1864 | |
---|
1865 | if((indj=find_pattern (data.embl.comments.others, "*source:"))>=0 && |
---|
1866 | ((indk=find_pattern(data.embl.comments.others+indj, "subspecies="))>=0 || |
---|
1867 | (indk=find_pattern(data.embl.comments.others+indj, "sub-species="))>=0 || |
---|
1868 | (indk=find_pattern(data.embl.comments.others+indj, "subsp.="))>=0)) |
---|
1869 | { |
---|
1870 | ;/* do nothing */ |
---|
1871 | } |
---|
1872 | else { |
---|
1873 | if (Lenstr(data.embl.comments.others)<=1) Freespace (&(data.embl.comments.others)); |
---|
1874 | |
---|
1875 | Append(&(data.embl.comments.others), "*source: subspecies="); |
---|
1876 | Append(&(data.embl.comments.others), data.macke.subspecies); |
---|
1877 | |
---|
1878 | if (not_ending_mark(data.embl.comments.others[Lenstr(data.embl.comments.others)-2])) { |
---|
1879 | Append_rm_eoln (&(data.embl.comments.others), ";\n"); |
---|
1880 | } |
---|
1881 | } |
---|
1882 | } |
---|
1883 | |
---|
1884 | return(1); |
---|
1885 | } |
---|