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 
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_ */
char csv_delim_
Definition: output_manager.hpp:69
boost::filesystem::path path_t
Definition: output_manager.hpp:21
std::string path(std::string const &fn) const
Definition: output_manager.hpp:41
path_t root_
Definition: output_manager.hpp:66
plot_type_map ptm_
Definition: output_manager.hpp:67
std::map< std::string, plot::Plot > plot_type_map
Definition: output_manager.hpp:23
Main namespace of vdj_pipe library.
Definition: keywords_variable.hpp:11
std::string path(std::string const &fn, const plot::Plot pt)
Definition: output_manager.hpp:57
#define VDJ_PIPE_DECL
Definition: config.hpp:23
Definition: output_manager.hpp:27
boost::error_info< struct errinfo_str1_, std::string > str1_t
Definition: exception.hpp:25
Output_manager(std::string const &base_out, std::string const &plot_list_path="", const char delim= '\t')
Definition: output_manager.hpp:29
void register_plot(std::string const &path, const plot::Plot pt)
Definition: output_manager.hpp:48
Definition: exception.hpp:23
boost::error_info< struct errinfo_message_, std::string > msg_t
Definition: exception.hpp:24
plot_type_map::value_type plot_pair
Definition: output_manager.hpp:24
std::string sanitize(const char c)
Definition: sanitize_string.cpp:53
Definition: output_manager.hpp:20
char delimiter() const
Definition: output_manager.hpp:39
std::string plot_list_
Definition: output_manager.hpp:68
Plot
File format types.
Definition: file_properties.hpp:58