Commit 8b809e84 authored by Armin Sobhani's avatar Armin Sobhani
Browse files

add fasta file format output capability with unit tests

parent bbf0119b
......@@ -34,7 +34,18 @@ public:
private:
virtual void do_print(std::basic_ostream<CharT,Traits>& out, const SeqT& s)
{}
{
out << '>' << s.long_name();
for (size_t i = 0; i < s.size(); ++i)
{
if (0 == i % 70)
out << std::endl;
out << s[i];
}
out << std::endl;
}
virtual void do_scan(std::basic_istream<CharT,Traits>& in, SeqT& s)
{
......
......@@ -15,7 +15,7 @@
#define BOOST_TEST_MODULE TestIOFasta
#include <boost/mpl/list.hpp>
#include <boost/test/unit_test.hpp>
// #include <boost/test/output_test_stream.hpp>
#include <boost/test/output_test_stream.hpp>
// #if (BOOST_VERSION >= 105900)
// # include <boost/test/unit_test_parameters.hpp>
// #else
......@@ -35,27 +35,28 @@
#include <boost/bioseq/components/description.hpp>
#include <boost/bioseq/io_formats/fasta.hpp>
namespace bioseq = boost::bioseq;
using boost::test_tools::output_test_stream;
namespace bsq = boost::bioseq;
// preparing str_seq type
template<class CharT, class AllocatorT> using bs_string
= std::basic_string<CharT, std::char_traits<CharT>, AllocatorT>;
typedef bioseq::sequence_host
typedef bsq::sequence_host
<
char
, std::allocator
, bs_string
, bioseq::component::name<>
, bioseq::component::description<>
, bsq::component::name<>
, bsq::component::description<>
> str_seq;
typedef bioseq::ioformat
typedef bsq::ioformat
<
char
, std::char_traits<char>
, str_seq
, bioseq::fasta_format
, bsq::fasta_format
> frmt1;
#if BOOST_WORKAROUND(BOOST_GCC, < 70000)
......@@ -63,24 +64,24 @@ typedef bioseq::ioformat
template<> struct io_format_traits<str_seq> { typedef frmt1 type; };
}}
#else
template<> struct bioseq::io_format_traits<str_seq> { typedef frmt1 type; };
template<> struct bsq::io_format_traits<str_seq> { typedef frmt1 type; };
#endif // BOOST_GCC < 70000
// preparing vec_seq type
typedef bioseq::sequence_host
typedef bsq::sequence_host
<
char
, std::allocator
, std::vector
, bioseq::component::name<>
, bioseq::component::description<>
, bsq::component::name<>
, bsq::component::description<>
> vec_seq;
typedef bioseq::ioformat
typedef bsq::ioformat
< char
, std::char_traits<char>
, vec_seq
, bioseq::fasta_format
, bsq::fasta_format
> frmt2;
#if BOOST_WORKAROUND(BOOST_GCC, < 70000)
......@@ -88,7 +89,7 @@ typedef bioseq::ioformat
template<> struct io_format_traits<vec_seq> { typedef frmt2 type; };
}}
#else
template<> struct bioseq::io_format_traits<vec_seq> { typedef frmt2 type; };
template<> struct bsq::io_format_traits<vec_seq> { typedef frmt2 type; };
#endif // BOOST_GCC < 70000
......@@ -97,38 +98,18 @@ typedef boost::mpl::list<vec_seq, str_seq> seq_types;
BOOST_AUTO_TEST_CASE_TEMPLATE(read_single_fasta, T, seq_types)
{
// auto start = std::chrono::high_resolution_clock::now();
// for (size_t i = 0; i < 1000; ++i)
// {
std::ifstream in(BOOST_BIOSEQ_TEST_DATA_PATH"/chrMT.fa");
T mt;
in >> mt;
// }
// 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;
BOOST_CHECK_EQUAL(mt[0], 'G');
BOOST_CHECK_EQUAL(mt[1], 'A');
BOOST_CHECK_EQUAL(mt[69], 'G');
BOOST_CHECK_EQUAL(mt[139], 'C');
BOOST_CHECK_EQUAL(mt[16566], 'A');
BOOST_CHECK_EQUAL(mt[16567], 'T');
BOOST_CHECK_EQUAL(mt[16568], 'G');
std::ifstream in(BOOST_BIOSEQ_TEST_DATA_PATH"/chrMT.fa");
T mt;
in >> mt;
BOOST_CHECK( 16569 == mt.size() );
BOOST_CHECK_EQUAL(mt.name(), "gi|113200490|gb|J01415.2|HUMMTCG");
BOOST_CHECK_EQUAL(mt.description(), "Homo sapiens mitochondrion, complete genome");
BOOST_CHECK_EQUAL(mt.long_name(), "gi|113200490|gb|J01415.2|HUMMTCG Homo sapiens mitochondrion, complete genome");
// BOOST_CHECK( mt.short_name() == "gi|113200490|gb|J01415.2|HUMMTCG" );
// BOOST_CHECK( mt.long_name()
// == "gi|113200490|gb|J01415.2|HUMMTCG "
// "Homo sapiens mitochondrion, complete genome" );
// output_test_stream cout(BOOST_BIOSEQ_TEST_DATA_PATH"/chrMT.fa");
// cout << mt;
// BOOST_CHECK(cout.match_pattern());
output_test_stream cout(BOOST_BIOSEQ_TEST_DATA_PATH"/chrMT.fa");
cout << mt;
BOOST_CHECK(cout.match_pattern());
}
BOOST_AUTO_TEST_CASE_TEMPLATE(read_multi_fasta, T, seq_types)
......@@ -162,6 +143,13 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(read_multi_fasta, T, seq_types)
BOOST_CHECK_EQUAL(reads[0].long_name(), "gi|406593966|ref|NC_018627.1|-40485/1");
output_test_stream cout(BOOST_BIOSEQ_TEST_DATA_PATH"/reads.fa");
for (const auto& read : reads)
{
cout << read;
BOOST_CHECK(cout.match_pattern());
}
// T copy(reads[0]);
// BOOST_CHECK_EQUAL(copy.name(), "gi|406593966|ref|NC_018627.1|-40485/1");
// BOOST_CHECK_EQUAL(copy.data(), "ACACCAGAAGCATCGTCTGTTGTGGTGATATATGCGGGCTCTTCTGTTATCTCGTTAAGATCGAGATGGAGATTCTTTACTGAGATGTTGTTGGTAGTTTGAAACTTCGTCCCAGGATGCATGCAGAGTATAGATTGAAGATTTTCATCA");
......
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