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 
31  Pipeline(
32  boost::property_tree::ptree const& pt,
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 
47  void add_step(boost::property_tree::ptree const& pt) {
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:
86  Pipe_environment pe_;
87  input_step ins_;
88  step_vector sv_;
89  vm_access vma_;
90 };
91 
92 }//namespace vdj_pipe
93 #endif /* PIPELINE_HPP_ */
Main namespace of vdj_pipe library.
Definition: sequence_file.hpp:14
Definition: pipe_environment.hpp:26
Definition: visitor.hpp:18
Definition: exception.hpp:23
Definition: pipeline.hpp:21
Definition: visitor.hpp:35