Commit d8785060 authored by Armin Sobhani's avatar Armin Sobhani
Browse files

add sub-range function overload to sequence_host class along with unit tests

parent 368ba4f9
......@@ -10,6 +10,7 @@
#ifndef BOOST_BIOSEQ_SEQUENCE_HPP
#define BOOST_BIOSEQ_SEQUENCE_HPP
#include <boost/range/sub_range.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/compute/system.hpp>
......@@ -137,6 +138,17 @@ public:
return *this;
}
boost::sub_range<sequence_host> operator() (
std::size_t start
, std::size_t length)
{
auto first = std::begin(*this);
std::advance(first, start);
auto last = first;
std::advance(last, length);
return boost::sub_range<sequence_host>(first, last);
}
std::basic_string<CharT> short_name() const
{
return get_name(has_name_component<self_type>());
......
......@@ -21,6 +21,8 @@
// # include <boost/test/detail/unit_test_parameters.hpp>
// #endif //BOOST_VERSION
// #include <boost/range/algorithm/copy.hpp>
#include <boost/bioseq/type_traits.hpp>
#include <boost/bioseq/sequence.hpp>
......@@ -236,3 +238,24 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(constructor_initializer_list, T, seq_types)
BOOST_CHECK_EQUAL(*(++b), 'G');
BOOST_CHECK_EQUAL(seq.size(), 4);
}
BOOST_AUTO_TEST_CASE_TEMPLATE(sub_range, T, seq_types)
{
T seq("ACGTUWSMKRYBDHVN-");
auto sub = seq(4, 4);
BOOST_CHECK_EQUAL(sub.size(), 4);
BOOST_CHECK_EQUAL(sub[0], 'U');
BOOST_CHECK_EQUAL(sub[1], 'W');
BOOST_CHECK_EQUAL(sub[2], 'S');
BOOST_CHECK_EQUAL(sub[3], 'M');
auto b = sub.begin();
BOOST_CHECK_EQUAL( *b , 'U');
BOOST_CHECK_EQUAL(*(++b), 'W');
BOOST_CHECK_EQUAL(*(++b), 'S');
BOOST_CHECK_EQUAL(*(++b), 'M');
// T subseq;
// boost::copy(seq(4, 4), std::back_inserter(subseq));
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment