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

Method store

src/openms/source/FORMAT/MSPFile.cpp:346–475  ·  view source on GitHub ↗

TODO adapt store to write new? format

Source from the content-addressed store, hash-verified

344
345 //TODO adapt store to write new? format
346 void MSPFile::store(const String & filename, const PeakMap & exp) const
347 {
348 if (!FileHandler::hasValidExtension(filename, FileTypes::MSP))
349 {
350 throw Exception::UnableToCreateFile(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
351 filename, "invalid file extension, expected '" + FileTypes::typeToName(FileTypes::MSP) + "'");
352 }
353
354 if (!File::writable(filename))
355 {
356 throw Exception::FileNotWritable(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, filename);
357 }
358
359 ofstream out(filename.c_str());
360
361 for (const MSSpectrum& it : exp)
362 {
363 if (!it.getPeptideIdentifications().empty() && !it.getPeptideIdentifications().begin()->getHits().empty())
364 {
365 PeptideHit hit = *it.getPeptideIdentifications().begin()->getHits().begin();
366 String peptide;
367 for (const Residue& pit : hit.getSequence())
368 {
369 if (pit.isModified() && pit.getOneLetterCode() == "M" &&
370 fabs(pit.getModification()->getDiffFormula().getMonoWeight() - 16.0) < 0.01)
371 {
372 peptide += "M(O)"; // TODO why are we writing specifically only oxidations?
373 }
374 else
375 {
376 peptide += pit.getOneLetterCode();
377 }
378 }
379 out << "Name: " << peptide << "/" << hit.getCharge() << "\n";
380 out << "MW: " << hit.getSequence().getMonoWeight() << "\n";
381 out << "Comment:";
382
383 // modifications
384 // e.g. 2/9,C,Carbamidomethyl/12,C,Carbamidomethyl
385 Size num_mods(0);
386 vector<String> modifications;
387 if (hit.getSequence().hasNTerminalModification())
388 {
389 String mod = hit.getSequence().getNTerminalModificationName();
390 ++num_mods;
391 String modification = "0," + hit.getSequence().begin()->getOneLetterCode() + "," + mod;
392 modifications.push_back(modification);
393 }
394
395 // @improvement improve writing support (Andreas)
396 UInt pos(0);
397 for (AASequence::ConstIterator pit = hit.getSequence().begin(); pit != hit.getSequence().end(); ++pit, ++pos)
398 {
399 if (!pit->isModified())
400 {
401 continue;
402 }
403

Callers 15

create_im.pyFile · 0.45
create_sonar.pyFile · 0.45
main_Method · 0.45
main_Method · 0.45
main_Method · 0.45
main_Method · 0.45
main_Method · 0.45
main_Method · 0.45
main_Method · 0.45
transform_Method · 0.45

Calls 15

getSequenceMethod · 0.80
getModificationNameMethod · 0.80
concatenateMethod · 0.80
getPositionMethod · 0.80
StringClass · 0.50
emptyMethod · 0.45
beginMethod · 0.45
isModifiedMethod · 0.45
getMonoWeightMethod · 0.45
getModificationMethod · 0.45
getChargeMethod · 0.45

Tested by 15

main_Method · 0.36
main_Method · 0.36
main_Method · 0.36
main_Method · 0.36
main_Method · 0.36
main_Method · 0.36
main_Method · 0.36
main_Method · 0.36
main_Method · 0.36
main_Method · 0.36
main_Method · 0.36
main_Method · 0.36