OpenMS  2.4.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-2018.
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  virtual ~MascotInfile();
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 != "")
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();
175  void setMissedCleavages(UInt missed_cleavages);
176 
178  float getPrecursorMassTolerance();
180  void setPrecursorMassTolerance(float precursor_mass_tolerance);
181 
183  float getPeakMassTolerance();
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 
void setMetaValue(const String &name, const DataValue &value)
Sets the DataValue corresponding to a name.
double mz_
parent mass
Definition: MascotInfile.h:204
A more convenient string class.
Definition: String.h:57
String search_title_
the search title of the mascot search
Definition: MascotInfile.h:210
void reset()
Resets all internal values.
void addSpectrum(const MSSpectrum &spectrum)
adds a spectrum to the list
void load(const String &filename, MapType &exp)
Definition: MascotInfile.h:82
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
String mass_type_
Monoisotopic/average mass.
Definition: MascotInfile.h:225
UInt missed_cleavages_
number of missed cleavages
Definition: MascotInfile.h:237
File not found exception.
Definition: Exception.h:523
String charges_
charge states to use
Definition: MascotInfile.h:207
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: Peak1D.h:110
String taxonomy_
taxonomy
Definition: MascotInfile.h:246
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
static bool exists(const String &file)
Method used to test if a file exists.
String db_
the DB to search in
Definition: MascotInfile.h:213
String instrument_
the used instrument
Definition: MascotInfile.h:234
void setPosition(PositionType const &position)
Mutable access to the position.
Definition: Peak1D.h:149
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:54
float ion_mass_tolerance_
m/z tolerance of ions in Da
Definition: MascotInfile.h:243
void setMSLevel(UInt ms_level)
Sets the MS level.
void setRT(double rt)
Sets the absolute retention time (in seconds)
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
String form_version_
form version
Definition: MascotInfile.h:249
std::vector< String > variable_mods_
variable Modifications
Definition: MascotInfile.h:231
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
std::vector< String > mods_
fixed Modifications
Definition: MascotInfile.h:228
String search_type_
search type: MIS, SQ or PMF
Definition: MascotInfile.h:216
Mascot input file adapter.
Definition: MascotInfile.h:58
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:54
float precursor_mass_tolerance_
precursor mass tolerance in Da
Definition: MascotInfile.h:240
String cleavage_
Enzyme used for cleavage.
Definition: MascotInfile.h:222
String hits_
number of hits to report
Definition: MascotInfile.h:219
String boundary_
the boundary used for the MIME format
Definition: MascotInfile.h:252
double retention_time_
the retention time
Definition: MascotInfile.h:255