Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
MsInspectFile.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_MSINSPECTFILE_H
36 #define OPENMS_FORMAT_MSINSPECTFILE_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 MsInspectFile
62  {
63 public:
65  MsInspectFile();
67  virtual ~MsInspectFile();
68 
77  template <typename FeatureMapType>
78  void load(const String& filename, FeatureMapType& feature_map)
79  {
80  // load input
81  TextFile input(filename);
82 
83  // reset map
84  FeatureMapType fmap;
85  feature_map = fmap;
86 
87  bool first_line = true;
88  for (TextFile::ConstIterator it = input.begin(); it != input.end(); ++it)
89  {
90  String line = *it;
91 
92  //ignore comment lines
93  if (line.empty() || line[0] == '#') continue;
94 
95  //skip leader line
96  if (first_line)
97  {
98  first_line = false;
99  continue;
100  }
101 
102  //split lines: scan\ttime\tmz\taccurateMZ\tmass\tintensity\tcharge\tchargeStates\tkl\tbackground\tmedian\tpeaks\tscanFirst\tscanLast\tscanCount\ttotalIntensity\tsumSquaresDist\tdescription
103  std::vector<String> parts;
104  line.split('\t', parts);
105 
106  if (parts.size() < 18)
107  {
108  throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "", String("Failed to convert line ") + String((it - input.begin()) + 1) + ". Not enough columns (expected 18 or more, got " + String(parts.size()) + ")");
109  }
110 
111  //create feature
112  Feature f;
113  Size column_to_convert = 0;
114  try
115  {
116  column_to_convert = 1;
117  f.setRT(parts[1].toDouble());
118  column_to_convert = 2;
119  f.setMZ(parts[2].toDouble());
120  column_to_convert = 5;
121  f.setIntensity(parts[5].toDouble());
122  column_to_convert = 6;
123  f.setCharge(parts[6].toInt());
124  column_to_convert = 8;
125  f.setOverallQuality(parts[8].toDouble());
126 
127  column_to_convert = 3;
128  f.setMetaValue("accurateMZ", parts[3]);
129  column_to_convert = 4;
130  f.setMetaValue("mass", parts[4].toDouble());
131  column_to_convert = 7;
132  f.setMetaValue("chargeStates", parts[7].toInt());
133  column_to_convert = 9;
134  f.setMetaValue("background", parts[9].toDouble());
135  column_to_convert = 10;
136  f.setMetaValue("median", parts[10].toDouble());
137  column_to_convert = 11;
138  f.setMetaValue("peaks", parts[11].toInt());
139  column_to_convert = 12;
140  f.setMetaValue("scanFirst", parts[12].toInt());
141  column_to_convert = 13;
142  f.setMetaValue("scanLast", parts[13].toInt());
143  column_to_convert = 14;
144  f.setMetaValue("scanCount", parts[14].toInt());
145  column_to_convert = 15;
146  f.setMetaValue("totalIntensity", parts[15].toDouble());
147  column_to_convert = 16;
148  f.setMetaValue("sumSquaresDist", parts[16].toDouble());
149  }
150  catch (Exception::BaseException /*&e*/)
151  {
152  throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "", String("Failed to convert value in column ") + String(column_to_convert + 1) + " into a number (line '" + String((it - input.begin()) + 1) + ")");
153  }
154  f.setMetaValue("description", parts[17]);
155  feature_map.push_back(f);
156  }
157 
158  }
159 
167  template <typename SpectrumType>
168  void store(const String& filename, const SpectrumType& spectrum) const
169  {
170  std::cerr << "Store() for MsInspectFile not implemented. Filename was: " << filename << ", spec of size " << spectrum.size() << "\n";
171  throw Exception::NotImplemented(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
172  }
173 
174  };
175 } // namespace OpenMS
176 
177 #endif // OPENMS_FORMAT_MSINSPECTFILE_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
void load(const String &filename, FeatureMapType &feature_map)
Loads a MsInspect file into a featureXML.
Definition: MsInspectFile.h:78
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
void setIntensity(IntensityType intensity)
Non-mutable access to the data point intensity (height)
Definition: Peak2D.h:173
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 setOverallQuality(QualityType q)
Set the overall quality.
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
void store(const String &filename, const SpectrumType &spectrum) const
Stores a featureXML as a MsInspect file.
Definition: MsInspectFile.h:168
void setCharge(const ChargeType &ch)
Set charge state.
ConstIterator begin() const
Gives access to the underlying text buffer.
File adapter for MsInspect files.
Definition: MsInspectFile.h:61
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:02 using doxygen 1.8.13