Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
KroenikFile.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_KROENIKFILE_H
36 #define OPENMS_FORMAT_KROENIKFILE_H
37 
42 #include <OpenMS/KERNEL/Feature.h>
43 #include <OpenMS/FORMAT/TextFile.h>
44 
45 #include <fstream>
46 #include <vector>
47 
48 namespace OpenMS
49 {
67  class OPENMS_DLLAPI KroenikFile
68  {
69 public:
71  KroenikFile();
73  virtual ~KroenikFile();
74 
83  template <typename FeatureMapType>
84  void load(const String & filename, FeatureMapType & feature_map)
85  {
86  // load input
87  TextFile input(filename);
88 
89  // reset map
90  FeatureMapType fmap;
91  feature_map = fmap;
92 
93  for (Size i = 1; i < input.size(); ++i)
94  {
95  String line = input[i];
96 
97  //split lines: File, First Scan, Last Scan, Num of Scans, Charge, Monoisotopic Mass, Base Isotope Peak, Best Intensity, Summed Intensity, First RTime, Last RTime, Best RTime, Best Correlation, Modifications
98  std::vector<String> parts;
99  line.split('\t', parts);
100 
101  if (parts.size() != 14)
102  {
103  throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, "",
104  String("Failed parsing in line ") + String(i + 1) + ": missing 14 tab-separated entries (got " + String(parts.size()) + ")\nLine was: '" + line + "'");
105  }
106  //create feature
107  Feature f;
108  f.setCharge(parts[4].toInt());
109  f.setMZ(parts[5].toDouble() / f.getCharge() + Constants::PROTON_MASS_U);
110  f.setRT(parts[11].toDouble());
111  f.setOverallQuality(parts[12].toDouble());
112  f.setIntensity(parts[8].toDouble());
113  ConvexHull2D hull;
115 
116  point.setX(parts[9].toDouble());
117  point.setY(f.getMZ());
118  hull.addPoint(point);
119 
120  point.setX(parts[9].toDouble());
121  point.setY(f.getMZ() + 3.0 / (DoubleReal)f.getCharge());
122  hull.addPoint(point);
123 
124  point.setX(parts[10].toDouble());
125  point.setY(f.getMZ() + 3.0 / (DoubleReal)f.getCharge());
126  hull.addPoint(point);
127 
128  point.setX(parts[10].toDouble());
129  point.setY(f.getMZ());
130  hull.addPoint(point);
131 
132  point.setX(parts[9].toDouble());
133  point.setY(f.getMZ());
134  hull.addPoint(point);
135 
136  std::vector<ConvexHull2D> hulls;
137  hulls.push_back(hull);
138  f.setConvexHulls(hulls);
139  f.setMetaValue("Mass", parts[5].toDouble());
140  f.setMetaValue("FirstScan", parts[1].toDouble());
141  f.setMetaValue("LastScan", parts[2].toInt());
142  f.setMetaValue("NumOfScans", parts[3].toDouble());
143  f.setMetaValue("AveragineModifications", parts[13]);
144  feature_map.push_back(f);
145  }
146 
147  LOG_INFO << "Hint: The convex hulls are approximated in m/z dimension (Kroenik lacks this information)!\n";
148  }
149 
157  template <typename SpectrumType>
158  void store(const String & filename, const SpectrumType & spectrum) const
159  {
160  std::cerr << "Store() for KroenikFile not implemented. Filename was: " << filename << ", spec of size " << spectrum.size() << "\n";
161  throw Exception::NotImplemented(__FILE__, __LINE__, __PRETTY_FUNCTION__);
162  }
163 
164  };
165 } // namespace OpenMS
166 
167 #endif // OPENMS_FORMAT_KROENIKFILE_H
void setMetaValue(const String &name, const DataValue &value)
sets the DataValue corresponding to a name
const ChargeType & getCharge() const
Non-mutable access to charge state.
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
#define LOG_INFO
Macro if a information, e.g. a status should be reported.
Definition: LogStream.h:455
void setY(CoordinateType c)
Name mutator for the second dimension. Only for DPosition&lt;2&gt;, for visualization.
Definition: DPosition.h:170
File adapter for Kroenik (HardKloer sibling) files.
Definition: KroenikFile.h:67
A 2-dimensional hull representation in [counter]clockwise direction - depending on axis labelling...
Definition: ConvexHull2D.h:75
const double PROTON_MASS_U
void setIntensity(IntensityType intensity)
Non-mutable access to the data point intensity (height)
Definition: Peak2D.h:167
void setRT(CoordinateType coordinate)
Mutable access to the RT coordinate (index 0)
Definition: Peak2D.h:209
void setX(CoordinateType c)
Name mutator for the first dimension. Only for DPosition&lt;2&gt;, for visualization.
Definition: DPosition.h:163
An LC-MS feature.
Definition: Feature.h:66
CoordinateType getMZ() const
Returns the m/z coordinate (index 1)
Definition: Peak2D.h:191
void store(const String &filename, const SpectrumType &spectrum) const
Stores a featureXML as a Kroenik file.
Definition: KroenikFile.h:158
void setConvexHulls(const std::vector< ConvexHull2D > &hulls)
Set the convex hulls of single mass traces.
bool addPoint(const PointType &point)
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:144
void setCharge(const ChargeType &ch)
Set charge state.
void load(const String &filename, FeatureMapType &feature_map)
Loads a Kroenik file into a featureXML.
Definition: KroenikFile.h:84
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
double DoubleReal
Double-precision real type.
Definition: Types.h:118

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