ARB
seq.cxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : seq.cxx //
4 // Purpose : //
5 // //
6 // =============================================================== //
7 
8 #include "seq.h"
9 #include "ali.h"
10 #include "reader.h"
11 
12 void Seq::out(Writer& write, Format outType) const {
13  ca_assert(outType == EMBL || outType == GENBANK); // others not implemented yet
14 
15  const char *sequence = get_seq();
16  int indk = 1;
17 
18  for (int indi = 0, indj = 0; indi < get_len(); indi++) {
19  if ((indk % 60) == 1) {
20  switch (outType) {
21  case EMBL: write.out(" "); break;
22  case GENBANK: write.outf(" %6d ", indk); break;
23  default: ca_assert(0); break;
24  }
25  }
26  write.out(sequence[indi]);
27  indj++;
28 
29  // blank space follows every 10 bases, but not before '\n'
30  if ((indk % 60) == 0) {
31  write.out('\n');
32  indj = 0;
33  }
34  else if (indj == 10 && indi != (get_len() - 1)) {
35  write.out(' ');
36  indj = 0;
37  }
38  indk++;
39  }
40 
41  if ((indk % 60) != 1)
42  write.out('\n');
43  write.out("//\n");
44 }
45 
46 void read_alignment(Alignment& ali, const FormattedFile& in) {
48  while (1) {
49  SeqPtr seq = new Seq;
50  if (!reader->read_one_entry(*seq)) break;
51  ali.add(seq);
52  }
53 }
54 
55 
Format
Definition: fun.h:10
Definition: ali.h:11
void read_alignment(Alignment &ali, const FormattedFile &in)
Definition: seq.cxx:46
#define ca_assert(cond)
Definition: global.h:33
Definition: reader.h:95
FILE * seq
Definition: rns.c:46
static SmartPtr< FormatReader > create(const FormattedFile &in)
Definition: convert.cxx:13
Generic smart pointer.
Definition: smartptr.h:149
Definition: fun.h:12
Definition: seq.h:43
virtual void out(char ch)=0
virtual int outf(const char *format,...) __ATTR__FORMAT_MEMBER(1)
Definition: reader.cxx:121
void add(SeqPtr sequence)
Definition: ali.h:28
Definition: fun.h:13
int get_len() const
Definition: seq.h:107
const char * get_seq() const
Definition: seq.h:110
void out(Writer &write, Format outType) const
Definition: seq.cxx:12