Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

KroenikFile.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Chris Bielow $
00032 // $Authors: Chris Bielow $
00033 // --------------------------------------------------------------------------
00034 
00035 #ifndef OPENMS_FORMAT_KROENIKFILE_H
00036 #define OPENMS_FORMAT_KROENIKFILE_H
00037 
00038 #include <OpenMS/CONCEPT/Constants.h>
00039 #include <OpenMS/DATASTRUCTURES/String.h>
00040 #include <OpenMS/CONCEPT/Exception.h>
00041 #include <OpenMS/CONCEPT/LogStream.h>
00042 #include <OpenMS/KERNEL/Feature.h>
00043 #include <OpenMS/FORMAT/TextFile.h>
00044 
00045 #include <fstream>
00046 #include <vector>
00047 
00048 namespace OpenMS
00049 {
00067   class OPENMS_DLLAPI KroenikFile
00068   {
00069 public:
00071     KroenikFile();
00073     virtual ~KroenikFile();
00074 
00083     template <typename FeatureMapType>
00084     void load(const String & filename, FeatureMapType & feature_map)
00085     {
00086       // load input
00087       TextFile input(filename);
00088 
00089       // reset map
00090       FeatureMapType fmap;
00091       feature_map = fmap;
00092 
00093       for (Size i = 1; i < input.size(); ++i)
00094       {
00095         String line = input[i];
00096 
00097         //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
00098         std::vector<String> parts;
00099         line.split('\t', parts);
00100 
00101         if (parts.size() != 14)
00102         {
00103           throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, "",
00104                                       String("Failed parsing in line ") + String(i + 1) + ": missing 14 tab-separated entries (got " + String(parts.size()) + ")\nLine was: '" + line + "'");
00105         }
00106         //create feature
00107         Feature f;
00108         f.setCharge(parts[4].toInt());
00109         f.setMZ(parts[5].toDouble() / f.getCharge() + Constants::PROTON_MASS_U);
00110         f.setRT(parts[11].toDouble());
00111         f.setOverallQuality(parts[12].toDouble());
00112         f.setIntensity(parts[8].toDouble());
00113         ConvexHull2D hull;
00114         ConvexHull2D::PointType point;
00115 
00116         point.setX(parts[9].toDouble());
00117         point.setY(f.getMZ());
00118         hull.addPoint(point);
00119 
00120         point.setX(parts[9].toDouble());
00121         point.setY(f.getMZ() + 3.0 / (DoubleReal)f.getCharge());
00122         hull.addPoint(point);
00123 
00124         point.setX(parts[10].toDouble());
00125         point.setY(f.getMZ() + 3.0 / (DoubleReal)f.getCharge());
00126         hull.addPoint(point);
00127 
00128         point.setX(parts[10].toDouble());
00129         point.setY(f.getMZ());
00130         hull.addPoint(point);
00131 
00132         point.setX(parts[9].toDouble());
00133         point.setY(f.getMZ());
00134         hull.addPoint(point);
00135 
00136         std::vector<ConvexHull2D> hulls;
00137         hulls.push_back(hull);
00138         f.setConvexHulls(hulls);
00139         f.setMetaValue("Mass", parts[5].toDouble());
00140         f.setMetaValue("FirstScan", parts[1].toDouble());
00141         f.setMetaValue("LastScan", parts[2].toInt());
00142         f.setMetaValue("NumOfScans", parts[3].toDouble());
00143         f.setMetaValue("AveragineModifications", parts[13]);
00144         feature_map.push_back(f);
00145       }
00146 
00147       LOG_INFO << "Hint: The convex hulls are approximated in m/z dimension (Kroenik lacks this information)!\n";
00148     }
00149 
00157     template <typename SpectrumType>
00158     void store(const String & filename, const SpectrumType & spectrum) const
00159     {
00160       std::cerr << "Store() for KroenikFile not implemented. Filename was: " << filename << ", spec of size " << spectrum.size() << "\n";
00161       throw Exception::NotImplemented(__FILE__, __LINE__, __PRETTY_FUNCTION__);
00162     }
00163 
00164   };
00165 } // namespace OpenMS
00166 
00167 #endif // OPENMS_FORMAT_KROENIKFILE_H

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:40 using doxygen 1.7.1