7 #ifndef SEQUENCE_FILE_MAP_HPP_ 8 #define SEQUENCE_FILE_MAP_HPP_ 10 #include "boost/assert.hpp" 11 #include "boost/multi_index_container.hpp" 12 #include "boost/multi_index/mem_fun.hpp" 13 #include "boost/multi_index/member.hpp" 14 #include "boost/multi_index/ordered_index.hpp" 25 typedef boost::multi_index_container<
27 boost::multi_index::indexed_by<
28 boost::multi_index::ordered_unique<
29 boost::multi_index::tag<struct id_tag>,
30 boost::multi_index::const_mem_fun<
31 Seq_file, Path_id, &Seq_file::id
34 boost::multi_index::ordered_unique<
35 boost::multi_index::tag<struct path_tag>,
36 boost::multi_index::const_mem_fun<
37 File, std::string
const&, &Seq_file::path
43 typedef file_map::index<id_tag>::type id_index;
44 typedef id_index::const_iterator id_iterator;
45 typedef file_map::index<path_tag>::type path_index;
46 typedef path_index::const_iterator path_iterator;
50 Pair(
const Path_id one,
const Path_id two): one_(one), two_(two) {}
54 typedef boost::multi_index_container<
56 boost::multi_index::indexed_by<
57 boost::multi_index::ordered_unique<
58 boost::multi_index::member<Pair, Path_id, &Pair::one_>
60 boost::multi_index::ordered_unique<
61 boost::multi_index::member<Pair, Path_id, &Pair::two_>
65 typedef pair_map::nth_index<0>::type index1;
66 typedef index1::const_iterator citer1;
67 typedef pair_map::nth_index<1>::type index2;
68 typedef index2::const_iterator citer2;
72 typedef file_map::iterator iterator;
73 typedef file_map::const_iterator const_iterator;
77 std::size_t size()
const {
return map_.size(); }
78 const_iterator begin()
const {
return map_.begin();}
79 const_iterator end()
const {
return map_.end();}
80 bool empty()
const {
return map_.empty();}
82 Seq_file
const& operator[](
const Path_id
id)
const {
83 id_index
const& ind = map_.get<id_tag>();
84 const id_iterator i = ind.find(
id);
85 BOOST_ASSERT(i != ind.end());
89 Seq_file
const& at(
const Path_id
id)
const {
90 id_index
const& ind = map_.get<id_tag>();
91 const id_iterator i = ind.find(
id);
92 if(i == ind.end()) BOOST_THROW_EXCEPTION(
94 << Err::msg_t(
"invalid path ID")
100 Seq_file
const* find(std::string
const& path)
const {
101 path_index
const& ind = map_.get<path_tag>();
102 const path_iterator i = ind.find(path);
103 if( i == ind.end() )
return 0;
107 void erase(
const Path_id
id) {map_.erase(
id);}
108 void clear() {map_.clear();}
110 std::pair<Path_id, bool> insert(Seq_file
const& file) {
111 typedef std::pair<Path_id,bool> pair;
112 if( Seq_file
const* sfp = find(file.path()) )
return pair(sfp->id(),
false);
113 const Path_id
id = *i_++;
117 return pair(
id,
true);
120 void set_seq_qual(
const Path_id seq_id,
const Path_id qual_id) {
121 if( (!seq_id) || (!qual_id) || seq_id == qual_id ) BOOST_THROW_EXCEPTION(
123 << Err::msg_t(
"files should be valid and distinct")
126 if( (*
this)[seq_id].format() != format::Fasta ) BOOST_THROW_EXCEPTION(
128 << Err::msg_t(
"sequence file should be in FASTA format")
131 if( (*
this)[qual_id].format() != format::Qual ) BOOST_THROW_EXCEPTION(
133 << Err::msg_t(
"quality file should be in QUAL format")
136 sqm_.insert(Pair(seq_id, qual_id));
139 void set_paired(
const Path_id frw_id,
const Path_id rev_id) {
140 if( (!frw_id) || (!rev_id) || frw_id == rev_id ) BOOST_THROW_EXCEPTION(
142 << Err::msg_t(
"files should be valid and distinct")
145 if( (*
this)[frw_id].format() != (*
this)[rev_id].format() ) BOOST_THROW_EXCEPTION(
147 << Err::msg_t(
"paired reads files should be in same format")
151 (*
this)[frw_id].format() != format::Fasta &&
152 (*
this)[frw_id].format() != format::Fastq
153 ) BOOST_THROW_EXCEPTION(
155 << Err::msg_t(
"paired reads files should be in FASTA or FASTQ formats")
158 frm_.insert(Pair(frw_id, rev_id));
161 void set_mid(
const Path_id seq_id,
const Path_id mid_id) {
162 if( (!seq_id) || (!mid_id) || seq_id == mid_id ) BOOST_THROW_EXCEPTION(
164 << Err::msg_t(
"files should be valid and distinct")
167 if( (*
this)[seq_id].format() != (*
this)[mid_id].format() ) BOOST_THROW_EXCEPTION(
169 << Err::msg_t(
"sequence and eMID files should be in same format")
173 (*
this)[seq_id].format() != format::Fasta &&
174 (*
this)[seq_id].format() != format::Fastq
175 ) BOOST_THROW_EXCEPTION(
177 << Err::msg_t(
"sequence files should be in FASTA or FASTQ formats")
180 smm_.insert(Pair(seq_id, mid_id));
183 Path_id qual2seq(
const Path_id qual_id)
const {
return get<1>(qual_id, sqm_);}
184 Path_id seq2qual(
const Path_id seq_id)
const {
return get<0>(seq_id, sqm_);}
185 Path_id rev2frw(
const Path_id rev_id)
const {
return get<1>(rev_id, frm_);}
186 Path_id frw2rev(
const Path_id frw_id)
const {
return get<0>(frw_id, frm_);}
187 Path_id mid2seq(
const Path_id mid_id)
const {
return get<1>(mid_id, smm_);}
188 Path_id seq2mid(
const Path_id seq_id)
const {
return get<0>(seq_id, smm_);}
197 template<
int N>
static 198 Path_id
get(
const Path_id pid, pair_map
const& pm) {
199 typedef typename pair_map::nth_index<N>::type index;
200 typedef typename index::const_iterator iter;
201 index
const& ind = pm.get<N>();
202 iter i = ind.find(pid);
203 if( i == ind.end() )
return Path_id();
204 return N ? i->one_ : i->two_;
Main namespace of vdj_pipe library.
Definition: sequence_file.hpp:14
Definition: sequence_file_map.hpp:24
Definition: sequence_file_map.hpp:74
Definition: sequence_file.hpp:19
Definition: exception.hpp:23