9 #include "boost/assert.hpp" 10 #include "boost/shared_ptr.hpp" 25 typedef boost::shared_ptr<map_type> map_ptr;
28 file_read_count_i = 2,
39 : map_(
new map_type())
41 const std::string rc =
"read_count";
43 BOOST_ASSERT(value_id(rc)() == read_count_i );
45 const std::string frc =
"file_read_count";
47 BOOST_ASSERT(value_id(frc)() == file_read_count_i );
49 const std::string sfn =
"seq_file_name";
51 BOOST_ASSERT(value_id(sfn)() == seq_fn_i );
53 const std::string ri =
"read_id";
55 BOOST_ASSERT(value_id(ri)() == read_id_i );
58 file_read_count_reset();
61 iterator begin()
const {
return map_->begin();}
62 iterator end()
const {
return map_->end();}
63 std::size_t size()
const {
return map_->size();}
66 for(iterator i = Val_id(read_id_i); i != end(); ++i) {
67 (*this)[*i] = value_variant();
71 std::string
const& name(
const Val_id vid)
const {
72 return map_->name(vid);
75 Val_id insert_name(std::string
const& name) {
76 return map_->insert_name(name);
79 Val_id insert_new_name(std::string
const& name) {
80 return map_->insert_new_name(name);
83 Val_id
const* find_id(std::string
const& name)
const {
84 return map_->find_id(name);
87 Val_id value_id(std::string
const& name)
const {
88 return map_->value_id(name);
91 value_variant
const& operator[](
const Val_id vid)
const {
95 value_variant& operator[](
const Val_id vid) {
99 long read_count()
const {
100 return value<long>(Val_id(read_count_i));
103 void read_count_reset() {
104 (*this)[Val_id(read_count_i)] = (long)0;
107 void read_count_incr() {
108 ++boost::get<long>((*map_)[Val_id(read_count_i)]);
111 long file_read_count()
const {
112 return value<long>(Val_id(file_read_count_i));
115 void file_read_count_reset() {
116 (*this)[Val_id(file_read_count_i)] = (long)0;
119 void file_read_count_incr() {
120 ++boost::get<long>((*map_)[Val_id(file_read_count_i)]);
123 std::string
const& seq_file_name()
const {
124 return value<std::string>(Val_id(seq_fn_i));
127 void seq_file_name(std::string
const& fn) {
128 (*this)[Val_id(seq_fn_i)] = fn;
131 std::string
const& read_id_nothrow()
const {
132 return str_nothrow(Val_id(read_id_i));
135 std::string
const& read_id()
const {
136 return value<std::string>(Val_id(read_id_i));
139 void read_id(std::string
const&
id) {
140 (*this)[Val_id(read_id_i)] = id;
143 template<
typename T> T
const& value(std::string
const& name)
const {
144 const Val_id
id = value_id(name);
145 if( !
id ) BOOST_THROW_EXCEPTION(
147 << Err::msg_t(
"unknown value name")
148 << Err::str1_t(sanitize(name))
153 template<
typename T> T
const* value_ptr(std::string
const& name)
const {
154 const Val_id
id = value_id(name);
155 if( !
id ) BOOST_THROW_EXCEPTION(
157 << Err::msg_t(
"unknown value name")
158 << Err::str1_t(sanitize(name))
160 return value_ptr<T>(id);
163 template<
typename T> T
const& value(
const Val_id
id)
const {
165 return boost::get<T>((*map_)[id]);
166 }
catch(std::exception
const&) {
167 BOOST_THROW_EXCEPTION(
169 << Err::msg_t(
"wrong value type")
170 << Err::str1_t(variable_type_str((*map_)[
id]))
171 << Err::str2_t(sanitize(name(
id)))
172 << Err::nested_t(boost::current_exception())
177 template<
typename T> T
const* value_ptr(
const Val_id
id)
const {
178 return boost::get<T>(&(*map_)[id]);
182 str_nothrow(
const Val_id
id)
const {
183 if( std::string
const* id_ptr = boost::get<std::string>(&(*map_)[
id]) )
185 static const std::string id_str =
"not_available";
191 std::string sequence(
193 const Val_id trim_id,
195 const bool reverse_compl
197 std::string
const& seq = value<std::string>(seq_id);
201 value<sequence_interval>(trim_id) :
202 sequence_interval(0U, seq.size()),
208 const Val_id qual_id,
209 const Val_id trim_id,
211 const bool reverse_compl
215 std::size_t n2 = q.size();
217 const sequence_interval si = value<sequence_interval>(trim_id);
221 if( n1 > q.size() || n2 > q.size() ) BOOST_THROW_EXCEPTION(
223 << Err::msg_t(
"sequence interval and quality score mismatch")
224 << Err::int1_t(std::max(n1, n2))
225 << Err::int2_t(q.size())
229 if( reverse_compl ) {
230 for(std::size_t i = 0, j = n2-1; i != q1.size(); ++i, --j) q1[i] = q[j];
232 for( std::size_t i = 0, j = n1; i != q1.size(); ++i, ++j) q1[i] = q[j];
Definition: sequence_record.hpp:35
Store values mapped against name strings and value IDs.
Definition: named_value_map.hpp:22
Definition: value_map.hpp:36
Main namespace of vdj_pipe library.
Definition: sequence_file.hpp:14
Definition: exception.hpp:23
Definition: id_iterator.hpp:16
std::string transform(const boost::string_ref seq, sequence_interval const &si, const bool reverse)
Reverse-complement (optionally) a portion of a sequence.
Definition: sequence_transform.hpp:34
Store values mapped against name strings and value IDs.
Definition: value_map.hpp:23