7 #ifndef SEQUENCE_STORE_HPP_ 8 #define SEQUENCE_STORE_HPP_ 9 #include "boost/assert.hpp" 10 #include "boost/foreach.hpp" 11 #include "boost/multi_index_container.hpp" 12 #include "boost/multi_index/hashed_index.hpp" 13 #include "boost/multi_index/ordered_index.hpp" 14 #include "boost/range.hpp" 15 #include "boost/shared_ptr.hpp" 33 typedef boost::shared_ptr<seq_map> seq_map_ptr;
38 std::string
const&, &Seq_entry::sequence
42 seq_map, Seq_id, Seq_entry,
43 unsigned, &Seq_entry::size
46 typedef boost::multi_index_container<
48 boost::multi_index::indexed_by<
49 boost::multi_index::hashed_unique<
50 boost::multi_index::tag<struct seq_tag>,
53 boost::multi_index::ordered_non_unique<
54 boost::multi_index::tag<struct size_tag>,
59 typedef seq_mi_t::index<seq_tag>::type seq_index;
60 typedef seq_mi_t::index<size_tag>::type size_index;
62 static seq_mi_t::ctor_args_list seq_index_init(seq_map
const& sm) {
63 return boost::make_tuple(
67 boost::hash<std::string>(),
68 std::equal_to<std::string>()
70 boost::make_tuple(get_size(sm), std::less<unsigned>())
81 typedef size_index::const_iterator size_iterator;
82 typedef boost::iterator_range<size_iterator> size_range;
85 typedef seq_index::iterator iterator;
86 typedef seq_index::const_iterator const_iterator;
89 : sm_(
new seq_map(Seq_id(1))),
90 si_(seq_index_init(*sm_)),
95 std::size_t size()
const {
return si_.size();}
96 const_iterator begin()
const {
return si_.begin();}
97 const_iterator end()
const {
return si_.end();}
98 bool empty()
const {
return si_.empty();}
99 Seq_entry
const& operator[](
const Seq_id sid)
const {
return (*sm_)[sid];}
100 boost::shared_ptr<seq_map> sequence_map() {
return sm_;}
103 size_range
by_size()
const {
return boost::make_iterator_range(si_.get<size_tag>());}
106 size_range
by_size(
const unsigned size)
const {
107 return boost::make_iterator_range(
108 si_.get<size_tag>().equal_range(size)
115 const unsigned to = std::numeric_limits<unsigned>::max()
117 return boost::make_iterator_range(
118 si_.get<size_tag>().lower_bound(from),
119 si_.get<size_tag>().upper_bound(to)
124 Seq_id
insert(
const Read_id rid,
const boost::string_ref seq) {
125 seq_index& ind = si_.get<seq_tag>();
126 const const_iterator i = ind.find(
128 boost::hash<boost::string_ref>(),
133 if( i == ind.end() ) {
134 sid = sm_->insert(Seq_entry(seq, rid));
139 s2i_.insert(sid).insert(
sub_seq(rid, 0));
140 i2s_.insert(rid).insert(
super_seq(sid, 0));
144 template<
class Super_seqs>
void 145 remove_subsequence(
const Seq_id sid, Super_seqs
const& ss) {
147 BOOST_FOREACH(
sub_seq const& subs, s2i_[sid]) {
148 const Read_id rid = subs.id_;
149 super_seq_set& super_ss = i2s_[rid];
150 BOOST_ASSERT(super_ss.
find(sid));
152 BOOST_FOREACH(
super_seq const& supers, ss) {
153 const unsigned pos = subs.pos_ + supers.pos_;
154 super_ss.insert(
super_seq(supers.id_, pos));
155 s2i_[supers.id_].insert(
sub_seq(rid, pos));
160 si_.get<seq_tag>().erase((*sm_)[sid].sequence());
164 super_seq_set
const& maps_to(
const Read_id iid)
const {
return i2s_[iid];}
165 sub_seq_set
const& maps_from(
const Seq_id sid)
const {
return s2i_[sid];}
value_type const * find(CompatType const &t) const
Definition: vector_set.hpp:69
size_range by_size(const unsigned size) const
Definition: sequence_store.hpp:106
Collection of unique objects stored in an ordered vector.
Definition: vector_set.hpp:18
size_range by_size() const
Definition: sequence_store.hpp:103
Main namespace of vdj_pipe library.
Definition: sequence_file.hpp:14
size_range by_size_range(const unsigned from, const unsigned to=std::numeric_limits< unsigned >::max()) const
Definition: sequence_store.hpp:113
Definition: id_map.hpp:20
Definition: sequence_position.hpp:15
Definition: string_ref.hpp:23
Extract object by its ID and apply member function.
Definition: get_by_id.hpp:25
Store sequence and related information.
Definition: sequence_store.hpp:30
Seq_id insert(const Read_id rid, const boost::string_ref seq)
insert name and sequence checking for duplicates
Definition: sequence_store.hpp:124
Definition: sequence_entry.hpp:19