OpenMS
MascotInfile.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: $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
13 #include <OpenMS/SYSTEM/File.h>
16 
17 #include <vector>
18 #include <fstream>
19 
20 namespace OpenMS
21 {
32  class OPENMS_DLLAPI MascotInfile :
33  public ProgressLogger
34  {
35 public:
36 
39 
41  ~MascotInfile() override;
42 
44  void store(const String & filename, const PeakSpectrum & spec, double mz, double retention_time, String search_title);
45 
47  void store(const String & filename, const PeakMap & experiment, String search_title);
48 
55  template <typename MapType>
56  void load(const String & filename, MapType & exp)
57  {
58  exp.reset();
59  if (!File::exists(filename))
60  {
61  throw Exception::FileNotFound(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, filename);
62  }
63 
64  std::ifstream is(filename.c_str());
65  std::vector<std::pair<double, double> > spec;
66  UInt charge(0);
67  double pre_mz(0), pre_int(0), rt(-1);
68  String title;
69  while (getNextSpectrum_(is, spec, charge, pre_mz, pre_int, rt, title))
70  {
71  typename MapType::SpectrumType spectrum;
72  for (std::vector<std::pair<double, double> >::const_iterator it = spec.begin(); it != spec.end(); ++it)
73  {
74  typename MapType::PeakType p;
75  p.setPosition(it->first);
76  p.setIntensity(it->second);
77  spectrum.push_back(p);
78  }
79  spectrum.setMSLevel(2);
80  spectrum.getPrecursors().resize(1);
81  spectrum.getPrecursors()[0].setMZ(pre_mz);
82  spectrum.getPrecursors()[0].setIntensity(pre_int);
83  spectrum.getPrecursors()[0].setCharge(charge);
84  spectrum.setRT(rt);
85  if (!title.empty())
86  {
87  spectrum.setMetaValue("TITLE", title);
88  title = "";
89  }
90 
91  exp.addSpectrum(spectrum);
92 
93  // clean up
94  spec.clear();
95  charge = 0;
96  pre_mz = 0;
97  pre_int = 0;
98  }
99  }
100 
102  const String & getBoundary();
104  void setBoundary(const String & boundary);
105 
107  const String & getDB();
109  void setDB(const String & db);
110 
114  void setSearchType(const String & search_type);
115 
117  const String & getHits();
119  void setHits(const String & hits);
120 
122  const String & getCleavage();
124  void setCleavage(const String & cleavage);
125 
127  const String & getMassType();
129  void setMassType(const String & mass_type);
130 
132  const std::vector<String> & getModifications();
134  void setModifications(const std::vector<String> & mods);
135 
137  const std::vector<String> & getVariableModifications();
139  void setVariableModifications(const std::vector<String> & mods);
140 
144  void setInstrument(const String & instrument);
145 
149  void setMissedCleavages(UInt missed_cleavages);
150 
154  void setPrecursorMassTolerance(float precursor_mass_tolerance);
155 
157  float getPeakMassTolerance() const;
159  void setPeakMassTolerance(float ion_mass_tolerance);
160 
162  const String & getTaxonomy();
164  void setTaxonomy(const String & taxonomy);
165 
169  void setFormVersion(const String & form_version);
170 
172  const String & getCharges();
174  void setCharges(std::vector<Int> & charges);
175 
176 protected:
178  double mz_;
179 
182 
185 
188 
191 
194 
197 
200 
202  std::vector<String> mods_;
203 
205  std::vector<String> variable_mods_;
206 
209 
212 
215 
218 
221 
224 
227 
230 
232  void writeParameterHeader_(const String & name, FILE * fp, bool line_break = true);
233 
235  void writeHeader_(FILE * fp);
236 
238  void writeSpectrum_(FILE * fp,
239  const String & filename,
240  const PeakSpectrum & peaks);
241 
243  void writeMSExperiment_(FILE * fp,
244  const String & filename,
245  const PeakMap & experiment);
246 
247  bool getNextSpectrum_(std::istream & is, std::vector<std::pair<double, double> > & spectrum, UInt & charge, double & precursor_mz, double & precursor_int, double & rt, String & title);
248  };
249 
250 } // namespace OpenMS
251 
File not found exception.
Definition: Exception.h:474
static bool exists(const String &file)
Method used to test if a file exists.
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
void addSpectrum(const MSSpectrum &spectrum)
adds a spectrum to the list
void reset()
Clear all internal data (spectra, ranges, metadata)
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
void setMSLevel(UInt ms_level)
Sets the MS level.
void setRT(double rt)
Sets the absolute retention time (in seconds)
Mascot input file adapter.
Definition: MascotInfile.h:34
std::vector< String > mods_
fixed Modifications
Definition: MascotInfile.h:202
const String & getHits()
returns the number of hits to report back
String instrument_
the used instrument
Definition: MascotInfile.h:208
void setSearchType(const String &search_type)
sets the search type (default: MIS). So far only MIS is supported! Valid types are "MIS" (MS/MS Ion S...
const String & getMassType()
returns the used mass type ("Monoisotopic" or "Average")
const String & getSearchType()
returns the search type
const std::vector< String > & getModifications()
returns a vector containing the fixed modifications (default: none)
String taxonomy_
taxonomy
Definition: MascotInfile.h:220
void setModifications(const std::vector< String > &mods)
sets the fixed modifications (default: none). See <mascot path>/config/mod_file for possible setting...
const String & getInstrument()
returns the instrument type
void setMissedCleavages(UInt missed_cleavages)
sets the number of allowed missed cleavages (default: 1)
void setCharges(std::vector< Int > &charges)
sets the charges (default: 1+, 2+ and 3+)
void writeSpectrum_(FILE *fp, const String &filename, const PeakSpectrum &peaks)
writes the spectrum
String form_version_
form version
Definition: MascotInfile.h:223
float getPrecursorMassTolerance() const
returns the precursor mass tolerance
String search_title_
the search title of the mascot search
Definition: MascotInfile.h:184
float precursor_mass_tolerance_
precursor mass tolerance in Da
Definition: MascotInfile.h:214
String db_
the DB to search in
Definition: MascotInfile.h:187
String boundary_
the boundary used for the MIME format
Definition: MascotInfile.h:226
String mass_type_
Monoisotopic/average mass.
Definition: MascotInfile.h:199
const String & getBoundary()
returns the boundary used for the MIME format
void writeMSExperiment_(FILE *fp, const String &filename, const PeakMap &experiment)
writes the MSExperiment
const std::vector< String > & getVariableModifications()
returns a vector containing the variable modifications (default: none)
void setCleavage(const String &cleavage)
sets the enzyme used for cleavage (default: Trypsin). See <mascot path>/config/enzymes for possible ...
const String & getCleavage()
returns the enzyme used for cleavage
const String & getCharges()
returns the charges
String cleavage_
Enzyme used for cleavage.
Definition: MascotInfile.h:196
UInt missed_cleavages_
number of missed cleavages
Definition: MascotInfile.h:211
void setVariableModifications(const std::vector< String > &mods)
sets the fixed modifications (default: none). See <mascot path>/config/mod_file for possible setting...
void writeHeader_(FILE *fp)
writes the full header
String hits_
number of hits to report
Definition: MascotInfile.h:193
void setPeakMassTolerance(float ion_mass_tolerance)
sets the peak mass tolerance in Da (default: 1.0)
bool getNextSpectrum_(std::istream &is, std::vector< std::pair< double, double > > &spectrum, UInt &charge, double &precursor_mz, double &precursor_int, double &rt, String &title)
void load(const String &filename, MapType &exp)
Definition: MascotInfile.h:56
const String & getTaxonomy()
returns the taxonomy
void setBoundary(const String &boundary)
sets the boundary used for the MIME format. By default a 22 character random string is used
std::vector< String > variable_mods_
variable Modifications
Definition: MascotInfile.h:205
void setTaxonomy(const String &taxonomy)
sets the taxonomy (default: All entries). See <mascot path>/config/taxonomy for possible settings.
void store(const String &filename, const PeakMap &experiment, String search_title)
stores the experiment data in a MascotInfile that can be used as input for MASCOT shell execution
double retention_time_
the retention time
Definition: MascotInfile.h:229
float ion_mass_tolerance_
m/z tolerance of ions in Da
Definition: MascotInfile.h:217
void store(const String &filename, const PeakSpectrum &spec, double mz, double retention_time, String search_title)
stores the peak list in a MascotInfile that can be used as input for MASCOT shell execution
void setFormVersion(const String &form_version)
sets the Mascot form version (default: 1.01)
String search_type_
search type: MIS, SQ or PMF
Definition: MascotInfile.h:190
void setPrecursorMassTolerance(float precursor_mass_tolerance)
sets the precursor mass tolerance in Da (default: 2.0)
void setMassType(const String &mass_type)
sets the used mass type "Monoisotopic" or "Average" (default: Monoisotopic)
void setDB(const String &db)
sets the DB to use (default: MSDB). See <mascot path>/config/mascot.dat in "Databases" section for po...
const String & getFormVersion()
returns the Mascot form version
const String & getDB()
returns the DB to use
void writeParameterHeader_(const String &name, FILE *fp, bool line_break=true)
writes a parameter header
float getPeakMassTolerance() const
returns the peak mass tolerance in Da
UInt getMissedCleavages() const
returns the number of allowed missed cleavages
void setHits(const String &hits)
sets the number of hits to report back (default: 20)
double mz_
parent mass
Definition: MascotInfile.h:178
MascotInfile()
constructor
void setInstrument(const String &instrument)
sets the instrument type (Default: Default). Possible instruments: ESI-QUAD-TOF, MALDI-TOF-PSD,...
String charges_
charge states to use
Definition: MascotInfile.h:181
~MascotInfile() override
constructor
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
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:27
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
A more convenient string class.
Definition: String.h:34
unsigned int UInt
Unsigned integer type.
Definition: Types.h:64
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19