1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
/* gcg.c - GCG sequence functions */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "sequence.h"
#include "sequence/gcg.h"
#include "compat.h"
#define crc_t unsigned long
/* Functions prototypes */
extern sequence_t *gcgy_parse(FILE *);
extern int gcgy_check(FILE *);
crc_t gcg_crc(char *);
/* Parse GCG sequence */
sequence_t *gcg_parse(FILE *f) {
sequence_t *seq;
seq = gcgy_parse(f);
return seq; }
/* Checks GCG sequence */
int gcg_check(FILE *f) {
int i;
i = gcgy_check(f);
return i; }
/* Print GCG sequence */
void gcg_print(FILE *f, sequence_t *seq) {
char *p, c, d[255];
const char *q;
double v;
long l;
time_t tt;
struct tm ts;
crc_t crc;
seqtyp_t t;
if (seq == NULL) { return; }
t = sequence_type(seq->str);
d[0] = '\0'; tt = time(NULL);
(void)localtime_r(&tt, &ts);
(void)strftime(d, 100, "%B %e, %Y %H:%M", &ts);
/* FIXME: Header (comment, annots, ...) */
c = (t == SEQTYP_PRO) ? 'A' : 'N'; v = 1.0;
(void)fprintf(f, "!!%cA_SEQUENCE %.1f\n", c, v);
c = (t == SEQTYP_PRO) ? 'P' : 'N';
q = "unknown"; crc = gcg_crc(seq->str);
(void)fprintf(f, "%s Length: %"PRIsiz" %s", q, seq->strlen, d);
(void)fprintf(f, " Type: %c Check: %04lu", c, crc);
(void)fprintf(f, " ..\n");
/* Sequence */
p = seq->str;
while (*p) {
l = p - seq->str;
if (l % 50 == 0 && l > 0) {
(void)fputc('\n', f); }
if (l % 50 == 0) {
(void)fprintf(f, "\n%8li ", l+1); }
if (l % 10 == 0 && l % 50 != 0) {
(void)fputc(' ', f); }
if (*p == '*') { p++; continue; }
(void)fputc(*p, f);
p++; }
(void)fputc('\n', f);
(void)fputc('\n', f);
return; }
/* Calculate GCG sequence CRC */
crc_t gcg_crc(char *str) {
char *p;
int i;
crc_t crc;
crc = 0; i = 0; p = str;
while (p && *p) {
crc += ((i % 57) + 1) * toupper((unsigned char)*p);
i++; p++; }
crc %= 10000;
return crc; }
|