Scaffolding  0.1
This program can assemble genome scaffolds using the pairing information in paired-end reads.
read_phytree.hpp
1 
2 #ifndef READ_PHYTREE_HPP
3 #define READ_PHYTREE_HPP
4 
5 #include <iostream>
6 #include <string>
7 
8 #include "utils/phylo_typedefs.hpp"
9 
10 namespace io {
11  static std::string delimeters("\t\n ,");
12  static std::string open_brackets("([{");
13  static std::string close_brackets("}])");
14  static std::string newlines("\r\n");
15  static std::string non_name_chars(delimeters + open_brackets + close_brackets);
16 
17  // read a tree in bracket notation and return success
18  bool read_rooted_tree_from_brackets_internal(PhyloNet& N, const PhyloNet::InternVertex& parent, std::istream& in){
19  // eat leading spaces
20  in >> std::ws;
21  // if we read eof prematurely (or the string is empty), return failure
22  if(in.eof()) return false;
23  // prepare vertex
24  PhyloNet::InternVertex root = N.add_vertex(parent);
25  // either read an open bracket and recurse or read the name of the leaf
26  int c;
27  if(open_brackets.find(in.peek()) != std::string::npos){
28  do{
29  // consume open bracket or delimeter and skip whitespces
30  in.get();
31  in >> std::ws;
32  // then recurse
33  if(!read_rooted_tree_from_brackets_internal(N, root, in)) return false;
34  // until we find no more delimeters
35  } while(delimeters.find(in.peek()) != std::string::npos);
36  // skip whitespaces to the closing bracket
37  in >> std::ws;
38  // consume the closing bracket
39  c = in.get();
40  if(close_brackets.find(c) == std::string::npos) return false;
41  } else {
42  // if we do not have children, we are a leaf
43  std::string name;
44  do{
45  c = in.peek();
46  if(non_name_chars.find(c) != std::string::npos) break;
47  in.get();
48  name += (char)c;
49  } while(true);
50  N.make_leaf(root, name);
51  }// if
52  return true;
53  }// function
54  // version without the index reference
55  bool read_rooted_tree_from_brackets(PhyloNet& N, std::istream& in){
56  return read_rooted_tree_from_brackets_internal(N, N.set_root(), in);
57  }
58 }
59 
60 
61 #endif
62 
Definition: read_phytree.hpp:10