ARB
SEC_io.cxx
Go to the documentation of this file.
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 
17 using namespace std;
18 
20  x_string.addXpair(get_sequence_start(), get_sequence_end());
21 }
22 
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 
33 SEC_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 
44 inline void do_indent(ostream& out, int indent) {
45  for (int i=0; i<indent; i++) out << "\t";
46 }
47 
48 class Block {
49  int& indent;
50  ostream& out;
51 public:
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 
68 void 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 
73 void 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 
80 void 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 
92 void 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 
109  delete xString;
110  xString = NULp;
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 
string result
void do_indent(ostream &out, int indent)
Definition: SEC_io.cxx:44
int getXleftOf(size_t abspos) const
Definition: SEC_abspos.cxx:114
char * buildStructureString()
Definition: SEC_io.cxx:108
STL namespace.
#define DATA_VERSION
Definition: SEC_root.hxx:43
void generate_x_string(XString &x_string)
Definition: SEC_io.cxx:19
void initialize()
Definition: SEC_abspos.cxx:60
Block(const char *name, ostream &Out, int &Indent)
Definition: SEC_io.cxx:52
Definition: output.h:122
~Block()
Definition: SEC_io.cxx:61
void generate_x_string()
Definition: SEC_io.cxx:23
void save(std::ostream &out, int indent, const XString &x_string)
Definition: SEC_io.cxx:73
#define NULp
Definition: cxxforward.h:116
Definition: SEC_io.cxx:48
#define sec_assert(cond)
Definition: SEC_defs.hxx:19
void addXpair(size_t start, size_t end)
Definition: SEC_abspos.hxx:62