MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / writeSpectrum

Method writeSpectrum

src/openms/source/FORMAT/MascotGenericFile.cpp:290–405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

288 }
289
290 void MascotGenericFile::writeSpectrum(ostream& os, const PeakSpectrum& spec, const String& filename, const String& native_id_type_accession)
291 {
292 Precursor precursor;
293 if (!spec.getPrecursors().empty())
294 {
295 precursor = spec.getPrecursors()[0];
296 }
297 if (spec.getPrecursors().size() > 1)
298 {
299 cerr << "Warning: The spectrum written to Mascot file has more than one precursor. The first precursor is used!\n";
300 }
301 if (spec.size() >= 10000)
302 {
303 String msg = "Spectrum to be written as MGF has " + String(spec.size()) +
304 " peaks; the upper limit is 10,000. Only centroided data is allowed - this is most likely profile data.";
305 throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
306 msg);
307 }
308 double mz(precursor.getMZ()), rt(spec.getRT());
309
310 if (mz == 0)
311 {
312 // retention time
313 cout << "No precursor m/z information for spectrum with rt " << rt
314 << " present, skipping spectrum!\n";
315 }
316 else
317 {
318 os << "\n";
319 os << "BEGIN IONS\n";
320 if (!store_compact_)
321 {
322 // if a TITLE is available, it was (most likely) parsed from an MGF
323 // or generated to be written out in an MGF
324 if (spec.metaValueExists("TITLE"))
325 {
326 os << "TITLE=" << spec.getMetaValue("TITLE") << "\n";
327 }
328 else
329 {
330 os << "TITLE=" << precisionWrapper(mz) << "_" << precisionWrapper(rt)
331 << "_" << spec.getNativeID() << "_" << filename << "\n";
332 }
333 os << "PEPMASS=" << precisionWrapper(mz) << "\n";
334 os << "RTINSECONDS=" << precisionWrapper(rt) << "\n";
335 if (native_id_type_accession == "UNKNOWN")
336 {
337 os << "SCANS=" << spec.getNativeID().substr(spec.getNativeID().find_last_of("=")+1) << "\n";
338 }
339 else
340 {
341 os << "SCANS=" << SpectrumLookup::extractScanNumber(spec.getNativeID(), native_id_type_accession) << "\n";
342 }
343 }
344 else
345 {
346 // if a TITLE is available, it was (most likely) parsed from an MGF
347 // or generated to be written out in an MGF

Callers 1

main_Method · 0.80

Calls 15

precisionWrapperFunction · 0.85
getPrecursorsMethod · 0.80
metaValueExistsMethod · 0.80
getMetaValueMethod · 0.80
getNativeIDMethod · 0.80
substrMethod · 0.80
StringClass · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
getMZMethod · 0.45
getRTMethod · 0.45
getChargeMethod · 0.45

Tested by

no test coverage detected