Commit 2ce82044 authored by Armin Sobhani's avatar Armin Sobhani
Browse files

add charsperline ouput stream manipulator for fasta file format

parent 8b809e84
......@@ -13,6 +13,10 @@
// #include <iostream>
#include <boost/algorithm/string.hpp>
#ifndef BOOST_BIOSEQ_IO_MANIPULATORS_HPP
#include <boost/bioseq/io_manipulators.hpp>
#endif // BOOST_BIOSEQ_IO_MANIPULATORS_HPP
namespace boost {
namespace bioseq {
......@@ -35,11 +39,15 @@ public:
private:
virtual void do_print(std::basic_ostream<CharT,Traits>& out, const SeqT& s)
{
unsigned chars_per_line = charsperline::get(out);
if (0 == chars_per_line)
chars_per_line = 70;
out << '>' << s.long_name();
for (size_t i = 0; i < s.size(); ++i)
{
if (0 == i % 70)
if (0 == i % chars_per_line)
out << std::endl;
out << s[i];
}
......
//----------------------------------------------------------------------------//
// Copyright (c) 2018 Armin Sobhani <arminms@gmail.com>
//
// Distributed under the Boost Software License Version 1.0.
// (See accompanying ${file} LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
//----------------------------------------------------------------------------//
#ifndef BOOST_BIOSEQ_IO_MANIPULATORS_HPP
#define BOOST_BIOSEQ_IO_MANIPULATORS_HPP
#ifndef BOOST_BIOSEQ_IO_MANIPULATOR_TEMPLATES_HPP
#include <boost/bioseq/io_manipulator_templates.hpp>
#endif // BOOST_BIOSEQ_IO_MANIPULATOR_TEMPLATES_HPP
namespace boost {
namespace bioseq {
//----------------------------------------------------------------------------//
typedef one_arg_omanip<unsigned, 1> charsperline;
//----------------------------------------------------------------------------//
} // end bioseq namespace
} // end boost namespace
#endif // BOOST_BIOSEQ_IO_MANIPULATORS_HPP
......@@ -150,6 +150,11 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(read_multi_fasta, T, seq_types)
BOOST_CHECK(cout.match_pattern());
}
// std::cout << bsq::charsperline(30) << reads[0];
// std::cout << bsq::charsperline(70) << reads[1];
// std::cout << bsq::charsperline(150) << reads[2];
// std::cout << bsq::charsperline(100) << reads[3];
// 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