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-2013.
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  for (Size i = 1; i < input.size(); ++i)
88  {
89  String line = input[i];
90 
91  std::vector<String> parts;
92  line.split('\t', parts);
93 
94  if (parts.size() < 5)
95  {
96  throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, "", String("Failed to convert line") + String(i + 1) + "not enough columns (expected 5 or more, got " + String(parts.size()) + ")");
97  }
98 
99  Feature f;
100  try
101  {
102  f.setMZ(parts[0].toDouble());
103  f.setRT(parts[1].toDouble() * 60.0);
104  f.setMetaValue("s/n", parts[2].toDouble());
105  f.setCharge(parts[3].toInt());
106  f.setIntensity(parts[4].toDouble());
107  }
108  catch (Exception::BaseException /*&e*/)
109  {
110  throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, "", String("Failed to convert value into a number (line '") + (i + 1) + ")");
111  }
112  feature_map.push_back(f);
113  }
114  }
115 
123  template <typename SpectrumType>
124  void store(const String & filename, const SpectrumType & spectrum) const
125  {
126  std::cerr << "Store() for SpecArrayFile not implemented. Filename was: " << filename << ", spec of size " << spectrum.size() << "\n";
127  throw Exception::NotImplemented(__FILE__, __LINE__, __PRETTY_FUNCTION__);
128  }
129 
130  };
131 } // namespace OpenMS
132 
133 #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:56
void setMZ(CoordinateType coordinate)
Mutable access to the m/z coordinate (index 1)
Definition: Peak2D.h:197
void store(const String &filename, const SpectrumType &spectrum) const
Stores a featureXML as a SpecArray file.
Definition: SpecArrayFile.h:124
void setIntensity(IntensityType intensity)
Non-mutable access to the data point intensity (height)
Definition: Peak2D.h:167
File adapter for SpecArray (.pepList) files.
Definition: SpecArrayFile.h:61
void setRT(CoordinateType coordinate)
Mutable access to the RT coordinate (index 0)
Definition: Peak2D.h:209
Exception base class.
Definition: Exception.h:90
An LC-MS feature.
Definition: Feature.h:66
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:144
void setCharge(const ChargeType &ch)
Set charge state.
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:608

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:21 using doxygen 1.8.5