Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pwiz_tools/Skyline/Model/DdaSearch/MsFraggerSearchEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,24 @@ private void FixPercolatorPepXml(string cruxOutputFilepath, string finalOutputFi
bool isBrukerSource = DataSourceUtil.GetSourceType(spectrumFilename.GetFilePath()) == DataSourceUtil.TYPE_BRUKER;
var lastPsmIdRegex = new Regex(@".* spectrum=""([^""]+?)"" .*",RegexOptions.Compiled);

// This looks for an ampersand that is NOT followed by:
// - "amp;", "lt;", "gt;", "quot;", "apos;" (predefined XML entities)
// - "&#" followed by any number of digits and a semicolon (decimal entity)
// - "&#x" followed by any number of hexadecimal digits and a semicolon (hexadecimal entity)
var unescapedAmpersandRegex = new Regex(@"&(?!amp;|lt;|gt;|quot;|apos;|#\d+;|#x[0-9A-Fa-f]+;)", RegexOptions.Compiled);

using (var pepXmlFile = new StreamReader(cruxOutputFilepath))
using (var fixedPepXmlFile = new StreamWriter(finalOutputFilepath))
{
string line;
string lastPsmId = "";
while ((line = pepXmlFile.ReadLine()) != null)
{
if (line.Contains(@"&"))
{
// Replace unescaped ampersands with the correct &
line = unescapedAmpersandRegex.Replace(line, @"&");
}
if (line.Contains(@"<spectrum_query"))
lastPsmId = lastPsmIdRegex.Replace(line, "$1");
else if (line.Contains(@"<search_score name=""hyperscore"""))
Expand Down