1 | /* ------------- File format converting subroutine ------------- */ |
---|
2 | |
---|
3 | #include <stdio.h> |
---|
4 | #include <stdlib.h> |
---|
5 | #include "convert.h" |
---|
6 | #include "global.h" |
---|
7 | |
---|
8 | /* ------------------------------------------------------------- |
---|
9 | * Function convert(). |
---|
10 | * For given input file and type, convert the file |
---|
11 | * to desired out type and save the result in |
---|
12 | * the out file. |
---|
13 | */ |
---|
14 | void convert(inf, outf, intype, outype) |
---|
15 | char *inf, *outf; |
---|
16 | int intype, outype; |
---|
17 | { |
---|
18 | int dd; /* copy stdin to outfile after first line */ |
---|
19 | dd = 0; |
---|
20 | if (outype == PHYLIP2){ |
---|
21 | outype = PHYLIP; |
---|
22 | dd = 1; |
---|
23 | } |
---|
24 | |
---|
25 | if(Cmpstr(inf, outf)==EQ) |
---|
26 | error(45, "Input file and output file must be different file.\n"); |
---|
27 | if(intype==GENBANK&&outype==MACKE) { |
---|
28 | genbank_to_macke(inf, outf); |
---|
29 | } else if(intype==GENBANK&&outype==GENBANK) { |
---|
30 | genbank_to_genbank(inf, outf); |
---|
31 | } else if(intype==GENBANK&&outype==PAUP) { |
---|
32 | to_paup(inf, outf, GENBANK); |
---|
33 | } else if(intype==GENBANK&&outype==PHYLIP) { |
---|
34 | to_phylip(inf, outf, GENBANK,dd); |
---|
35 | } else if(intype==GENBANK&&outype==PROTEIN) { |
---|
36 | error(69, "Sorry, cannot convert from GENBANK to SWISSPROT, Exit"); |
---|
37 | } else if(intype==GENBANK&&outype==EMBL) { |
---|
38 | genbank_to_embl(inf, outf); |
---|
39 | } else if(intype==GENBANK&&outype==PRINTABLE) { |
---|
40 | to_printable(inf, outf, GENBANK); |
---|
41 | } else if(intype==GENBANK&&outype==ALMA) { |
---|
42 | genbank_to_alma(inf, outf); |
---|
43 | } else if(intype==MACKE&&outype==GENBANK) { |
---|
44 | macke_to_genbank(inf, outf); |
---|
45 | } else if(intype==MACKE&&outype==PAUP) { |
---|
46 | to_paup(inf, outf, MACKE); |
---|
47 | } else if(intype==MACKE&&outype==PHYLIP) { |
---|
48 | to_phylip(inf, outf, MACKE,dd); |
---|
49 | } else if(intype==MACKE&&outype==PROTEIN) { |
---|
50 | macke_to_embl(inf, outf); |
---|
51 | } else if(intype==MACKE&&outype==EMBL) { |
---|
52 | macke_to_embl(inf, outf); |
---|
53 | } else if(intype==MACKE&&outype==PRINTABLE) { |
---|
54 | to_printable(inf, outf, MACKE); |
---|
55 | } else if(intype==MACKE&&outype==ALMA) { |
---|
56 | macke_to_alma(inf, outf); |
---|
57 | } else if(intype==PAUP&&outype==GENBANK) { |
---|
58 | error(6, "Sorry, cannot convert from Paup to GENBANK, Exit.\n"); |
---|
59 | } else if(intype==PAUP&&outype==MACKE) { |
---|
60 | error(81, "Sorry, cannot convert from Paup to AE2, Exit.\n"); |
---|
61 | } else if(intype==PAUP&&outype==PHYLIP) { |
---|
62 | error(8, "Sorry, cannot convert from Paup to Phylip, Exit.\n"); |
---|
63 | } else if(intype==PAUP&&outype==PROTEIN) { |
---|
64 | error(71, "Sorry, cannot convert from Paup to SWISSPROT, Exit."); |
---|
65 | } else if(intype==PAUP&&outype==EMBL) { |
---|
66 | error(78, "Sorry, cannot convert from Paup to SWISSPROT, Exit."); |
---|
67 | } else if(intype==PHYLIP&&outype==GENBANK) { |
---|
68 | error(85, "Sorry, cannot convert from Phylip to GenBank, Exit.\n"); |
---|
69 | } else if(intype==PHYLIP&&outype==MACKE) { |
---|
70 | error(88, "Sorry, cannot convert from Phylip to AE2, Exit.\n"); |
---|
71 | } else if(intype==PHYLIP&&outype==PAUP) { |
---|
72 | error(89, "Sorry, cannot convert from Phylip to Paup, Exit.\n"); |
---|
73 | } else if(intype==PHYLIP&&outype==PROTEIN) { |
---|
74 | error(72, "Sorry, cannot convert from Phylip to SWISSPROT, Exit.\n"); |
---|
75 | } else if(intype==PHYLIP&&outype==EMBL) { |
---|
76 | error(79, "Sorry, cannot convert from Phylip to SWISSPROT, Exit.\n"); |
---|
77 | } else if(intype==PROTEIN&&outype==MACKE) { |
---|
78 | embl_to_macke(inf, outf, PROTEIN); |
---|
79 | } else if(intype==PROTEIN&&outype==GENBANK) { |
---|
80 | error(78, "GenBank doesn't maintain protein data."); |
---|
81 | /* embl_to_genbank(inf, outf, PROTEIN); */ |
---|
82 | /* protein_to_genbank(inf, outf); */ |
---|
83 | } else if(intype==PROTEIN&&outype==PAUP) { |
---|
84 | to_paup(inf, outf, PROTEIN); |
---|
85 | } else if(intype==PROTEIN&&outype==PHYLIP) { |
---|
86 | to_phylip(inf, outf, PROTEIN,dd); |
---|
87 | } else if(intype==PROTEIN&&outype==EMBL) { |
---|
88 | error(58, "EMBL doesn't maintain protein data."); |
---|
89 | /* embl_to_embl(inf, outf, PROTEIN); */ |
---|
90 | } else if(intype==PROTEIN&&outype==PRINTABLE) { |
---|
91 | to_printable(inf, outf, PROTEIN); |
---|
92 | } else if(intype==EMBL&&outype==EMBL) { |
---|
93 | embl_to_embl(inf, outf); |
---|
94 | } else if(intype==EMBL&&outype==GENBANK) { |
---|
95 | embl_to_genbank(inf, outf); |
---|
96 | } else if(intype==EMBL&&outype==MACKE) { |
---|
97 | embl_to_macke(inf, outf, EMBL); |
---|
98 | } else if(intype==EMBL&&outype==PROTEIN) { |
---|
99 | embl_to_embl(inf, outf); |
---|
100 | } else if(intype==EMBL&&outype==PAUP) { |
---|
101 | to_paup(inf, outf, EMBL); |
---|
102 | } else if(intype==EMBL&&outype==PHYLIP) { |
---|
103 | to_phylip(inf, outf, EMBL,dd); |
---|
104 | } else if(intype==EMBL&&outype==PRINTABLE) { |
---|
105 | to_printable(inf, outf, EMBL); |
---|
106 | } else if(intype==EMBL&&outype==ALMA) { |
---|
107 | embl_to_alma(inf, outf); |
---|
108 | } else if(intype==ALMA&&outype==MACKE) { |
---|
109 | alma_to_macke(inf, outf); |
---|
110 | } else if(intype==ALMA&&outype==GENBANK) { |
---|
111 | alma_to_genbank(inf, outf); |
---|
112 | } else if(intype==ALMA&&outype==PAUP) { |
---|
113 | to_paup(inf, outf, ALMA); |
---|
114 | } else if(intype==ALMA&&outype==PHYLIP) { |
---|
115 | to_phylip(inf, outf, ALMA,dd); |
---|
116 | } else if(intype==ALMA&&outype==PRINTABLE) { |
---|
117 | to_printable(inf, outf, ALMA); |
---|
118 | } else if(outype==GCG) { |
---|
119 | to_gcg(intype, inf); |
---|
120 | } else error(90, "Unidentified input type or output type, Exit\n"); |
---|
121 | } |
---|
122 | |
---|
123 | /* ------------------- COMMON SUBROUTINES ----------------------- */ |
---|
124 | |
---|
125 | /* -------------------------------------------------------------- |
---|
126 | * Function init(). |
---|
127 | * Initialize data structure at the very beginning of running |
---|
128 | * any program. |
---|
129 | */ |
---|
130 | void |
---|
131 | init() { |
---|
132 | |
---|
133 | /* initialize macke format */ |
---|
134 | data.macke.seqabbr = NULL; |
---|
135 | data.macke.name = NULL; |
---|
136 | data.macke.atcc = NULL; |
---|
137 | data.macke.rna = NULL; |
---|
138 | data.macke.date = NULL; |
---|
139 | data.macke.nbk = NULL; |
---|
140 | data.macke.acs = NULL; |
---|
141 | data.macke.who = NULL; |
---|
142 | data.macke.remarks = NULL; |
---|
143 | data.macke.numofrem = 0; |
---|
144 | data.macke.rna_or_dna = 'd'; |
---|
145 | data.macke.journal = NULL; |
---|
146 | data.macke.title = NULL; |
---|
147 | data.macke.author = NULL; |
---|
148 | data.macke.strain = NULL; |
---|
149 | data.macke.subspecies = NULL; |
---|
150 | /* initialize gnebank format */ |
---|
151 | data.gbk.locus = NULL; |
---|
152 | data.gbk.definition = NULL; |
---|
153 | data.gbk.accession = NULL; |
---|
154 | data.gbk.keywords = NULL; |
---|
155 | data.gbk.source = NULL; |
---|
156 | data.gbk.organism = NULL; |
---|
157 | data.gbk.numofref = 0; |
---|
158 | data.gbk.reference = NULL; |
---|
159 | data.gbk.comments.orginf.exist = 0; |
---|
160 | data.gbk.comments.orginf.source = NULL; |
---|
161 | data.gbk.comments.orginf.cc = NULL; |
---|
162 | data.gbk.comments.orginf.formname = NULL; |
---|
163 | data.gbk.comments.orginf.nickname = NULL; |
---|
164 | data.gbk.comments.orginf.commname = NULL; |
---|
165 | data.gbk.comments.orginf.hostorg = NULL; |
---|
166 | data.gbk.comments.seqinf.exist = 0; |
---|
167 | data.gbk.comments.seqinf.RDPid = NULL; |
---|
168 | data.gbk.comments.seqinf.gbkentry = NULL; |
---|
169 | data.gbk.comments.seqinf.methods = NULL; |
---|
170 | data.gbk.comments.seqinf.comp5 = ' '; |
---|
171 | data.gbk.comments.seqinf.comp3 = ' '; |
---|
172 | data.gbk.comments.others = NULL; |
---|
173 | /* initialize paup format */ |
---|
174 | data.paup.ntax = 0; |
---|
175 | data.paup.equate = "~=.|><"; |
---|
176 | data.paup.gap = '-'; |
---|
177 | /* initial phylip data */ |
---|
178 | /* initial embl data */ |
---|
179 | data.embl.id = NULL; |
---|
180 | data.embl.dateu = NULL; |
---|
181 | data.embl.datec = NULL; |
---|
182 | data.embl.description = NULL; |
---|
183 | data.embl.os = NULL; |
---|
184 | data.embl.accession = NULL; |
---|
185 | data.embl.keywords = NULL; |
---|
186 | data.embl.dr = NULL; |
---|
187 | data.embl.numofref = 0; |
---|
188 | data.embl.reference = NULL; |
---|
189 | data.embl.comments.orginf.exist = 0; |
---|
190 | data.embl.comments.orginf.source = NULL; |
---|
191 | data.embl.comments.orginf.cc = NULL; |
---|
192 | data.embl.comments.orginf.formname = NULL; |
---|
193 | data.embl.comments.orginf.nickname = NULL; |
---|
194 | data.embl.comments.orginf.commname = NULL; |
---|
195 | data.embl.comments.orginf.hostorg = NULL; |
---|
196 | data.embl.comments.seqinf.exist = 0; |
---|
197 | data.embl.comments.seqinf.RDPid = NULL; |
---|
198 | data.embl.comments.seqinf.gbkentry = NULL; |
---|
199 | data.embl.comments.seqinf.methods = NULL; |
---|
200 | data.embl.comments.seqinf.comp5 = ' '; |
---|
201 | data.embl.comments.seqinf.comp3 = ' '; |
---|
202 | data.embl.comments.others = NULL; |
---|
203 | /* initial alma data */ |
---|
204 | data.alma.id = NULL; |
---|
205 | data.alma.filename = NULL; |
---|
206 | data.alma.format = UNKNOWN; |
---|
207 | data.alma.defgap = '-'; |
---|
208 | data.alma.num_of_sequence = 0; |
---|
209 | data.alma.sequence = NULL; |
---|
210 | /* inital NBRF data format */ |
---|
211 | data.nbrf.id = NULL; |
---|
212 | data.nbrf.description = NULL; |
---|
213 | /* initial sequence data */ |
---|
214 | data.numofseq = 0; |
---|
215 | data.seq_length = 0; |
---|
216 | data.max = INITSEQ; |
---|
217 | data.sequence = (char*)calloc(1,(unsigned)(sizeof(char)*INITSEQ+1)); |
---|
218 | |
---|
219 | data.ids = NULL; |
---|
220 | data.seqs = NULL; |
---|
221 | data.lengths = NULL; |
---|
222 | data.allocated = 0; |
---|
223 | } |
---|
224 | /* -------------------------------------------------------------- |
---|
225 | * Function init_seq_data(). |
---|
226 | * Init. seq. data. |
---|
227 | */ |
---|
228 | void |
---|
229 | init_seq_data() { |
---|
230 | data.numofseq = 0; |
---|
231 | data.seq_length = 0; |
---|
232 | } |
---|