libsequence  1.9.5
Fasta.cc
1 /*
2 
3 Copyright (C) 2003-2009 Kevin Thornton, krthornt[]@[]uci.edu
4 
5 Remove the brackets to email me.
6 
7 This file is part of libsequence.
8 
9 libsequence is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 libsequence is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 long with libsequence. If not, see <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #include <Sequence/Fasta.hpp>
25 #include <stdexcept>
26 #include <iostream>
27 #include <functional>
28 
29 namespace Sequence
30 {
31  Fasta::Fasta() : Seq() {}
32 
33  Fasta::Fasta (const Seq & seq) : Seq(seq)
35  {}
36 
37  Fasta::Fasta( Seq && seq ) : Seq(std::move(seq))
38  {
39  }
40 
41  std::istream & Fasta::read (std::istream & stream)
42  {
43  name.clear();
44  seq.clear();
45  std::string temp;
46  int ch = stream.peek();
47  if( stream.eof() ) { return stream; }
48  if (char(ch) != '>')
49  {
50  throw std::runtime_error("Fasta.cc: error, file not in FASTA format");
51  }
52  //Read in name
53  //stream >> ch >> std::ws;
54  ch = stream.get();
55  std::getline(stream,name);
56  stream >> std::ws;
57  seq.reserve(1000);
58  while( char( ch = stream.peek() ) != '>' && ! stream.eof() )
59  {
60  std::getline(stream,temp);
61  seq += temp;
62  }
63  return (stream);
64  }
65 
66  std::ostream & Fasta::print (std::ostream & stream) const
67  {
68  stream << '>'
69  << name
70  << '\n'
71  << seq;
72  return stream;
73  }
74 }
std::ostream & print(std::ostream &s) const
Definition: Fasta.cc:66
Abstract interface to sequence objects.
Definition: Seq.hpp:46
The namespace in which this library resides.
std::istream & read(std::istream &s)
Definition: Fasta.cc:41
Declaration of Sequence::Fasta streams.
Seq(void)
Definition: Seq.cc:32