Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
00087 TextFile input(filename);
00088
00089
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
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
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 }
00166
00167 #endif // OPENMS_FORMAT_KROENIKFILE_H