~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to source/FORMAT/FastaIteratorIntern.C

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2012-11-12 15:58:12 UTC
  • Revision ID: package-import@ubuntu.com-20121112155812-vr15wtg9b50cuesg
Tags: upstream-1.9.0
ImportĀ upstreamĀ versionĀ 1.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: C++; tab-width: 2; -*-
 
2
// vi: set ts=2:
 
3
//
 
4
// --------------------------------------------------------------------------
 
5
//                   OpenMS Mass Spectrometry Framework
 
6
// --------------------------------------------------------------------------
 
7
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
 
8
//
 
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.
 
13
//
 
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.
 
18
//
 
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
 
22
//
 
23
// --------------------------------------------------------------------------
 
24
// $Maintainer: Clemens Groepl,Andreas Bertsch$
 
25
// $Authors: $
 
26
// --------------------------------------------------------------------------
 
27
 
 
28
 
 
29
#include <OpenMS/FORMAT/FastaIteratorIntern.h>
 
30
#include <OpenMS/FORMAT/FASTAFile.h>
 
31
 
 
32
#include <vector>
 
33
 
 
34
namespace OpenMS
 
35
{
 
36
 
 
37
        typedef std::pair<String,String> FASTAEntry;
 
38
        
 
39
        FastaIteratorIntern::FastaIteratorIntern() :
 
40
                fasta_file_("")
 
41
        {
 
42
        }
 
43
        
 
44
        FastaIteratorIntern::~FastaIteratorIntern()
 
45
        {
 
46
                
 
47
        }
 
48
 
 
49
        FastaIteratorIntern::FastaIteratorIntern(const FastaIteratorIntern & source) :
 
50
                PepIterator (source),
 
51
                fasta_file_(source.fasta_file_),
 
52
                entrys_(source.entrys_),
 
53
                it_(source.it_)
 
54
        {
 
55
                
 
56
        }
 
57
 
 
58
        FASTAEntry FastaIteratorIntern::operator*()
 
59
        {
 
60
                if (fasta_file_=="")
 
61
                {
 
62
                        throw Exception::InvalidIterator(__FILE__, __LINE__, __PRETTY_FUNCTION__);
 
63
                }
 
64
                return *it_;
 
65
        }
 
66
        
 
67
        PepIterator & FastaIteratorIntern::operator++()
 
68
        {
 
69
                if (fasta_file_=="")
 
70
                {
 
71
                        throw Exception::InvalidIterator(__FILE__, __LINE__, __PRETTY_FUNCTION__);
 
72
                }
 
73
                ++it_;
 
74
                return *this;
 
75
        }
 
76
        
 
77
        PepIterator * FastaIteratorIntern::operator++(int)
 
78
        {
 
79
                if (fasta_file_=="")
 
80
                {
 
81
                        throw Exception::InvalidIterator(__FILE__, __LINE__, __PRETTY_FUNCTION__);
 
82
                }
 
83
                PepIterator * old = new FastaIteratorIntern (*this);
 
84
                ++it_;
 
85
                return old;
 
86
        }
 
87
        
 
88
        void FastaIteratorIntern::setFastaFile (const String & f)
 
89
        {
 
90
                
 
91
                FASTAFile ffile;
 
92
                std::vector<FASTAFile::FASTAEntry> entries;
 
93
                                
 
94
                ffile.load (f,entries);
 
95
                entrys_.clear();
 
96
                entrys_.resize(entries.size(), std::make_pair("", ""));
 
97
                for (Size i = 0; i < entries.size(); ++i)
 
98
                {
 
99
                        entrys_[i].first = (entries[i].identifier + " " + entries[i].description);
 
100
                        entrys_[i].second = entries[i].sequence;
 
101
                }               
 
102
                
 
103
                fasta_file_ = f;
 
104
                it_ = entrys_.begin();
 
105
        }
 
106
 
 
107
        String FastaIteratorIntern::getFastaFile ()
 
108
        {
 
109
                return (fasta_file_);
 
110
        }
 
111
        
 
112
        bool FastaIteratorIntern::begin ()
 
113
        {
 
114
                if (fasta_file_=="")
 
115
                {
 
116
                        throw Exception::InvalidIterator(__FILE__, __LINE__, __PRETTY_FUNCTION__);
 
117
                }
 
118
                return true;
 
119
        }
 
120
        
 
121
        bool FastaIteratorIntern::isAtEnd ()
 
122
        {
 
123
                return (it_ == entrys_.end());
 
124
        }
 
125
 
 
126
}