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<
34 boost::multi_index::ordered_unique<
35 boost::multi_index::tag<struct path_tag>,
36 boost::multi_index::const_mem_fun<
43 typedef file_map::index<id_tag>::type
id_index;
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;
77 std::size_t
size()
const {
return map_.size(); }
79 const_iterator
end()
const {
return map_.end();}
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(
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;
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);
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")
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")
153 ) BOOST_THROW_EXCEPTION(
155 <<
Err::msg_t(
"paired reads files should be in FASTA or FASTQ formats")
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")
175 ) BOOST_THROW_EXCEPTION(
177 <<
Err::msg_t(
"sequence files should be in FASTA or FASTQ formats")
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_;
void clear()
Definition: sequence_file_map.hpp:108
file_map::index< id_tag >::type id_index
Definition: sequence_file_map.hpp:43
path_index::const_iterator path_iterator
Definition: sequence_file_map.hpp:46
boost::multi_index_container< Seq_file, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< struct id_tag >, boost::multi_index::const_mem_fun< Seq_file, Path_id,&Seq_file::id > >, boost::multi_index::ordered_unique< boost::multi_index::tag< struct path_tag >, boost::multi_index::const_mem_fun< File, std::string const &,&Seq_file::path > > > > file_map
Definition: sequence_file_map.hpp:41
const_iterator end() const
Definition: sequence_file_map.hpp:79
file_map::const_iterator const_iterator
Definition: sequence_file_map.hpp:73
Definition: sequence_file_map.hpp:49
Pair(const Path_id one, const Path_id two)
Definition: sequence_file_map.hpp:50
index1::const_iterator citer1
Definition: sequence_file_map.hpp:66
Path_id seq2qual(const Path_id seq_id) const
Definition: sequence_file_map.hpp:184
void set_mid(const Path_id seq_id, const Path_id mid_id)
Definition: sequence_file_map.hpp:161
id_index::const_iterator id_iterator
Definition: sequence_file_map.hpp:44
file_map::iterator iterator
Definition: sequence_file_map.hpp:72
Seq_file_map()
Definition: sequence_file_map.hpp:76
pair_map frm_
Definition: sequence_file_map.hpp:194
void erase(const Path_id id)
Definition: sequence_file_map.hpp:107
void set_seq_qual(const Path_id seq_id, const Path_id qual_id)
Definition: sequence_file_map.hpp:120
Path_id qual2seq(const Path_id qual_id) const
Definition: sequence_file_map.hpp:183
boost::multi_index_container< Pair, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::member< Pair, Path_id,&Pair::one_ > >, boost::multi_index::ordered_unique< boost::multi_index::member< Pair, Path_id,&Pair::two_ > > > > pair_map
Definition: sequence_file_map.hpp:64
boost::error_info< struct errinfo_int1_, int > int1_t
Definition: exception.hpp:28
Seq_file const & operator[](const Path_id id) const
Definition: sequence_file_map.hpp:82
Main namespace of vdj_pipe library.
Definition: keywords_variable.hpp:11
Path_id mid2seq(const Path_id mid_id) const
Definition: sequence_file_map.hpp:187
Path_id two_
Definition: sequence_file_map.hpp:51
static const int N
Definition: find_shared.cpp:275
std::string const & path() const
Definition: file.hpp:74
Definition: sequence_file_map.hpp:24
Definition: sequence_file_map.hpp:74
Path_id pid_
Definition: sequence_file.hpp:41
pair_map::nth_index< 0 >::type index1
Definition: sequence_file_map.hpp:65
Path_id one_
Definition: sequence_file_map.hpp:51
index2::const_iterator citer2
Definition: sequence_file_map.hpp:68
Seq_file const & at(const Path_id id) const
Definition: sequence_file_map.hpp:89
Id_iterator< Path_id > i_
Definition: sequence_file_map.hpp:191
file_map::index< path_tag >::type path_index
Definition: sequence_file_map.hpp:45
pair_map::nth_index< 1 >::type index2
Definition: sequence_file_map.hpp:67
Path_id rev2frw(const Path_id rev_id) const
Definition: sequence_file_map.hpp:185
Path_id frw2rev(const Path_id frw_id) const
Definition: sequence_file_map.hpp:186
Definition: sequence_file.hpp:19
pair_map sqm_
Definition: sequence_file_map.hpp:193
Path_id seq2mid(const Path_id seq_id) const
Definition: sequence_file_map.hpp:188
std::pair< std::size_t, std::size_t > pair
Definition: find_interval_run.cpp:18
bool empty() const
Definition: sequence_file_map.hpp:80
Seq_file value_type
Definition: sequence_file_map.hpp:71
std::size_t size() const
Definition: sequence_file_map.hpp:77
std::pair< Path_id, bool > insert(Seq_file const &file)
Definition: sequence_file_map.hpp:110
Definition: exception.hpp:23
boost::error_info< struct errinfo_message_, std::string > msg_t
Definition: exception.hpp:24
pair_map smm_
Definition: sequence_file_map.hpp:195
Seq_file const * find(std::string const &path) const
Definition: sequence_file_map.hpp:100
Path_id id() const
Definition: sequence_file.hpp:32
void set_paired(const Path_id frw_id, const Path_id rev_id)
Definition: sequence_file_map.hpp:139
file_map map_
Definition: sequence_file_map.hpp:192
const_iterator begin() const
Definition: sequence_file_map.hpp:78