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

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2012-11-12 15:58:12 UTC
  • Revision ID: package-import@ubuntu.com-20121112155812-vr15wtg9b50cuesg
Tags: upstream-1.9.0
ImportĀ upstreamĀ versionĀ 1.9.0

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
//                    Flex series file support
 
6
// --------------------------------------------------------------------------
 
7
//  Copyright (C) 2009 -- Guillaume Belz (guillaume.belz@chu-lyon.fr)
 
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: Guillaume Belz$
 
25
// $Authors: Guillaume Belz$
 
26
// --------------------------------------------------------------------------
 
27
 
 
28
#ifndef OPENMS_FORMAT_XMASSFILE_H
 
29
#define OPENMS_FORMAT_XMASSFILE_H
 
30
 
 
31
#include <OpenMS/FORMAT/HANDLERS/AcqusHandler.h>
 
32
#include <OpenMS/FORMAT/HANDLERS/FidHandler.h>
 
33
#include <OpenMS/CONCEPT/ProgressLogger.h>
 
34
#include <OpenMS/KERNEL/MSExperiment.h>
 
35
 
 
36
namespace OpenMS
 
37
{
 
38
        /**
 
39
                @brief File adapter for 'XMass Analysis (fid)' files.
 
40
                
 
41
                XMass Analysis files is native format for Bruker spectrometer Flex Series.<br />
 
42
                Each spectrum are saved in one directory. Each directory contains several files. 
 
43
                We use 2 files for import in OpenMS :<br />
 
44
                <b>acqus</b> : contains meta data about calibration (conversion for time to mz ratio), 
 
45
                instrument specification and acquisition method.<br />
 
46
                <b>fid</b> : contains intensity array. Intensity for each point are coded in 4 bytes integer.
 
47
                
 
48
                @note MZ ratio are calculed with forumla based on article :<br />
 
49
    <i>A database application for pre-processing, storage and comparison of mass spectra 
 
50
    derived from patients and controls</i><br />
 
51
    <b>Mark K Titulaer, Ivar Siccama, Lennard J Dekker, Angelique LCT van Rijswijk, 
 
52
    Ron MA Heeren, Peter A Sillevis Smitt, and Theo M Luider</b><br />
 
53
    BMC Bioinformatics. 2006; 7: 403<br />
 
54
    http://www.pubmedcentral.nih.gov/picrender.fcgi?artid=1594579&blobtype=pdf<br />
 
55
        
 
56
        @ingroup FileIO
 
57
  */
 
58
  
 
59
  class OPENMS_DLLAPI XMassFile
 
60
          :     public ProgressLogger
 
61
  {
 
62
    public:
 
63
      /// Default constructor
 
64
      XMassFile();
 
65
      /// Destructor
 
66
      virtual ~XMassFile();
 
67
      
 
68
                        /**
 
69
                                @brief Loads a spectrum from a XMass file.
 
70
 
 
71
        @param filename Name of the XMass file which should be loaded.
 
72
        @param spectrum Spectrum in which the data loaded from the file should be stored.
 
73
 
 
74
                                @exception Exception::FileNotFound is thrown if the file could not be read
 
75
                        */      
 
76
      template <class PeakType>
 
77
      void load(const String& filename, MSSpectrum<PeakType>& spectrum)
 
78
      {
 
79
        Internal::AcqusHandler acqus(filename.prefix(filename.length()-3) + String("acqus"));
 
80
        
 
81
        Internal::FidHandler fid(filename);
 
82
        if (!fid)
 
83
                                {
 
84
                                        throw Exception::FileNotFound(__FILE__, __LINE__, __PRETTY_FUNCTION__, filename);
 
85
                                }      
 
86
                                
 
87
        //  Delete old spectrum
 
88
                                spectrum.clear(true);
 
89
                                
 
90
                                //temporary variables
 
91
                                PeakType p;
 
92
                                                        
 
93
        while (spectrum.size() < acqus.getSize())
 
94
        {
 
95
                                  //fill peak
 
96
                                  p.setPosition( (typename PeakType::PositionType) acqus.getPosition(fid.getIndex()) );
 
97
                                  p.setIntensity( (typename PeakType::IntensityType) fid.getIntensity() );
 
98
                                  spectrum.push_back(p);
 
99
        }
 
100
        fid.close();
 
101
        
 
102
        // import metadata
 
103
        spectrum.setRT(0.0);
 
104
        spectrum.setMSLevel(1);
 
105
        spectrum.setName("Xmass analysis file " + acqus.getParam("$ID_raw"));
 
106
        spectrum.setType(SpectrumSettings::RAWDATA);
 
107
        spectrum.setNativeID("spectrum=xsd:" + acqus.getParam("$ID_raw").remove('<').remove('>'));
 
108
        spectrum.setComment("no comment");
 
109
        
 
110
        InstrumentSettings instrument_settings;
 
111
        instrument_settings.setScanMode(InstrumentSettings::MASSSPECTRUM);
 
112
        instrument_settings.setZoomScan(false);
 
113
 
 
114
        if(acqus.getParam(".IONIZATION MODE") == "LD+")
 
115
                                {
 
116
          instrument_settings.setPolarity(IonSource::POSITIVE);
 
117
                                }
 
118
        else if (acqus.getParam(".IONIZATION MODE") == "LD-")
 
119
                                {
 
120
                instrument_settings.setPolarity(IonSource::NEGATIVE);
 
121
                                }
 
122
        else 
 
123
                                {
 
124
                                        instrument_settings.setPolarity(IonSource::POLNULL);
 
125
                                }
 
126
        spectrum.setInstrumentSettings(instrument_settings);
 
127
        
 
128
        AcquisitionInfo acquisition_info;
 
129
        acquisition_info.setMethodOfCombination("Sum of " + acqus.getParam("$NoSHOTS") + " raw spectrum");
 
130
        spectrum.setAcquisitionInfo(acquisition_info);
 
131
          
 
132
        SourceFile source_file;
 
133
        source_file.setNameOfFile("fid");
 
134
        source_file.setPathToFile(filename.prefix(filename.length()-3));
 
135
        source_file.setFileSize(4.0 * acqus.getSize() / 1024 / 1024); // 4 bytes / point
 
136
        source_file.setFileType("Xmass analysis file (fid)");
 
137
        spectrum.setSourceFile(source_file);
 
138
        
 
139
        DataProcessing data_processing;
 
140
        Software software;
 
141
        software.setName("FlexControl");
 
142
        String fc_ver = acqus.getParam("$FCVer"); // FlexControlVersion
 
143
        if(fc_ver.hasPrefix("<flexControl "))
 
144
                                {
 
145
                                        fc_ver = fc_ver.suffix(' ');
 
146
                                }
 
147
        if(fc_ver.hasSuffix(">"))
 
148
                                {
 
149
                                        fc_ver = fc_ver.prefix('>');
 
150
                                }
 
151
        software.setVersion(fc_ver);
 
152
        software.setMetaValue("Acquisition method", DataValue(acqus.getParam("$ACQMETH").remove('<').remove('>')));
 
153
        data_processing.setSoftware(software);
 
154
        std::set<DataProcessing::ProcessingAction> actions;
 
155
        actions.insert(DataProcessing::SMOOTHING);
 
156
        actions.insert(DataProcessing::BASELINE_REDUCTION);
 
157
        actions.insert(DataProcessing::CALIBRATION);
 
158
        data_processing.setProcessingActions(actions);
 
159
        data_processing.setCompletionTime(DateTime::now());
 
160
          
 
161
        std::vector<DataProcessing> data_processing_vector;
 
162
          data_processing_vector.push_back(data_processing);
 
163
        spectrum.setDataProcessing(data_processing_vector);
 
164
      }
 
165
 
 
166
                        /**
 
167
                                @brief Import settings from a XMass file.
 
168
 
 
169
        @param filename File from which the experimental settings should be loaded.
 
170
        @param exp MSExperiment where the experimental settings will be stored.
 
171
 
 
172
        @exception Exception::FileNotFound is thrown if the file could not be opened.
 
173
                        */              
 
174
      template <class PeakType>
 
175
      void importExperimentalSettings(const String& filename, MSExperiment<PeakType>& exp)
 
176
      {
 
177
        Internal::AcqusHandler acqus(filename.prefix(filename.length()-3) + String("acqus"));
 
178
  
 
179
        ExperimentalSettings& experimental_settings = exp.getExperimentalSettings();
 
180
        
 
181
        Instrument& instrument = experimental_settings.getInstrument();
 
182
        instrument.setName(acqus.getParam("SPECTROMETER/DATASYSTEM"));
 
183
        instrument.setVendor(acqus.getParam("ORIGIN"));
 
184
        instrument.setModel(acqus.getParam("$InstrID").remove('<').remove('>'));
 
185
          
 
186
        std::vector<IonSource>& ionSourceList = instrument.getIonSources();
 
187
        ionSourceList.clear();
 
188
        ionSourceList.resize(1);
 
189
        if (acqus.getParam(".INLET") == "DIRECT")
 
190
                                {
 
191
                ionSourceList[0].setInletType(IonSource::DIRECT);
 
192
                                }
 
193
        else
 
194
                                {
 
195
                ionSourceList[0].setInletType(IonSource::INLETNULL);
 
196
          ionSourceList[0].setIonizationMethod(IonSource::MALDI);
 
197
                                }
 
198
        if (acqus.getParam(".IONIZATION MODE") == "LD+")
 
199
                                {
 
200
                ionSourceList[0].setPolarity(IonSource::POSITIVE);
 
201
                                }
 
202
        else if (acqus.getParam(".IONIZATION MODE") == "LD-")
 
203
                                {
 
204
                ionSourceList[0].setPolarity(IonSource::NEGATIVE);
 
205
                                }
 
206
        else 
 
207
                                {
 
208
                ionSourceList[0].setPolarity(IonSource::POLNULL);
 
209
                                }
 
210
        ionSourceList[0].setMetaValue("MALDI target reference", DataValue(acqus.getParam("$TgIDS").remove('<').remove('>')));
 
211
        ionSourceList[0].setOrder(0);
 
212
            
 
213
        std::vector<MassAnalyzer>& massAnalyzerList = instrument.getMassAnalyzers();
 
214
        massAnalyzerList.clear();
 
215
        massAnalyzerList.resize(1);  
 
216
        if(acqus.getParam(".SPECTROMETER TYPE") == "TOF")
 
217
                                {
 
218
                massAnalyzerList[0].setType(MassAnalyzer::TOF);
 
219
                                }
 
220
        else
 
221
                                {
 
222
                massAnalyzerList[0].setType(MassAnalyzer::ANALYZERNULL);
 
223
                                }
 
224
        
 
225
        DateTime date;
 
226
        date.set(acqus.getParam("$AQ_DATE").remove('<').remove('>') );
 
227
        experimental_settings.setDateTime(date);
 
228
      }
 
229
 
 
230
                        /**
 
231
                                @brief Stores a spectrum in a XMass file (not avaible)
 
232
 
 
233
                                @exception Exception::FileNotWritable is thrown
 
234
                        */
 
235
      template <typename SpectrumType>
 
236
      void store(const String& /*filename*/, const SpectrumType& /*spectrum*/)
 
237
      {
 
238
        throw Exception::NotImplemented(__FILE__, __LINE__, __PRETTY_FUNCTION__);
 
239
      }
 
240
      
 
241
  };
 
242
} // namespace OpenMS
 
243
 
 
244
#endif // OPENMS_FORMAT_XMASSFILE_H
 
245