Commit 79fa8658 authored by Armin Sobhani's avatar Armin Sobhani
Browse files

add copy constructor for sequence_host class with unit tests

parent 9c57dfaa
......@@ -22,9 +22,11 @@ template <typename CharT = char>
public:
/// \name Construction
//@{
name_component(const std::basic_string<CharT>& name = "")
: _name(std::move(name))
name_component()
{}
// name_component(const std::basic_string<CharT>& name = "")
// : _name(std::move(name))
// {}
//@}
/// \name Attributes
......@@ -37,7 +39,7 @@ public:
//@}
// Implementation
private:
protected:
std::basic_string<CharT> _name;
};
......
......@@ -61,6 +61,21 @@ public:
self_type::insert(self_type::begin(), s, s + count);
}
sequence_host(
const sequence_host& other
, const AllocatorT<CharT>& alloc = AllocatorT<CharT>() )
: ContainerT<CharT, AllocatorT<CharT>>(other)
{
copy_name(other, has_name_component<self_type>());
// std::cout << "copy called" << std::endl;
}
sequence_host(
sequence_host&& other)
: ContainerT<CharT, AllocatorT<CharT>>(other)
{}
// { std::cout << "move called" << std::endl; }
sequence_host(
std::initializer_list<CharT> init
, const AllocatorT<CharT>& alloc = AllocatorT<CharT>() )
......@@ -68,6 +83,10 @@ public:
{}
private:
void copy_name(const sequence_host& other, std::true_type)
{ self_type::_name = other._name; }
void copy_name(const sequence_host& other, std::false_type)
{}
};
//----------------------------------------------------------------------------//
......
......@@ -128,8 +128,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(read_single_fasta, T, seq_types)
BOOST_AUTO_TEST_CASE_TEMPLATE(read_multi_fasta, T, seq_types)
{
// std::ifstream in(BOOST_BIOSEQ_TEST_DATA_PATH"/reads.fa");
std::ifstream in(BOOST_BIOSEQ_TEST_DATA_PATH"/all_genomes.fna");
std::ifstream in(BOOST_BIOSEQ_TEST_DATA_PATH"/reads.fa");
// std::ifstream in(BOOST_BIOSEQ_TEST_DATA_PATH"/all_genomes.fna");
// in >> std::skipws;
......@@ -169,32 +169,38 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(read_multi_fasta, T, seq_types)
// for (auto read : reads | boost)
// std::cout << read.name() << '\n' << read.data() << std::endl;
auto start = std::chrono::high_resolution_clock::now();
std::list<T> rc_reads;
for (auto read : reads)
{
T rc_read;
// std::cout << read.name() << '\n'
// << read.data()
// << std::endl;
boost::copy(
read | boost::adaptors::transformed(
[] (char b) { if ('A' == b) return 'T';
else if ('T' == b) return 'A';
else if ('C' == b) return 'G';
else if ('G' == b) return 'C';
else return b ; } )
| boost::adaptors::reversed
, std::back_inserter(rc_read));
// , std::ostream_iterator<char>(std::cout) );
// std::cout << std::endl;
// rc_reads.push_back(std::move(rc_read));
rc_reads.push_back(rc_read);
}
auto d = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start);
std::cout << "Elapsed time: " << d.count() << " ms" << std::endl;
// auto start = std::chrono::high_resolution_clock::now();
// std::list<T> rc_reads;
// for (const auto& read : reads)
// {
// T rc_read;
// std::cout << read.name() << '\n'
// << read.data()
// << std::endl;
// boost::copy(
// read | boost::adaptors::transformed(
// [] (char b) { if ('A' == b) return 'T';
// else if ('T' == b) return 'A';
// else if ('C' == b) return 'G';
// else if ('G' == b) return 'C';
// else return b ; } )
// | boost::adaptors::reversed
// , std::back_inserter(rc_read));
// // , std::ostream_iterator<char>(std::cout) );
// // std::cout << std::endl;
// // rc_reads.push_back(std::move(rc_read));
// std::cout << rc_read.name() << ' '
// << rc_read.size() << '\n'
// << rc_read.data()
// << std::endl;
// rc_reads.push_back(rc_read);
// }
// auto d = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start);
// std::cout << "Elapsed time: " << d.count() << " ms" << std::endl;
}
......@@ -47,24 +47,24 @@ typedef boost::mpl::list<vec_32seq, str_32seq> seq32_types;
BOOST_AUTO_TEST_CASE_TEMPLATE(constructor_char_pointer_n, T, seq_types)
{
auto start = std::chrono::high_resolution_clock::now();
for (size_t i = 0; i < 1000000; ++i)
//T seq("ATCGN", 4);
T seq(
"ACTGCAACTCCAAAGCCACCCCTCACCCACTAGGATACCAACAAACCTACCCACCCTTAACAGTACATAG"
"TACATAAAGCCATTTACCGTACATAGCACATTACAGTCAAATCCCTTCTCGTCCCCATGGATGACCCCCC"
"TCAGATAGGGGTCCCTTGACCACCATCCTCCGTGAAATCAATATCCCGCACAAGAGTGCTACTCTCCTCG"
"CTCCGGGCCCATAACACTTGGGGGTAGCTAAAGTGAACTGTATCCGACATCTGGTTCCTACTTCAGGGTC", 280);
auto d = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start);
std::cout << "Elapsed time: " << d.count() << " ms" << std::endl;
// auto b = seq.cbegin();
// BOOST_CHECK_EQUAL( *b , 'A');
// BOOST_CHECK_EQUAL(*(++b), 'T');
// BOOST_CHECK_EQUAL(*(++b), 'C');
// BOOST_CHECK_EQUAL(*(++b), 'G');
// BOOST_CHECK_EQUAL(seq.size(), 4);
// BOOST_CHECK(++b == seq.end());
// auto start = std::chrono::high_resolution_clock::now();
// for (size_t i = 0; i < 1000000; ++i)
T seq("ATCGN", 4);
// T seq(
// "ACTGCAACTCCAAAGCCACCCCTCACCCACTAGGATACCAACAAACCTACCCACCCTTAACAGTACATAG"
// "TACATAAAGCCATTTACCGTACATAGCACATTACAGTCAAATCCCTTCTCGTCCCCATGGATGACCCCCC"
// "TCAGATAGGGGTCCCTTGACCACCATCCTCCGTGAAATCAATATCCCGCACAAGAGTGCTACTCTCCTCG"
// "CTCCGGGCCCATAACACTTGGGGGTAGCTAAAGTGAACTGTATCCGACATCTGGTTCCTACTTCAGGGTC", 280);
// auto d = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start);
// std::cout << "Elapsed time: " << d.count() << " ms" << std::endl;
auto b = seq.cbegin();
BOOST_CHECK_EQUAL( *b , 'A');
BOOST_CHECK_EQUAL(*(++b), 'T');
BOOST_CHECK_EQUAL(*(++b), 'C');
BOOST_CHECK_EQUAL(*(++b), 'G');
BOOST_CHECK_EQUAL(seq.size(), 4);
BOOST_CHECK(++b == seq.end());
}
BOOST_AUTO_TEST_CASE_TEMPLATE(constructor_wchar_pointer_n, T, wseq_types)
......@@ -108,24 +108,24 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(constructor_char32_pointer_n, T, seq32_types)
BOOST_AUTO_TEST_CASE_TEMPLATE(constructor_char_pointer, T, seq_types)
{
auto start = std::chrono::high_resolution_clock::now();
for (size_t i = 0; i < 1000000; ++i)
// T seq("ATCG");
T seq(
"ACTGCAACTCCAAAGCCACCCCTCACCCACTAGGATACCAACAAACCTACCCACCCTTAACAGTACATAG"
"TACATAAAGCCATTTACCGTACATAGCACATTACAGTCAAATCCCTTCTCGTCCCCATGGATGACCCCCC"
"TCAGATAGGGGTCCCTTGACCACCATCCTCCGTGAAATCAATATCCCGCACAAGAGTGCTACTCTCCTCG"
"CTCCGGGCCCATAACACTTGGGGGTAGCTAAAGTGAACTGTATCCGACATCTGGTTCCTACTTCAGGGTC" );
auto d = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start);
std::cout << "Elapsed time: " << d.count() << " ms" << std::endl;
// auto b = seq.cbegin();
// BOOST_CHECK_EQUAL( *b , 'A');
// BOOST_CHECK_EQUAL(*(++b), 'T');
// BOOST_CHECK_EQUAL(*(++b), 'C');
// BOOST_CHECK_EQUAL(*(++b), 'G');
// BOOST_CHECK_EQUAL(seq.size(), 4);
// BOOST_CHECK(++b == seq.end());
// auto start = std::chrono::high_resolution_clock::now();
// for (size_t i = 0; i < 1000000; ++i)
T seq("ATCG");
// T seq(
// "ACTGCAACTCCAAAGCCACCCCTCACCCACTAGGATACCAACAAACCTACCCACCCTTAACAGTACATAG"
// "TACATAAAGCCATTTACCGTACATAGCACATTACAGTCAAATCCCTTCTCGTCCCCATGGATGACCCCCC"
// "TCAGATAGGGGTCCCTTGACCACCATCCTCCGTGAAATCAATATCCCGCACAAGAGTGCTACTCTCCTCG"
// "CTCCGGGCCCATAACACTTGGGGGTAGCTAAAGTGAACTGTATCCGACATCTGGTTCCTACTTCAGGGTC" );
// auto d = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start);
// std::cout << "Elapsed time: " << d.count() << " ms" << std::endl;
auto b = seq.cbegin();
BOOST_CHECK_EQUAL( *b , 'A');
BOOST_CHECK_EQUAL(*(++b), 'T');
BOOST_CHECK_EQUAL(*(++b), 'C');
BOOST_CHECK_EQUAL(*(++b), 'G');
BOOST_CHECK_EQUAL(seq.size(), 4);
BOOST_CHECK(++b == seq.end());
}
BOOST_AUTO_TEST_CASE_TEMPLATE(constructor_wchar_pointer, T, wseq_types)
......@@ -167,6 +167,19 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(constructor_char32_pointer, T, seq32_types)
BOOST_CHECK(++b == seq.end());
}
BOOST_AUTO_TEST_CASE_TEMPLATE(copy_constructor, T, seq_types)
{
T seq("ATCG");
T copy(seq);
auto b = copy.cbegin();
BOOST_CHECK_EQUAL( *b , 'A');
BOOST_CHECK_EQUAL(*(++b), 'T');
BOOST_CHECK_EQUAL(*(++b), 'C');
BOOST_CHECK_EQUAL(*(++b), 'G');
BOOST_CHECK_EQUAL(seq.size(), 4);
}
BOOST_AUTO_TEST_CASE_TEMPLATE(constructor_initializer_list, T, seq_types)
{
T seq{ 'A', 'T', 'C', 'G'};
......@@ -176,4 +189,5 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(constructor_initializer_list, T, seq_types)
BOOST_CHECK_EQUAL(*(++b), 'T');
BOOST_CHECK_EQUAL(*(++b), 'C');
BOOST_CHECK_EQUAL(*(++b), 'G');
BOOST_CHECK_EQUAL(seq.size(), 4);
}
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