source: branches/profile/SECEDIT/SEC_io.cxx

Last change on this file was 6385, checked in by westram, 14 years ago
  • removed trailing whitespace
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1// =============================================================== //
2//                                                                 //
3//   File      : SEC_io.cxx                                        //
4//   Purpose   : io-related things                                 //
5//                                                                 //
6//   Institute of Microbiology (Technical University Munich)       //
7//   http://www.arb-home.de/                                       //
8//                                                                 //
9// =============================================================== //
10
11
12#include <sstream>
13
14#include "SEC_root.hxx"
15#include "SEC_iter.hxx"
16
17using namespace std;
18
19void SEC_region::generate_x_string(XString& x_string) {
20    x_string.addXpair(get_sequence_start(), get_sequence_end());
21}
22
23void SEC_root::generate_x_string() {
24    sec_assert(!xString);
25    xString = new XString(db->length());
26
27    for (SEC_base_part_iterator part(this); part; ++part) {
28        part->get_region()->generate_x_string(*xString);
29    }
30    xString->initialize();
31}
32
33SEC_helix_strand * SEC_segment::get_previous_strand() {
34    SEC_helix_strand *strand_pointer = next_helix_strand;
35    SEC_segment *segment_pointer = strand_pointer->get_next_segment();
36
37    while (segment_pointer != this) {
38        strand_pointer = segment_pointer->get_next_strand();
39        segment_pointer = strand_pointer->get_next_segment();
40    }
41    return strand_pointer;
42}
43
44inline void do_indent(ostream& out, int indent) {
45    for (int i=0; i<indent; i++) out << "\t";
46}
47
48class Block {
49    int&     indent;
50    ostream& out;
51public:
52    Block(const char *name, ostream& Out, int& Indent)
53        : indent(Indent)
54        , out(Out)
55    {
56        do_indent(out, indent);
57        out << name << "={\n";
58        ++indent;
59    }
60
61    ~Block() {
62        --indent;
63        do_indent(out, indent);
64        out << "}\n";
65    }
66};
67
68void SEC_segment::save(ostream & out, int indent, const XString& x_string) {
69    Block b("SEGMENT", out, indent);
70    get_region()->save(out, indent, x_string);
71}
72
73void SEC_region::save(ostream & out, int indent, const XString& x_string) {
74    int x_count_start = x_string.getXleftOf(sequence_start);
75    int x_count_end   = x_string.getXleftOf(sequence_end);
76
77    do_indent(out, indent); out << "SEQ=" << x_count_start << ":" << x_count_end << "\n";
78}
79
80void SEC_helix::save(ostream & out, int indent, const XString& x_string) {
81    Block b("STRAND", out, indent);
82
83    strandToOutside()->get_region()->save(out, indent, x_string);
84
85    do_indent(out, indent); out << "REL=" << get_rel_angle().radian() << "\n";
86    do_indent(out, indent); out << "LENGTH=" << minSize() << ":" << maxSize() << "\n";
87
88    outsideLoop()->save(out, indent, x_string);
89    strandToRoot()->get_region()->save(out, indent, x_string);
90}
91
92void SEC_loop::save(ostream & out, int indent, const XString& x_string) {
93    Block b("LOOP", out, indent);
94
95    do_indent(out, indent); out << "RADIUS=" << minSize() << ":" << maxSize() << "\n";
96    do_indent(out, indent); out << "REL=" << get_rel_angle().radian() << "\n";
97
98    SEC_helix *primary   = get_fixpoint_helix();
99    bool       root_loop = is_root_loop();
100
101    for (SEC_strand_iterator strand(this); strand; ++strand) {
102        SEC_helix *helix = strand->get_helix();
103        if (helix != primary || root_loop) helix->save(out, indent, x_string);
104        strand->get_next_segment()->save(out, indent, x_string);
105    }
106}
107
108char *SEC_root::buildStructureString() {
109    delete xString;
110    xString = 0;
111    if (db->canDisplay()) generate_x_string();
112
113    ostringstream out;
114
115    out << "VERSION=" << DATA_VERSION << "\n";
116
117    get_root_loop()->save(out, 0, *xString);
118
119    out << '\0';
120
121    const string&  outstr = out.str();
122    char          *result = new char[outstr.length()+1];
123    strcpy(result, outstr.c_str());
124
125    return result;
126}
127
Note: See TracBrowser for help on using the repository browser.