ARB
printable.cxx
Go to the documentation of this file.
1 #include "input_format.h"
2 #include "reader.h"
3 #include "ali.h"
4 
5 #define PRTLENGTH 62
6 
7 static void printable_print_line(const char *id, const char *sequence, int start, int base_count, Writer& write) {
8  // print one printable line.
9  int indi, index, count, bnum, seq_length;
10 
11  write.out(' ');
12  if ((bnum = str0len(id)) > 10) {
13  // truncate if length of id is greater than 10
14  for (indi = 0; indi < 10; indi++) write.out(id[indi]);
15  bnum = 1;
16  }
17  else {
18  write.out(id);
19  bnum = 10 - bnum + 1;
20  }
21  // fill in the blanks to make up 10 chars id spaces
22  seq_length = str0len(sequence);
23  if (start < seq_length)
24  for (indi = 0; indi < bnum; indi++) write.out(' ');
25  else {
26  write.out('\n');
27  return;
28  }
29  write.outf("%4d ", base_count);
30  for (index = start, count = 0; count < PRTLENGTH && index < seq_length; index++) {
31  write.out(sequence[index]);
32  count++;
33  }
34  write.out('\n');
35 }
36 
37 void to_printable(const FormattedFile& in, const char *outf) {
38  // Convert from some format to PRINTABLE format.
39  if (!is_input_format(in.type())) {
41  }
42 
43  FileWriter write(outf);
44 
45  Alignment ali;
46  read_alignment(ali, in);
47 
48  int total_seq = ali.get_count();
49  int maxsize = ali.get_max_len();
50 
51  ca_assert(implicated(total_seq == 0, maxsize == -1));
52 
53  if (total_seq>0) {
54  int base_nums[total_seq];
55  for (int i = 0; i<total_seq; ++i) base_nums[i] = 0;
56 
57  int current = 0;
58  while (maxsize > current) {
59  for (int indi = 0; indi < total_seq; indi++) {
60  const Seq& seq = ali.get(indi);
61  int length = seq.get_len();
62  const char *sequence = seq.get_seq();
63  int base_count = 0;
64  for (int index = 0; index < PRTLENGTH && (current + index) < length; index++)
65  if (!is_gapchar(sequence[index + current]))
66  base_count++;
67 
68  // check if the first char is base or not
69  int start;
70  if (current < length && !is_gapchar(sequence[current]))
71  start = base_nums[indi] + 1;
72  else
73  start = base_nums[indi];
74 
75  printable_print_line(seq.get_id(), seq.get_seq(), current, start, write);
76  base_nums[indi] += base_count;
77  }
78  current += PRTLENGTH;
79  if (maxsize > current)
80  write.out("\n\n");
81  }
82  }
83 
84  write.seq_done(ali.get_count());
85  write.expect_written();
86 }
87 
CONSTEXPR_INLINE int str0len(const char *str)
Definition: global.h:98
void seq_done()
Definition: reader.h:148
int get_count() const
Definition: ali.h:15
void out(char ch) FINAL_OVERRIDE
Definition: reader.h:139
#define implicated(hypothesis, conclusion)
Definition: arb_assert.h:289
Definition: ali.h:11
Format type() const
Definition: fun.h:62
#define ca_assert(cond)
Definition: global.h:33
void expect_written()
Definition: reader.cxx:97
const char * get_id() const
Definition: seq.h:93
Definition: reader.h:95
FILE * seq
Definition: rns.c:46
int get_max_len() const
Definition: ali.h:22
static HelixNrInfo * start
static void printable_print_line(const char *id, const char *sequence, int start, int base_count, Writer &write)
Definition: printable.cxx:7
Definition: seq.h:43
virtual void out(char ch)=0
CONSTEXPR_INLINE bool is_input_format(Format inType)
Definition: fun.h:28
virtual int outf(const char *format,...) __ATTR__FORMAT_MEMBER(1)
Definition: reader.cxx:121
const Seq & get(int idx) const
Definition: ali.h:19
void throw_conversion_not_supported(Format inType, Format ouType)
Definition: fconv.cxx:27
int get_len() const
Definition: seq.h:107
void to_printable(const FormattedFile &in, const char *outf)
Definition: printable.cxx:37
bool is_gapchar(char ch)
Definition: global.h:119
Definition: fun.h:23
void read_alignment(Alignment &ali, const FormattedFile &in)
Definition: seq.cxx:46
const char * get_seq() const
Definition: seq.h:110
#define PRTLENGTH
Definition: printable.cxx:5
size_t length