Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster write of (id)XML #3976

Merged
merged 4 commits into from Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/openms/include/OpenMS/CHEMISTRY/DigestionEnzymeDB.h
Expand Up @@ -41,7 +41,7 @@
#include <OpenMS/FORMAT/ParamXMLFile.h>
#include <OpenMS/SYSTEM/File.h>

#include <boost/unordered_map.hpp>
#include <unordered_map>
#include <set>

namespace OpenMS
Expand Down Expand Up @@ -259,7 +259,7 @@ namespace OpenMS
return;
}

boost::unordered_map<String, const DigestionEnzymeType*> enzyme_names_; // index by names
std::unordered_map<std::string, const DigestionEnzymeType*> enzyme_names_; // index by names

Map<String, const DigestionEnzymeType*> enzyme_regex_; // index by regex

Expand Down
59 changes: 28 additions & 31 deletions src/openms/include/OpenMS/CONCEPT/ClassTest.h
Expand Up @@ -284,15 +284,15 @@ namespace OpenMS
{
std__cout << " + line " << line << ": TEST_EQUAL("
<< expression_1_stringified << ','
<< expression_2_stringified << "): got " << expression_1
<< ", expected " << expression_2 << std::endl;
<< expression_2_stringified << "): got '" << expression_1
<< "', expected '" << expression_2 << "'\n";
}
else
{
std__cout << " - line " << line << ": TEST_EQUAL("
<< expression_1_stringified << ','
<< expression_2_stringified << "): got " << expression_1
<< ", expected " << expression_2 << std::endl;
<< expression_2_stringified << "): got '" << expression_1
<< "', expected '" << expression_2 << "'\n";
failed_lines_list.push_back(line);
}
}
Expand All @@ -315,15 +315,15 @@ namespace OpenMS
{
std__cout << " + line " << line << ": TEST_NOT_EQUAL("
<< expression_1_stringified << ','
<< expression_2_stringified << "): got " << expression_1
<< ", forbidden is " << expression_2 << std::endl;
<< expression_2_stringified << "): got '" << expression_1
<< "', forbidden is '" << expression_2 << "'\n";
}
else
{
std__cout << " - line " << line << ": TEST_NOT_EQUAL("
<< expression_1_stringified << ','
<< expression_2_stringified << "): got " << expression_1
<< ", forbidden is " << expression_2 << std::endl;
<< expression_2_stringified << "): got '" << expression_1
<< "', forbidden is '" << expression_2 << "'\n";
failed_lines_list.push_back(line);
}
}
Expand Down Expand Up @@ -635,8 +635,7 @@ namespace TEST = OpenMS::Internal::ClassTest;
<< "' (line " \
<< __LINE__ \
<< ")!" \
<< std::endl \
<< std::flush; \
<< std::endl; \
} \
std__cout << std::endl;

Expand Down Expand Up @@ -707,6 +706,8 @@ namespace TEST = OpenMS::Internal::ClassTest;
#define TEST_FILE_EQUAL(filename, templatename) \
{ \
++TEST::test_count; \
TEST::test_line = __LINE__; \
\
TEST::equal_files = true; \
TEST::infile.open(filename, std::ios::in); \
TEST::templatefile.open(templatename, std::ios::in); \
Expand All @@ -730,7 +731,7 @@ namespace TEST = OpenMS::Internal::ClassTest;
TEST::initialNewline(); \
std__cout << " TEST_FILE_EQUAL: line mismatch:\n got: '" \
<< TEST_FILE__line << "'\n expected: '" \
<< TEST_FILE__template_line << "'" << std::endl; \
<< TEST_FILE__template_line << "'\n"; \
} \
} \
} \
Expand All @@ -755,7 +756,7 @@ namespace TEST = OpenMS::Internal::ClassTest;
{ \
std__cout << templatename << "\" (template file) "; \
} \
std__cout << std::endl; \
std__cout << "'\n"; \
\
} \
} \
Expand Down Expand Up @@ -863,8 +864,7 @@ namespace TEST = OpenMS::Internal::ClassTest;
<< precisionWrapper(TEST::ratio) \
<< " (" \
<< precisionWrapper(TEST::ratio_max_allowed) \
<< ")" \
<< std::endl; \
<< ")\n"; \
std__cout << "message: \n"; \
std__cout << TEST::fuzzy_message; \
} \
Expand Down Expand Up @@ -897,7 +897,7 @@ namespace TEST = OpenMS::Internal::ClassTest;
TEST::initialNewline(); \
std__cout << " + line " << __LINE__ << \
": TOLERANCE_RELATIVE(" << TEST::ratio_max_allowed << \
") (\"" # a "\")" << std::endl; \
") (\"" # a "\")\n"; \
}

/** @brief Define the absolute tolerance for floating point comparisons.
Expand All @@ -917,7 +917,7 @@ namespace TEST = OpenMS::Internal::ClassTest;
TEST::initialNewline(); \
std__cout << " + line " << __LINE__ << \
": TOLERANCE_ABSOLUTE(" << TEST::absdiff_max_allowed << \
") (\"" # a "\")" << std::endl; \
") (\"" # a "\")\n"; \
}

/** @brief Define the whitelist_ used by #TEST_STRING_SIMILAR and #TEST_FILE_SIMILAR.
Expand Down Expand Up @@ -971,25 +971,25 @@ namespace TEST = OpenMS::Internal::ClassTest;
case 0: \
std__cout << " - line " << TEST::test_line << \
": TEST_EXCEPTION(" # exception_type "," # command \
"): no exception thrown!" << std::endl; \
"): no exception thrown!\n"; \
TEST::failed_lines_list.push_back(TEST::test_line); \
break; \
case 1: \
std__cout << " + line " << TEST::test_line << \
": TEST_EXCEPTION(" # exception_type "," # command \
"): OK" << std::endl; \
"): OK\n"; \
break; \
case 2: \
std__cout << " - line " << TEST::test_line << \
": TEST_EXCEPTION(" # exception_type "," # command \
"): wrong exception thrown! \"" \
<< TEST::exception_name << "\"" << std::endl; \
<< TEST::exception_name << "\"\n"; \
TEST::failed_lines_list.push_back(TEST::test_line); \
break; \
case 3: \
std__cout << " - line " << TEST::test_line << \
": TEST_EXCEPTION(" # exception_type "," # command \
"): wrong exception thrown!" << std::endl; \
"): wrong exception thrown!\n"; \
TEST::failed_lines_list.push_back(TEST::test_line); \
break; \
} \
Expand Down Expand Up @@ -1084,26 +1084,26 @@ namespace TEST = OpenMS::Internal::ClassTest;
case 0: \
std__cout << " - line " << TEST::test_line << \
": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
"): no exception thrown!" << std::endl; \
"): no exception thrown!\n"; \
TEST::failed_lines_list.push_back(TEST::test_line); \
break; \
case 1: \
/* this is actually what we want to get: */ \
std__cout << " + line " << TEST::test_line << \
": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
"): OK" << std::endl; \
"): OK\n"; \
break; \
case 2: \
std__cout << " - line " << TEST::test_line << \
": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
"): wrong exception thrown! \"" << \
TEST::exception_name << "\"" << std::endl; \
TEST::exception_name << "\"\n"; \
TEST::failed_lines_list.push_back(TEST::test_line); \
break; \
case 3: \
std__cout << " - line " << TEST::test_line << \
": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
"): wrong exception thrown!" << std::endl; \
"): wrong exception thrown!\n"; \
TEST::failed_lines_list.push_back(TEST::test_line); \
break; \
case 4: \
Expand All @@ -1112,8 +1112,7 @@ namespace TEST = OpenMS::Internal::ClassTest;
"): exception has wrong message: got '" << \
TEST::exception_message << \
"', expected '" << \
(message) << \
"'" << std::endl; \
(message) << "'\n"; \
TEST::failed_lines_list.push_back(TEST::test_line); \
break; \
} \
Expand Down Expand Up @@ -1145,8 +1144,7 @@ namespace TEST = OpenMS::Internal::ClassTest;
<< filename \
<< "' (line " \
<< __LINE__ \
<< ")" \
<< std::endl; \
<< ")\n"; \
} \
}

Expand All @@ -1163,8 +1161,7 @@ namespace TEST = OpenMS::Internal::ClassTest;
{ \
TEST::initialNewline(); \
std__cout << " - line " << __LINE__ << \
": ABORT_IF(" # condition "): TEST ABORTED" << \
std::endl; \
": ABORT_IF(" # condition "): TEST ABORTED\n"; \
TEST::failed_lines_list.push_back(TEST::test_line); \
} \
break; \
Expand Down Expand Up @@ -1194,7 +1191,7 @@ namespace TEST = OpenMS::Internal::ClassTest;
<< __LINE__ \
<< ": status: " \
<< message \
<< std::endl; \
<< "\n"; \
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/openms/include/OpenMS/FORMAT/IdXMLFile.h
Expand Up @@ -41,6 +41,7 @@
#include <OpenMS/FORMAT/XMLFile.h>

#include <vector>
#include <unordered_map>

namespace OpenMS
{
Expand Down Expand Up @@ -113,7 +114,8 @@ namespace OpenMS
void startElement(const XMLCh* const /*uri*/, const XMLCh* const /*local_name*/, const XMLCh* const qname, const xercesc::Attributes& attributes) override;

/// Add data from ProteinGroups to a MetaInfoInterface
void addProteinGroups_(MetaInfoInterface& meta, const std::vector<ProteinIdentification::ProteinGroup>& groups, const String& group_name, const std::map<String, UInt>& accession_to_id);
void addProteinGroups_(MetaInfoInterface& meta, const std::vector<ProteinIdentification::ProteinGroup>& groups,
const String& group_name, const std::unordered_map<std::string, UInt>& accession_to_id);

/// Read and store ProteinGroup data
void getProteinGroups_(std::vector<ProteinIdentification::ProteinGroup>& groups, const String& group_name);
Expand All @@ -122,20 +124,20 @@ namespace OpenMS
* Helper function to create the XML string for the amino acids before and after the peptide position in a protein.
* Can be reused by e.g. ConsensusXML, FeatureXML to write PeptideHit elements
*/
static String createFlankingAAXMLString_(const std::vector<PeptideEvidence> & pes);
static std::ostream& createFlankingAAXMLString_(const std::vector<PeptideEvidence> & pes, std::ostream& os);

/**
* Helper function to create the XML string for the position of the peptide in a protein.
* Can be reused by e.g. ConsensusXML, FeatureXML to write PeptideHit elements
*/
static String createPositionXMLString_(const std::vector<PeptideEvidence> & pes);
static std::ostream& createPositionXMLString_(const std::vector<PeptideEvidence> & pes, std::ostream& os);


/**
* Helper function to write out fragment annotations as user param fragment_annotation
*/
static void writeFragmentAnnotations_(const String & tag_name, std::ostream & os,
std::vector<PeptideHit::PeakAnnotation> annotations, UInt indent);
const std::vector<PeptideHit::PeakAnnotation>& annotations, UInt indent);

/**
* Helper function to parse fragment annotations from string
Expand Down Expand Up @@ -170,7 +172,7 @@ namespace OpenMS
/// Temporary peptide evidences
std::vector<PeptideEvidence> peptide_evidences_;
/// Map from protein id to accession
std::map<String, String> proteinid_to_accession_;
std::unordered_map<std::string, String> proteinid_to_accession_;
/// Document identifier
String* document_id_;
/// true if a prot id is contained in the current run
Expand Down
4 changes: 2 additions & 2 deletions src/openms/source/FORMAT/ConsensusXMLFile.cpp
Expand Up @@ -983,8 +983,8 @@ namespace OpenMS

vector<PeptideEvidence> pes = id.getHits()[j].getPeptideEvidences();

os << IdXMLFile::createFlankingAAXMLString_(pes);
os << IdXMLFile::createPositionXMLString_(pes);
IdXMLFile::createFlankingAAXMLString_(pes, os);
IdXMLFile::createPositionXMLString_(pes, os);

String accs;
for (vector<PeptideEvidence>::const_iterator pe = pes.begin(); pe != pes.end(); ++pe)
Expand Down
4 changes: 2 additions & 2 deletions src/openms/source/FORMAT/FeatureXMLFile.cpp
Expand Up @@ -1073,8 +1073,8 @@ namespace OpenMS

const vector<PeptideEvidence>& pes = id.getHits()[j].getPeptideEvidences();

os << IdXMLFile::createFlankingAAXMLString_(pes);
os << IdXMLFile::createPositionXMLString_(pes);
IdXMLFile::createFlankingAAXMLString_(pes, os);
IdXMLFile::createPositionXMLString_(pes, os);

String accs;
for (vector<PeptideEvidence>::const_iterator pe = pes.begin(); pe != pes.end(); ++pe)
Expand Down