Skip to content
Snippets Groups Projects
Commit 37ef59a2 authored by Armin Sobhani's avatar Armin Sobhani
Browse files

update fasta_format::do_scan() to read sequence portion of fasta file

parent 4e1f1720
Branches
No related tags found
No related merge requests found
......@@ -10,6 +10,8 @@
#ifndef BOOST_BIOSEQ_IO_FORMATS_FASTA_HPP
#define BOOST_BIOSEQ_IO_FORMATS_FASTA_HPP
#include <iostream>
namespace boost {
namespace bioseq {
......@@ -35,8 +37,31 @@ private:
virtual void do_scan(std::basic_istream<CharT,Traits>& in, SeqT& s)
{
auto c = in.peek();
if (c != '>')
{
in.setstate(std::ios::failbit);
return;
}
std::basic_string<CharT,Traits> line;
line.reserve(71);
std::getline(in, line);
std::list<std::basic_string<CharT,Traits>> lines;
c = in.peek();
while (c != '>' && std::getline(in, line))
{
lines.push_back(std::move(line));
c = in.peek();
}
std::cout << "Number of lines: " << lines.size() << std::endl;
for (auto line : lines)
s.insert(s.end(), line.begin(), line.end());
std::cout << "Sequence Size: " << s.size() << std::endl;
// s.insert(0, "ACGT");
s.insert(s.begin(), 'A');
// s.insert(s.begin(), 'A');
}
};
......
......@@ -26,16 +26,19 @@
namespace bioseq = 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<char, std::allocator, bs_string> str_seq;
typedef bioseq::ioformat<char,std::char_traits<char>,str_seq,bioseq::fasta_format> frmt1;
template<> struct bioseq::io_format_traits<str_seq> { typedef frmt1 type; };
// preparing vec_seq type
typedef bioseq::sequence_host<char, std::allocator, std::vector> vec_seq;
typedef bioseq::ioformat<char,std::char_traits<char>,vec_seq,bioseq::fasta_format> frmt2;
template<> struct bioseq::io_format_traits<vec_seq> { typedef frmt2 type; };
// adding sequence types to the test list
typedef boost::mpl::list<vec_seq, str_seq> seq_types;
BOOST_AUTO_TEST_CASE_TEMPLATE(read_single_fasta, T, seq_types)
......@@ -44,7 +47,13 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(read_single_fasta, T, seq_types)
T mt;
in >> mt;
BOOST_CHECK_EQUAL(mt[0], 'A');
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');
// BOOST_CHECK( mt == "ACGT" );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment