00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <Sequence/Fasta.hpp>
00025 #include <stdexcept>
00026 #include <iostream>
00027
00028 namespace Sequence
00029 {
00031 Fasta::Fasta (const std::string &name, const std::string &seq):
00032 Seq(name.c_str(),seq.c_str())
00036 {}
00037 Fasta::Fasta (const char *name,const char *seq):Seq(name,seq)
00041 {}
00042
00043 Fasta::Fasta (const Seq & seq) : Seq(seq)
00045 {}
00046
00047 std::istream & Fasta::read (std::istream & stream) throw (Sequence::badFormat,std::exception)
00048 {
00049 char ch;
00050 bool seqflag;
00051
00052 if (!(stream >> ch))
00053 {
00054 stream.setstate (std::ios::badbit);
00055 return (stream);
00056 }
00057 else
00058 stream.putback (ch);
00059
00060 std::string temp;
00061
00062 stream >> ch;
00063
00064 if (ch != '>')
00065 {
00066 throw badFormat("Fasta.cc: error, file not in FASTA format");
00067 }
00068 first.clear();
00069 while (1)
00070 {
00071 stream.get (ch);
00072 if (ch == '\n')
00073 break;
00074 first += ch;
00075 }
00076 seqflag = 1;
00077 second.clear();
00078 second.reserve(1000);
00079 while (seqflag)
00080 {
00081 stream >> ch;
00082 if (ch == '>')
00083 {
00084 stream.putback (ch);
00085 seqflag = 0;
00086 }
00087 else if (stream.eof ())
00088 seqflag = 0;
00089 else
00090 {
00091 second += ch;
00092 std::getline(stream,temp);
00093 second += temp;
00094 }
00095 }
00096 return (stream);
00097 }
00098
00099 std::ostream & Fasta::print (std::ostream & stream) const
00100 {
00101 stream << '>'
00102 << first
00103 << '\n'
00104 << second;
00105 return stream;
00106 }
00107 }