OpenMS
XMassFile.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg $
6 // $Authors: Guillaume Belz $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
16 
17 namespace OpenMS
18 {
40  class OPENMS_DLLAPI XMassFile :
41  public ProgressLogger
42  {
43 public:
47  ~XMassFile() override;
48 
57  void load(const String & filename, MSSpectrum & spectrum)
58  {
59  Internal::AcqusHandler acqus(filename.prefix(filename.length() - 3) + String("acqus"));
60 
61  Internal::FidHandler fid(filename);
62  if (!fid)
63  {
64  throw Exception::FileNotFound(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, filename);
65  }
66 
67  // Delete old spectrum
68  spectrum.clear(true);
69 
70  //temporary variables
71  Peak1D p;
72 
73  while (spectrum.size() < acqus.getSize())
74  {
75  //fill peak
78  spectrum.push_back(p);
79  }
80  fid.close();
81 
82  // import metadata
83  spectrum.setRT(0.0);
84  spectrum.setMSLevel(1);
85  spectrum.setName("Xmass analysis file " + acqus.getParam("$ID_raw"));
87  spectrum.setNativeID("spectrum=xsd:" + acqus.getParam("$ID_raw").remove('<').remove('>'));
88  spectrum.setComment("no comment");
89 
90  InstrumentSettings instrument_settings;
91  instrument_settings.setScanMode(InstrumentSettings::MASSSPECTRUM);
92  instrument_settings.setZoomScan(false);
93 
94  if (acqus.getParam(".IONIZATION MODE") == "LD+")
95  {
96  instrument_settings.setPolarity(IonSource::POSITIVE);
97  }
98  else if (acqus.getParam(".IONIZATION MODE") == "LD-")
99  {
100  instrument_settings.setPolarity(IonSource::NEGATIVE);
101  }
102  else
103  {
104  instrument_settings.setPolarity(IonSource::POLNULL);
105  }
106  spectrum.setInstrumentSettings(instrument_settings);
107 
108  AcquisitionInfo acquisition_info;
109  acquisition_info.setMethodOfCombination("Sum of " + acqus.getParam("$NoSHOTS") + " raw spectrum");
110  spectrum.setAcquisitionInfo(acquisition_info);
111 
112  SourceFile source_file;
113  source_file.setNameOfFile("fid");
114  source_file.setPathToFile(filename.prefix(filename.length() - 3));
115  source_file.setFileSize(4.0 * acqus.getSize() / 1024 / 1024); // 4 bytes / point
116  source_file.setFileType("Xmass analysis file (fid)");
117  spectrum.setSourceFile(source_file);
118 
119  DataProcessing data_processing;
120  Software software;
121  software.setName("FlexControl");
122  String fc_ver = acqus.getParam("$FCVer"); // FlexControlVersion
123  if (fc_ver.hasPrefix("<flexControl "))
124  {
125  fc_ver = fc_ver.suffix(' ');
126  }
127  if (fc_ver.hasSuffix(">"))
128  {
129  fc_ver = fc_ver.prefix('>');
130  }
131  software.setVersion(fc_ver);
132  software.setMetaValue("Acquisition method", DataValue(acqus.getParam("$ACQMETH").remove('<').remove('>')));
133  data_processing.setSoftware(software);
134  std::set<DataProcessing::ProcessingAction> actions;
135  actions.insert(DataProcessing::SMOOTHING);
136  actions.insert(DataProcessing::BASELINE_REDUCTION);
137  actions.insert(DataProcessing::CALIBRATION);
138  data_processing.setProcessingActions(actions);
139  data_processing.setCompletionTime(DateTime::now());
140 
141  std::vector< boost::shared_ptr< DataProcessing> > data_processing_vector;
142  data_processing_vector.push_back( boost::shared_ptr< DataProcessing>(new DataProcessing(data_processing)) );
143  spectrum.setDataProcessing(data_processing_vector);
144  }
145 
154  void importExperimentalSettings(const String & filename, PeakMap & exp)
155  {
156  Internal::AcqusHandler acqus(filename.prefix(filename.length() - 3) + String("acqus"));
157 
158  ExperimentalSettings & experimental_settings = exp.getExperimentalSettings();
159 
160  Instrument & instrument = experimental_settings.getInstrument();
161  instrument.setName(acqus.getParam("SPECTROMETER/DATASYSTEM"));
162  instrument.setVendor(acqus.getParam("ORIGIN"));
163  instrument.setModel(acqus.getParam("$InstrID").remove('<').remove('>'));
164 
165  std::vector<IonSource> & ionSourceList = instrument.getIonSources();
166  ionSourceList.clear();
167  ionSourceList.resize(1);
168  if (acqus.getParam(".INLET") == "DIRECT")
169  {
170  ionSourceList[0].setInletType(IonSource::DIRECT);
171  }
172  else
173  {
174  ionSourceList[0].setInletType(IonSource::INLETNULL);
175  ionSourceList[0].setIonizationMethod(IonSource::MALDI);
176  }
177  if (acqus.getParam(".IONIZATION MODE") == "LD+")
178  {
179  ionSourceList[0].setPolarity(IonSource::POSITIVE);
180  }
181  else if (acqus.getParam(".IONIZATION MODE") == "LD-")
182  {
183  ionSourceList[0].setPolarity(IonSource::NEGATIVE);
184  }
185  else
186  {
187  ionSourceList[0].setPolarity(IonSource::POLNULL);
188  }
189  ionSourceList[0].setMetaValue("MALDI target reference", DataValue(acqus.getParam("$TgIDS").remove('<').remove('>')));
190  ionSourceList[0].setOrder(0);
191 
192  std::vector<MassAnalyzer> & massAnalyzerList = instrument.getMassAnalyzers();
193  massAnalyzerList.clear();
194  massAnalyzerList.resize(1);
195  if (acqus.getParam(".SPECTROMETER TYPE") == "TOF")
196  {
197  massAnalyzerList[0].setType(MassAnalyzer::TOF);
198  }
199  else
200  {
201  massAnalyzerList[0].setType(MassAnalyzer::ANALYZERNULL);
202  }
203 
204  DateTime date;
205  date.set(acqus.getParam("$AQ_DATE").remove('<').remove('>'));
206  experimental_settings.setDateTime(date);
207  }
208 
214  void store(const String & /*filename*/, const MSSpectrum & /*spectrum*/)
215  {
216  throw Exception::NotImplemented(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
217  }
218 
219  };
220 } // namespace OpenMS
221 
Description of the combination of raw data to a single spectrum.
Definition: AcquisitionInfo.h:29
void setMethodOfCombination(const String &method_of_combination)
sets the method of combination
Description of the applied preprocessing steps.
Definition: DataProcessing.h:27
void setCompletionTime(const DateTime &completion_time)
sets the time of completion taking a DateTime object
void setSoftware(const Software &software)
sets the software used for processing
void setProcessingActions(const std::set< ProcessingAction > &actions)
sets the description of the applied processing
@ CALIBRATION
Calibration of m/z positions.
Definition: DataProcessing.h:43
@ SMOOTHING
Smoothing of the signal to reduce noise.
Definition: DataProcessing.h:37
@ BASELINE_REDUCTION
Baseline reduction.
Definition: DataProcessing.h:40
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:33
DateTime Class.
Definition: DateTime.h:33
static DateTime now()
Returns the current date and time.
void set(UInt month, UInt day, UInt year, UInt hour, UInt minute, UInt second)
sets data from six integers
File not found exception.
Definition: Exception.h:474
Not implemented exception.
Definition: Exception.h:399
Description of the experimental settings.
Definition: ExperimentalSettings.h:36
const Instrument & getInstrument() const
returns a const reference to the MS instrument description
void setDateTime(const DateTime &date)
sets the date the experiment was performed
Description of the settings a MS Instrument was run with.
Definition: InstrumentSettings.h:23
void setPolarity(IonSource::Polarity polarity)
sets the polarity
void setZoomScan(bool zoom_scan)
sets if this scan is a zoom (enhanced resolution) scan
void setScanMode(ScanMode scan_mode)
sets the scan mode
@ MASSSPECTRUM
general spectrum type
Definition: InstrumentSettings.h:29
Description of a MS instrument.
Definition: Instrument.h:39
const std::vector< MassAnalyzer > & getMassAnalyzers() const
returns a const reference to the mass analyzer list
void setName(const String &name)
sets the name of the instrument
void setModel(const String &model)
sets the instrument model
void setVendor(const String &vendor)
sets the instrument vendor
const std::vector< IonSource > & getIonSources() const
returns a const reference to the ion source list
Read-only acqus File handler for XMass Analysis.
Definition: AcqusHandler.h:27
Size getSize() const
Get size of spectrum.
String getParam(const String &param)
Read param as string.
double getPosition(Size index) const
Conversion from index to MZ ratio using internal calibration params.
Read-only fid File handler for XMass Analysis.
Definition: FidHandler.h:27
Size getIndex() const
Get index of current position (without position moving).
Size getIntensity()
Get intensity of current position and move to next position.
@ DIRECT
Direct.
Definition: IonSource.h:29
@ INLETNULL
Unknown.
Definition: IonSource.h:28
@ POSITIVE
Positive polarity.
Definition: IonSource.h:117
@ NEGATIVE
Negative polarity.
Definition: IonSource.h:118
@ POLNULL
Unknown.
Definition: IonSource.h:116
@ MALDI
Matrix-assisted laser desorption ionization.
Definition: IonSource.h:81
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:45
const ExperimentalSettings & getExperimentalSettings() const
returns the meta information of this experiment (const access)
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
void setMSLevel(UInt ms_level)
Sets the MS level.
void setName(const String &name)
Sets the name.
void clear(bool clear_meta_data)
Clears all data and meta data.
void setRT(double rt)
Sets the absolute retention time (in seconds)
@ ANALYZERNULL
Unknown.
Definition: MassAnalyzer.h:28
@ TOF
Time-of-flight.
Definition: MassAnalyzer.h:33
void setMetaValue(const String &name, const DataValue &value)
Sets the DataValue corresponding to a name.
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:28
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: Peak1D.h:84
void setPosition(PositionType const &position)
Mutable access to the position.
Definition: Peak1D.h:123
float IntensityType
Intensity type.
Definition: Peak1D.h:36
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:27
Description of the software used for processing.
Definition: Software.h:24
void setName(const String &name)
Sets the name of the software.
void setVersion(const String &version)
Sets the software version.
Description of a file location, used to store the origin of (meta) data.
Definition: SourceFile.h:22
void setFileType(const String &file_type)
sets the file type
void setPathToFile(const String &path_path_to_file)
sets the file path
void setNameOfFile(const String &name_of_file)
sets the file name
void setFileSize(float file_size)
sets the file size in MB
void setComment(const String &comment)
sets the free-text comment
void setInstrumentSettings(const InstrumentSettings &instrument_settings)
sets the instrument settings of the current spectrum
void setType(SpectrumType type)
sets the spectrum type
void setSourceFile(const SourceFile &source_file)
sets the source file
void setDataProcessing(const std::vector< DataProcessingPtr > &data_processing)
sets the description of the applied processing
@ PROFILE
profile data
Definition: SpectrumSettings.h:48
void setAcquisitionInfo(const AcquisitionInfo &acquisition_info)
sets the acquisition info
void setNativeID(const String &native_id)
sets the native identifier for the spectrum, used by the acquisition software.
A more convenient string class.
Definition: String.h:34
bool hasPrefix(const String &string) const
true if String begins with string, false otherwise
String & remove(char what)
Remove all occurrences of the character what.
String prefix(SizeType length) const
returns the prefix of length length
bool hasSuffix(const String &string) const
true if String ends with string, false otherwise
String suffix(SizeType length) const
returns the suffix of length length
Definition: XMassFile.h:42
void importExperimentalSettings(const String &filename, PeakMap &exp)
Import settings from a XMass file.
Definition: XMassFile.h:154
~XMassFile() override
Destructor.
void load(const String &filename, MSSpectrum &spectrum)
Definition: XMassFile.h:57
XMassFile()
Default constructor.
void store(const String &, const MSSpectrum &)
Stores a spectrum in a XMass file (not available)
Definition: XMassFile.h:214
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19