File: fasta.c

package info (click to toggle)
squizz 0.99d%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,772 kB
  • sloc: sh: 4,799; ansic: 2,640; lex: 1,992; yacc: 1,650; makefile: 123
file content (62 lines) | stat: -rw-r--r-- 1,112 bytes parent folder | download | duplicates (5)
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
/* fasta.c - FASTA sequence functions */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>

#include "sequence.h"
#include "sequence/fasta.h"


/* Functions prototypes */
extern sequence_t *fastay_parse(FILE *);
extern int fastay_check(FILE *);


/* Parse FASTA sequence */
sequence_t *fasta_parse(FILE *f) {
  sequence_t *seq;

  seq = fastay_parse(f);

  return seq; }


/* Check FASTA formatted sequence */
int fasta_check(FILE *f) {
  int i;

  i = fastay_check(f);

  return i; }


/* Print FASTA sequence */
void fasta_print(FILE *f, sequence_t *seq) {
  char *p, c;
  const char *q;
  int max;
  long l;

  if (seq == NULL) { return; }

  /* Header */
  q = (seq->nam != NULL) ? seq->nam : "unknown";
  (void)fprintf(f, ">%s", q);
  if (seq->dsc) { (void)fprintf(f, " %s", seq->dsc); }
  (void)fputc('\n', f);

  /* Sequence */
  p = seq->str; max = 80;
  while (*p) {
    l = p - seq->str;
    if (l % max == 0 && l > 0) { (void)fputc('\n', f); }
    c = *p;
    if (c == '~' || c == '.' || c == '?') { c = '-'; }
    (void)fputc(c, f);
    p++; }
  (void)fputc('\n', f);

  return; }