Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
SpecArrayFile.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: Chris Bielow $
32 // $Authors: Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_FORMAT_SPECARRAYFILE_H
36 #define OPENMS_FORMAT_SPECARRAYFILE_H
37 
41 #include <OpenMS/KERNEL/Feature.h>
42 #include <OpenMS/FORMAT/TextFile.h>
43 
44 #include <fstream>
45 #include <vector>
46 
47 namespace OpenMS
48 {
61  class OPENMS_DLLAPI SpecArrayFile
62  {
63 public:
65  SpecArrayFile();
67  virtual ~SpecArrayFile();
68 
77  template <typename FeatureMapType>
78  void load(const String& filename, FeatureMapType& feature_map)
79  {
80  // load input
81  TextFile input(filename, false);
82 
83  // reset map
84  FeatureMapType fmap;
85  feature_map = fmap;
86 
87  TextFile::ConstIterator it = input.begin();
88  if (it == input.end()) return; // no data to load
89 
90  // skip header line
91  ++it;
92  // process content
93  for (; it != input.end(); ++it)
94  {
95  String line = *it;
96 
97  std::vector<String> parts;
98  line.split('\t', parts);
99 
100  if (parts.size() < 5)
101  {
102  throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "", String("Failed to convert line") + String((it - input.begin()) + 1) + "not enough columns (expected 5 or more, got " + String(parts.size()) + ")");
103  }
104 
105  Feature f;
106  try
107  {
108  f.setMZ(parts[0].toDouble());
109  f.setRT(parts[1].toDouble() * 60.0);
110  f.setMetaValue("s/n", parts[2].toDouble());
111  f.setCharge(parts[3].toInt());
112  f.setIntensity(parts[4].toDouble());
113  }
114  catch (Exception::BaseException /*&e*/)
115  {
116  throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "", String("Failed to convert value into a number (line '") + String((it - input.begin()) + 1) + ")");
117  }
118  feature_map.push_back(f);
119  }
120  }
121 
129  template <typename SpectrumType>
130  void store(const String& filename, const SpectrumType& spectrum) const
131  {
132  std::cerr << "Store() for SpecArrayFile not implemented. Filename was: " << filename << ", spec of size " << spectrum.size() << "\n";
133  throw Exception::NotImplemented(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
134  }
135 
136  };
137 } // namespace OpenMS
138 
139 #endif // OPENMS_FORMAT_SPECARRAYFILE_H
void setMetaValue(const String &name, const DataValue &value)
Sets the DataValue corresponding to a name.
A more convenient string class.
Definition: String.h:57
void setMZ(CoordinateType coordinate)
Mutable access to the m/z coordinate (index 1)
Definition: Peak2D.h:203
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
void setIntensity(IntensityType intensity)
Non-mutable access to the data point intensity (height)
Definition: Peak2D.h:173
File adapter for SpecArray (.pepList) files.
Definition: SpecArrayFile.h:61
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
void setRT(CoordinateType coordinate)
Mutable access to the RT coordinate (index 0)
Definition: Peak2D.h:215
std::vector< String >::const_iterator ConstIterator
Non-mutable iterator.
Definition: TextFile.h:57
ConstIterator end() const
Gives access to the underlying text buffer.
Exception base class.
Definition: Exception.h:90
An LC-MS feature.
Definition: Feature.h:70
void store(const String &filename, const SpectrumType &spectrum) const
Stores a featureXML as a SpecArray file.
Definition: SpecArrayFile.h:130
void setCharge(const ChargeType &ch)
Set charge state.
ConstIterator begin() const
Gives access to the underlying text buffer.
void load(const String &filename, FeatureMapType &feature_map)
Loads a SpecArray file into a featureXML.
Definition: SpecArrayFile.h:78
bool split(const char splitter, std::vector< String > &substrings, bool quote_protect=false) const
Splits a string into substrings using splitter as delimiter.
Not implemented exception.
Definition: Exception.h:437
This class provides some basic file handling methods for text files.
Definition: TextFile.h:47
Parse Error exception.
Definition: Exception.h:623

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