vdj_pipe
pipeline for processing DNA sequence data
file.hpp
Go to the documentation of this file.
1 
7 #ifndef FILE_HPP_
8 #define FILE_HPP_
9 #include <iosfwd>
10 #include <string>
11 #include <utility>
12 #include "vdj_pipe/config.hpp"
14 #include "vdj_pipe/exception.hpp"
16 
17 namespace vdj_pipe{
18 
21 VDJ_PIPE_DECL compression::Compression
22 guess_compression_ext(std::string const& path);
23 
26 VDJ_PIPE_DECL compression::Compression
27 guess_compression_magic(std::string const& path);
28 
31 VDJ_PIPE_DECL std::pair<compression::Compression, format::Format>
32 guess_compression_format(std::string const& path);
33 
36 VDJ_PIPE_DECL format::Format
37 guess_format(std::string const& path, const compression::Compression c);
38 
41 VDJ_PIPE_DECL std::string ensure_path_writable(std::string const& path);
42 
46 VDJ_PIPE_DECL std::string ensure_path_writable(
47  std::string const& path,
48  std::string const& header
49 );
50 
53 VDJ_PIPE_DECL bool is_path_readable(std::string const& path);
54 
58 VDJ_PIPE_DECL std::string ensure_path_readable(std::string const& path);
59 
62 class File {
63 public:
64  struct Err : public base_exception {};
65 
66  explicit File(
67  std::string const& path,
68  const compression::Compression compr = compression::unknown,
69  const format::Format fmt = format::unknown
70  )
71  : path_(path), compr_(compr), fmt_(fmt)
72  {}
73 
74  std::string const& path() const {return path_;}
75  format::Format format() const {return fmt_;}
76  compression::Compression compression() const {return compr_;}
77  bool operator==(File const& f2) const {return path_ == f2.path_;}
78  bool operator<(File const& f2) const {return path_ < f2.path_;}
79  VDJ_PIPE_COMPARISON_OPERATOR_MEMBERS(File)
80 
81 protected:
82  std::string path_;
84  format::Format fmt_;
85 };
86 
89 VDJ_PIPE_DECL std::size_t hash_value(File const& f);
90 
93 class File_input : public File {
94 public:
95  explicit File_input(std::string const& path)
96  : File(ensure_path_readable(path))
97  {
98  compr_ = guess_compression_magic(path_);
99  fmt_ = guess_format(path_, compr_);
100  }
101 };
102 
105 class File_output : public File {
106 public:
107 
108  File_output(const format::Format fmt)
109  : File("", compression::unknown, fmt)
110  {}
111 
112  explicit File_output(
113  std::string const& path,
114  const compression::Compression compr = compression::unknown,
115  const format::Format fmt = format::unknown
116  )
117  : File(
118  ensure_path_writable(path),
119  compr == compression::unknown ? guess_compression_ext(path) : compr,
120  fmt == format::unknown ? guess_compression_format(path).second : fmt
121  )
122  {}
123 };
124 
125 }//namespace vdj_pipe
126 #endif /* FILE_HPP_ */
Format
File format types.
Definition: file_properties.hpp:42
Compression
File compression types.
Definition: file_properties.hpp:19
Definition: file.hpp:62
VDJ_PIPE_DECL compression::Compression guess_compression_ext(std::string const &path)
Definition: file.hpp:64
Main namespace of vdj_pipe library.
Definition: sequence_file.hpp:14
File target is supposed to exist at construction time.
Definition: file.hpp:93
VDJ_PIPE_DECL std::pair< compression::Compression, format::Format > guess_compression_format(std::string const &path)
VDJ_PIPE_DECL std::string ensure_path_writable(std::string const &path)
create file if does not exist along with parent directories if needed
VDJ_PIPE_DECL compression::Compression guess_compression_magic(std::string const &path)
VDJ_PIPE_DECL bool is_path_readable(std::string const &path)
VDJ_PIPE_DECL std::string ensure_path_readable(std::string const &path)
Definition: exception.hpp:23
VDJ_PIPE_DECL format::Format guess_format(std::string const &path, const compression::Compression c)
File target is created if needed at construction time.
Definition: file.hpp:105