Repeating a search from a Mascot results file.
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using matrix_science.msparser;
namespace MsParserExamples
{
public class repeat_search
{
public static void Main(string[] argv)
{
if (argv.Length < 1)
{
usage();
return;
}
repeatSearch(argv[0]);
}
private static bool repeatSearch(string filename)
{
bool success = false;
ms_mascotresfilebase file = ms_mascotresfilebase.createResfile(filename, 0, "");
if (file.isValid())
{
StringBuilder s = new StringBuilder();
s.Append("----12345\n");
s.Append("Content-Disposition: form-data; name=\"QUE\"");
s.Append("\n\n");
VectorString keys = new VectorString();
VectorString values = new VectorString();
file.getSearchParametersKeyValues(keys, values);
for (int i = 0; i < keys.Count; ++i) {
string key = keys[i];
string val = values[i];
if (val.Length > 0 && !key.Equals("INTERMEDIATE") && !key.Equals("RULES") && !key.Equals("INTERNALS") && !key.Equals("SEARCH"))
{
s.Append(string.Format("{0}={1}\n", key, val));
}
}
s.Append("SEARCH=SQ\n");
s.Append("INTERMEDIATE=").Append(filename).Append("\n");
for (int q = 1; q <= file.getNumQueries(); q++)
{
s.Append(file.getRepeatSearchString(q)).Append("\n");
}
s.Append("----12345--\n");
try
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"./nph-mascot.exe";
start.Arguments = "4 -commandline";
start.RedirectStandardOutput = true;
start.RedirectStandardInput = true;
start.UseShellExecute = false;
using (Process process = Process.Start(start))
{
using (StreamWriter writer = process.StandardInput)
{
writer.Write(s.ToString());
writer.Flush();
}
using (StreamReader reader = process.StandardOutput)
{
string buf;
while ((buf = reader.ReadLine()) != null)
{
if (buf.Contains("SUCCESS"))
{
if ((buf = reader.ReadLine()) != null)
{
Console.WriteLine(buf);
compareResults(file, buf);
success = true;
}
}
else if (buf.Contains("ERROR"))
{
}
}
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
else
{
Console.WriteLine("Cannot open results file {0}", filename);
Console.WriteLine(file.getLastErrorString());
}
return success;
}
private static void compareResults(ms_mascotresfilebase originalSearch, string repeatedSearchFileName)
{
ms_mascotresfilebase repeatedSearch = ms_mascotresfilebase.createResfile(repeatedSearchFileName, 0, "");
Boolean anyReport = false;
if (repeatedSearch.isValid())
{
if (originalSearch.anyPMF())
{
ms_proteinsummary originalResults = new ms_proteinsummary(originalSearch,
(uint) ms_mascotresults.FLAGS.MSRES_GROUP_PROTEINS, 0, 1, null, null);
ms_proteinsummary repeatedResults = new ms_proteinsummary(repeatedSearch,
(uint)ms_mascotresults.FLAGS.MSRES_GROUP_PROTEINS, 0, 1, null, null);
ms_protein originalProt = originalResults.getHit(1);
ms_protein repeatedProt = repeatedResults.getHit(1);
if (originalProt != null & repeatedProt != null)
{
double diff = repeatedProt.getScore() - originalProt.getScore();
if (diff > 10)
{
Console.WriteLine("Protein score is {0} higher for search {1} than {2}",
diff, repeatedSearchFileName, originalSearch.getFileName());
anyReport = true;
}
}
}
else
{
ms_peptidesummary originalResults = new ms_peptidesummary(originalSearch,
(uint)ms_mascotresults.FLAGS.MSRES_GROUP_PROTEINS, 0, 1, null, 0, 0, null);
ms_peptidesummary repeatedResults = new ms_peptidesummary(repeatedSearch,
(uint)ms_mascotresults.FLAGS.MSRES_GROUP_PROTEINS, 0, 1, null, 0, 0, null);
for (int q = 1; q <= originalSearch.getNumQueries(); q++)
{
ms_peptide pepOriginal = originalResults.getPeptide(q, 1);
ms_peptide pepRepeated = repeatedResults.getPeptide(q, 1);
if (pepOriginal != null && pepRepeated != null)
{
double diff = pepRepeated.getIonsScore() - pepOriginal.getIonsScore();
if (diff > 10)
{
Console.WriteLine("Query {0} has core {1} higher for search {2} than {3}",
q, diff, repeatedSearchFileName, originalSearch.getFileName());
anyReport = true;
}
}
}
}
if (!anyReport)
{
Console.WriteLine("Similar results for {0} and {1}", originalSearch.getFileName(), repeatedSearchFileName);
}
}
else
{
Console.WriteLine("Invalid repeat search: {0}", repeatedSearch.getLastErrorString());
}
}
private static void usage()
{
Console.WriteLine("Usage: repeat_search <results_file> ");
Console.WriteLine("Given a mascot results file name, repeat the search ");
Console.WriteLine("against the same data");
Console.WriteLine(" result_file is a full path to a result file");
Console.WriteLine("The program must be run from the mascot cgi directory");
}
}
}