vdj_pipe
pipeline for processing DNA sequence data
input_csv.hpp
Go to the documentation of this file.
1 
7 #ifndef INPUT_CSV_HPP_
8 #define INPUT_CSV_HPP_
9 #include <istream>
10 #include <string>
11 #include <vector>
12 #include "boost/foreach.hpp"
13 #include "boost/property_tree/ptree.hpp"
14 namespace bpt = boost::property_tree;
15 #include "boost/tokenizer.hpp"
17 
18 namespace vdj_pipe{
19 
22 void input_csv_to_tree(std::istream& is, bpt::ptree& pt) {
23  std::vector<std::string> cols;
24  std::string line;
25  typedef Input_manager::Err Err;
26  getline(is, line);
27  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
28  typedef tokenizer::const_iterator iterator;
29  boost::char_separator<char> separator(",\t");
30  tokenizer tok(line, separator);
31  BOOST_FOREACH(std::string const& col_name, tok) {
32  if( col_name.empty() ) BOOST_THROW_EXCEPTION(
33  Err()
34  << Err::msg_t("empty column name")
35  );
36  cols.push_back(col_name);
37  }
38 
39  for( int line_num = 2; getline(is, line); ++line_num ) {
40  tokenizer tok(line, separator);
41  iterator i = tok.begin();
42  if( i.at_end() ) continue;
43  bpt::ptree pt1;
44  for( std::size_t n = 0; ! i.at_end(); ++i, ++n ) {
45  if( n == cols.size() ) BOOST_THROW_EXCEPTION(
46  Err()
47  << Err::msg_t("too many values")
48  << Err::line_t(line_num)
49  );
50  pt1.put(cols[n], *i);
51  }
52  pt.push_back(bpt::ptree::value_type("", pt1));
53  }
54 }
55 
56 }//namespace vdj_pipe
57 #endif /* INPUT_CSV_HPP_ */
Definition: file_properties.hpp:59
Definition: input_manager.hpp:29
Main namespace of vdj_pipe library.
Definition: keywords_variable.hpp:11
boost::tokenizer< boost::char_separator< char > > tokenizer
Definition: me_factory.cpp:34
const std::size_t n
Definition: vector_set_test.cpp:26
bpt::ptree ptree
Definition: processing_step_utils.hpp:19
void input_csv_to_tree(std::istream &is, bpt::ptree &pt)
Convert input data descriptions in CSV format into property tree.
Definition: input_csv.hpp:22
boost::char_separator< char > separator(",\t|")