vdj_pipe
pipeline for processing DNA sequence data
output_manager.hpp
Go to the documentation of this file.
1 
7 #ifndef OUTPUT_MANAGER_HPP_
8 #define OUTPUT_MANAGER_HPP_
9 #include <map>
10 #include <string>
11 #include "boost/filesystem/path.hpp"
12 #include "vdj_pipe/config.hpp"
13 #include "vdj_pipe/exception.hpp"
15 
16 namespace vdj_pipe{
17 
20 class VDJ_PIPE_DECL Output_manager {
21  typedef boost::filesystem::path path_t;
22  static path_t make_dir(std::string const& dir);
23  typedef std::map<std::string,plot::Plot> plot_type_map;
24  typedef plot_type_map::value_type plot_pair;
25 
26 public:
27  struct Err : public base_exception {};
28 
29  explicit Output_manager(
30  std::string const& base_out,
31  std::string const& plot_list_path = "",
32  const char delim = '\t'
33  )
34  : root_(make_dir(base_out)),
35  plot_list_(path(plot_list_path)),
36  csv_delim_(delim)
37  {}
38 
39  char delimiter() const {return csv_delim_;}
40 
41  std::string path(std::string const& fn) const {
42  if( root_.empty() ) return fn;
43  const path_t p(fn);
44  if( p.is_absolute() ) return p.string();
45  return (root_ / p).string();
46  }
47 
48  void register_plot(std::string const& path, const plot::Plot pt) {
49  if( ! ptm_.insert(plot_pair(path, pt)).second ) BOOST_THROW_EXCEPTION(
50  Err()
51  << Err::msg_t("output already registered")
52  << Err::str1_t(sanitize(path))
53  );
54  }
55 
57  std::string path(std::string const& fn, const plot::Plot pt) {
58  const std::string p = path(fn);
59  register_plot(p, pt);
60  return p;
61  }
62 
63  void finish() const;
64 
65 private:
66  path_t root_;
67  plot_type_map ptm_;
68  std::string plot_list_;
69  char csv_delim_;
70 };
71 
72 }//namespace vdj_pipe
73 #endif /* OUTPUT_MANAGER_HPP_ */
Plot
File format types.
Definition: file_properties.hpp:58
Main namespace of vdj_pipe library.
Definition: sequence_file.hpp:14
std::string path(std::string const &fn, const plot::Plot pt)
Definition: output_manager.hpp:57
Definition: output_manager.hpp:27
Definition: exception.hpp:23
Definition: output_manager.hpp:20