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

FileHandler.h (Maintainer: Marc Sturm)

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // --------------------------------------------------------------------------
00005 //                   OpenMS Mass Spectrometry Framework
00006 // --------------------------------------------------------------------------
00007 //  Copyright (C) 2003-2008 -- Oliver Kohlbacher, Knut Reinert
00008 //
00009 //  This library is free software; you can redistribute it and/or
00010 //  modify it under the terms of the GNU Lesser General Public
00011 //  License as published by the Free Software Foundation; either
00012 //  version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //  This library is distributed in the hope that it will be useful,
00015 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //  Lesser General Public License for more details.
00018 //
00019 //  You should have received a copy of the GNU Lesser General Public
00020 //  License along with this library; if not, write to the Free Software
00021 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // --------------------------------------------------------------------------
00024 // $Maintainer: Marc Sturm $
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       //load right file
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 } //namespace
00199 
00200 #endif //OPENMS_FORMAT_FILEHANDLER_H

Generated Tue Apr 1 15:36:34 2008 -- using doxygen 1.5.4 OpenMS / TOPP 1.1