TODO adapt store to write new? format
| 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 |