source: branches/port5/CONVERTALN/alma.c

Last change on this file was 5390, checked in by westram, 17 years ago
  • TAB-Ex
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 25.2 KB
Line 
1#include <stdio.h>
2#include <ctype.h>
3#include <string.h>
4#include "convert.h"
5#include "global.h"
6
7extern int  warning_out;
8
9/* --------------------------------------------------------------
10 *   Function init_alma().
11 *       Init. ALMA data.
12 */
13void init_alma()    {
14    Freespace(&(data.alma.id));
15    Freespace(&(data.alma.filename));
16    Freespace(&(data.alma.sequence));
17    data.alma.format=UNKNOWN;
18    data.alma.defgap='-';
19    data.alma.num_of_sequence=0;
20    /* init. nbrf too */
21    Freespace(&(data.nbrf.id));
22    Freespace(&(data.nbrf.description));
23}
24/* ----------------------------------------------------------------
25 *   Function alma_to_macke().
26 *       Convert from ALMA format to Macke format.
27 */
28void
29alma_to_macke(inf, outf)
30     char   *inf, *outf;
31{
32    FILE        *IFP, *ofp;
33    FILE_BUFFER  ifp;
34    char         temp[TOKENNUM];
35    int          indi, total_num;
36
37    if((IFP=fopen(inf, "r"))==NULL) {
38        sprintf(temp,
39                "Cannot open input file %s, EXIT.", inf);
40        error(46, temp);
41    }
42    ifp              = create_FILE_BUFFER(inf, IFP);
43    if(Lenstr(outf) <= 0)   ofp = stdout;
44    else if((ofp=fopen(outf, "w"))==NULL)   {
45        sprintf(temp,
46                "Cannot open output file %s, EXIT.", outf);
47        error(47, temp);
48    }
49
50    init();
51    /* macke format seq irrelenvant header */
52    macke_out_header(ofp);
53    for(indi=0; indi<3; indi++) {
54        FILE_BUFFER_rewind(ifp);
55        init_seq_data();
56        init_macke();
57        init_alma();
58        while(alma_in(ifp)!=EOF)    {
59            data.numofseq++;
60            if(atom()) {
61                /* convert from alma form to macke form */
62                switch(indi)    {
63                    case 0:
64                        /* output seq display format */
65                        macke_out0(ofp, ALMA);
66                        break;
67                    case 1:
68                        /* output seq information */
69                        macke_out1(ofp);
70                        break;
71                    case 2:
72                        /* output seq data */
73                        macke_out2(ofp);
74                        break;
75                    default: ;
76                }
77            } else error(48,
78                         "Conversion from alma to macke fails, Exit.");
79            init_alma();
80            init_macke();
81        }
82        total_num = data.numofseq;
83        if(indi==0) {
84            fprintf(ofp, "#-\n");
85            /* no warning messages for next loop */
86            warning_out = 0;
87        }
88    }   /* for each seq; loop */
89    warning_out = 1;    /* resume warning messages */
90
91#ifdef log
92    fprintf(stderr,
93            "Total %d sequences have been processed\n",
94            total_num);
95#endif
96}
97/* ----------------------------------------------------------------
98 *   Function alma_to_genbank().
99 *       Convert from ALMA format to GenBank format.
100 */
101void
102alma_to_genbank(inf, outf)
103     char   *inf, *outf;
104{
105    FILE        *IFP, *ofp;
106    FILE_BUFFER  ifp;
107    char         temp[TOKENNUM];
108
109    if((IFP=fopen(inf, "r"))==NULL) {
110        sprintf(temp,
111                "Cannot open input file %s, EXIT.", inf);
112        error(73, temp);
113    }
114    ifp              = create_FILE_BUFFER(inf, IFP);
115    if(Lenstr(outf) <= 0)   ofp = stdout;
116    else if((ofp=fopen(outf, "w"))==NULL)   {
117        sprintf(temp,
118                "Cannot open output file %s, EXIT.", outf);
119        error(74, temp);
120    }
121
122    init();
123    init_seq_data();
124    init_macke();
125    init_genbank();
126    init_alma();
127    while(alma_in(ifp)!=EOF)    {
128        data.numofseq++;
129        if(atom()&&mtog()) {
130            genbank_out(ofp);
131            init_alma();
132            init_macke();
133            init_genbank();
134        }
135    }   /* for each seq; loop */
136
137#ifdef log
138    fprintf(stderr,
139            "Total %d sequences have been processed\n",
140            data.numofseq);
141#endif
142}
143/* ----------------------------------------------------------------
144 *   Function alma_in().
145 *       Read in one ALMA sequence data.
146 */
147char
148alma_in(fp)
149     FILE_BUFFER fp;
150{
151    char    eoen, *eof, line[LINENUM];
152    /*  char    temp[LINENUM]; */
153    char    key[TOKENNUM], *format;
154    int indi, len, index;
155    /*  int alma_key_word(); */
156    /*  void    alma_one_entry(), Freespace(), error(); */
157
158    /* end-of-entry; set to be 'y' after reaching end of entry */
159    format=NULL;
160    eoen = ' ';
161    for(eof=Fgetline(line, LINENUM, fp); eof!=NULL&&eoen!='y'; )
162    {
163        if(Lenstr(line)<=1) {
164            eof=Fgetline(line, LINENUM, fp);
165            continue;   /* skip empty line */
166        }
167        index = alma_key_word(line, 0, key, TOKENNUM);
168        eoen='n';
169        if((Cmpstr(key, "NXT ENTRY"))==EQ)  {
170            /* do nothing, just indicate beginning of entry */
171        } else if((Cmpstr(key, "ENTRY ID"))==EQ)    {
172            alma_one_entry(line, index, &(data.alma.id));
173            for(indi=0, len=Lenstr(data.alma.id); indi<len;
174                indi++)
175                if(data.alma.id[indi]==' ')
176                    data.alma.id[indi]='_';
177        } else if((Cmpstr(key, "SEQUENCE"))==EQ)    {
178            alma_one_entry(line, index,
179                           &(data.alma.filename));
180        } else if((Cmpstr(key, "FORMAT"))==EQ)  {
181            alma_one_entry(line, index, &format);
182            if((Cmpstr(format, "NBRF"))==EQ)
183                data.alma.format=NBRF;
184            else if((Cmpstr(format, "UWGCG"))==EQ
185                    ||(Cmpstr(format, "GCG"))==EQ)
186                data.alma.format=GCG;
187            else if((Cmpstr(format, "EMBL"))==EQ)
188                data.alma.format=EMBL;
189            else if((Cmpstr(format, "STADEN"))==EQ)
190                data.alma.format=STADEN;
191            else    {
192                sprintf(line,
193                        "Unidentified file format %s in ALMA format, Exit.",
194                        format);
195                error(49, line);
196            }
197            Freespace(&(format));
198        } else if((Cmpstr(key, "DEFGAP"))==EQ)  {
199            /* skip white spaces */
200            for(;line[index]!='['&&line[index]!='\n'
201                    &&line[index]!='\0'; index++) ;
202            if(line[index]=='[')
203                data.alma.defgap = line[index+1];
204        } else if((Cmpstr(key, "GAPS"))==EQ)    {
205            eof=alma_in_gaps(fp);
206            eoen='y';
207        } else if((Cmpstr(key, "END FILE"))==EQ)    {
208            return(EOF);
209        }
210        if(eoen!='y') eof=Fgetline(line, LINENUM, fp);
211    }
212    if(eof==NULL) return(EOF);
213    else return(EOF+1);
214}
215/* ----------------------------------------------------------------
216 *   Function alma_key_word().
217 *       Get the key_word from line beginning at index.
218 */
219int
220alma_key_word(line, index, key, length)
221     char    *line;
222     int index;
223     char    *key;
224     int length;
225{
226    int indi, indj;
227
228    if(line==NULL)  { key[0]='\0'; return(index); }
229    for(indi=index, indj=0;
230        (index-indi)<length&&line[indi]!='>'
231            &&line[indi]!='\n'&&line[indi]!='\0';
232        indi++, indj++)
233        key[indj] = line[indi];
234    key[indj] = '\0';
235    if(line[indi]=='>') return(indi+1);
236    else return(indi);
237}
238/* --------------------------------------------------------------
239 *   Function alma_one_entry().
240 *       Read in one ALMA entry lines.
241 */
242void
243alma_one_entry(line, index, datastring)
244     char    *line;
245     int index;
246     char    **datastring;
247{
248    int indi, length;
249    /*  void    replace_entry(); */
250
251    index = Skip_white_space(line, index);
252
253    for(indi=index, length=Lenstr(line+index)+index;
254        indi<length; indi++)
255        if(line[indi]=='\n') line[indi]='\0';
256
257    replace_entry(datastring, line+index);
258}
259/* -------------------------------------------------------------
260 *   Function alma_in_gaps().
261 *       Get sequence data and merge with gaps(alignment).
262 */
263char
264*alma_in_gaps(fp)
265     FILE_BUFFER fp;
266{
267    int return_num, gaps, residues, count=0;
268    int indi, numofseq, bases_not_matching;
269    char    line[LINENUM], gap_chars[LINENUM];
270    char    *eof;
271    /*  void    alma_in_sequence(), warning(); */
272
273    alma_in_sequence();
274
275    numofseq = 0;
276
277    bases_not_matching=0;
278    /* alignment, merger with gaps information */
279    {
280        while (1) {
281            char *gotLine = Fgetline(line, LINENUM, fp);
282            if (!gotLine) break;
283
284            return_num = sscanf(line, "%d %d %s", &gaps, &residues, gap_chars);
285            if (return_num == 0 || gaps == -1) {
286                FILE_BUFFER_back(fp, line);
287                break;
288            }
289
290            data.alma.sequence = (char*)Reallocspace(data.alma.sequence, (unsigned)(sizeof(char)*(numofseq+gaps+1)));
291
292            for(indi=0; indi<gaps; indi++) data.alma.sequence[numofseq+indi] = gap_chars[1];
293
294            numofseq += gaps;
295
296            if(residues>(data.seq_length-count)) bases_not_matching = 1;
297
298            data.alma.sequence = (char*)Reallocspace (data.alma.sequence, (unsigned)(sizeof(char)*(numofseq+residues+1)));
299
300            /* fill with gap if seq data is not enough as required */
301            for(indi=0; indi<residues; indi++) {
302                if(count>=data.seq_length) data.alma.sequence[numofseq+indi] = gap_chars[1];
303                else                       data.alma.sequence[numofseq+indi] = data.sequence[count++];
304            }
305
306            numofseq += residues;
307
308        }
309    }
310
311    if(bases_not_matching)  {
312        sprintf(line,
313                "Bases number in ALMA file is larger than that in data file %s",
314                data.alma.filename);
315
316        warning(142, line);
317    }
318
319    if(count<data.seq_length)   {
320        sprintf(line,
321                "Bases number in ALMA file is less than that in data file %s",
322                data.alma.filename);
323
324        warning(143, line);
325
326        /* Append the rest of the data at the end */
327        data.alma.sequence = (char*)Reallocspace (data.alma.sequence, (unsigned)(sizeof(char)*(numofseq+data.seq_length-count+1)));
328
329        for(indi=0; count<data.seq_length; indi++) data.alma.sequence[numofseq++] = data.sequence[count++];
330    }
331    data.alma.sequence[numofseq]='\0';
332
333    /* update sequence data */
334    if(numofseq>data.max)   {
335        data.max=numofseq;
336        data.sequence=(char*)Reallocspace(data.sequence, (unsigned)(sizeof(char)*data.max));
337    }
338
339    data.seq_length = numofseq;
340
341    for(indi=0; indi<numofseq; indi++) data.sequence[indi]=data.alma.sequence[indi];
342
343    data.alma.num_of_sequence = numofseq;
344
345    if(return_num!=0) {
346        /* skip END ENTRY> line */
347        if(Fgetline(line, LINENUM, fp)==NULL) eof=NULL;
348        else eof = line;
349    } else eof = NULL;
350
351    return(eof);
352}
353/* -------------------------------------------------------------
354 *   Function alma_in_sequence().
355 *       Read in sequence data.
356 */
357void
358alma_in_sequence()  {
359
360    char         temp[LINENUM];
361    FILE        *IFP; /* ex-infile */
362    FILE_BUFFER  ifp;
363
364    if((IFP=fopen(data.alma.filename, "r"))==NULL) {
365        sprintf(temp, "Cannot open file %s, Exit.", data.alma.filename);
366        error(51, temp);
367    }
368
369    ifp = create_FILE_BUFFER(data.alma.filename, IFP);
370
371    if(data.alma.format==NBRF)  {
372        nbrf_in(ifp);
373    } else if(data.alma.format==GCG)    {
374        gcg_in(ifp);
375    } else if(data.alma.format==EMBL)   {
376        init_embl();
377        embl_in(ifp);
378    } else if(data.alma.format==STADEN) {
379        staden_in(ifp);
380    } else {
381        sprintf(temp, "Unidentified file format %d in ALMA file, Exit.", data.alma.format);
382        error(50, temp);
383    }
384    destroy_FILE_BUFFER(ifp);
385}
386/* --------------------------------------------------------------
387 *   Function nbrf_in().
388 *       Read in nbrf data.
389 */
390void
391nbrf_in(fp)
392     FILE_BUFFER fp;
393{
394    int length, index, reach_end;
395    char    line[LINENUM], temp[TOKENNUM], *eof;
396    /*  char    *Fgetline(), *Dupstr(); */
397    /*  char    *Reallocspace(); */
398    /*  void    Cpystr(), replace_entry(), error(); */
399
400    if((eof=Fgetline(line, LINENUM, fp))==NULL)
401        error(52,
402              "Cannot find id line in NBRF file, Exit.");
403    Cpystr(temp, line+4);
404    length=Lenstr(temp);
405    if(temp[length-1]=='\n') temp[length-1]='\0';
406
407    replace_entry(&(data.nbrf.id), temp);
408
409    if((eof=Fgetline(line, LINENUM, fp))==NULL)
410        error(54,
411              "Cannot find description line in NBRF file, Exit.");
412
413    replace_entry(&(data.nbrf.description), line);
414
415    /* read in sequence data */
416    data.seq_length = 0;
417    for(eof=Fgetline(line, LINENUM, fp), reach_end='n';
418        eof!=NULL&&reach_end!='y';
419        eof=Fgetline(line, LINENUM, fp))
420    {
421        for(index=0; line[index]!='\n'&&line[index]!='\0';
422            index++)
423        {
424            if(line[index]=='*') {
425                reach_end='y';
426                continue;
427            }
428            if(line[index]!=' '&&data.seq_length>=data.max){
429                data.max += 100;
430
431                data.sequence = (char*)Reallocspace
432                    (data.sequence,
433                     (unsigned)(sizeof(char)*data.max));
434            }
435            if(line[index]!=' ')
436                data.sequence[data.seq_length++]
437                    = line[index];
438        }   /* scan through each line */
439        data.sequence[data.seq_length] = '\0';
440    }   /* for each line */
441}
442/* ----------------------------------------------------------------
443 *   Function gcg_in().
444 *       Read in one data entry in UWGCG format.
445 */
446void
447gcg_in(fp)
448     FILE_BUFFER    fp;
449{
450    char line[LINENUM];
451
452    while (Fgetline(line, LINENUM, fp)) {
453        char *two_dots = strstr(line, "..");
454        if (two_dots) {
455            FILE_BUFFER_back(fp, two_dots+2);
456            genbank_origin(line, fp);
457        }
458    }
459}
460/* ----------------------------------------------------------------
461 *   Fnction staden_in().
462 *       Read in sequence data in STADEN format.
463 */
464void
465staden_in(fp)
466     FILE_BUFFER fp;
467{
468    char    line[LINENUM];
469    int len, start, indi;
470
471    data.seq_length=0;
472    while(Fgetline(line, LINENUM, fp)!=NULL)    {
473        /* skip empty line */
474        if((len=Lenstr(line))<=1) continue;
475
476        start = data.seq_length;
477        data.seq_length += len;
478        line[len-1]='\0';
479
480        if(data.seq_length>data.max)    {
481            data.max += (data.seq_length + 100);
482            data.sequence = (char*)Reallocspace
483                (data.sequence,
484                 (unsigned)(sizeof(char)*data.max));
485        }
486
487        for(indi=0; indi<len; indi++)
488            data.sequence[start+indi] = line[indi];
489    }
490}
491/* -------------------------------------------------------------
492 *   Function atom().
493 *       Convert one ALMA entry to Macke entry.
494 */
495int
496atom()
497{
498    /*  int indi, len; */
499    /*  char    *Dupstr(), *Reallocspace(); */
500    /*  void    replace_entry(), error(); */
501
502    if(data.alma.format==NBRF)  {
503        data.macke.numofrem=1;
504        data.macke.remarks=(char**)Reallocspace
505            ((char*)data.macke.remarks,
506             (unsigned)(sizeof(char*)));
507        data.macke.remarks[0]
508            =(char*)Dupstr(data.nbrf.description);
509    } else if(data.alma.format==EMBL)   {
510        etom();
511    } else if(data.alma.format==GCG)    {
512    } else if(data.alma.format==STADEN) {
513    } else {
514        error(53,
515              "Unidentified format type in ALMA file, Exit.");
516    }
517
518    replace_entry(&(data.macke.seqabbr), data.alma.id);
519
520    return(1);
521}
522/* -------------------------------------------------------------
523 *   Function embl_to_alma().
524 *       Convert from EMBL to ALMA.
525 */
526void
527embl_to_alma(inf, outf)
528     char   *inf, *outf;
529{
530    FILE        *IFP, *ofp;
531    FILE_BUFFER  ifp;
532    char         temp[TOKENNUM];
533
534    if((IFP=fopen(inf, "r"))==NULL) {
535        sprintf(temp, "Cannot open input file %s, EXIT.", inf);
536        error(134, temp);
537    }
538    ifp = create_FILE_BUFFER(inf, IFP);
539    if((ofp=fopen(outf, "w"))==NULL)    {
540        sprintf(temp, "Cannot open output file %s, EXIT.", outf);
541        error(135, temp);
542    }
543
544    init();
545    init_embl();
546    init_alma();
547    alma_out_header(ofp);
548
549    while(embl_in(ifp)!=EOF)    {
550        if(data.numofseq>0) fprintf(ofp, "\n");
551        data.numofseq++;
552        if(etoa())  {
553            FILE *outfile = alma_out(ofp, EMBL);
554            embl_out(outfile);
555            fclose(outfile);
556        }
557        init_embl();
558        init_alma();
559    }
560
561    fprintf(ofp, "END FILE>\n");
562
563#ifdef log
564    fprintf(stderr,
565            "Total %d sequences have been processed\n",
566            data.numofseq);
567#endif
568
569    destroy_FILE_BUFFER(ifp);   fclose(ofp);
570}
571/* ------------------------------------------------------------
572 *   Function genbank_to_alma().
573 *       Convert from GenBank to ALMA.
574 */
575void
576genbank_to_alma(inf, outf)
577     char   *inf, *outf;
578{
579    FILE        *IFP, *ofp;
580    FILE_BUFFER  ifp;
581    char         temp[TOKENNUM];
582
583    if((IFP=fopen(inf, "r"))==NULL) {
584        sprintf(temp,
585                "Cannot open input file %s, EXIT.", inf);
586        error(61, temp);
587    }
588    ifp = create_FILE_BUFFER(inf, IFP);
589    if((ofp=fopen(outf, "w")) == NULL)  {
590        sprintf(temp,
591                "Cannot open output file %s, EXIT.", outf);
592        error(62, temp);
593    }
594
595    init();
596    init_genbank();
597    init_embl();
598    init_alma();
599    alma_out_header(ofp);
600
601    while(genbank_in(ifp)!=EOF) {
602        if(data.numofseq>0) fprintf(ofp, "\n");
603        data.numofseq++;
604        if(gtoe()&&etoa())  {
605            FILE *outfile = alma_out(ofp, EMBL);
606            embl_out(outfile);
607            fclose(outfile);
608        }
609        init_genbank();
610        init_embl();
611        init_alma();
612    }
613
614    fprintf(ofp, "END FILE>\n");
615
616#ifdef log
617    fprintf(stderr,
618            "Total %d sequences have been processed\n",
619            data.numofseq);
620#endif
621
622    destroy_FILE_BUFFER(ifp);   fclose(ofp);
623}
624/* -------------------------------------------------------------
625 *   Function macke_to_alma().
626 *       Convert from MACKE to ALMA.
627 */
628void
629macke_to_alma(inf, outf)
630     char   *inf, *outf;
631{
632    FILE        *IFP1, *IFP2, *IFP3, *ofp;
633    FILE_BUFFER  ifp1, ifp2, ifp3;
634    char         temp[TOKENNUM];
635
636    if((IFP1=fopen(inf, "r"))==NULL ||
637       (IFP2=fopen(inf, "r"))==NULL ||
638       (IFP3=fopen(inf, "r"))==NULL)
639    {
640        sprintf(temp,
641                "Cannot open input file %s, EXIT.", inf);
642        error(59, temp);
643    }
644
645    ifp1 = create_FILE_BUFFER(inf, IFP1);
646    ifp2 = create_FILE_BUFFER(inf, IFP2);
647    ifp3 = create_FILE_BUFFER(inf, IFP3);
648
649    if((ofp=fopen(outf, "w"))==NULL)    {
650        sprintf(temp,
651                "Cannot open output file %s, EXIT.", outf);
652        error(60, temp);
653    }
654
655    init();
656    init_macke();
657    init_genbank();
658    init_embl();
659    init_alma();
660    alma_out_header(ofp);
661    while(macke_in(ifp1, ifp2, ifp3)!=EOF)  {
662        if(data.numofseq>0) fprintf(ofp, "\n");
663        data.numofseq++;
664        if(mtog()&&gtoe()&&partial_mtoe()&&etoa()) {
665            FILE *outfile = alma_out(ofp, EMBL);
666            embl_out(outfile);
667            fclose(outfile);
668        }
669        init_macke();
670        init_genbank();
671        init_embl();
672        init_alma();
673    }
674
675    fprintf(ofp, "END FILE>\n");
676
677#ifdef log
678    fprintf(stderr,
679            "Total %d sequences have been processed\n",
680            data.numofseq);
681#endif
682
683    destroy_FILE_BUFFER(ifp1);  destroy_FILE_BUFFER(ifp2);
684    destroy_FILE_BUFFER(ifp3);  fclose(ofp);
685}
686/* -------------------------------------------------------------
687 *   Function etoa().
688 *       Convert from EMBL to ALMA format.
689 */
690int
691etoa()
692{
693    char    temp[TOKENNUM], t1[TOKENNUM], t2[TOKENNUM], t3[TOKENNUM];
694    /*  char    *Dupstr(), *Catstr(); */
695    /*  void    embl_key_word(), Cpystr(); */
696    /*  void    replace_entry(); */
697
698    embl_key_word(data.embl.id, 0, temp, TOKENNUM);
699    if(Lenstr(data.embl.dr)>1)      {
700        /* get short_id from DR line if there is RDP def. */
701        Cpystr(t3, "dummy");
702        sscanf(data.embl.dr, "%s %s %s", t1, t2, t3);
703        if(Cmpstr(t1, "RDP;")==EQ)      {
704            if(Cmpstr(t3, "dummy")!=EQ)     {
705                Cpystr(temp, t3);
706            } else Cpystr(temp, t2);
707            temp[Lenstr(temp)-1]='\0'; /* remove '.' */
708        }
709    }
710    replace_entry(&(data.alma.id), temp);
711
712    return(1);
713}
714/* -------------------------------------------------------------
715 *   Function alma_out_header().
716 *       Output alma format header.
717 */
718void
719alma_out_header(fp)
720     FILE    *fp;
721{
722    fprintf(fp, "SCREEN WIDTH>   80\n");
723    fprintf(fp, "ID COLUMN>    1\n");
724    fprintf(fp, "LINK COLUMN>   10\n");
725    fprintf(fp, "INFO LINE>   24\n");
726    fprintf(fp, "ACTIVE WINDOW>    1    1\n");
727    fprintf(fp,
728            "SEQUENCE WINDOW>    1    1    1   23   12   80\n");
729    fprintf(fp, "SCROLL DISTANCE>    1    1   50\n");
730    fprintf(fp, "SEQ NUMBERS>    1    1    0    0\n");
731    fprintf(fp, "CURSOR SCREEN>    1    1   11   54\n");
732    fprintf(fp, "CURSOR ALIGNMENT>    1    1    9  143\n");
733    fprintf(fp, "LINK ACTIVE>    2\n");
734    fprintf(fp, "SCROLL>    2\n");
735    fprintf(fp, "MULTI WINDOWS>F\n");
736    fprintf(fp, "COLOURS>F\n");
737    fprintf(fp, "UPDATE INT#>T\n");
738    fprintf(fp, "HOMOLOGY>F\n");
739    fprintf(fp, "PRINT>\n");
740    fprintf(fp, "FILE_A>\n");
741    fprintf(fp, "FILE_B>\n");
742    fprintf(fp, "FILE_C>\n");
743    fprintf(fp, "FILE_D>\n");
744    fprintf(fp, "FILE_E>\n");
745    fprintf(fp, "ALIGNMENT TITLE>\n");
746    fprintf(fp, "PRINT TITLE>    0\n");
747    fprintf(fp, "PRINT DEVICE>    0\n");
748    fprintf(fp, "SPACERS TOP>    0\n");
749    fprintf(fp, "FONT>    0\n");
750    fprintf(fp, "FONT SIZE>    0\n");
751    fprintf(fp, "PAGE WIDTH>    0\n");
752    fprintf(fp, "PRINT FORMAT>    0\n");
753    fprintf(fp, "PAGE LENGTH>    0\n");
754    fprintf(fp, "SKIP LINES>    0\n");
755    fprintf(fp, "COLOURING>    0\n");
756    fprintf(fp,
757            "COLOUR ACTIVE>    0    0    0    0    0    0    0    0    0    0\n");
758    fprintf(fp, "RESIDUE B(LINK)>\n");
759    fprintf(fp, "RESIDUE R(EVERSE)>\n");
760    fprintf(fp, "RESIDUE I(NCREASE)>\n");
761    fprintf(fp, "RESIDUE B+R>\n");
762    fprintf(fp, "RESIDUE B+I>\n");
763    fprintf(fp, "RESIDUE R+I>\n");
764    fprintf(fp, "RESIDUE B+R+I>\n");
765    fprintf(fp, "HOMOEF_A>    0\n");
766    fprintf(fp, "HOMOEF_B>    0\n");
767    fprintf(fp, "HOMOEF_C>    0\n");
768    fprintf(fp, "HOMOEF_D>    0\n");
769    fprintf(fp, "HOMOEF_E>    0\n");
770    fprintf(fp, "HOMOEF_F>    0\n");
771    fprintf(fp, "HOMOEF_G>    0\n");
772    fprintf(fp, "HOMOEF_H>    0\n");
773    fprintf(fp, "HOMOEF_I>    0\n");
774    fprintf(fp, "HOMOEF_J>    0\n");
775    fprintf(fp, "HOMOEF_K>    0\n");
776    fprintf(fp, "HOMOEF_L>    0\n");
777    fprintf(fp, "HOMOEF_M>    0\n");
778    fprintf(fp, "HOMOEF_N>    0\n");
779    fprintf(fp, "HOMOEF_O>    0\n");
780    fprintf(fp, "HOMOEF_P>    0\n");
781    fprintf(fp, "HOMOEF_Q>    0\n");
782    fprintf(fp, "HOMOEF_R>    0\n");
783    fprintf(fp, "HOMOEF_S>    0\n");
784    fprintf(fp, "HOMOEF_T>    0\n");
785}
786/* -------------------------------------------------------------
787 *   Function alma_out().
788 *       Output one alma entry.
789 */
790FILE *
791alma_out(fp, format)
792     FILE   *fp;
793     int    format;
794{
795    int   indi, len;
796    char  filename[TOKENNUM];
797    FILE *outfile;
798
799    Cpystr(filename, data.alma.id);
800    for(indi=0, len=Lenstr(filename); indi<len; indi++)
801        if(!isalnum(filename[indi])) filename[indi] = '_';
802    Catstr(filename, ".EMBL");
803
804    outfile = alma_out_entry_header(fp, data.alma.id, filename, format);
805    alma_out_gaps(fp);
806
807    return outfile;
808}
809/* --------------------------------------------------------------
810 *  Function alma_out_entry_header().
811 *      Output one ALMA entry header.
812 */
813FILE *
814alma_out_entry_header(fp, entry_id, filename, format_type)
815     FILE    *fp;
816     char    *entry_id, *filename;
817     int format_type;
818{
819    char  temp[TOKENNUM];
820    FILE *outfile = 0;
821
822    fprintf(fp, "NXT ENTRY>S\n");
823    fprintf(fp, "ENTRY ID>%s\n", entry_id);
824
825    if(fopen(filename, "r")!=NULL)  {
826        sprintf(temp,
827                "file %s is overwritten.", filename);
828        warning(55, temp);
829    }
830    if((outfile=fopen(filename, "w"))==NULL)    {
831        sprintf(temp, "Cannot open file: %s, Exit.",
832                filename);
833        error(56, temp);
834    }
835    fprintf(fp, "SEQUENCE>%s\n", filename);
836    if(format_type==EMBL)
837        fprintf(fp, "FORMAT>EMBL\n");
838    else if(format_type==NBRF)
839        fprintf(fp, "FORMAT>NBRF\n");
840    else if(format_type==GCG)
841        fprintf(fp, "FORMAT>UWGCG\n");
842    else if(format_type==STADEN)
843        fprintf(fp, "FORMAT>STADEN\n");
844    else    error(57,
845                  "Unknown format type when writing ALMA format, EXIT.");
846
847    fprintf(fp, "ACCEPT>ALL\n");
848    fprintf(fp, "DEFGAP>[-]\n");
849    fprintf(fp, "PARAMS>1\n");
850    fprintf(fp, "GAPS>\n");
851
852    return outfile;
853}
854/* --------------------------------------------------------------
855 *  Function alma_out_gaps().
856 *       Output gaps information of one ALMA entry.
857 */
858void
859alma_out_gaps(fp)
860     FILE    *fp;
861{
862    int indi, index, residue, gnum, rnum, tempcount;
863
864    gnum=rnum=0;
865
866    if(data.sequence[0]=='.'||data.sequence[0]=='-'
867       ||data.sequence[0]=='~')
868        residue=0;
869    else residue=1;
870
871    tempcount=data.seq_length;
872    for(indi=index=0; indi<tempcount; indi++)   {
873        if(data.sequence[indi]=='.'
874           ||data.sequence[indi]=='-'
875           ||data.sequence[indi]=='~') {
876            if(residue) {
877                fprintf(fp, " %4d %4d [-]\n",
878                        gnum, rnum);
879                gnum=rnum=residue=0;
880            }
881            gnum++; data.seq_length--;
882        } else  {
883            residue=1;
884            rnum++;
885            data.sequence[index++]
886                =data.sequence[indi];
887        }
888    }
889    data.sequence[index]='\0';
890    fprintf(fp, " %4d %4d [-]\n", gnum, rnum);
891    fprintf(fp, "   -1   -1 [-]\n");
892    fprintf(fp, "END ENTRY>\n");
893}
Note: See TracBrowser for help on using the repository browser.