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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
/* codata.c - CODATA sequence functions */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#ifdef STDC_HEADERS
# include <string.h>
#endif
#include "sequence.h"
#include "sequence/codata.h"
#include "sequence/protein.h"
/* Functions prototypes */
extern sequence_t *codatay_parse(FILE *);
extern int codatay_check(FILE *);
unsigned int codata_checksum(char *);
/* Parse CODATA sequence */
sequence_t *codata_parse(FILE *f) {
sequence_t *seq;
seq = codatay_parse(f);
return seq; }
/* Checks CODATA sequence */
int codata_check(FILE *f) {
int i;
i = codatay_check(f);
return i; }
/* Print CODATA sequence */
void codata_print(FILE *f, sequence_t *seq) {
char *p, *q, **x;
const char *r, *s;
float w;
int i, max;
long l;
size_t len, sep;
unsigned int c;
if (seq == NULL) { return; }
/* Inits */
max = 80;
/* Name */
r = (seq->nam != NULL) ? seq->nam : "UNKNWN" ; s = "complete";
(void)fprintf(f, "ENTRY %.6s #type %s\n", r, s);
/* Description */
p = seq->dsc; i = 1;
while (p && *p) {
while (*p && *p == ' ') { p++; }
if (i == 1) {
(void)fprintf(f, "TITLE "); i = 0; }
else {
(void)fprintf(f, " "); }
q = p;
while (*q && q - p < max - 16) { q++; }
while (*q && *q != ' ') { q--; }
while (*p && q - p > 0) {
(void)fputc(*p, f); p++; }
(void)fputc('\n', f);
p = q; }
/* Accession */
x = seq->acc; l = 0;
while (x && *x) {
switch (l) {
case 0: s = "ACCESSIONS "; break;
case 16: s = ""; break;
default: s = "; "; break; }
len = strlen(*x); sep = strlen(s);
if (l + sep + len + 2 > max - 5) {
l = 0; (void)fprintf(f, ";\n"); continue; }
(void)fprintf(f, "%s%s", s, *x);
l += sep + len; x++; }
if (l != 0) { (void)fputc('\n', f); }
/* Sequence Header */
w = protein_weight(seq->str); c = codata_checksum(seq->str);
(void)fprintf(f, "SUMMARY #length %lu", seq->strlen);
(void)fprintf(f, " #molecular-weight %u ", (unsigned int)w);
(void)fprintf(f, " #checksum %u", c);
(void)fputc('\n', f);
/* Sequence */
(void)fprintf(f, "SEQUENCE\n");
(void)fprintf(f, " ");
for (i = 5; i <= 30; i += 5) {
(void)fprintf(f, "%10i", i); }
(void)fputc('\n', f);
p = seq->str;
while (*p) {
l = p - seq->str;
if (l % 30 == 0 && l > 0) {
(void)fputc('\n', f); }
if (l % 30 == 0) {
(void)fprintf(f, "%8li", l+1); }
if (*p == '*') { p++; continue; }
(void)fputc(' ', f);
(void)fputc(*p, f);
p++; }
(void)fputc('\n', f);
/* End */
(void)fprintf(f, "///\n");
return; }
/* Codata sequence checksum */
unsigned int codata_checksum(char *seq) {
char *p;
unsigned int nb, lsum, cksum;
p = seq; cksum = nb = 0;
while (*p) {
nb++;
cksum += nb * (*p);
if (nb == 57) { nb = 0; }
p++; }
lsum = cksum / 10000;
cksum -= lsum * 10000;
return cksum; }
|