~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to include/OpenMS/FORMAT/FileHandler.h

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2013-12-20 11:30:16 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131220113016-wre5g9bteeheq6he
Tags: 1.11.1-3
* remove version number from libbost development package names;
* ensure that AUTHORS is correctly shipped in all packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- mode: C++; tab-width: 2; -*-
2
 
// vi: set ts=2:
3
 
//
4
 
// --------------------------------------------------------------------------
5
 
//                   OpenMS Mass Spectrometry Framework
6
 
// --------------------------------------------------------------------------
7
 
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
8
 
//
9
 
//  This library is free software; you can redistribute it and/or
10
 
//  modify it under the terms of the GNU Lesser General Public
11
 
//  License as published by the Free Software Foundation; either
12
 
//  version 2.1 of the License, or (at your option) any later version.
13
 
//
14
 
//  This library is distributed in the hope that it will be useful,
15
 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 
//  Lesser General Public License for more details.
18
 
//
19
 
//  You should have received a copy of the GNU Lesser General Public
20
 
//  License along with this library; if not, write to the Free Software
21
 
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
 
//
23
 
// --------------------------------------------------------------------------
24
 
// $Maintainer: Andreas Bertsch $
 
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: Stephan Aiche $
25
32
// $Authors: Marc Sturm $
26
33
// --------------------------------------------------------------------------
27
34
 
50
57
 
51
58
namespace OpenMS
52
59
{
53
 
        /**
54
 
                @brief Facilitates file handling by file type recognition.
55
 
 
56
 
                This class provides file type recognition from the file name and
57
 
                from the file content.
58
 
 
59
 
                It also offer a common interface to load MSExperiment data
60
 
                and allows querying for supported file types.
61
 
 
62
 
                @see FileTypes
63
 
 
64
 
                @ingroup FileIO
65
 
        */
66
 
        class OPENMS_DLLAPI FileHandler
67
 
        {
68
 
         public:
69
 
 
70
 
                /// String representations of the file types
71
 
                static const std::string NamesOfTypes[FileTypes::SIZE_OF_TYPE];
72
 
 
73
 
                /**
74
 
                        @brief Tries to determine the file type (by name or content)
75
 
 
76
 
                        First the type is determined from the file name.
77
 
                        If this fails, the type is determined from the file content.
78
 
 
79
 
                        @exception Exception::FileNotFound is thrown if the file is not present
80
 
                */
81
 
                static FileTypes::Type getType(const String& filename);
82
 
 
83
 
 
84
 
                /// Determines the file type from a file name
85
 
                static FileTypes::Type getTypeByFileName(const String& filename);
86
 
 
87
 
                /**
88
 
                        @brief Determines the file type of a file by parsing the first few lines
89
 
 
90
 
                        @exception Exception::FileNotFound is thrown if the file is not present
91
 
                */
92
 
                static FileTypes::Type getTypeByContent(const String& filename);
93
 
 
94
 
                /// Converts a file type name into a Type
95
 
                static FileTypes::Type nameToType(const String& name);
96
 
 
97
 
                /// Converts a Type into a file type name
98
 
                static String typeToName(FileTypes::Type type);
99
 
 
100
 
                /// Returns if the file type is supported in this build of the library
101
 
                static bool isSupported(FileTypes::Type type);
 
60
  /**
 
61
    @brief Facilitates file handling by file type recognition.
 
62
 
 
63
    This class provides file type recognition from the file name and
 
64
    from the file content.
 
65
 
 
66
    It also offer a common interface to load MSExperiment data
 
67
    and allows querying for supported file types.
 
68
 
 
69
    @see FileTypes
 
70
 
 
71
    @ingroup FileIO
 
72
  */
 
73
  class OPENMS_DLLAPI FileHandler
 
74
  {
 
75
public:
 
76
    /**
 
77
      @brief Tries to determine the file type (by name or content)
 
78
 
 
79
      First the type is determined from the file name.
 
80
      If this fails, the type is determined from the file content.
 
81
 
 
82
      @exception Exception::FileNotFound is thrown if the file is not present
 
83
    */
 
84
    static FileTypes::Type getType(const String& filename);
 
85
 
 
86
 
 
87
    /// Determines the file type from a file name
 
88
    static FileTypes::Type getTypeByFileName(const String& filename);
 
89
 
 
90
    /**
 
91
      @brief Determines the file type of a file by parsing the first few lines
 
92
 
 
93
      @exception Exception::FileNotFound is thrown if the file is not present
 
94
    */
 
95
    static FileTypes::Type getTypeByContent(const String& filename);
 
96
 
 
97
    /// Returns if the file type is supported in this build of the library
 
98
    static bool isSupported(FileTypes::Type type);
102
99
 
103
100
    /// Mutable access to the options for loading/storing
104
101
    PeakFileOptions& getOptions();
106
103
    /// Non-mutable access to the options for loading/storing
107
104
    const PeakFileOptions& getOptions() const;
108
105
 
109
 
                /**
110
 
                        @brief Loads a file into an MSExperiment
111
 
                        
112
 
                        @param filename The file name of the file to load.
113
 
                        @param exp The experiment to load the data into.
114
 
                        @param force_type Forces to load the file with that file type. If no type is forced, it is determined from the extention ( or from the content if that fails).
115
 
                        @param log Progress logging mode
116
 
                        
117
 
                        @return true if the file could be loaded, false otherwise
118
 
                        
119
 
                        @exception Exception::FileNotFound is thrown if the file could not be opened
120
 
                        @exception Exception::ParseError is thrown if an error occurs during parsing
121
 
                */
122
 
                template <class PeakType> bool loadExperiment(const String& filename, MSExperiment<PeakType>& exp, FileTypes::Type force_type = FileTypes::UNKNOWN, ProgressLogger::LogType log = ProgressLogger::NONE)
123
 
                {
124
 
                        //determine file type
125
 
                        FileTypes::Type type;
126
 
                        if (force_type != FileTypes::UNKNOWN)
127
 
                        {
128
 
                                type = force_type;
129
 
                        }
130
 
                        else
131
 
                        {
132
 
                                try
133
 
                                {
134
 
                                        type = getType(filename);
135
 
                                }
136
 
                                catch(Exception::FileNotFound)
137
 
                                {
138
 
                                        return false;
139
 
                                }
140
 
                        }
141
 
 
142
 
                        //load right file
143
 
                        switch(type)
144
 
                        {
145
 
                                case FileTypes::DTA:
146
 
                                        exp.reset();
147
 
                                        exp.resize(1);
148
 
                                        DTAFile().load(filename,exp[0]);
149
 
                                        return true;
150
 
                                        break;
151
 
                                case FileTypes::DTA2D:
152
 
                                        {
153
 
                                                DTA2DFile f;
154
 
                                                f.getOptions() = options_;
155
 
                                                f.setLogType(log);
156
 
                                                f.load(filename,exp);
157
 
                                                return true;
158
 
                                        }
159
 
                                        break;
160
 
                                case FileTypes::MZXML:
161
 
                                        {
162
 
                                                MzXMLFile f;
163
 
                                                f.getOptions() = options_;
164
 
                                                f.setLogType(log);
165
 
                                                f.load(filename,exp);
166
 
                                                return true;
167
 
                                        }
168
 
                                        break;
169
 
                                case FileTypes::MZDATA:
170
 
                                        {
171
 
                                                MzDataFile f;
172
 
                                                f.getOptions() = options_;
173
 
                                                f.setLogType(log);
174
 
                                                f.load(filename,exp);
175
 
                                                return true;
176
 
                                        }
177
 
                                        break;
178
 
                                case FileTypes::MZML:
179
 
                                        {
180
 
                                                MzMLFile f;
181
 
                                                f.getOptions() = options_;
182
 
                                                f.setLogType(log);
183
 
                                                f.load(filename,exp);
184
 
                                                ChromatogramTools().convertSpectraToChromatograms<MSExperiment<PeakType> >(exp, true);
185
 
                                                return true;
186
 
                                        }
187
 
                                        break;
188
 
                                case FileTypes::MGF:
189
 
                                        {
190
 
                                                MascotGenericFile f;
191
 
                                                f.setLogType(log);
192
 
                                                f.load(filename, exp);
193
 
                                                return true;
194
 
                                        }
195
 
                                case FileTypes::MS2:
196
 
                                        {
197
 
                                                MS2File f;
198
 
                                                f.setLogType(log);
199
 
                                                f.load(filename, exp);
200
 
                                                return true;
201
 
                                        }
202
 
                                case FileTypes::XMASS:
203
 
                                {
204
 
                                        exp.reset();
205
 
                                        exp.resize(1);
206
 
                                        XMassFile().load(filename, exp[0]);
207
 
                                        XMassFile().importExperimentalSettings(filename, exp);
208
 
                                        return true;
209
 
                                }
210
 
                                default:
211
 
                                        break;
212
 
                        }
213
 
                        
214
 
                        return false;
215
 
                }
216
 
 
217
 
                /**
218
 
                        @brief Stores an MSExperiment to a file
219
 
                        
220
 
                        The file type to store the data in is determined by the file name. Supported formats for storing are mzML, mzXML, mzData and DTA2D. If the file format cannot be determined from the file name, the mzML format is used.
221
 
                        
222
 
                        @param filename The name of the file to store the data in.
223
 
                        @param exp The experiment to store.
224
 
                        @param log Progress logging mode
225
 
                        
226
 
                        @exception Exception::UnableToCreateFile is thrown if the file could not be written
227
 
                */
228
 
                template <class PeakType> void storeExperiment(const String& filename, const MSExperiment<PeakType>& exp, ProgressLogger::LogType log = ProgressLogger::NONE)
229
 
                {
230
 
                        //load right file
231
 
                        switch(getTypeByFileName(filename))
232
 
                        {
233
 
                                case FileTypes::DTA2D:
234
 
                                        {
235
 
                                                DTA2DFile f;
236
 
                                                f.getOptions() = options_;
237
 
                                                f.setLogType(log);
238
 
                                                f.store(filename,exp);
239
 
                                        }
240
 
                                        break;
241
 
                                case FileTypes::MZXML:
242
 
                                        {
243
 
                                                MzXMLFile f;
244
 
                                                f.getOptions() = options_;
245
 
                                                f.setLogType(log);
246
 
            if ( !exp.getChromatograms().empty() )
247
 
                                                {
248
 
                                                        MSExperiment<PeakType> exp2 = exp;
249
 
                                                        ChromatogramTools().convertChromatogramsToSpectra<MSExperiment<PeakType> >(exp2);
250
 
                                                        f.store(filename,exp2);
251
 
                                                }
252
 
                                                else
253
 
                                                {
254
 
                                                        f.store(filename, exp);
255
 
                                                }
256
 
                                        }
257
 
                                        break;
258
 
                                case FileTypes::MZDATA:
259
 
                                        {
260
 
                                                MzDataFile f;
261
 
                                                f.getOptions() = options_;
262
 
                                                f.setLogType(log);
263
 
            if ( !exp.getChromatograms().empty() )
264
 
                                                {
265
 
                                                        MSExperiment<PeakType> exp2 = exp;
266
 
                                                        ChromatogramTools().convertChromatogramsToSpectra<MSExperiment<PeakType> >(exp2);
267
 
                                                        f.store(filename,exp2);
268
 
                                                }
269
 
                                                else
270
 
                                                {
271
 
                                                        f.store(filename, exp);
272
 
                                                }
273
 
                                        }
274
 
                                        break;
275
 
                                default:
276
 
                                        {
277
 
                                                MzMLFile f;
278
 
                                                f.getOptions() = options_;
279
 
                                                f.setLogType(log);
280
 
                                                f.store(filename,exp);
281
 
                                        }
282
 
                                        break;
283
 
                        }
284
 
                }
285
 
 
286
 
 
287
 
                /**
288
 
                        @brief Loads a file into a FeatureMap
289
 
                        
290
 
                        @param filename the file name of the file to load.
291
 
                        @param map The FeatureMap to load the data into.
292
 
                        @param force_type Forces to load the file with that file type. If no type is forced, it is determined from the extention ( or from the content if that fails).
293
 
                        
294
 
                        @return true if the file could be loaded, false otherwise
295
 
                        
296
 
                        @exception Exception::FileNotFound is thrown if the file could not be opened
297
 
                        @exception Exception::ParseError is thrown if an error occurs during parsing
298
 
                */
299
 
                template <class FeatureType> bool loadFeatures(const String& filename, FeatureMap<FeatureType>& map, FileTypes::Type force_type = FileTypes::UNKNOWN)
300
 
                {
301
 
                        //determine file type
302
 
                        FileTypes::Type type;
303
 
                        if (force_type != FileTypes::UNKNOWN)
304
 
                        {
305
 
                                type = force_type;
306
 
                        }
307
 
                        else
308
 
                        {
309
 
                                try
310
 
                                {
311
 
                                        type = getType(filename);
312
 
                                }
313
 
                                catch(Exception::FileNotFound)
314
 
                                {
315
 
                                        return false;
316
 
                                }
317
 
                        }
318
 
 
319
 
                        //load right file
320
 
                        if (type==FileTypes::FEATUREXML)
321
 
                        {
322
 
                                FeatureXMLFile().load(filename,map);
323
 
                        }
324
 
                        else if (type==FileTypes::TSV)
325
 
      {
326
 
        MsInspectFile().load(filename,map);
327
 
      }
328
 
                        else if (type==FileTypes::PEPLIST)
329
 
      {
330
 
        SpecArrayFile().load(filename,map);
331
 
      }
332
 
                        else if (type==FileTypes::KROENIK)
333
 
      {
334
 
        KroenikFile().load(filename,map);
335
 
      }
336
 
      else
337
 
      {
338
 
        return false;
339
 
      }
340
 
 
341
 
      return true;
342
 
                }
343
 
 
344
 
                private:
345
 
                  PeakFileOptions options_;
346
 
        };
 
106
    /**
 
107
      @brief Loads a file into an MSExperiment
 
108
 
 
109
      @param filename The file name of the file to load.
 
110
      @param exp The experiment to load the data into.
 
111
      @param force_type Forces to load the file with that file type. If no type is forced, it is determined from the extention ( or from the content if that fails).
 
112
      @param log Progress logging mode
 
113
      @param compute_hash Computes a hash value for the loaded file and stores it in the SourceFile
 
114
 
 
115
      @return true if the file could be loaded, false otherwise
 
116
 
 
117
      @exception Exception::FileNotFound is thrown if the file could not be opened
 
118
      @exception Exception::ParseError is thrown if an error occurs during parsing
 
119
    */
 
120
    template <class PeakType>
 
121
    bool loadExperiment(const String& filename, MSExperiment<PeakType>& exp, FileTypes::Type force_type = FileTypes::UNKNOWN, ProgressLogger::LogType log = ProgressLogger::NONE, const bool compute_hash = true)
 
122
    {
 
123
      //determine file type
 
124
      FileTypes::Type type;
 
125
      if (force_type != FileTypes::UNKNOWN)
 
126
      {
 
127
        type = force_type;
 
128
      }
 
129
      else
 
130
      {
 
131
        try
 
132
        {
 
133
          type = getType(filename);
 
134
        }
 
135
        catch (Exception::FileNotFound)
 
136
        {
 
137
          return false;
 
138
        }
 
139
      }
 
140
 
 
141
      //load right file
 
142
      switch (type)
 
143
      {
 
144
      case FileTypes::DTA:
 
145
        exp.reset();
 
146
        exp.resize(1);
 
147
        DTAFile().load(filename, exp[0]);
 
148
        break;
 
149
 
 
150
      case FileTypes::DTA2D:
 
151
      {
 
152
        DTA2DFile f;
 
153
        f.getOptions() = options_;
 
154
        f.setLogType(log);
 
155
        f.load(filename, exp);
 
156
      }
 
157
 
 
158
      break;
 
159
 
 
160
      case FileTypes::MZXML:
 
161
      {
 
162
        MzXMLFile f;
 
163
        f.getOptions() = options_;
 
164
        f.setLogType(log);
 
165
        f.load(filename, exp);
 
166
      }
 
167
 
 
168
      break;
 
169
 
 
170
      case FileTypes::MZDATA:
 
171
      {
 
172
        MzDataFile f;
 
173
        f.getOptions() = options_;
 
174
        f.setLogType(log);
 
175
        f.load(filename, exp);
 
176
      }
 
177
      break;
 
178
 
 
179
      case FileTypes::MZML:
 
180
      {
 
181
        MzMLFile f;
 
182
        f.getOptions() = options_;
 
183
        f.setLogType(log);
 
184
        f.load(filename, exp);
 
185
        ChromatogramTools().convertSpectraToChromatograms<MSExperiment<PeakType> >(exp, true);
 
186
      }
 
187
      break;
 
188
 
 
189
      case FileTypes::MGF:
 
190
      {
 
191
        MascotGenericFile f;
 
192
        f.setLogType(log);
 
193
        f.load(filename, exp);
 
194
      }
 
195
 
 
196
      break;
 
197
 
 
198
      case FileTypes::MS2:
 
199
      {
 
200
        MS2File f;
 
201
        f.setLogType(log);
 
202
        f.load(filename, exp);
 
203
      }
 
204
 
 
205
      break;
 
206
 
 
207
      case FileTypes::XMASS:
 
208
        exp.reset();
 
209
        exp.resize(1);
 
210
        XMassFile().load(filename, exp[0]);
 
211
        XMassFile().importExperimentalSettings(filename, exp);
 
212
 
 
213
        break;
 
214
 
 
215
      default:
 
216
        return false;
 
217
 
 
218
        break;
 
219
      }
 
220
 
 
221
      SourceFile src_file;
 
222
      src_file.setNameOfFile(File::basename(filename));
 
223
      src_file.setPathToFile(String("file:///") + File::path(filename));
 
224
      // this is more complicated since the data formats allowed by mzML are very verbose.
 
225
      // this is prone to changing CV's... our writer will fall back to a default if the name given here is invalid.
 
226
      src_file.setFileType(FileTypes::typeToMZML(type));
 
227
 
 
228
      if (compute_hash)
 
229
      {
 
230
        src_file.setChecksum(computeFileHash_(filename), SourceFile::SHA1);
 
231
      }
 
232
 
 
233
      exp.getSourceFiles().clear();
 
234
      exp.getSourceFiles().push_back(src_file);
 
235
 
 
236
      return true;
 
237
    }
 
238
 
 
239
    /**
 
240
      @brief Stores an MSExperiment to a file
 
241
 
 
242
      The file type to store the data in is determined by the file name. Supported formats for storing are mzML, mzXML, mzData and DTA2D. If the file format cannot be determined from the file name, the mzML format is used.
 
243
 
 
244
      @param filename The name of the file to store the data in.
 
245
      @param exp The experiment to store.
 
246
      @param log Progress logging mode
 
247
 
 
248
      @exception Exception::UnableToCreateFile is thrown if the file could not be written
 
249
    */
 
250
    template <class PeakType>
 
251
    void storeExperiment(const String& filename, const MSExperiment<PeakType>& exp, ProgressLogger::LogType log = ProgressLogger::NONE)
 
252
    {
 
253
      //load right file
 
254
      switch (getTypeByFileName(filename))
 
255
      {
 
256
      case FileTypes::DTA2D:
 
257
      {
 
258
        DTA2DFile f;
 
259
        f.getOptions() = options_;
 
260
        f.setLogType(log);
 
261
        f.store(filename, exp);
 
262
      }
 
263
      break;
 
264
 
 
265
      case FileTypes::MZXML:
 
266
      {
 
267
        MzXMLFile f;
 
268
        f.getOptions() = options_;
 
269
        f.setLogType(log);
 
270
        if (!exp.getChromatograms().empty())
 
271
        {
 
272
          MSExperiment<PeakType> exp2 = exp;
 
273
          ChromatogramTools().convertChromatogramsToSpectra<MSExperiment<PeakType> >(exp2);
 
274
          f.store(filename, exp2);
 
275
        }
 
276
        else
 
277
        {
 
278
          f.store(filename, exp);
 
279
        }
 
280
      }
 
281
      break;
 
282
 
 
283
      case FileTypes::MZDATA:
 
284
      {
 
285
        MzDataFile f;
 
286
        f.getOptions() = options_;
 
287
        f.setLogType(log);
 
288
        if (!exp.getChromatograms().empty())
 
289
        {
 
290
          MSExperiment<PeakType> exp2 = exp;
 
291
          ChromatogramTools().convertChromatogramsToSpectra<MSExperiment<PeakType> >(exp2);
 
292
          f.store(filename, exp2);
 
293
        }
 
294
        else
 
295
        {
 
296
          f.store(filename, exp);
 
297
        }
 
298
      }
 
299
      break;
 
300
 
 
301
      default:
 
302
      {
 
303
        MzMLFile f;
 
304
        f.getOptions() = options_;
 
305
        f.setLogType(log);
 
306
        f.store(filename, exp);
 
307
      }
 
308
      break;
 
309
      }
 
310
    }
 
311
 
 
312
    /**
 
313
      @brief Loads a file into a FeatureMap
 
314
 
 
315
      @param filename the file name of the file to load.
 
316
      @param map The FeatureMap to load the data into.
 
317
      @param force_type Forces to load the file with that file type. If no type is forced, it is determined from the extention (or from the content if that fails).
 
318
 
 
319
      @return true if the file could be loaded, false otherwise
 
320
 
 
321
      @exception Exception::FileNotFound is thrown if the file could not be opened
 
322
      @exception Exception::ParseError is thrown if an error occurs during parsing
 
323
    */
 
324
    template <class FeatureType>
 
325
    bool loadFeatures(const String& filename, FeatureMap<FeatureType>& map, FileTypes::Type force_type = FileTypes::UNKNOWN)
 
326
    {
 
327
      //determine file type
 
328
      FileTypes::Type type;
 
329
      if (force_type != FileTypes::UNKNOWN)
 
330
      {
 
331
        type = force_type;
 
332
      }
 
333
      else
 
334
      {
 
335
        try
 
336
        {
 
337
          type = getType(filename);
 
338
        }
 
339
        catch (Exception::FileNotFound)
 
340
        {
 
341
          return false;
 
342
        }
 
343
      }
 
344
 
 
345
      //load right file
 
346
      if (type == FileTypes::FEATUREXML)
 
347
      {
 
348
        FeatureXMLFile().load(filename, map);
 
349
      }
 
350
      else if (type == FileTypes::TSV)
 
351
      {
 
352
        MsInspectFile().load(filename, map);
 
353
      }
 
354
      else if (type == FileTypes::PEPLIST)
 
355
      {
 
356
        SpecArrayFile().load(filename, map);
 
357
      }
 
358
      else if (type == FileTypes::KROENIK)
 
359
      {
 
360
        KroenikFile().load(filename, map);
 
361
      }
 
362
      else
 
363
      {
 
364
        return false;
 
365
      }
 
366
 
 
367
      return true;
 
368
    }
 
369
 
 
370
private:
 
371
    PeakFileOptions options_;
 
372
 
 
373
    /**
 
374
      @brief Computes a SHA-1 hash value for the content of the given file.
 
375
 
 
376
      @return The SHA-1 hash of the given file.
 
377
    */
 
378
    String computeFileHash_(const String& filename) const;
 
379
  };
347
380
 
348
381
} //namespace
349
382