Repeating a search from a Mascot results file.
#include "msparser.hpp"
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <string>
#ifdef _WIN32
#define popen _popen
#define pclose _pclose
#endif
using namespace matrix_science;
static bool repeatSearch(const char * filename);
static int usage(const char * progName);
const char * repeatedSearchFileName);
int main(int argc, char * argv[])
{
if (argc == 2)
return repeatSearch(argv[1]);
else
return usage(argv[0]);
}
static bool repeatSearch(const char * filename)
{
bool success = false;
{
std::ostringstream s;
s << "----12345\n"
<< "Content-Disposition: form-data; name=\"QUE\""
<< std::endl << std::endl;
std::vector<std::string> keys, values;
file. getSearchParametersKeyValues(keys, values);
for (std::vector<std::string>::size_type i = 0; i < keys.size(); ++i) {
std::string key = keys[i];
std::string val = values[i];
if (!val.empty() && key != "INTERMEDIATE" && key != "RULES" && key != "SEARCH")
s << key << "=" << val << std::endl;
}
s << "SEARCH=SQ" << std::endl;
s << "INTERMEDIATE=" << filename << std::endl;
s << "----12345--\n";
FILE * f = popen("./nph-mascot.exe 4 -commandline > tmp.txt", "w");
if (f)
{
fwrite(s.str().c_str(), s.str().length(), 1, f);
pclose(f);
if ((f = fopen("tmp.txt", "r")) != 0)
{
char buf[1000];
while (fgets(buf, sizeof(buf), f))
{
if (strstr(buf, "SUCCESS") && fgets(buf, sizeof(buf), f))
{
if (buf[strlen(buf)-1] == '\n')
buf[strlen(buf)-1] = '\0';
compareResults(file, buf);
success = true;
}
else if (strstr(buf, "ERROR"))
{
std::cout << "Search failed: " << buf;
while (fgets(buf, sizeof(buf), f))
{
std::cout << buf;
}
}
}
fclose(f);
}
else
{
std::cout << "Can't open tmp file. \n";
}
}
else
{
std::cout << "Cannot open pipe to nph-mascot.exe to repeat search for file "
<< filename << std::endl;
}
}
else
{
std::cout << "Cannot open results file " << filename
}
return success;
}
const char * repeatedSearchFileName)
{
bool anyReport = false;
{
{
ms_protein * originalProt = originalResults.getHit(1);
ms_protein * repeatedProt = repeatedResults.getHit(1);
if (originalProt && repeatedProt)
{
if (diff > 10.0)
{
std::cout << "Protein score is "
<< diff
<< " higher for search "
<< " than "
<< repeatedSearchFileName
<< std::endl;
anyReport = true;
}
}
}
else
{
{
if (originalResults.getPeptide(q, 1, pepOriginal)
&& repeatedResults.getPeptide(q, 1, pepRepeated))
{
if (diff > 10.0)
{
std::cout << "Query " << q
<< "has score " << diff
<< " higher for search "
<< " than "
<< repeatedSearchFileName
<< std::endl;
anyReport = true;
}
}
}
}
if (!anyReport)
std::cout << "Similar results for "
<< " and "
<< repeatedSearchFileName
<< std::endl;
}
else
std::cout << "Invalid repeat search "
}
static int usage(const char * progName)
{
std::cout << progName << " results_file " << std::endl
<< "Given an mascot results file name, repeat the search "
<< "against the same data" << std::endl
<< " results_file is a full path to a results file" << std::endl
<< "The program must be run from the mascot cgi directory"
<< std::endl;
return 1;
}
bool isValid() const
Call this function to determine if there have been any errors.
Definition: ms_errors.cpp:1472
Abstract base class of ms_mascotresfile_dat and ms_mascotresfile_msr.
Definition: ms_mascotresfilebase.hpp:72
std::string getLastErrorString() const
Return the last error number - or an empty string.
Definition: ms_mascotresfilebase.cpp:824
virtual bool anyPMF() const =0
Returns true if any of the queries in the search just contain a single peptide mass.
virtual std::string getRepeatSearchString(const int query, const bool fullQuery=false) const =0
To perform a repeat search need to build up appropriate string.
virtual int getNumQueries(const int resfileID=0) const =0
Returns the number of queries (peptide masses or ms-ms spectra).
virtual std::string getFileName(const int id=1) const =0
Returns the name of the results file passed into the constructor.
This class encapsulates a peptide from the mascot results file.
Definition: ms_peptide.hpp:57
double getIonsScore() const
Returns the ions score.
Definition: ms_peptide.cpp:1050
Use this class to get peptide summary results.
Definition: ms_peptidesummary.hpp:51
This class encapsulates a protein in the mascot results file.
Definition: ms_protein.hpp:57
double getScore() const
Return the protein score for this protein.
Definition: ms_protein.cpp:574
Definition: ms_proteinsummary.hpp:45