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())) { |
---|
40 | throw_conversion_not_supported(in.type(), PRINTABLE); |
---|
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 | |
---|