Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
FASTAFile.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2017.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: Nico Pfeifer, Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_FORMAT_FASTAFILE_H
36 #define OPENMS_FORMAT_FASTAFILE_H
37 
40 
41 #include <functional>
42 #include <fstream>
43 #include <memory>
44 #include <utility>
45 #include <vector>
46 
47 namespace OpenMS
48 {
62  class OPENMS_DLLAPI FASTAFile
63  {
64 public:
74  struct FASTAEntry
75  {
79 
81  identifier(),
82  description(),
83  sequence()
84  {
85  }
86 
87  FASTAEntry(String id, String desc, String seq) :
88  identifier(id),
89  description(desc),
90  sequence(seq)
91  {
92  }
93 
94  FASTAEntry(const FASTAEntry& rhs)
95  :
96  identifier(rhs.identifier),
97  description(rhs.description),
98  sequence(rhs.sequence)
99  {
100  }
101 
102  FASTAEntry(FASTAEntry&& rhs) noexcept
103  :
104  identifier(::std::move(rhs.identifier)),
105  description(::std::move(rhs.description)),
106  sequence(::std::move(rhs.sequence))
107  {
108  }
109 
111  {
112  if (*this == rhs) return *this;
113  identifier = rhs.identifier;
114  description = rhs.description;
115  sequence = rhs.sequence;
116  return *this;
117  }
118 
119  bool operator==(const FASTAEntry& rhs) const
120  {
121  return identifier == rhs.identifier
122  && description == rhs.description
123  && sequence == rhs.sequence;
124  }
125 
126  bool headerMatches(const FASTAEntry& rhs) const
127  {
128  return identifier == rhs.identifier &&
129  description == rhs.description;
130  }
131 
132  bool sequenceMatches(const FASTAEntry& rhs) const
133  {
134  return sequence == rhs.sequence;
135  }
136  };
137 
139  FASTAFile();
140 
142  virtual ~FASTAFile();
143 
150  void readStart(const String& filename);
151 
161  bool readNext(FASTAEntry& protein);
162 
163 
169  void writeStart(const String& filename);
170 
178  void writeNext(const FASTAEntry& protein);
179 
184  void writeEnd();
185 
186 
195  void static load(const String& filename, std::vector<FASTAEntry>& data);
196 
204  void static store(const String& filename, const std::vector<FASTAEntry>& data);
205 
206 protected:
207  std::fstream infile_; //< filestream for reading; init using FastaFile::readStart()
208  std::ofstream outfile_; //< filestream for writing; init using FastaFile::writeStart()
209  std::unique_ptr<void, std::function<void(void*) > > reader_; //< filestream for reading; init using FastaFile::readStart(); needs to be a pointer, since its not copy-constructable; we use void* here, to avoid pulling in seqan includes
210  Size entries_read_; //< some internal book-keeping during reading
211  };
212 
213 } // namespace OpenMS
214 
215 #endif // OPENMS_FORMAT_FASTAFILE_H
Size entries_read_
Definition: FASTAFile.h:210
A more convenient string class.
Definition: String.h:57
FASTAEntry()
Definition: FASTAFile.h:80
bool operator==(const FASTAEntry &rhs) const
Definition: FASTAFile.h:119
bool sequenceMatches(const FASTAEntry &rhs) const
Definition: FASTAFile.h:132
FASTAEntry(FASTAEntry &&rhs) noexcept
Definition: FASTAFile.h:102
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
std::fstream infile_
Definition: FASTAFile.h:207
bool headerMatches(const FASTAEntry &rhs) const
Definition: FASTAFile.h:126
FASTAEntry & operator=(const FASTAEntry &rhs)
Definition: FASTAFile.h:110
FASTAEntry(String id, String desc, String seq)
Definition: FASTAFile.h:87
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
String sequence
Definition: FASTAFile.h:78
std::ofstream outfile_
Definition: FASTAFile.h:208
FASTA entry type (identifier, description and sequence)
Definition: FASTAFile.h:74
std::unique_ptr< void, std::function< void(void *) > > reader_
Definition: FASTAFile.h:209
String identifier
Definition: FASTAFile.h:76
This class serves for reading in and writing FASTA files.
Definition: FASTAFile.h:62
String description
Definition: FASTAFile.h:77
FASTAEntry(const FASTAEntry &rhs)
Definition: FASTAFile.h:94

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:00 using doxygen 1.8.13