1
// -*- mode: C++; tab-width: 2; -*-
4
// --------------------------------------------------------------------------
5
// OpenMS Mass Spectrometry Framework
6
// --------------------------------------------------------------------------
7
// Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Lesser General Public
11
// License as published by the Free Software Foundation; either
12
// version 2.1 of the License, or (at your option) any later version.
14
// This library 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 GNU
17
// Lesser General Public License for more details.
19
// You should have received a copy of the GNU Lesser General Public
20
// License along with this library; if not, write to the Free Software
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
// --------------------------------------------------------------------------
24
// $Maintainer: Clemens Groepl, Andreas Bertsch $
25
// $Authors: Chris Bauer $
26
// --------------------------------------------------------------------------
29
#include <OpenMS/FORMAT/FastaIterator.h>
36
typedef std::pair <String, String> FASTAEntry;
38
FastaIterator::FastaIterator() : PepIterator()
44
input_file_ = new std::ifstream();
47
FastaIterator::~FastaIterator()
52
FastaIterator::FastaIterator(const FastaIterator & source) : PepIterator(source)
54
is_at_end_ = (source.is_at_end_);
55
input_file_ = (source.input_file_);
56
fasta_file_ = (source.fasta_file_);
57
actual_seq_ =(source.actual_seq_);
58
header_ = (source.header_);
59
last_header_ = (source.last_header_);
62
PepIterator * FastaIterator::operator++(int)
66
throw Exception::InvalidIterator(__FILE__, __LINE__, __PRETTY_FUNCTION__);
68
PepIterator * old = new FastaIterator (*this);
69
actual_seq_ = next_();
73
FASTAEntry FastaIterator::operator*()
77
throw Exception::InvalidIterator(__FILE__, __LINE__, __PRETTY_FUNCTION__);
79
return FASTAEntry (last_header_,actual_seq_);
82
PepIterator & FastaIterator::operator++()
86
throw Exception::InvalidIterator(__FILE__, __LINE__, __PRETTY_FUNCTION__);
88
actual_seq_ = next_();
92
void FastaIterator::setFastaFile (const String & f)
98
throw Exception::FileNotFound(__FILE__, __LINE__, __PRETTY_FUNCTION__, f);
103
String FastaIterator::getFastaFile()
105
return (fasta_file_);
108
std::string FastaIterator::next_()
110
if (input_file_->eof())
116
std::getline(*input_file_, line);
117
if (line[0] == '>' || input_file_->eof())
119
last_header_ = header_;
123
return (std::string(line)+next_());
126
bool FastaIterator::begin()
130
throw Exception::InvalidIterator(__FILE__, __LINE__, __PRETTY_FUNCTION__);
132
input_file_->open(fasta_file_.c_str());
137
std::getline(*input_file_,line);
140
actual_seq_ = next_();
148
bool FastaIterator::isAtEnd ()