vdj_pipe
pipeline for processing DNA sequence data
pipeline.hpp
Go to the documentation of this file.
1 
7 #ifndef PIPELINE_HPP_
8 #define PIPELINE_HPP_
9 #include <vector>
10 #include "boost/foreach.hpp"
11 #include "boost/property_tree/ptree.hpp"
14 #include "vdj_pipe/exception.hpp"
16 
17 namespace vdj_pipe{
18 
21 template<class Config> class Pipeline {
22  typedef typename Config::input_step input_step;
23  typedef typename Config::processing_step processing_step;
24  typedef typename Config::value_map_access vm_access;
25  typedef std::vector<processing_step> step_vector;
26 public:
27  static std::string const& name() {return Config::name();}
28 
29  explicit Pipeline(Pipe_environment const& pe) : pe_(pe) {}
30 
33  Pipe_environment const& pe
34  )
35  : pe_(pe),
36  sv_(),
37  vma_()
38  {
39  BOOST_FOREACH(
40  boost::property_tree::ptree::value_type const& vt,
41  pt.get_child(name())
42  ) {
43  add_step(vt);
44  }
45  }
46 
48  add_step(create_step<Config>(vma_, pt, pe_));
49  }
50 
51  void add_step(processing_step const& step) {sv_.push_back(step);}
52 
53  vm_access const& value_map() const {return vma_;}
54  vm_access& value_map() {return vma_;}
55 
56  void process_read() {
57  try{
58  Run_visitor rv;
59  BOOST_FOREACH(processing_step& step, sv_) {
60  boost::apply_visitor(rv, step);
61  }
62  } catch(std::exception const&) {
63  BOOST_THROW_EXCEPTION(
65  << base_exception::msg_t("error processing read")
66  << base_exception::str1_t(sanitize(vma_.read_id_nothrow()))
67  << base_exception::nested_t(boost::current_exception())
68  );
69  }
70  vma_.clear_values();
71  }
72 
73  std::size_t size() const {return sv_.size();}
74  processing_step const& step(const std::size_t n) const {return sv_[n];}
75 
76  void run() {while( ins_.run() ) process_read();}
77 
78  void finalize() {
79  Finish_visitor finish;
80  BOOST_FOREACH(processing_step& step, sv_) {
81  boost::apply_visitor(finish, step);
82  }
83  }
84 
85 private:
87  input_step ins_;
88  step_vector sv_;
89  vm_access vma_;
90 };
91 
92 }//namespace vdj_pipe
93 #endif /* PIPELINE_HPP_ */
input_step ins_
Definition: pipeline.hpp:87
vm_access vma_
Definition: pipeline.hpp:89
void finalize()
Definition: pipeline.hpp:78
void add_step(processing_step const &step)
Definition: pipeline.hpp:51
step_vector sv_
Definition: pipeline.hpp:88
vm_access & value_map()
Definition: pipeline.hpp:54
Pipeline(boost::property_tree::ptree const &pt, Pipe_environment const &pe)
Definition: pipeline.hpp:31
Pipeline(Pipe_environment const &pe)
Definition: pipeline.hpp:29
Config::input_step input_step
Definition: pipeline.hpp:22
std::vector< processing_step > step_vector
Definition: pipeline.hpp:25
Main namespace of vdj_pipe library.
Definition: keywords_variable.hpp:11
static std::string const & name()
Definition: pipeline.hpp:27
vm_access const & value_map() const
Definition: pipeline.hpp:53
Config::processing_step processing_step
Definition: pipeline.hpp:23
std::size_t size() const
Definition: pipeline.hpp:73
boost::errinfo_nested_exception nested_t
Definition: exception.hpp:32
Definition: pipe_environment.hpp:26
Config::value_map_access vm_access
Definition: pipeline.hpp:24
void add_step(boost::property_tree::ptree const &pt)
Definition: pipeline.hpp:47
void run()
Definition: pipeline.hpp:76
void process_read()
Definition: pipeline.hpp:56
Definition: visitor.hpp:18
boost::error_info< struct errinfo_str1_, std::string > str1_t
Definition: exception.hpp:25
const std::size_t n
Definition: vector_set_test.cpp:26
Definition: exception.hpp:23
Pipe_environment pe_
Definition: pipeline.hpp:86
boost::error_info< struct errinfo_message_, std::string > msg_t
Definition: exception.hpp:24
std::string sanitize(const char c)
Definition: sanitize_string.cpp:53
Definition: pipeline.hpp:21
processing_step const & step(const std::size_t n) const
Definition: pipeline.hpp:74
bpt::ptree ptree
Definition: processing_step_utils.hpp:19
Definition: visitor.hpp:35