| 1 | /* -------------------- Macke related subroutines -------------- */ |
|---|
| 2 | |
|---|
| 3 | #include <stdio.h> |
|---|
| 4 | #include "convert.h" |
|---|
| 5 | #include "global.h" |
|---|
| 6 | |
|---|
| 7 | #define MACKELIMIT 10000 |
|---|
| 8 | |
|---|
| 9 | /* ------------------------------------------------------------- |
|---|
| 10 | * Function init_mache(). |
|---|
| 11 | * Initialize macke entry. |
|---|
| 12 | */ |
|---|
| 13 | void |
|---|
| 14 | init_macke() { |
|---|
| 15 | |
|---|
| 16 | /* void Freespace(); */ |
|---|
| 17 | /* char *Dupstr(); */ |
|---|
| 18 | int indi; |
|---|
| 19 | |
|---|
| 20 | /* initialize macke format */ |
|---|
| 21 | Freespace(&(data.macke.seqabbr)); |
|---|
| 22 | Freespace(&(data.macke.name)); |
|---|
| 23 | Freespace(&(data.macke.atcc)); |
|---|
| 24 | Freespace(&(data.macke.rna)); |
|---|
| 25 | Freespace(&(data.macke.date)); |
|---|
| 26 | Freespace(&(data.macke.nbk)); |
|---|
| 27 | Freespace(&(data.macke.acs)); |
|---|
| 28 | Freespace(&(data.macke.who)); |
|---|
| 29 | for(indi=0; indi<data.macke.numofrem; indi++) { |
|---|
| 30 | Freespace(&(data.macke.remarks[indi])); |
|---|
| 31 | } |
|---|
| 32 | Freespace((char**)&(data.macke.remarks)); |
|---|
| 33 | Freespace(&(data.macke.journal)); |
|---|
| 34 | Freespace(&(data.macke.title)); |
|---|
| 35 | Freespace(&(data.macke.author)); |
|---|
| 36 | Freespace(&(data.macke.strain)); |
|---|
| 37 | Freespace(&(data.macke.subspecies)); |
|---|
| 38 | |
|---|
| 39 | data.macke.seqabbr=Dupstr(""); |
|---|
| 40 | data.macke.name=Dupstr("\n"); |
|---|
| 41 | data.macke.atcc=Dupstr("\n"); |
|---|
| 42 | data.macke.rna=Dupstr("\n"); |
|---|
| 43 | data.macke.date=Dupstr("\n"); |
|---|
| 44 | data.macke.nbk=Dupstr("\n"); |
|---|
| 45 | data.macke.acs=Dupstr("\n"); |
|---|
| 46 | data.macke.who=Dupstr("\n"); |
|---|
| 47 | data.macke.numofrem=0; |
|---|
| 48 | data.macke.rna_or_dna='d'; |
|---|
| 49 | data.macke.journal=Dupstr("\n"); |
|---|
| 50 | data.macke.title=Dupstr("\n"); |
|---|
| 51 | data.macke.author=Dupstr("\n"); |
|---|
| 52 | data.macke.strain=Dupstr("\n"); |
|---|
| 53 | data.macke.subspecies=Dupstr("\n"); |
|---|
| 54 | } |
|---|
| 55 | /* ------------------------------------------------------------- |
|---|
| 56 | * Function macke_in(). |
|---|
| 57 | * Read in one sequence data from Macke file. |
|---|
| 58 | */ |
|---|
| 59 | char |
|---|
| 60 | macke_in(fp1, fp2, fp3) |
|---|
| 61 | FILE_BUFFER fp1; |
|---|
| 62 | FILE_BUFFER fp2; |
|---|
| 63 | FILE_BUFFER fp3; |
|---|
| 64 | { |
|---|
| 65 | static char line1[LINENUM]; |
|---|
| 66 | static char line2[LINENUM]; |
|---|
| 67 | static char line3[LINENUM]; |
|---|
| 68 | static int first_time = 1; |
|---|
| 69 | char oldname[TOKENNUM], name[TOKENNUM]; |
|---|
| 70 | char /*seq[LINENUM], */ key[TOKENNUM], temp[LINENUM]; |
|---|
| 71 | char *eof1, *eof2, *eof3; |
|---|
| 72 | /* char *Reallocspace(), *Dupstr(); */ |
|---|
| 73 | /* char *Fgetline(), *macke_origin(); */ |
|---|
| 74 | /* char *macke_one_entry_in(); */ |
|---|
| 75 | int numofrem = 0 /*, seqnum*/; |
|---|
| 76 | /* int indj; */ |
|---|
| 77 | int index; |
|---|
| 78 | /* int Cmpstr(), macke_abbrev(); */ |
|---|
| 79 | /* void Freespace(), warning(); */ |
|---|
| 80 | |
|---|
| 81 | /* file 1 points to seq. information */ |
|---|
| 82 | /* file 2 points to seq. data */ |
|---|
| 83 | /* file 3 points to seq. names */ |
|---|
| 84 | if(first_time) { |
|---|
| 85 | /* skip to next "#:" line */ |
|---|
| 86 | for(eof1=Fgetline(line1, LINENUM, fp1); |
|---|
| 87 | eof1!=NULL&&(line1[0]!='#'||line1[1]!=':'); |
|---|
| 88 | eof1=Fgetline(line1, LINENUM, fp1)) ; |
|---|
| 89 | |
|---|
| 90 | /* skip all "#" lines to where seq. data is */ |
|---|
| 91 | for(eof2=Fgetline(line2, LINENUM, fp2); |
|---|
| 92 | eof2!=NULL |
|---|
| 93 | &&(line2[0]=='\n'||line2[0]==' '||line2[0]=='#'); |
|---|
| 94 | eof2=Fgetline(line2, LINENUM, fp2)) ; |
|---|
| 95 | |
|---|
| 96 | /* skip to "#=" lines */ |
|---|
| 97 | for(eof3=Fgetline(line3, LINENUM, fp3); |
|---|
| 98 | eof3!=NULL&&(line3[0]!='#'||line3[1]!='='); |
|---|
| 99 | eof3=Fgetline(line3, LINENUM, fp3)) ; |
|---|
| 100 | |
|---|
| 101 | first_time = 0; |
|---|
| 102 | } else |
|---|
| 103 | eof3=Fgetline(line3, LINENUM, fp3); |
|---|
| 104 | |
|---|
| 105 | /* end of reading seq names */ |
|---|
| 106 | if(line3[0]!='#'||line3[1]!='=') return(EOF); |
|---|
| 107 | |
|---|
| 108 | /* skip to next "#:" line or end of file */ |
|---|
| 109 | if(line1[0]!='#'||line1[1]!=':') { |
|---|
| 110 | for( ;eof1!=NULL&&(line1[0]!='#'||line1[1]!=':'); |
|---|
| 111 | eof1=Fgetline(line1, LINENUM, fp1)) ; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | /* read in seq name */ |
|---|
| 115 | index = macke_abbrev(line3, oldname, 2); |
|---|
| 116 | Freespace(&data.macke.seqabbr); |
|---|
| 117 | data.macke.seqabbr=Dupstr(oldname); |
|---|
| 118 | |
|---|
| 119 | /* read seq. information */ |
|---|
| 120 | for(index=macke_abbrev(line1, name, 2); |
|---|
| 121 | eof1!=NULL&&line1[0]=='#'&&line1[1]==':' |
|---|
| 122 | &&Cmpstr(name, oldname)==EQ; ) |
|---|
| 123 | { |
|---|
| 124 | index = macke_abbrev(line1, key, index); |
|---|
| 125 | if(Cmpstr(key, "name")==EQ) { |
|---|
| 126 | eof1 = macke_one_entry_in(fp1, "name", oldname, |
|---|
| 127 | &(data.macke.name), line1, index); |
|---|
| 128 | } else if(Cmpstr(key, "atcc")==EQ) { |
|---|
| 129 | eof1 = macke_one_entry_in(fp1, "atcc", oldname, |
|---|
| 130 | &(data.macke.atcc), line1, index); |
|---|
| 131 | } else if(Cmpstr(key, "rna")==EQ) { |
|---|
| 132 | /* old version entry */ |
|---|
| 133 | eof1 = macke_one_entry_in(fp1, "rna", oldname, |
|---|
| 134 | &(data.macke.rna), line1, index); |
|---|
| 135 | } else if(Cmpstr(key, "date")==EQ) { |
|---|
| 136 | eof1 = macke_one_entry_in(fp1, "date", oldname, |
|---|
| 137 | &(data.macke.date), line1, index); |
|---|
| 138 | } else if(Cmpstr(key, "nbk")==EQ) { |
|---|
| 139 | /* old version entry */ |
|---|
| 140 | eof1 = macke_one_entry_in(fp1, "nbk", oldname, |
|---|
| 141 | &(data.macke.nbk), line1, index); |
|---|
| 142 | } else if(Cmpstr(key, "acs")==EQ) { |
|---|
| 143 | eof1 = macke_one_entry_in(fp1, "acs", oldname, |
|---|
| 144 | &(data.macke.acs), line1, index); |
|---|
| 145 | } else if(Cmpstr(key, "subsp")==EQ) { |
|---|
| 146 | eof1 = macke_one_entry_in(fp1, "subsp", oldname, |
|---|
| 147 | &(data.macke.subspecies), line1, index); |
|---|
| 148 | } else if(Cmpstr(key, "strain")==EQ) { |
|---|
| 149 | eof1 = macke_one_entry_in(fp1, "strain", oldname, |
|---|
| 150 | &(data.macke.strain), line1, index); |
|---|
| 151 | } else if(Cmpstr(key, "auth")==EQ) { |
|---|
| 152 | eof1 = macke_one_entry_in(fp1, "auth", oldname, |
|---|
| 153 | &(data.macke.author), line1, index); |
|---|
| 154 | } else if(Cmpstr(key, "title")==EQ) { |
|---|
| 155 | eof1 = macke_one_entry_in(fp1, "title", oldname, |
|---|
| 156 | &(data.macke.title), line1, index); |
|---|
| 157 | } else if(Cmpstr(key, "jour")==EQ) { |
|---|
| 158 | eof1 = macke_one_entry_in(fp1, "jour", oldname, |
|---|
| 159 | &(data.macke.journal), line1, index); |
|---|
| 160 | } else if(Cmpstr(key, "who")==EQ) { |
|---|
| 161 | eof1 = macke_one_entry_in(fp1, "who", oldname, |
|---|
| 162 | &(data.macke.who), line1, index); |
|---|
| 163 | } else if(Cmpstr(key, "rem")==EQ) { |
|---|
| 164 | data.macke.remarks = (char**)Reallocspace((char*)data.macke.remarks, (unsigned) (sizeof(char*)*(numofrem+1))); |
|---|
| 165 | data.macke.remarks[numofrem++] = Dupstr(line1+index); |
|---|
| 166 | eof1=Fgetline(line1, LINENUM, fp1); |
|---|
| 167 | } else { |
|---|
| 168 | sprintf(temp, |
|---|
| 169 | "Unidentified AE2 key word #%s#\n", key); |
|---|
| 170 | warning(144, temp); |
|---|
| 171 | eof1=Fgetline(line1, LINENUM, fp1); |
|---|
| 172 | } |
|---|
| 173 | if(eof1!=NULL&&line1[0]=='#'&&line1[1]==':') |
|---|
| 174 | index=macke_abbrev(line1, name, 2); |
|---|
| 175 | else index = 0; |
|---|
| 176 | } |
|---|
| 177 | data.macke.numofrem = numofrem; |
|---|
| 178 | |
|---|
| 179 | /* read in sequence data */ |
|---|
| 180 | eof2=macke_origin(oldname, line2, fp2); |
|---|
| 181 | |
|---|
| 182 | return(EOF+1); |
|---|
| 183 | } |
|---|
| 184 | /* ----------------------------------------------------------------- |
|---|
| 185 | * Function macke_one_entry_in(). |
|---|
| 186 | * Get one Macke entry. |
|---|
| 187 | */ |
|---|
| 188 | char |
|---|
| 189 | *macke_one_entry_in(fp, key, oldname, var, line, index) |
|---|
| 190 | FILE_BUFFER fp; |
|---|
| 191 | const char *key; |
|---|
| 192 | char *oldname, **var, *line; |
|---|
| 193 | int index; |
|---|
| 194 | { |
|---|
| 195 | char *eof; |
|---|
| 196 | |
|---|
| 197 | if(Lenstr((*var))>1) Append_rp_eoln(var, line+index); |
|---|
| 198 | else replace_entry(var, line+index); |
|---|
| 199 | |
|---|
| 200 | eof = (char*)macke_continue_line(key, oldname, var, line, fp); |
|---|
| 201 | |
|---|
| 202 | return(eof); |
|---|
| 203 | |
|---|
| 204 | } |
|---|
| 205 | /* -------------------------------------------------------------- |
|---|
| 206 | * Function macke_continue_line(). |
|---|
| 207 | * Append macke continue line. |
|---|
| 208 | */ |
|---|
| 209 | char *macke_continue_line(key, oldname, var, line, fp) |
|---|
| 210 | const char *key; |
|---|
| 211 | char *oldname, **var, *line; |
|---|
| 212 | FILE_BUFFER fp; |
|---|
| 213 | { |
|---|
| 214 | char *eof, name[TOKENNUM], newkey[TOKENNUM]; |
|---|
| 215 | int index; |
|---|
| 216 | /* int macke_abbrev(); */ |
|---|
| 217 | /* void Append_rp_eoln(); */ |
|---|
| 218 | |
|---|
| 219 | for(eof=Fgetline(line, LINENUM, fp); |
|---|
| 220 | eof!=NULL; eof=Fgetline(line, LINENUM, fp)) { |
|---|
| 221 | if(Lenstr(line)<=1) continue; |
|---|
| 222 | |
|---|
| 223 | index = macke_abbrev(line, name, 0); |
|---|
| 224 | if(Cmpstr(name, oldname)!=EQ) break; |
|---|
| 225 | |
|---|
| 226 | index = macke_abbrev(line, newkey, index); |
|---|
| 227 | if(Cmpstr(newkey, key)!=EQ) break; |
|---|
| 228 | |
|---|
| 229 | Append_rp_eoln(var, line+index); |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | return(eof); |
|---|
| 233 | } |
|---|
| 234 | /* ---------------------------------------------------------------- |
|---|
| 235 | * Function macke_origin(). |
|---|
| 236 | * Read in sequence data in macke file. |
|---|
| 237 | */ |
|---|
| 238 | char |
|---|
| 239 | *macke_origin(key, line, fp) |
|---|
| 240 | char *key, *line; |
|---|
| 241 | FILE_BUFFER fp; |
|---|
| 242 | { |
|---|
| 243 | int index, indj, seqnum; |
|---|
| 244 | char *eof, name[TOKENNUM], seq[LINENUM]; |
|---|
| 245 | |
|---|
| 246 | /* read in seq. data */ |
|---|
| 247 | data.seq_length=0; |
|---|
| 248 | /* read in line by line */ |
|---|
| 249 | |
|---|
| 250 | index=macke_abbrev(line, name, 0); |
|---|
| 251 | eof=line; |
|---|
| 252 | for(; eof!=NULL&&Cmpstr(key, name)==EQ; ){ |
|---|
| 253 | sscanf(line+index, "%d%s", &seqnum, seq); |
|---|
| 254 | for(indj=data.seq_length; indj<seqnum; indj++) |
|---|
| 255 | if(indj<data.max) |
|---|
| 256 | data.sequence[data.seq_length++] |
|---|
| 257 | = '.'; |
|---|
| 258 | else { |
|---|
| 259 | data.max += 100; |
|---|
| 260 | data.sequence = (char*)Reallocspace |
|---|
| 261 | (data.sequence, (unsigned) |
|---|
| 262 | (sizeof(char)*data.max)); |
|---|
| 263 | data.sequence[data.seq_length++] |
|---|
| 264 | = '.'; |
|---|
| 265 | } |
|---|
| 266 | for(indj=0; seq[indj]!='\n'&&seq[indj]!='\0'; indj++) |
|---|
| 267 | if(data.seq_length<data.max) |
|---|
| 268 | data.sequence[data.seq_length++] |
|---|
| 269 | = seq[indj]; |
|---|
| 270 | else { |
|---|
| 271 | data.max += 100; |
|---|
| 272 | data.sequence = (char*)Reallocspace |
|---|
| 273 | (data.sequence, (unsigned) |
|---|
| 274 | (sizeof(char)*data.max)); |
|---|
| 275 | data.sequence[data.seq_length++] |
|---|
| 276 | = seq[indj]; |
|---|
| 277 | } |
|---|
| 278 | data.sequence[data.seq_length] = '\0'; |
|---|
| 279 | eof=Fgetline(line, LINENUM, fp); |
|---|
| 280 | if(eof!=NULL) index = macke_abbrev(line, name, 0); |
|---|
| 281 | |
|---|
| 282 | } /* reading seq loop */ |
|---|
| 283 | |
|---|
| 284 | return(eof); |
|---|
| 285 | } |
|---|
| 286 | /* -------------------------------------------------------------- |
|---|
| 287 | * Function macke_abbrev(). |
|---|
| 288 | * Find the key in Macke line. |
|---|
| 289 | */ |
|---|
| 290 | int |
|---|
| 291 | macke_abbrev(line, key, index) |
|---|
| 292 | char *line, *key; |
|---|
| 293 | int index; |
|---|
| 294 | { |
|---|
| 295 | int indi; |
|---|
| 296 | |
|---|
| 297 | /* skip white space */ |
|---|
| 298 | index = Skip_white_space(line, index); |
|---|
| 299 | |
|---|
| 300 | for(indi=index; line[indi]!=' '&&line[indi]!=':' |
|---|
| 301 | &&line[indi]!='\t'&&line[indi]!='\n'&&line[indi]!='\0'; |
|---|
| 302 | indi++) |
|---|
| 303 | key[indi-index]=line[indi]; |
|---|
| 304 | |
|---|
| 305 | key[indi-index]='\0'; |
|---|
| 306 | return(indi+1); |
|---|
| 307 | } |
|---|
| 308 | /* -------------------------------------------------------------- |
|---|
| 309 | * Function macke_rem_continue_line(). |
|---|
| 310 | * If there is 3 blanks at the beginning of the line, |
|---|
| 311 | * it is continued line. |
|---|
| 312 | */ |
|---|
| 313 | int |
|---|
| 314 | macke_rem_continue_line(strings, index) |
|---|
| 315 | char **strings; |
|---|
| 316 | int index; |
|---|
| 317 | { |
|---|
| 318 | if(strings[index][0]==':'&&strings[index][1]==' ' |
|---|
| 319 | &&strings[index][2]==' ') |
|---|
| 320 | return(1); |
|---|
| 321 | else return(0); |
|---|
| 322 | } |
|---|
| 323 | /* ------------------------------------------------------------- |
|---|
| 324 | * Function macke_in_name(). |
|---|
| 325 | * Read in next sequence name and data only. |
|---|
| 326 | */ |
|---|
| 327 | char |
|---|
| 328 | macke_in_name(fp) |
|---|
| 329 | FILE_BUFFER fp; |
|---|
| 330 | { |
|---|
| 331 | static char line[LINENUM]; |
|---|
| 332 | static int first_time = 1; |
|---|
| 333 | char /*oldname[TOKENNUM],*/ name[TOKENNUM]; |
|---|
| 334 | char seq[LINENUM]/*, key[TOKENNUM]*/; |
|---|
| 335 | char *eof; |
|---|
| 336 | /* char *Reallocspace(), *Dupstr(); */ |
|---|
| 337 | /* char *Fgetline(); */ |
|---|
| 338 | int numofrem = 0, seqnum; |
|---|
| 339 | int index, indj; |
|---|
| 340 | /* int Cmpstr(), macke_abbrev(); */ |
|---|
| 341 | /* void Freespace(); */ |
|---|
| 342 | |
|---|
| 343 | /* skip other information, file index points to seq. data */ |
|---|
| 344 | if(first_time) { |
|---|
| 345 | |
|---|
| 346 | /* skip all "#" lines to where seq. data is */ |
|---|
| 347 | for(eof=Fgetline(line, LINENUM, fp); |
|---|
| 348 | eof!=NULL&&line[0]=='#'; |
|---|
| 349 | eof=Fgetline(line, LINENUM, fp)) ; |
|---|
| 350 | |
|---|
| 351 | first_time = 0; |
|---|
| 352 | |
|---|
| 353 | } else if(line[0]==EOF) { |
|---|
| 354 | |
|---|
| 355 | line[0]=EOF+1; |
|---|
| 356 | first_time = 1; |
|---|
| 357 | return(EOF); |
|---|
| 358 | } |
|---|
| 359 | |
|---|
| 360 | /* read in seq. data */ |
|---|
| 361 | data.macke.numofrem = numofrem; |
|---|
| 362 | data.seq_length=0; |
|---|
| 363 | |
|---|
| 364 | /* read in line by line */ |
|---|
| 365 | Freespace(&(data.macke.seqabbr)); |
|---|
| 366 | for(index=macke_abbrev(line, name, 0), |
|---|
| 367 | data.macke.seqabbr=Dupstr(name); |
|---|
| 368 | line[0]!=EOF&&Cmpstr(data.macke.seqabbr, name)==EQ; ) |
|---|
| 369 | { |
|---|
| 370 | sscanf(line+index, "%d%s", &seqnum, seq); |
|---|
| 371 | for(indj=data.seq_length; indj<seqnum; indj++) |
|---|
| 372 | if(data.seq_length<data.max) |
|---|
| 373 | data.sequence[data.seq_length++] |
|---|
| 374 | = '.'; |
|---|
| 375 | else { |
|---|
| 376 | data.max += 100; |
|---|
| 377 | data.sequence = (char*)Reallocspace |
|---|
| 378 | (data.sequence, (unsigned) |
|---|
| 379 | (sizeof(char)*data.max)); |
|---|
| 380 | data.sequence[data.seq_length++] |
|---|
| 381 | = '.'; |
|---|
| 382 | } |
|---|
| 383 | for(indj=0; seq[indj]!='\n'&&seq[indj]!='\0'; |
|---|
| 384 | indj++) |
|---|
| 385 | { |
|---|
| 386 | if(data.seq_length<data.max) |
|---|
| 387 | data.sequence[data.seq_length++] |
|---|
| 388 | = seq[indj]; |
|---|
| 389 | else { |
|---|
| 390 | data.max += 100; |
|---|
| 391 | data.sequence = (char*)Reallocspace |
|---|
| 392 | (data.sequence, (unsigned) |
|---|
| 393 | (sizeof(char)*data.max)); |
|---|
| 394 | data.sequence[data.seq_length++] |
|---|
| 395 | = seq[indj]; |
|---|
| 396 | } |
|---|
| 397 | } |
|---|
| 398 | data.sequence[data.seq_length] = '\0'; |
|---|
| 399 | |
|---|
| 400 | if((eof=Fgetline(line, LINENUM, fp))!=NULL) |
|---|
| 401 | index = macke_abbrev(line, name, 0); |
|---|
| 402 | else line[0] = EOF; |
|---|
| 403 | |
|---|
| 404 | } /* reading seq loop */ |
|---|
| 405 | |
|---|
| 406 | return(EOF+1); |
|---|
| 407 | } |
|---|
| 408 | /* ------------------------------------------------------------ |
|---|
| 409 | * Fucntion macke_out_header(). |
|---|
| 410 | * Output the Macke format header. |
|---|
| 411 | */ |
|---|
| 412 | void |
|---|
| 413 | macke_out_header(fp) |
|---|
| 414 | FILE *fp; |
|---|
| 415 | { |
|---|
| 416 | char *date; |
|---|
| 417 | /* void Freespace(), Cypstr(); */ |
|---|
| 418 | |
|---|
| 419 | fprintf(fp, "#-\n#-\n#-\teditor\n"); |
|---|
| 420 | date = today_date(); |
|---|
| 421 | fprintf(fp, "#-\t%s#-\n#-\n", date); |
|---|
| 422 | Freespace(&date); |
|---|
| 423 | } |
|---|
| 424 | /* ------------------------------------------------------------ |
|---|
| 425 | * Fucntion macke_out0(). |
|---|
| 426 | * Output the Macke format each sequence format. |
|---|
| 427 | */ |
|---|
| 428 | void |
|---|
| 429 | macke_out0(fp, format) |
|---|
| 430 | FILE *fp; |
|---|
| 431 | int format; |
|---|
| 432 | { |
|---|
| 433 | /* int Lenstr(); */ |
|---|
| 434 | char token[TOKENNUM], direction[TOKENNUM]; |
|---|
| 435 | /* void Cpystr(); */ |
|---|
| 436 | |
|---|
| 437 | if(format==PROTEIN) { |
|---|
| 438 | Cpystr(token, "pro"); |
|---|
| 439 | Cpystr(direction, "n>c"); |
|---|
| 440 | } else { |
|---|
| 441 | Cpystr(direction, "5>3"); |
|---|
| 442 | if(data.macke.rna_or_dna=='r') Cpystr(token, "rna"); |
|---|
| 443 | else Cpystr(token, "dna"); |
|---|
| 444 | } |
|---|
| 445 | if(data.numofseq==1) { |
|---|
| 446 | fprintf(fp, "#-\tReference sequence: %s\n", |
|---|
| 447 | data.macke.seqabbr); |
|---|
| 448 | fprintf(fp, "#-\tAttributes:\n"); |
|---|
| 449 | |
|---|
| 450 | if(Lenstr(data.macke.seqabbr)<8) |
|---|
| 451 | fprintf(fp, |
|---|
| 452 | "#=\t\t%s\t \tin out vis prt ord %s lin %s func ref\n", |
|---|
| 453 | data.macke.seqabbr, token, direction); |
|---|
| 454 | else |
|---|
| 455 | fprintf(fp, |
|---|
| 456 | "#=\t\t%s\tin out vis prt ord %s lin %s func ref\n", |
|---|
| 457 | data.macke.seqabbr, token, direction); |
|---|
| 458 | |
|---|
| 459 | } else |
|---|
| 460 | if(Lenstr(data.macke.seqabbr)<8) |
|---|
| 461 | fprintf(fp, |
|---|
| 462 | "#=\t\t%s\t\tin out vis prt ord %s lin %s func\n", |
|---|
| 463 | data.macke.seqabbr, token, direction); |
|---|
| 464 | else |
|---|
| 465 | fprintf(fp, |
|---|
| 466 | "#=\t\t%s\tin out vis prt ord %s lin %s func\n", |
|---|
| 467 | data.macke.seqabbr, token, direction); |
|---|
| 468 | } |
|---|
| 469 | /* --------------------------------------------------------------- |
|---|
| 470 | * Fucntion macke_out1(). |
|---|
| 471 | * Output sequences information. |
|---|
| 472 | */ |
|---|
| 473 | void macke_out1(fp) |
|---|
| 474 | FILE *fp; |
|---|
| 475 | { |
|---|
| 476 | /* void macke_print_line_78(), macke_print_keyword_rem(); */ |
|---|
| 477 | char temp[LINENUM]; |
|---|
| 478 | int indi; |
|---|
| 479 | /* int indj, indk, indl, len, maxc, lineno; */ |
|---|
| 480 | /* int last_word(), Lenstr(); */ |
|---|
| 481 | /* int macke_in_one_line(); */ |
|---|
| 482 | |
|---|
| 483 | if(Lenstr(data.macke.name)>1) { |
|---|
| 484 | sprintf(temp, "#:%s:name:", data.macke.seqabbr); |
|---|
| 485 | macke_print_line_78(fp, temp, data.macke.name); |
|---|
| 486 | } |
|---|
| 487 | if(Lenstr(data.macke.strain)>1) { |
|---|
| 488 | sprintf(temp, "#:%s:strain:", data.macke.seqabbr); |
|---|
| 489 | macke_print_line_78(fp, temp, data.macke.strain); |
|---|
| 490 | } |
|---|
| 491 | if(Lenstr(data.macke.subspecies)>1) { |
|---|
| 492 | sprintf(temp, "#:%s:subsp:", data.macke.seqabbr); |
|---|
| 493 | macke_print_line_78 |
|---|
| 494 | (fp, temp, data.macke.subspecies); |
|---|
| 495 | } |
|---|
| 496 | if(Lenstr(data.macke.atcc)>1) { |
|---|
| 497 | sprintf(temp, "#:%s:atcc:", data.macke.seqabbr); |
|---|
| 498 | macke_print_line_78(fp, temp, data.macke.atcc); |
|---|
| 499 | } |
|---|
| 500 | if(Lenstr(data.macke.rna)>1) { |
|---|
| 501 | /* old version entry */ |
|---|
| 502 | sprintf(temp, "#:%s:rna:", data.macke.seqabbr); |
|---|
| 503 | macke_print_line_78(fp, temp, data.macke.rna); |
|---|
| 504 | } |
|---|
| 505 | if(Lenstr(data.macke.date)>1) { |
|---|
| 506 | sprintf(temp, "#:%s:date:", data.macke.seqabbr); |
|---|
| 507 | macke_print_line_78(fp, temp, data.macke.date); |
|---|
| 508 | } |
|---|
| 509 | if(Lenstr(data.macke.acs)>1) { |
|---|
| 510 | sprintf(temp, "#:%s:acs:", data.macke.seqabbr); |
|---|
| 511 | macke_print_line_78(fp, temp, data.macke.acs); |
|---|
| 512 | } |
|---|
| 513 | else if(Lenstr(data.macke.nbk)>1) { |
|---|
| 514 | /* old version entry */ |
|---|
| 515 | sprintf(temp, "#:%s:acs:", data.macke.seqabbr); |
|---|
| 516 | macke_print_line_78(fp, temp, data.macke.nbk); |
|---|
| 517 | } |
|---|
| 518 | if(Lenstr(data.macke.author)>1) { |
|---|
| 519 | sprintf(temp, "#:%s:auth:", data.macke.seqabbr); |
|---|
| 520 | macke_print_line_78(fp, temp, data.macke.author); |
|---|
| 521 | } |
|---|
| 522 | if(Lenstr(data.macke.journal)>1) { |
|---|
| 523 | sprintf(temp, "#:%s:jour:", data.macke.seqabbr); |
|---|
| 524 | macke_print_line_78(fp, temp, data.macke.journal); |
|---|
| 525 | } |
|---|
| 526 | if(Lenstr(data.macke.title)>1) { |
|---|
| 527 | sprintf(temp, "#:%s:title:", data.macke.seqabbr); |
|---|
| 528 | macke_print_line_78(fp, temp, data.macke.title); |
|---|
| 529 | } |
|---|
| 530 | if(Lenstr(data.macke.who)>1) { |
|---|
| 531 | sprintf(temp, "#:%s:who:", data.macke.seqabbr); |
|---|
| 532 | macke_print_line_78(fp, temp, data.macke.who); |
|---|
| 533 | } |
|---|
| 534 | |
|---|
| 535 | /* print out remarks, wrap around if more than 78 columns */ |
|---|
| 536 | for(indi=0; indi<data.macke.numofrem; indi++) |
|---|
| 537 | { |
|---|
| 538 | /* Check if it is general comment or GenBank entry */ |
|---|
| 539 | /* if general comment, macke_in_one_line return(1). */ |
|---|
| 540 | if(macke_in_one_line(data.macke.remarks[indi])) |
|---|
| 541 | { |
|---|
| 542 | sprintf(temp,"#:%s:rem:", data.macke.seqabbr); |
|---|
| 543 | macke_print_line_78 |
|---|
| 544 | (fp, temp, data.macke.remarks[indi]); |
|---|
| 545 | continue; |
|---|
| 546 | } |
|---|
| 547 | |
|---|
| 548 | /* if GenBank entry comments */ |
|---|
| 549 | macke_print_keyword_rem(indi, fp); |
|---|
| 550 | |
|---|
| 551 | } /* for each remark */ |
|---|
| 552 | } |
|---|
| 553 | /* ---------------------------------------------------------------- |
|---|
| 554 | * Function macke_print_keyword_rem(). |
|---|
| 555 | * Print out keyworded remark line in Macke file with |
|---|
| 556 | * wrap around functionality. |
|---|
| 557 | * (Those keywords are defined in GenBank COMMENTS by |
|---|
| 558 | * RDP group) |
|---|
| 559 | */ |
|---|
| 560 | void |
|---|
| 561 | macke_print_keyword_rem(index, fp) |
|---|
| 562 | int index; |
|---|
| 563 | FILE *fp; |
|---|
| 564 | { |
|---|
| 565 | int indj, indk, indl, lineno, len, maxc; |
|---|
| 566 | |
|---|
| 567 | lineno = 0; |
|---|
| 568 | len = Lenstr(data.macke.remarks[index])-1; |
|---|
| 569 | for(indj=0; indj<len; indj+=(indk+1)) { |
|---|
| 570 | indk= maxc =MACKEMAXCHAR-7 |
|---|
| 571 | -Lenstr(data.macke.seqabbr); |
|---|
| 572 | if(lineno!=0) indk = maxc = maxc - 3; |
|---|
| 573 | if((Lenstr(data.macke.remarks[index]+indj)-1) |
|---|
| 574 | > maxc) { |
|---|
| 575 | /* Search the last word */ |
|---|
| 576 | for(indk=maxc-1; indk>=0&& |
|---|
| 577 | !last_word(data.macke.remarks |
|---|
| 578 | [index][indk+indj]); indk--) ; |
|---|
| 579 | |
|---|
| 580 | if(lineno==0) { |
|---|
| 581 | fprintf(fp,"#:%s:rem:", |
|---|
| 582 | data.macke.seqabbr); |
|---|
| 583 | lineno++; |
|---|
| 584 | } else |
|---|
| 585 | fprintf(fp,"#:%s:rem:: ", |
|---|
| 586 | data.macke.seqabbr); |
|---|
| 587 | |
|---|
| 588 | for(indl=0; indl<indk; indl++) |
|---|
| 589 | fprintf(fp,"%c", |
|---|
| 590 | data.macke.remarks[index][indj+indl]); |
|---|
| 591 | |
|---|
| 592 | if(data.macke.remarks[index][indj+indk]!=' ') |
|---|
| 593 | fprintf(fp,"%c", |
|---|
| 594 | data.macke.remarks[index][indj+indk]); |
|---|
| 595 | fprintf(fp, "\n"); |
|---|
| 596 | |
|---|
| 597 | } else if(lineno==0) |
|---|
| 598 | fprintf(fp,"#:%s:rem:%s", data.macke.seqabbr, |
|---|
| 599 | data.macke.remarks[index]+indj); |
|---|
| 600 | else |
|---|
| 601 | fprintf(fp,"#:%s:rem:: %s", |
|---|
| 602 | data.macke.seqabbr, |
|---|
| 603 | data.macke.remarks[index]+indj); |
|---|
| 604 | } /* for every MACKEMAXCHAR columns */ |
|---|
| 605 | } |
|---|
| 606 | /* --------------------------------------------------------------- |
|---|
| 607 | * Function macke_print_line_78(). |
|---|
| 608 | * print a macke line and wrap around line after |
|---|
| 609 | * 78(MACKEMAXCHAR) column. |
|---|
| 610 | */ |
|---|
| 611 | void |
|---|
| 612 | macke_print_line_78(fp, line1, line2) |
|---|
| 613 | FILE *fp; |
|---|
| 614 | char *line1, *line2; |
|---|
| 615 | { |
|---|
| 616 | int len, indi, indj, indk, ibuf; |
|---|
| 617 | |
|---|
| 618 | for(indi=0, len=Lenstr(line2); indi<len; indi+=indj) { |
|---|
| 619 | |
|---|
| 620 | indj=78-Lenstr(line1); |
|---|
| 621 | |
|---|
| 622 | if((Lenstr(line2+indi))>indj) { |
|---|
| 623 | |
|---|
| 624 | ibuf = indj; |
|---|
| 625 | |
|---|
| 626 | for(; indj>0&&!last_word(line2[indi+indj]); |
|---|
| 627 | indj--) ; |
|---|
| 628 | |
|---|
| 629 | if(indj==0) indj=ibuf; |
|---|
| 630 | else if(line2[indi+indj+1]==' ') indj++; |
|---|
| 631 | |
|---|
| 632 | fprintf(fp, "%s", line1); |
|---|
| 633 | |
|---|
| 634 | for(indk=0; indk<indj; indk++) |
|---|
| 635 | fprintf(fp, "%c", line2[indi+indk]); |
|---|
| 636 | |
|---|
| 637 | /* print out the last char if it is not blank */ |
|---|
| 638 | if(line2[indi+indj]==' ') |
|---|
| 639 | indj++; |
|---|
| 640 | |
|---|
| 641 | fprintf(fp, "\n"); |
|---|
| 642 | |
|---|
| 643 | } else fprintf(fp, "%s%s", line1, line2+indi); |
|---|
| 644 | |
|---|
| 645 | } /* for loop */ |
|---|
| 646 | } |
|---|
| 647 | /* ----------------------------------------------------------- |
|---|
| 648 | * Function macke_key_word(). |
|---|
| 649 | * Find the key in Macke line. |
|---|
| 650 | */ |
|---|
| 651 | int |
|---|
| 652 | macke_key_word(line, index, key, length) |
|---|
| 653 | char *line; |
|---|
| 654 | int index; |
|---|
| 655 | char *key; |
|---|
| 656 | int length; |
|---|
| 657 | { |
|---|
| 658 | int indi; |
|---|
| 659 | |
|---|
| 660 | if(line==NULL) { key[0]='\0'; return(index); } |
|---|
| 661 | |
|---|
| 662 | /* skip white space */ |
|---|
| 663 | index = Skip_white_space(line, index); |
|---|
| 664 | |
|---|
| 665 | for(indi=index; (indi-index)<(length-1)&&line[indi]!=':' |
|---|
| 666 | &&line[indi]!='\n'&&line[indi]!='\0'; indi++) |
|---|
| 667 | key[indi-index]=line[indi]; |
|---|
| 668 | |
|---|
| 669 | key[indi-index]='\0'; |
|---|
| 670 | |
|---|
| 671 | return(indi+1); |
|---|
| 672 | } |
|---|
| 673 | /* ------------------------------------------------------------ |
|---|
| 674 | * Function macke_in_one_line(). |
|---|
| 675 | * Check if string should be in one line. |
|---|
| 676 | */ |
|---|
| 677 | int macke_in_one_line(string) |
|---|
| 678 | char *string; |
|---|
| 679 | { |
|---|
| 680 | char keyword[TOKENNUM]; |
|---|
| 681 | int iskey; |
|---|
| 682 | |
|---|
| 683 | macke_key_word(string, 0, keyword, TOKENNUM); |
|---|
| 684 | iskey=0; |
|---|
| 685 | if(Cmpstr(keyword, "KEYWORDS")==EQ) |
|---|
| 686 | iskey=1; |
|---|
| 687 | else if(Cmpstr(keyword, "GenBank ACCESSION")==EQ) |
|---|
| 688 | iskey=1; |
|---|
| 689 | else if(Cmpstr(keyword, "auth")==EQ) |
|---|
| 690 | iskey = 1; |
|---|
| 691 | else if(Cmpstr(keyword, "title")==EQ) |
|---|
| 692 | iskey = 1; |
|---|
| 693 | else if(Cmpstr(keyword, "jour")==EQ) |
|---|
| 694 | iskey = 1; |
|---|
| 695 | else if(Cmpstr(keyword, "standard")==EQ) |
|---|
| 696 | iskey = 1; |
|---|
| 697 | else if(Cmpstr(keyword, "Source of strain")==EQ) |
|---|
| 698 | iskey=1; |
|---|
| 699 | else if(Cmpstr(keyword, "Former name")==EQ) |
|---|
| 700 | iskey = 1; |
|---|
| 701 | else if(Cmpstr(keyword, "Alternate name")==EQ) |
|---|
| 702 | iskey = 1; |
|---|
| 703 | else if(Cmpstr(keyword, "Common name")==EQ) |
|---|
| 704 | iskey = 1; |
|---|
| 705 | else if(Cmpstr(keyword, "Host organism")==EQ) |
|---|
| 706 | iskey = 1; |
|---|
| 707 | else if(Cmpstr(keyword, "RDP ID")==EQ) |
|---|
| 708 | iskey = 1; |
|---|
| 709 | else if(Cmpstr(keyword, "Sequencing methods")==EQ) |
|---|
| 710 | iskey = 1; |
|---|
| 711 | else if(Cmpstr(keyword, "3' end complete")==EQ) |
|---|
| 712 | iskey = 1; |
|---|
| 713 | else if(Cmpstr(keyword, "5' end complete")==EQ) |
|---|
| 714 | iskey = 1; |
|---|
| 715 | |
|---|
| 716 | /* is-key then could be more than one line */ |
|---|
| 717 | /* otherwise, must be in one line */ |
|---|
| 718 | if(iskey) return(0); |
|---|
| 719 | else return(1); |
|---|
| 720 | } |
|---|
| 721 | /* -------------------------------------------------------------- |
|---|
| 722 | * Function macke_out2(). |
|---|
| 723 | * Output Macke format sequences data. |
|---|
| 724 | */ |
|---|
| 725 | void macke_out2(fp) |
|---|
| 726 | FILE *fp; |
|---|
| 727 | { |
|---|
| 728 | int indj, indk; |
|---|
| 729 | char temp[LINENUM]; |
|---|
| 730 | |
|---|
| 731 | if (data.seq_length > MACKELIMIT) { |
|---|
| 732 | sprintf(temp, "Lenght of sequence data is %d over AE2's limit %d.\n", |
|---|
| 733 | data.seq_length, MACKELIMIT); |
|---|
| 734 | warning(145, temp); |
|---|
| 735 | } |
|---|
| 736 | |
|---|
| 737 | for (indk=indj=0; indk<data.seq_length; indk++) |
|---|
| 738 | { |
|---|
| 739 | if(indj==0) fprintf(fp,"%s%6d ", data.macke.seqabbr, indk); |
|---|
| 740 | |
|---|
| 741 | fputc(data.sequence[indk], fp); |
|---|
| 742 | |
|---|
| 743 | indj++; |
|---|
| 744 | if(indj==50) { indj=0; fprintf(fp, "\n"); } |
|---|
| 745 | |
|---|
| 746 | } /* every line */ |
|---|
| 747 | |
|---|
| 748 | if(indj!=0) fprintf(fp, "\n"); |
|---|
| 749 | /* every sequence */ |
|---|
| 750 | } |
|---|