libsequence  1.9.5
fastq.cc
1 #include <Sequence/fastq.hpp>
2 #include <functional>
3 #include <iostream>
4 
5 namespace Sequence
6 {
7  fastq::fastq(void) : Seq(), quality(std::string()), repeat_name(true) {}
8 
9  fastq::fastq(const std::string &name, const std::string &seq,
10  const std::string &qual)
11  : Seq(name, seq), quality(qual), repeat_name(true)
12  {
13  }
14 
15  fastq::fastq(std::string &&name, std::string &&seq, std::string &&qual)
16  : Seq(std::move(name), std::move(seq)), quality(std::move(qual)),
17  repeat_name(true)
18  {
19  }
20 
21  fastq::fastq(const Seq &s)
22  : Seq(s.name, s.seq), quality(std::string()), repeat_name(true)
23  {
24  }
25 
26  fastq::fastq(Seq &&s)
27  : Seq(std::move(s)), quality(std::string()), repeat_name(true)
28  {
29  }
30 
31  void
32  fastq::repname(const bool &b)
33  {
34  repeat_name = b;
35  }
36 
37  std::istream &
38  fastq::read(std::istream &stream)
39  {
40  if (stream.peek() == EOF)
41  return stream;
42  if (char(stream.peek()) != '@')
43  throw std::runtime_error("Sequence::fastq::read - error: record "
44  "did not begin with \'@\'");
45  std::string temp;
46  stream.ignore(1, '@');
47  std::getline(stream, name);
48  std::getline(stream, seq);
49  stream >> std::ws;
50  if (char(stream.peek()) != '+')
51  throw std::runtime_error("Sequence::fastq::read - error: third "
52  "line did not begin with \'+\'");
53  stream >> temp >> std::ws;
54  if (temp.size() == 1)
55  repeat_name = false;
56  quality.resize(seq.length());
57  stream.read(&quality[0], std::streamsize(seq.length()));
58  stream >> std::ws;
59  if (seq.length() != quality.length())
60  throw std::runtime_error("Sequence::fastq::read - error: sequence "
61  "and quality strings differ in length");
62  return stream;
63  }
64 
65  std::ostream &
66  fastq::print(std::ostream &stream) const
67  {
68  stream << '@' << name << '\n' << seq << '\n' << '+';
69  if (this->repeat_name)
70  {
71  stream << name;
72  }
73  stream << '\n' << quality;
74  return stream;
75  }
76 } //ns Sequence
std::ostream & print(std::ostream &s) const
Definition: fastq.cc:66
void repname(const bool &)
Set to true or false for repeating the seq name on third line of output.
Definition: fastq.cc:32
Abstract interface to sequence objects.
Definition: Seq.hpp:46
STL namespace.
The namespace in which this library resides.
std::istream & read(std::istream &s)
Definition: fastq.cc:38
FASTQ class.