OpenMS  3.0.0
MascotInfile.h
Go to the documentation of this file.
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-2022.
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: Timo Sachsenberg $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
39 #include <OpenMS/SYSTEM/File.h>
42 
43 #include <vector>
44 #include <fstream>
45 
46 namespace OpenMS
47 {
58  class OPENMS_DLLAPI MascotInfile :
59  public ProgressLogger
60  {
61 public:
62 
64  MascotInfile();
65 
67  ~MascotInfile() override;
68 
70  void store(const String & filename, const PeakSpectrum & spec, double mz, double retention_time, String search_title);
71 
73  void store(const String & filename, const PeakMap & experiment, String search_title);
74 
81  template <typename MapType>
82  void load(const String & filename, MapType & exp)
83  {
84  exp.reset();
85  if (!File::exists(filename))
86  {
87  throw Exception::FileNotFound(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, filename);
88  }
89 
90  std::ifstream is(filename.c_str());
91  std::vector<std::pair<double, double> > spec;
92  UInt charge(0);
93  double pre_mz(0), pre_int(0), rt(-1);
94  String title;
95  while (getNextSpectrum_(is, spec, charge, pre_mz, pre_int, rt, title))
96  {
97  typename MapType::SpectrumType spectrum;
98  for (std::vector<std::pair<double, double> >::const_iterator it = spec.begin(); it != spec.end(); ++it)
99  {
100  typename MapType::PeakType p;
101  p.setPosition(it->first);
102  p.setIntensity(it->second);
103  spectrum.push_back(p);
104  }
105  spectrum.setMSLevel(2);
106  spectrum.getPrecursors().resize(1);
107  spectrum.getPrecursors()[0].setMZ(pre_mz);
108  spectrum.getPrecursors()[0].setIntensity(pre_int);
109  spectrum.getPrecursors()[0].setCharge(charge);
110  spectrum.setRT(rt);
111  if (!title.empty())
112  {
113  spectrum.setMetaValue("TITLE", title);
114  title = "";
115  }
116 
117  exp.addSpectrum(spectrum);
118 
119  // clean up
120  spec.clear();
121  charge = 0;
122  pre_mz = 0;
123  pre_int = 0;
124  }
125  }
126 
128  const String & getBoundary();
130  void setBoundary(const String & boundary);
131 
133  const String & getDB();
135  void setDB(const String & db);
136 
138  const String & getSearchType();
140  void setSearchType(const String & search_type);
141 
143  const String & getHits();
145  void setHits(const String & hits);
146 
148  const String & getCleavage();
150  void setCleavage(const String & cleavage);
151 
153  const String & getMassType();
155  void setMassType(const String & mass_type);
156 
158  const std::vector<String> & getModifications();
160  void setModifications(const std::vector<String> & mods);
161 
163  const std::vector<String> & getVariableModifications();
165  void setVariableModifications(const std::vector<String> & mods);
166 
168  const String & getInstrument();
170  void setInstrument(const String & instrument);
171 
173  UInt getMissedCleavages() const;
175  void setMissedCleavages(UInt missed_cleavages);
176 
178  float getPrecursorMassTolerance() const;
180  void setPrecursorMassTolerance(float precursor_mass_tolerance);
181 
183  float getPeakMassTolerance() const;
185  void setPeakMassTolerance(float ion_mass_tolerance);
186 
188  const String & getTaxonomy();
190  void setTaxonomy(const String & taxonomy);
191 
193  const String & getFormVersion();
195  void setFormVersion(const String & form_version);
196 
198  const String & getCharges();
200  void setCharges(std::vector<Int> & charges);
201 
202 protected:
204  double mz_;
205 
208 
211 
214 
217 
220 
223 
226 
228  std::vector<String> mods_;
229 
231  std::vector<String> variable_mods_;
232 
235 
238 
241 
244 
247 
250 
253 
256 
258  void writeParameterHeader_(const String & name, FILE * fp, bool line_break = true);
259 
261  void writeHeader_(FILE * fp);
262 
264  void writeSpectrum_(FILE * fp,
265  const String & filename,
266  const PeakSpectrum & peaks);
267 
269  void writeMSExperiment_(FILE * fp,
270  const String & filename,
271  const PeakMap & experiment);
272 
273  bool getNextSpectrum_(std::istream & is, std::vector<std::pair<double, double> > & spectrum, UInt & charge, double & precursor_mz, double & precursor_int, double & rt, String & title);
274  };
275 
276 } // namespace OpenMS
277 
OpenMS::MSExperiment::reset
void reset()
Clear all internal data (spectra, ranges, metadata)
OpenMS::MascotInfile::db_
String db_
the DB to search in
Definition: MascotInfile.h:213
OpenMS::MascotInfile::instrument_
String instrument_
the used instrument
Definition: MascotInfile.h:234
OpenMS::MascotInfile::variable_mods_
std::vector< String > variable_mods_
variable Modifications
Definition: MascotInfile.h:231
OpenMS::MascotInfile
Mascot input file adapter.
Definition: MascotInfile.h:58
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::Exception::FileNotFound
File not found exception.
Definition: Exception.h:509
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:70
OpenMS::SpectrumSettings::getPrecursors
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
OpenMS::MascotInfile::form_version_
String form_version_
form version
Definition: MascotInfile.h:249
OpenMS::Peak1D::setIntensity
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: Peak1D.h:110
OpenMS::MascotInfile::retention_time_
double retention_time_
the retention time
Definition: MascotInfile.h:255
OpenMS::MascotInfile::mods_
std::vector< String > mods_
fixed Modifications
Definition: MascotInfile.h:228
OpenMS::MascotInfile::cleavage_
String cleavage_
Enzyme used for cleavage.
Definition: MascotInfile.h:222
OpenMS::MascotInfile::search_type_
String search_type_
search type: MIS, SQ or PMF
Definition: MascotInfile.h:216
OpenMS::File::exists
static bool exists(const String &file)
Method used to test if a file exists.
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::MSExperiment::addSpectrum
void addSpectrum(const MSSpectrum &spectrum)
adds a spectrum to the list
OpenMS::MascotInfile::precursor_mass_tolerance_
float precursor_mass_tolerance_
precursor mass tolerance in Da
Definition: MascotInfile.h:240
OpenMS::ProgressLogger
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:52
OpenMS::MetaInfoInterface::setMetaValue
void setMetaValue(const String &name, const DataValue &value)
Sets the DataValue corresponding to a name.
ProgressLogger.h
OpenMS::MascotInfile::boundary_
String boundary_
the boundary used for the MIME format
Definition: MascotInfile.h:252
OpenMS::MascotInfile::hits_
String hits_
number of hits to report
Definition: MascotInfile.h:219
OpenMS::MascotInfile::mz_
double mz_
parent mass
Definition: MascotInfile.h:204
OpenMS::Peak1D::setPosition
void setPosition(PositionType const &position)
Mutable access to the position.
Definition: Peak1D.h:149
OpenMS::MSSpectrum::setMSLevel
void setMSLevel(UInt ms_level)
Sets the MS level.
OpenMS::Peak1D
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:53
OpenMS::MascotInfile::search_title_
String search_title_
the search title of the mascot search
Definition: MascotInfile.h:210
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::MascotInfile::charges_
String charges_
charge states to use
Definition: MascotInfile.h:207
MSExperiment.h
OpenMS::MascotInfile::load
void load(const String &filename, MapType &exp)
Definition: MascotInfile.h:82
OpenMS::MascotInfile::mass_type_
String mass_type_
Monoisotopic/average mass.
Definition: MascotInfile.h:225
OpenMS::MascotInfile::taxonomy_
String taxonomy_
taxonomy
Definition: MascotInfile.h:246
String.h
OpenMS::MSSpectrum
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
OpenMS::MascotInfile::missed_cleavages_
UInt missed_cleavages_
number of missed cleavages
Definition: MascotInfile.h:237
OpenMS::MascotInfile::ion_mass_tolerance_
float ion_mass_tolerance_
m/z tolerance of ions in Da
Definition: MascotInfile.h:243
OpenMS::MSSpectrum::setRT
void setRT(double rt)
Sets the absolute retention time (in seconds)
StandardTypes.h
File.h