| 73 | } |
| 74 | |
| 75 | void IdXMLFile::store(const String& filename, const std::vector<ProteinIdentification>& protein_ids, const std::vector<PeptideIdentification>& peptide_ids, const String& document_id) |
| 76 | { |
| 77 | if (!FileHandler::hasValidExtension(filename, FileTypes::IDXML)) |
| 78 | { |
| 79 | throw Exception::UnableToCreateFile( |
| 80 | __FILE__, |
| 81 | __LINE__, |
| 82 | OPENMS_PRETTY_FUNCTION, |
| 83 | filename, |
| 84 | "invalid file extension, expected '" + FileTypes::typeToName(FileTypes::IDXML) + "'"); |
| 85 | } |
| 86 | |
| 87 | //set filename for the handler. Just in case (e.g. when fatalError function is used). |
| 88 | file_ = filename; |
| 89 | |
| 90 | //open stream |
| 91 | std::ofstream os(filename.c_str()); |
| 92 | if (!os) |
| 93 | { |
| 94 | throw Exception::UnableToCreateFile(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, filename); |
| 95 | } |
| 96 | |
| 97 | startProgress(0, peptide_ids.size(), "Storing idXML"); |
| 98 | |
| 99 | os.precision(writtenDigits<double>(0.0)); |
| 100 | |
| 101 | // write header |
| 102 | os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
| 103 | os << "<?xml-stylesheet type=\"text/xsl\" href=\"https://www.openms.de/xml-stylesheet/IdXML.xsl\" ?>\n"; |
| 104 | os << "<IdXML version=\"" << getVersion() << "\""; |
| 105 | if (!document_id.empty()) |
| 106 | { |
| 107 | os << " id=\"" << document_id << "\""; |
| 108 | } |
| 109 | os << " xsi:noNamespaceSchemaLocation=\"https://www.openms.de/xml-schema/IdXML_1_5.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"; |
| 110 | |
| 111 | // look up different search parameters |
| 112 | std::vector<ProteinIdentification::SearchParameters> params; |
| 113 | for (std::vector<ProteinIdentification>::const_iterator it = protein_ids.begin(); it != protein_ids.end(); ++it) |
| 114 | { |
| 115 | if (find(params.begin(), params.end(), it->getSearchParameters()) == params.end()) |
| 116 | { |
| 117 | params.push_back(it->getSearchParameters()); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | // write search parameters |
| 122 | for (Size i = 0; i != params.size(); ++i) |
| 123 | { |
| 124 | os << "\t<SearchParameters " |
| 125 | << "id=\"SP_" << i << "\" " |
| 126 | << "db=\"" << writeXMLEscape(params[i].db) << "\" " |
| 127 | << "db_version=\"" << writeXMLEscape(params[i].db_version) << "\" " |
| 128 | << "taxonomy=\"" << writeXMLEscape(params[i].taxonomy) << "\" "; |
| 129 | if (params[i].mass_type == ProteinIdentification::MONOISOTOPIC) |
| 130 | { |
| 131 | os << "mass_type=\"monoisotopic\" "; |
| 132 | } |
nothing calls this directly
no test coverage detected