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 #ifndef OPENMS_FORMAT_FILEHANDLER_H
00028 #define OPENMS_FORMAT_FILEHANDLER_H
00029
00030 #include <OpenMS/config.h>
00031 #include <OpenMS/FORMAT/DTAFile.h>
00032 #include <OpenMS/FORMAT/DTA2DFile.h>
00033 #include <OpenMS/FORMAT/MzXMLFile.h>
00034 #include <OpenMS/FORMAT/MzDataFile.h>
00035 #include <OpenMS/FORMAT/MascotInfile.h>
00036 #include <OpenMS/CONCEPT/ProgressLogger.h>
00037
00038 #ifdef ANDIMS_DEF
00039 #include <OpenMS/FORMAT/ANDIFile.h>
00040 #endif
00041
00042 namespace OpenMS
00043 {
00055 class FileHandler
00056 {
00057 public:
00063 enum Type
00064 {
00065 UNKNOWN,
00066 DTA,
00067 DTA2D,
00068 MZDATA,
00069 MZXML,
00070 FEATUREXML,
00071 FEATUREPAIRSXML,
00072 ANDIMS,
00073 IDXML,
00074 CONSENSUSXML,
00075 MGF,
00076 SIZE_OF_TYPE
00077 };
00078
00080 static const std::string NamesOfTypes[SIZE_OF_TYPE];
00081
00083 Type getTypeByFileName(const String& filename);
00084
00086 Type getTypeByContent(const String& filename) throw (Exception::FileNotFound);
00087
00089 Type nameToType(const String& name);
00090
00092 String typeToName(Type type);
00093
00095 bool isSupported(Type type);
00096
00098 PeakFileOptions& getOptions();
00099
00101 const PeakFileOptions& getOptions() const;
00102
00113 template <class PeakType> bool loadExperiment(const String& filename, MSExperiment<PeakType>& exp, Type force_type = UNKNOWN, ProgressLogger::LogType log = ProgressLogger::NONE)
00114 {
00115 Type type;
00116 if (force_type != UNKNOWN)
00117 {
00118 type = force_type;
00119 }
00120 else
00121 {
00122 type = getTypeByFileName(filename);
00123 try
00124 {
00125 if (type == UNKNOWN)
00126 {
00127 type = getTypeByContent(filename);
00128 }
00129 }
00130 catch(Exception::FileNotFound)
00131 {
00132 return false;
00133 }
00134 }
00135
00136
00137 switch(type)
00138 {
00139 case DTA:
00140 exp.reset();
00141 exp.resize(1);
00142 DTAFile().load(filename,exp[0]);
00143 return true;
00144 break;
00145 case DTA2D:
00146 {
00147 DTA2DFile f;
00148 f.getOptions() = options_;
00149 f.setLogType(log);
00150 f.load(filename,exp);
00151 return true;
00152 }
00153 break;
00154 case MZXML:
00155 {
00156 MzXMLFile f;
00157 f.getOptions() = options_;
00158 f.setLogType(log);
00159 f.load(filename,exp);
00160 return true;
00161 }
00162 break;
00163 case MZDATA:
00164 {
00165 MzDataFile f;
00166 f.getOptions() = options_;
00167 f.setLogType(log);
00168 f.load(filename,exp);
00169 return true;
00170 }
00171 break;
00172 #ifdef ANDIMS_DEF
00173 case ANDIMS:
00174 {
00175 ANDIFile f;
00176 f.setLogType(log);
00177 f.load(filename,exp);
00178 return true;
00179 }
00180 break;
00181 #endif
00182 case MGF:
00183 {
00184 MascotInfile f;
00185 f.setLogType(log);
00186 f.load(filename, exp);
00187 return true;
00188 }
00189 default:
00190 return false;
00191 }
00192 }
00193
00194 private:
00195 PeakFileOptions options_;
00196 };
00197
00198 }
00199
00200 #endif //OPENMS_FORMAT_FILEHANDLER_H