|
From: <rb...@us...> - 2010-08-24 18:00:20
|
Revision: 5117
http://sashimi.svn.sourceforge.net/sashimi/?rev=5117&view=rev
Author: rbs66
Date: 2010-08-24 18:00:12 +0000 (Tue, 24 Aug 2010)
Log Message:
-----------
Revised interface so charge models are in the same tab with new charge specific roc curve and error data. Updates to Mixture Model write this data in the xml files. Changed many groups of similar variables to array to compress code.
Modified Paths:
--------------
trunk/trans_proteomic_pipeline/src/Validation/ModelParser/ModelParser.cxx
trunk/trans_proteomic_pipeline/src/Validation/ModelParser/ModelParser.h
trunk/trans_proteomic_pipeline/src/Validation/ModelParser/ModelParserMain.cxx
Modified: trunk/trans_proteomic_pipeline/src/Validation/ModelParser/ModelParser.cxx
===================================================================
--- trunk/trans_proteomic_pipeline/src/Validation/ModelParser/ModelParser.cxx 2010-08-24 17:45:30 UTC (rev 5116)
+++ trunk/trans_proteomic_pipeline/src/Validation/ModelParser/ModelParser.cxx 2010-08-24 18:00:12 UTC (rev 5117)
@@ -1,8 +1,8 @@
-/*
-Program : ModelParser
-Author : J.Eng and Andrew Keller <ak...@sy...>, Robert Hubley, and
- open source code
-Date : 11.27.02
+/*
+Program : ModelParser
+Author : J.Eng and Andrew Keller <ak...@sy...>, Robert Hubley, and
+ open source code
+Date : 11.27.02
Primary data object holding all mixture distributions for each precursor ion charge
@@ -24,10 +24,9 @@
Andrew Keller
Insitute for Systems Biology
-1441 North 34th St.
+1441 North 34th St.
Seattle, WA 98103 USA
ak...@sy...
-
*/
#include <string.h>
@@ -39,1285 +38,1422 @@
#include "ModelParser.h"
-ModelParser::ModelParser(const char* xmlfile, const char* timestamp, const char* spectrum, const char* scores, char* prob) : Parser(NULL) {
+ModelParser::ModelParser(const char* xmlfile, const char* timestamp, const char* spectrum, const char* scores, char* prob) : Parser(NULL)
+{
+ timestamp_ = NULL;
- timestamp_ = NULL;
+ if(timestamp != NULL)
+ {
+ timestamp_ = new char[strlen(timestamp)+1];
+ strcpy(timestamp_, timestamp);
+ }
- if(timestamp != NULL) {
- timestamp_ = new char[strlen(timestamp)+1];
- strcpy(timestamp_, timestamp);
- }
+ spectrum_ = new char[strlen(spectrum)+1];
+ strcpy(spectrum_, spectrum);
- spectrum_ = new char[strlen(spectrum)+1];
- strcpy(spectrum_, spectrum);
+ scores_ = new char[strlen(scores)+1];
+ strcpy(scores_, scores);
+ // change : to =
+ for(int k = 0; scores_[k]; k++)
+ if(scores_[k] == ':')
+ scores_[k] = '=';
- scores_ = new char[strlen(scores)+1];
- strcpy(scores_, scores);
- // change : to =
- for(int k = 0; scores_[k]; k++)
- if(scores_[k] == ':')
- scores_[k] = '=';
+ inputfiles_ = new Array<char*>;
- inputfiles_ = new Array<char*>;
+ display_fval_ = setFvalue(scores_);
+ charge_ = -1;
- display_fval_ = setFvalue(scores_);
- charge_ = -1;
+ if(strlen(spectrum_) > 2 && spectrum_[strlen(spectrum_) - 2] == '.')
+ charge_ = spectrum_[strlen(spectrum_) - 1] - 48;
- if(strlen(spectrum_) > 2 && spectrum_[strlen(spectrum_)-2] == '.')
- charge_ = spectrum_[strlen(spectrum_)-1] - 48;
+ adjusted_ = False;
- adjusted_ = False;
+ if(strlen(prob) > 0 && prob[strlen(prob)-1] == 'a')
+ {
+ adjusted_ = True;
+ prob[strlen(prob) - 1] = 0;
+ }
+ prob_ = new char[strlen(prob) + 1];
+ strcpy(prob_, prob);
- if(strlen(prob) > 0 && prob[strlen(prob)-1] == 'a') {
- adjusted_ = True;
- prob[strlen(prob)-1] = 0;
- }
- prob_ = new char[strlen(prob)+1];
- strcpy(prob_, prob);
+ model_tags_ = new Array<Array<Tag*>*>;
- model_tags_ = new Array<Array<Tag*>*>;
+ est_tot_num_correct_ = 0.0;
- est_tot_num_correct_ = 0.0;
+ errors_ = new double[NUM_ERRORS];
+ errors_[0] = 0.0;
+ errors_[1] = 0.025;
+ errors_[2] = 0.05;
+ min_prob_threshes_ = new double[NUM_ERRORS];
+ min_prob_threshes_[0] = 0.0;
+ min_prob_threshes_[1] = 0.0;
+ min_prob_threshes_[2] = 0.0;
- num_errors_ = 3;
+ est_num_corrects_ = new int[NUM_ERRORS];
+ est_num_corrects_[0] = 0;
+ est_num_corrects_[1] = 0;
+ est_num_corrects_[2] = 0;
- errors_ = new double[num_errors_];
- errors_[0] = 0.0;
- errors_[1] = 0.025;
- errors_[2] = 0.05;
- min_prob_threshes_ = new double[num_errors_];
- min_prob_threshes_[0] = 0.0;
- min_prob_threshes_[1] = 0.0;
- min_prob_threshes_[2] = 0.0;
+ prophet_name_ = NULL;
+ PeptideProphetParser* prophet = new PeptideProphetParser();
+ if(prophet != NULL)
+ {
+ const char* prophet_name = prophet->getName();
+ if(prophet_name != NULL)
+ {
+ prophet_name_ = new char[strlen(prophet_name)+1];
+ strcpy(prophet_name_, prophet_name);
+ }
+ delete prophet;
+ }
+ else
+ {
+ cout << "error: no name for peptideprophet" << std::endl;
+ exit(1);
+ }
- est_num_corrects_ = new int[num_errors_];
- est_num_corrects_[0] = 0;
- est_num_corrects_[1] = 0;
- est_num_corrects_[2] = 0;
+ char *xf=strdup(xmlfile);
+ fixPath(xf,1); //tidy up path seperators etc - expect existence
- prophet_name_ = NULL;
- PeptideProphetParser* prophet = new PeptideProphetParser();
- if(prophet != NULL) {
- const char* prophet_name = prophet->getName();
- if(prophet_name != NULL) {
- prophet_name_ = new char[strlen(prophet_name)+1];
- strcpy(prophet_name_, prophet_name);
- }
- delete prophet;
- }
- else {
- cout << "error: no name for peptideprophet" << std::endl;
- exit(1);
- }
-
- char *xf=strdup(xmlfile);
- fixPath(xf,1); // tidy up path seperators etc - expect existence
-
- init(xf);
- free(xf);
+ init(xf);
+ free(xf);
}
-ModelParser::~ModelParser() {
- delete prophet_name_;
- delete timestamp_;
- delete spectrum_;
- delete scores_;
- free(pngfile0_);
- free(pngfile1_);
- free(pngfile2_);
- free(pngfile3_);
- free(pngfile4_);
- free(pngfile5_);
- free(pngfile6_);
- free(pngfile7_);
+ModelParser::~ModelParser()
+{
+ delete prophet_name_;
+ delete timestamp_;
+ delete spectrum_;
+ delete scores_;
+ free(pngSensGraphAll_);
- free(pngZfile1_);
- free(pngZfile2_);
- free(pngZfile3_);
- free(pngZfile4_);
- free(pngZfile5_);
- free(pngZfile6_);
- free(pngZfile7_);
+ for(char i = 0; i != MAX_CHARGE; i++)
+ {
+ free(pngModel_[i]);
+ free(pngModelZoom_[i]);
+ free(pngSensGraph_[i]);
+ }
- delete prob_;
- delete errors_;
- delete min_prob_threshes_;
- delete est_num_corrects_;
- if(model_tags_ != NULL) {
- for(int k = 0; k < model_tags_->length(); k++)
- if((*model_tags_)[k] != NULL) {
- for(int j = 0; j < (*model_tags_)[k]->length(); j++)
- if((*(*model_tags_)[k])[j] != NULL)
- delete (*(*model_tags_)[k])[j];
- } // if not null
- delete model_tags_;
- }
- if(inputfiles_ != NULL) {
- for(int k = 0; k < inputfiles_->length(); k++)
- if((*inputfiles_)[k] != NULL)
- delete (*inputfiles_)[k];
- delete inputfiles_;
- }
+ delete prob_;
+ delete errors_;
+ delete min_prob_threshes_;
+ delete est_num_corrects_;
+ if(model_tags_ != NULL)
+ {
+ for(int k = 0; k < model_tags_->length(); k++)
+ if((*model_tags_)[k] != NULL)
+ {
+ for(int j = 0; j < (*model_tags_)[k]->length(); j++)
+ if((*(*model_tags_)[k])[j] != NULL)
+ delete (*(*model_tags_)[k])[j];
+ } //if not null
+ delete model_tags_;
+ }
+
+ if(inputfiles_ != NULL)
+ {
+ for(int k = 0; k < inputfiles_->length(); k++)
+ if((*inputfiles_)[k] != NULL)
+ delete (*inputfiles_)[k];
+ delete inputfiles_;
+ }
}
-void ModelParser::parse(const char* xmlfile) {
+void ModelParser::parse(const char* xmlfile)
+{
+ Boolean debug = False; //True;
- Boolean debug = False; //True;
+ int range[] = {0, 0, 0, 0, 0, 0, 0};
- int range[] = {0, 0, 0, 0, 0, 0, 0};
+ Tag* tag = NULL;
+ char* data = NULL;
- Tag* tag = NULL;
- char* data = NULL;
+ Boolean analyze = False;
- Boolean analyze = False;
+ Array<sens_err*>* sensitivity = new Array<sens_err*>; // collect sens data
+ sens_err* next_sens = NULL;
- Array<sens_err*>* sensitivity = new Array<sens_err*>; // collect sens data
- sens_err* next_sens = NULL;
+ roc_error_data chargeModelData[MAX_CHARGE]; //holds roc and error info for charge specific models tab
- Array<distr_pt*>* distributions = new Array<distr_pt*>;
- distr_pt* next_distr = NULL;
+ for(char i = 0; i != MAX_CHARGE; i++)
+ {
+ chargeModelData[i].hasData = false; //this will change later on if data is found
+ chargeModelData[i].sensitivity = new Array<sens_err*>;
+ }
- pwiz::util::random_access_compressed_ifstream fin(xmlfile); // can read gzipped files
- if(! fin) {
- cerr << "ModelParser: error opening " << xmlfile << endl;
- exit(1);
- }
- Boolean done = False;
- Boolean collect = False;
+ Array<distr_pt*>* distributions = new Array<distr_pt*>;
+ distr_pt* next_distr = NULL;
- int error_index = 0;
+ pwiz::util::random_access_compressed_ifstream fin(xmlfile); // can read gzipped files
+ if(! fin)
+ {
+ cerr << "ModelParser: error opening " << xmlfile << endl;
+ exit(1);
+ }
- char options[1000];
- options[0] = 0;
+ Boolean done = False;
+ Boolean collect = False;
+ Boolean collectRocErr = False;
+ int chargeRocErr = 0;
- char *nextline = new char[line_width_];
+ int error_index = 0;
+ char options[1000];
+ options[0] = 0;
- while(! done && fin.getline(nextline, line_width_)) {
+ char *nextline = new char[line_width_];
- data = strstr(nextline, "<");
- while(data != NULL) {
- tag = new Tag(data);
- setFilter(tag);
+ while(! done && fin.getline(nextline, line_width_))
+ {
+ data = strstr(nextline, "<");
- if(tag != NULL) {
+ while(data != NULL)
+ {
+ tag = new Tag(data);
+ setFilter(tag);
- if(filter_)
- analyze = True;
+ if(tag != NULL)
+ {
+ if(filter_)
+ analyze = True;
- if(tag->isStart() && ! strcmp(tag->getName(), "peptideprophet_summary")) {
- est_tot_num_correct_ = atof(tag->getAttributeValue("est_tot_num_correct"));
- strcpy(options, tag->getAttributeValue("options"));
- }
- if(analyze && tag->isEnd() && ! strcmp(tag->getName(), "peptideprophet_summary")) {
- analyze = False; // done
- done = True;
- break; // no more need to read summary
- }
+ if(tag->isStart() && ! strcmp(tag->getName(), "peptideprophet_summary"))
+ {
+ est_tot_num_correct_ = atof(tag->getAttributeValue("est_tot_num_correct"));
+ strcpy(options, tag->getAttributeValue("options"));
+ }
- if(analyze) { // grab desired data
- if(tag->isStart() && ! strcmp(tag->getName(), "inputfile")) {
- char* nextfile = new char[strlen(tag->getAttributeValue("name"))+1];
- strcpy(nextfile, tag->getAttributeValue("name"));
- inputfiles_->insertAtEnd(nextfile);
- }
- else if(! strcmp(tag->getName(), "roc_data_point")) {
- next_sens = new sens_err;
- next_sens->minprob = atof(tag->getAttributeValue("min_prob"));
- next_sens->sens = atof(tag->getAttributeValue("sensitivity"));
- next_sens->err = atof(tag->getAttributeValue("error"));
- sensitivity->insertAtEnd(next_sens);
- } // roc
- else if(error_index < num_errors_ && tag->isStart() && ! strcmp(tag->getName(), "error_point")) {
- double nexterr = atof(tag->getAttributeValue("error"));
- double maxdiff = 0.005;
- if( nexterr == errors_[error_index] ||
- (nexterr > errors_[error_index] && nexterr - errors_[error_index] <= maxdiff) ||
- (nexterr < errors_[error_index] && errors_[error_index] - nexterr <= maxdiff)) {
- min_prob_threshes_[error_index] = atof(tag->getAttributeValue("min_prob"));
- est_num_corrects_[error_index] = atoi(tag->getAttributeValue("num_corr"));
- error_index++;
- }
- }
- else if(! strcmp(tag->getName(), "distribution_point")) {
- next_distr = new distr_pt;
- next_distr->fval = atof(tag->getAttributeValue("fvalue"));
- next_distr->obs1 = atoi(tag->getAttributeValue("obs_1_distr"));
- next_distr->modelpos1 = atof(tag->getAttributeValue("model_1_pos_distr"));
- next_distr->modelneg1 = atof(tag->getAttributeValue("model_1_neg_distr"));
- next_distr->obs2 = atoi(tag->getAttributeValue("obs_2_distr"));
- next_distr->modelpos2 = atof(tag->getAttributeValue("model_2_pos_distr"));
- next_distr->modelneg2 = atof(tag->getAttributeValue("model_2_neg_distr"));
- next_distr->obs3 = atoi(tag->getAttributeValue("obs_3_distr"));
- next_distr->modelpos3 = atof(tag->getAttributeValue("model_3_pos_distr"));
- next_distr->modelneg3 = atof(tag->getAttributeValue("model_3_neg_distr"));
- const char* tmp = tag->getAttributeValue("obs_4_distr");
- if (tmp != NULL) {
- next_distr->obs4 = atoi(tag->getAttributeValue("obs_4_distr"));
- next_distr->modelpos4 = atof(tag->getAttributeValue("model_4_pos_distr"));
- next_distr->modelneg4 = atof(tag->getAttributeValue("model_4_neg_distr"));
- }
- tmp = tag->getAttributeValue("obs_5_distr");
- if (tmp != NULL) {
- next_distr->obs5 = atoi(tag->getAttributeValue("obs_5_distr"));
- next_distr->modelpos5 = atof(tag->getAttributeValue("model_5_pos_distr"));
- next_distr->modelneg5 = atof(tag->getAttributeValue("model_5_neg_distr"));
- }
- tmp = tag->getAttributeValue("obs_6_distr");
- if (tmp != NULL) {
- next_distr->obs6 = atoi(tag->getAttributeValue("obs_6_distr"));
- next_distr->modelpos6 = atof(tag->getAttributeValue("model_6_pos_distr"));
- next_distr->modelneg6 = atof(tag->getAttributeValue("model_6_neg_distr"));
- }
- tmp = tag->getAttributeValue("obs_7_distr");
- if (tmp != NULL) {
- next_distr->obs7 = atoi(tag->getAttributeValue("obs_7_distr"));
- next_distr->modelpos7 = atof(tag->getAttributeValue("model_7_pos_distr"));
- next_distr->modelneg7 = atof(tag->getAttributeValue("model_7_neg_distr"));
- }
- if(next_distr->obs1 > range[0])
- range[0] = next_distr->obs1;
- if(next_distr->obs2 > range[1])
- range[1] = next_distr->obs2;
- if(next_distr->obs3 > range[2])
- range[2] = next_distr->obs3;
- if(next_distr->obs4 > range[3])
- range[3] = next_distr->obs4;
- if(next_distr->obs5 > range[4])
- range[4] = next_distr->obs5;
- if(next_distr->obs6 > range[5])
- range[5] = next_distr->obs6;
- if(next_distr->obs7 > range[6])
- range[6] = next_distr->obs7;
+ if(analyze && tag->isEnd() && ! strcmp(tag->getName(), "peptideprophet_summary"))
+ {
+ analyze = False; // done
+ done = True;
+ break; // no more need to read summary
+ }
- distributions->insertAtEnd(next_distr);
- } // distribution
+ if(analyze) //grab desired data
+ {
+ if(tag->isStart() && !strcmp(tag->getName(), "inputfile"))
+ {
+ char* nextfile = new char[strlen(tag->getAttributeValue("name"))+1];
+ strcpy(nextfile, tag->getAttributeValue("name"));
+ inputfiles_->insertAtEnd(nextfile);
+ }
+ else if(! strcmp(tag->getName(), "distribution_point"))
+ {
+ next_distr = new distr_pt;
+ next_distr->fval = atof(tag->getAttributeValue("fvalue"));
- if(tag->isStart() && ! strcmp(tag->getName(), "mixture_model")) {
- Array<Tag*>* next = new Array<Tag*>;
- model_tags_->insertAtEnd(next);
- collect = True;
- }
- else if(tag->isEnd() && ! strcmp(tag->getName(), "mixture_model")) {
- collect = False;
- }
- if(collect)
- (*model_tags_)[model_tags_->length()-1]->insertAtEnd(tag);
+ char* tmp = new char[20];
- } // if analyze
- if(! collect)
- delete tag;
- } // if not null
- data = strstr(data+1, "<");
- } // next tag
-
+ for (char i = 0; i != MAX_CHARGE; i++)
+ {
+ sprintf(tmp, "obs_%d_distr", i + 1);
+ sprintf(tmp, tag->getAttributeValue(tmp));
- } // next line
- fin.close();
- delete []nextline;
+ if (tmp != NULL)
+ {
+ next_distr->obs[i] = atoi(tmp);
+ sprintf(tmp, "model_%d_pos_distr", i + 1);
+ next_distr->modelpos[i] = atof(tag->getAttributeValue(tmp));
+ sprintf(tmp, "model_%d_neg_distr", i + 1);
+ next_distr->modelneg[i] = atof(tag->getAttributeValue(tmp));
+ }
- // now ready to write png files
- char szModelFileBasename[SIZE_FILE],
- szModelDir[SIZE_FILE],
- szSpectrum[SIZE_FILE],
- szRandom[SIZE_FILE],
- szWebserverRoot[SIZE_FILE],
- szRelativePath[SIZE_FILE],
- szBuf[SIZE_BUFF];
- const char *pStr;
+ if(next_distr->obs[i] > range[i])
+ range[i] = next_distr->obs[i];
+ }
- double dProbability=0.0;
- int bNewFileType=FALSE; /* new file type includes 1+ */
- data = NULL;
- char esifile[SIZE_FILE];
- char suffix[] = ".model.txt";
- char esi_suffix[] = ".htm.esi";
- char* result = NULL;
- int abbrev = 0; // whether or not probabilities are single digits (from incomplete analysis)
- int icat = 0;
- char icat_indicator[] = "icat cys";
- int glyc = 0;
- char glyc_indicator[] = "N glyc motif";
- int nmc = 0;
- char nmc_indicator[] = "no. missed";
-
- // these are ok for Linux and Windows/Cygwin (for now)
- char gnuplot_black[] = "-1";
- char gnuplot_pink[] = "4"; //5"; //"4";
- char gnuplot_red[] = "1";
- char gnuplot_blue[] = "3"; //"8";
- int test_blue = 3;
- char gnuplot_green[] = "2";
- esifile[0] = 0; // length 0
- szSpectrum[0] = 0; // length 0
+ distributions->insertAtEnd(next_distr);
+ } //distribution
- if(timestamp_ != NULL && strcmp(prob_, "-nofigs")) {
+ if(tag->isStart() && ! strcmp(tag->getName(), "mixture_model"))
+ {
+ Array<Tag*>* next = new Array<Tag*>;
+ model_tags_->insertAtEnd(next);
+ collect = True;
+ }
+ else if(tag->isEnd() && ! strcmp(tag->getName(), "mixture_model"))
+ {
+ collect = False;
+ }
- pStr=getWebserverRoot();
- if (pStr==NULL)
- {
- printf("<PRE> Environment variable WEBSERVER_ROOT does not exist.\n\n");
-#ifdef WINDOWS_CYGWIN
- printf(" For Windows users, you can set this environment variable\n");
- printf(" through the Advanced tab under System Properties when you\n");
- printf(" right-mouse-click on your My Computer icon.\n\n");
+ if(collect)
+ (*model_tags_)[model_tags_->length() - 1]->insertAtEnd(tag);
- printf(" Set this environment variable to your webserver's document\n");
- printf(" root directory such as c:\\inetpub\\wwwroot for IIS or\n");
- printf(" c:\\website\\htdocs or WebSite Pro.\n\n");
-#endif
- printf(" Exiting.\n");
- exit(0);
- }
- else {
- // must first pass to cygpath program
-#ifdef WINDOWS_CYGWIN
- char szCommand[SIZE_FILE];
- sprintf(szCommand, "cygpath '%s'", pStr);
- FILE* fp;
- if((fp = popen(szCommand, "r")) == NULL) {
- printf("cygpath error, exiting\n");
- exit(1);
- }
- else {
- fgets(szBuf, SIZE_BUFF, fp);
- pclose(fp);
- szBuf[strlen(szBuf)-1] = 0;
- strcpy(szWebserverRoot, szBuf);
+ //collect roc error data
+ if(tag->isStart() && !strcmp(tag->getName(), "roc_error_data"))
+ {
+ collectRocErr = True;
- }
-#else
- strcpy(szWebserverRoot, pStr);
-#endif
- }
- /*
- * Check if szWebserverRoot is present
- */
- if (access(szWebserverRoot, F_OK))
- {
- printf(" Cannot access the webserver's root directory:\n");
- printf(" %s\n", szWebserverRoot);
- printf(" This was set as the environment variable WEBSERVER_ROOT\n\n");
+ if (strcmp(tag->getAttributeValue("charge"), "all"))
+ {
+ chargeRocErr = atoi(tag->getAttributeValue("charge"));
+ chargeModelData[chargeRocErr - 1].hasData = true;
+ chargeModelData[chargeRocErr - 1].charge_est_correct = atof(tag->getAttributeValue("charge_est_correct"));
+ }
+ }
+ else if(tag->isEnd() && !strcmp(tag->getName(), "roc_error_data"))
+ {
+ collectRocErr = False;
+ }
- printf(" For Windows users, you can check this environment variable\n");
- printf(" through the Advanced tab under System Properties when you\n");
- printf(" right-mouse-click on your My Computer icon.\n\n");
- printf(" Exiting.\n");
- exit(1);
- }
+ if(collectRocErr)
+ {
+ if (chargeRocErr) //roc_error_data tag is considering data from a single charge
+ {
+ //load all data into roc_error_data struct
+ if (!strcmp(tag->getName(), "roc_data_point"))
+ {
+ next_sens = new sens_err;
+ next_sens->minprob = atof(tag->getAttributeValue("min_prob"));
+ next_sens->sens = atof(tag->getAttributeValue("sensitivity"));
+ next_sens->err = atof(tag->getAttributeValue("error"));
+ chargeModelData[chargeRocErr - 1].sensitivity->insertAtEnd(next_sens);
+ } //roc
+ else if(error_index < NUM_ERRORS && tag->isStart() && ! strcmp(tag->getName(), "error_point"))
+ {
+ double nexterr = atof(tag->getAttributeValue("error"));
+ double maxdiff = 0.005;
+ if(nexterr == errors_[error_index] ||
+ (nexterr > errors_[error_index] && nexterr - errors_[error_index] <= maxdiff) ||
+ (nexterr < errors_[error_index] && errors_[error_index] - nexterr <= maxdiff))
+ {
+ chargeModelData[chargeRocErr - 1].errorMPT[error_index] = atof(tag->getAttributeValue("min_prob"));
+ chargeModelData[chargeRocErr - 1].errorENC[error_index] = atoi(tag->getAttributeValue("num_corr"));
+ error_index++;
+ }
+ }
+ else
+ error_index = 0;
+ }
+ else //roc_error_data tag is considering all data
+ {
+ if (!strcmp(tag->getName(), "roc_data_point"))
+ {
+ next_sens = new sens_err;
+ next_sens->minprob = atof(tag->getAttributeValue("min_prob"));
+ next_sens->sens = atof(tag->getAttributeValue("sensitivity"));
+ next_sens->err = atof(tag->getAttributeValue("error"));
+ sensitivity->insertAtEnd(next_sens);
+ } //roc
+ else if(error_index < NUM_ERRORS && tag->isStart() && ! strcmp(tag->getName(), "error_point"))
+ {
+ double nexterr = atof(tag->getAttributeValue("error"));
+ double maxdiff = 0.005;
+ if(nexterr == errors_[error_index] ||
+ (nexterr > errors_[error_index] && nexterr - errors_[error_index] <= maxdiff) ||
+ (nexterr < errors_[error_index] && errors_[error_index] - nexterr <= maxdiff))
+ {
+ min_prob_threshes_[error_index] = atof(tag->getAttributeValue("min_prob"));
+ est_num_corrects_[error_index] = atoi(tag->getAttributeValue("num_corr"));
+ error_index++;
+ }
+ }
+ else
+ error_index = 0;
+ }
+ }
+ } //if analyze
- strcpy(szModelFileBasename, xmlfile_);
- replace_path_with_webserver_tmp(szModelFileBasename,sizeof(szModelFileBasename)); // do this in designated tmpdir, if any
+ if(!collect)
+ delete tag;
+ } //if not null
- // remove any aging tmpfiles that may be around for any reason
- std::string pngMask(szModelFileBasename);
- int rslash = findRightmostPathSeperator(pngMask);
- if (rslash>0) {
- pngMask = pngMask.substr(0,rslash+1);
- }
- pngMask += "*.ISB.png";
- remove_files_olderthan(pngMask,10*60); // kill any png files more than 10 minutes old
+ data = strstr(data + 1, "<");
+ } // next tag
+ } // next line
- // add a random element to szModelFileBasename
- strcat(szModelFileBasename,".XXXXXX");
- safe_fclose(FILE_mkstemp(szModelFileBasename)); // create then close a uniquely named file
- unlink(szModelFileBasename); // we only wanted its name, we never actually use it
- strcpy(szModelDir, szModelFileBasename);
- char *slash;
- if (slash=findRightmostPathSeperator(szModelDir))
- {
- *slash='\0';
- }
+ tag = NULL;
+ delete[] tag;
- result = strstri(szModelFileBasename, szWebserverRoot);
- if(result != NULL) {
- if(strlen(result) > strlen(szWebserverRoot) && result[strlen(szWebserverRoot)] != '/') {
- sprintf(szRelativePath, "/%s", result + strlen(szWebserverRoot));
- }
- else {
- strcpy(szRelativePath, result + strlen(szWebserverRoot));
- }
- }
- else {
- strcpy(szRelativePath, szModelFileBasename);
- }
+ fin.close();
+ delete[] nextline;
- char szTmpPlotFile[SIZE_FILE],
- szTmpImageFile[SIZE_FILE],
- szTmpDataFile[SIZE_FILE];
- FILE *fpTmp;
- time_t tStartTime;
- int tot_num_pos = -1;
- double max_pos[MAX_CHARGE];
- double max_obs[MAX_CHARGE];
- result = NULL;
+ data = NULL;
+ /* bunch of unused variables, not sure what they are for
+ int bNewFileType = 0; //new file type includes 1+
+ data = NULL;
+ char esifile[SIZE_FILE];
+ char suffix[] = ".model.txt";
+ char esi_suffix[] = ".htm.esi";
+ int abbrev = 0; // whether or not probabilities are single digits (from incomplete analysis)
+ int icat = 0;
+ char icat_indicator[] = "icat cys";
+ int glyc = 0;
+ char glyc_indicator[] = "N glyc motif";
+ int nmc = 0;
+ char nmc_indicator[] = "no. missed";
+ */
- strcpy(szTmpPlotFile, szModelFileBasename);
- strcpy(szTmpDataFile, szModelFileBasename);
- strcat(szTmpPlotFile, ".gp");
- strcat(szTmpDataFile, ".data");
+ if(timestamp_ != NULL && strcmp(prob_, "-nofigs"))
+ {
+ char* filePath = new char[SIZE_FILE];
+ strcpy(filePath, xmlfile);
- if ( (fpTmp=fopen(szTmpDataFile, "w"))==NULL)
- {
- printf("Error - cannot create 1st image data file %s.", szTmpDataFile);
- }
- else
- {
- for(int k = 0; k < sensitivity->length(); k++)
- fprintf(fpTmp, "%0.2f\t%0.3f\t%0.3f\n", (*sensitivity)[k]->minprob,
- (*sensitivity)[k]->sens, (*sensitivity)[k]->err);
- }
- fclose(fpTmp);
- tStartTime=time((time_t *)NULL);
- srandom((int)(strlen(szModelFileBasename)+10*dProbability+tStartTime+szModelFileBasename[strlen(szModelFileBasename)-3]));
+ //filePath should be something like: c:/Inetpub/wwwroot/ISB/data/class/iProphet/xtandem/interact.iproph.pep.xml.a15956
- sprintf(szRandom, "%ld", (long)random());
- sprintf(szTmpImageFile, "%s.%s.ISB.png", szModelFileBasename, szRandom);
- // note: we'll clean up the tmp image files
- // via the mechanism used by makeTmpPNGFileSrcRef, which is
- // that IMG SRC is a cgi that shows the image then deletes it
+ char* performPath = setFilePaths(filePath);
+ removeOldFiles(filePath);
+ char* szTmpDataFile = new char[SIZE_FILE];
+ sprintf(szTmpDataFile, "%s.data", filePath);
+ // write data files
+ FILE* fpTmp;
- if ( (fpTmp=fopen(szTmpPlotFile, "w"))==NULL)
- {
- printf("Error - cannot create 1st image file %s.", szTmpPlotFile);
- }
- else
- {
- char *pStr;
- fprintf(fpTmp, "set terminal png;\n");
- fprintf(fpTmp, "set output \"%s\";\n", szTmpImageFile);
- fprintf(fpTmp, "set border;\n");
- fprintf(fpTmp, "set title \"Sensitivity & Error Rates\";\n");
- fprintf(fpTmp, "set xlabel \"Min Probability Threshhold (MPT) To Accept\";\n");
- fprintf(fpTmp, "set ylabel \"Sensitivity & Error\";\n");
- fprintf(fpTmp, "set grid;\n");
- fprintf(fpTmp, "set size 0.55,0.6;\n");
- fprintf(fpTmp, "set xrange [0:1];\n");
- fprintf(fpTmp, "set yrange [0:1];\n");
- fprintf(fpTmp, "plot \"%s\" using 1:2 title 'sensitivity' with lines lc %s, \\\n", szTmpDataFile, gnuplot_red);
- fprintf(fpTmp, " \"%s\" using 1:3 title 'error' with lines lc %s\n", szTmpDataFile, gnuplot_green);
+ time_t tStartTime = time((time_t *)NULL);;
+ double max_pos[MAX_CHARGE];
+ double max_obs[MAX_CHARGE];
+ long random = (long)random(); //create random number that becomes part of the file paths
+ srandom((int)(strlen(filePath) + tStartTime + filePath[strlen(filePath) - 3]));
- fclose(fpTmp);
+ //these are ok for Linux and Windows/Cygwin (for now)
+ char gnuplotBlack = -1;
+ char gnuplotRed = 1;
+ char gnuplotGreen = 2;
+ char gnuplotBlue = 3; //8;
+ char gnuplotPink = 4; //5;
- if ( pStr=findRightmostPathSeperator(szTmpPlotFile))
- strcpy(szTmpPlotFile, pStr+1);
+ //create data and image files for sensitivity graphs
- sprintf(szBuf, "cd %s ; %s %s; rm -f %s %s", szModelDir, GNUPLOT_BINARY, szTmpPlotFile, szTmpPlotFile, szTmpDataFile);
+ //write info to data file (all charges)s
+ if((fpTmp = fopen(szTmpDataFile, "w")) == NULL)
+ printf("Error - cannot create main sensitivity graph data file %s.", szTmpDataFile);
+ else
+ {
+ for(int k = 0; k < sensitivity->length(); k++)
+ fprintf(fpTmp, "%0.2f\t%0.3f\t%0.3f\n", (*sensitivity)[k]->minprob, (*sensitivity)[k]->sens, (*sensitivity)[k]->err);
+ }
+ fclose(fpTmp);
- verified_system(szBuf); // like system(), but handles multiple commmands in win32
- strcpy(szTmpPlotFile, szModelFileBasename);
- strcat(szTmpPlotFile, ".gp");
- sprintf(szTmpImageFile, "%s.%s.ISB.png", szRelativePath, szRandom);
-#ifdef USING_RELATIVE_WEBSERVER_PATH // for example, in win32 understand /foo/bar as /Inetpub/wwwroot/foo/bar // fix up the image path
- pngfile0_ = translate_relative_webserver_root_path_to_absolute_filesystem_path(szTmpImageFile);
-#else
- pngfile0_ = strdup(szTmpImageFile);
-#endif
- }
+ //call function to plot sensitivity graph
+ pngSensGraphAll_ = plotSensitivity(filePath, 0, random, gnuplotRed, gnuplotGreen);
- unlink(szTmpPlotFile);
-
- //DDS:
- for (int i=0; i<MAX_CHARGE; i++) {
- max_pos[i] = 1;
- max_obs[i] = 1;
- }
+ //create and plot the sensitivity graph for indvidual charges
+ for(char i = 0; i != MAX_CHARGE; i++)
+ {
+ if(chargeModelData[i].hasData)
+ {
+ if((fpTmp = fopen(szTmpDataFile, "w")) == NULL)
+ printf("Error - cannot create charge sensitivity graph data file %s.", szTmpDataFile);
+ else
+ {
+ for(int k = 0; k < chargeModelData[i].sensitivity->length(); k++)
+ {
+ fprintf(fpTmp, "%0.2f\t%0.3f\t%0.3f\n",
+ (*chargeModelData[i].sensitivity)[k]->minprob, (*chargeModelData[i].sensitivity)[k]->sens, (*chargeModelData[i].sensitivity)[k]->err);
+ }
+ }
+ fclose(fpTmp);
- if ( (fpTmp=fopen(szTmpDataFile, "w"))==NULL)
- {
- printf("Error - cannot create 2nd image data file %s.", szTmpDataFile);
- }
- else
- {
- for(int k = 0; k < distributions->length(); k++) {
- fprintf(fpTmp,
-"%0.2f\t%d\t%0.3f\t%0.3f\t%d\t%0.3f\t%0.3f\t%d\t%0.3f\t%0.3f\t%d\t%0.3f\t%0.3f\t%d\t%0.3f\t%0.3f\t%d\t%0.3f\t%0.3f\t%d\t%0.3f\t%0.3f\n",
- (*distributions)[k]->fval,
- (*distributions)[k]->obs1, (*distributions)[k]->modelpos1, (*distributions)[k]->modelneg1,
- (*distributions)[k]->obs2, (*distributions)[k]->modelpos2, (*distributions)[k]->modelneg2,
- (*distributions)[k]->obs3, (*distributions)[k]->modelpos3, (*distributions)[k]->modelneg3,
- (*distributions)[k]->obs4, (*distributions)[k]->modelpos4, (*distributions)[k]->modelneg4,
- (*distributions)[k]->obs5, (*distributions)[k]->modelpos5, (*distributions)[k]->modelneg5,
- (*distributions)[k]->obs6, (*distributions)[k]->modelpos6, (*distributions)[k]->modelneg6,
- (*distributions)[k]->obs7, (*distributions)[k]->modelpos7, (*distributions)[k]->modelneg7);
- //DDS:
- if (max_pos[0] < (*distributions)[k]->modelpos1) {
- max_pos[0] = (*distributions)[k]->modelpos1;
- }
- if (max_pos[1] < (*distributions)[k]->modelpos2) {
- max_pos[1] = (*distributions)[k]->modelpos2;
- }
- if (max_pos[2] < (*distributions)[k]->modelpos3) {
- max_pos[2] = (*distributions)[k]->modelpos3;
- }
- if (max_pos[3] < (*distributions)[k]->modelpos4) {
- max_pos[3] = (*distributions)[k]->modelpos4;
- }
- if (max_pos[4] < (*distributions)[k]->modelpos5) {
- max_pos[4] = (*distributions)[k]->modelpos5;
- }
- if (max_pos[5] < (*distributions)[k]->modelpos6) {
- max_pos[5] = (*distributions)[k]->modelpos6;
- }
- if (max_pos[6] < (*distributions)[k]->modelpos7) {
- max_pos[6] = (*distributions)[k]->modelpos7;
- }
+ pngSensGraph_[i] = plotSensitivity(filePath, i + 1, random, gnuplotRed, gnuplotGreen);
+ }
+ else
+ pngSensGraph_[i] = NULL;
+ }
- if (max_obs[0] < (*distributions)[k]->obs1) {
- max_obs[0] = (*distributions)[k]->obs1;
- }
- if (max_obs[1] < (*distributions)[k]->obs2) {
- max_obs[1] = (*distributions)[k]->obs2;
- }
- if (max_obs[2] < (*distributions)[k]->obs3) {
- max_obs[2] = (*distributions)[k]->obs3;
- }
- if (max_obs[3] < (*distributions)[k]->obs4) {
- max_obs[3] = (*distributions)[k]->obs4;
- }
- if (max_obs[4] < (*distributions)[k]->obs5) {
- max_obs[4] = (*distributions)[k]->obs5;
- }
- if (max_obs[5] < (*distributions)[k]->obs6) {
- max_obs[5] = (*distributions)[k]->obs6;
- }
- if (max_obs[6] < (*distributions)[k]->obs7) {
- max_obs[6] = (*distributions)[k]->obs7;
- }
- }
+ //create data and image files for charge models
- }
- fclose(fpTmp);
+ for (char i = 0; i != MAX_CHARGE; i++)
+ {
+ max_pos[i] = 1;
+ max_obs[i] = 1;
+ }
- pngfile1_ = plotModel(1, False, max_obs[0], range[0], szModelFileBasename, szModelDir,
- szTmpPlotFile, szTmpDataFile, szRelativePath, szRandom,
- gnuplot_black, gnuplot_pink, gnuplot_blue, gnuplot_red);
- //DDS: Now the Zoom 1+
- pngZfile1_ = plotModel(1, True, max_pos[0], range[0], szModelFileBasename, szModelDir,
- szTmpPlotFile, szTmpDataFile, szRelativePath, szRandom,
- gnuplot_black, gnuplot_pink, gnuplot_blue, gnuplot_red);
+ if ((fpTmp = fopen(szTmpDataFile, "w")) == NULL)
+ printf("Error - cannot create charge model image data file %s.", szTmpDataFile);
+ else
+ {
+ for(int k = 0; k < distributions->length(); k++)
+ {
+ fprintf(fpTmp, "%0.2f", (*distributions)[k]->fval);
+ for(char i = 0; i != MAX_CHARGE; i++)
+ {
+ fprintf(fpTmp, "\t%d\t%0.3f\t%0.3f", (*distributions)[k]->obs[i], (*distributions)[k]->modelpos[i], (*distributions)[k]->modelneg[i]);
- pngfile2_ = plotModel(2, False, max_obs[1], range[1], szModelFileBasename, szModelDir,
- szTmpPlotFile, szTmpDataFile, szRelativePath, szRandom,
- gnuplot_black, gnuplot_pink, gnuplot_blue, gnuplot_red);
- //DDS: Zoom 2+
- pngZfile2_ = plotModel(2, True, max_pos[1], range[1], szModelFileBasename, szModelDir,
- szTmpPlotFile, szTmpDataFile, szRelativePath, szRandom,
- gnuplot_black, gnuplot_pink, gnuplot_blue, gnuplot_red);
+ if (max_pos[i] < (*distributions)[k]->modelpos[i])
+ max_pos[i] = (*distributions)[k]->modelpos[i];
- pngfile3_ = plotModel(3, False, max_obs[2], range[2], szModelFileBasename, szModelDir,
- szTmpPlotFile, szTmpDataFile, szRelativePath, szRandom,
- gnuplot_black, gnuplot_pink, gnuplot_blue, gnuplot_red);
- //DDS: Zoom 3+
- pngZfile3_ = plotModel(3, True, max_pos[2], range[2], szModelFileBasename, szModelDir,
- szTmpPlotFile, szTmpDataFile, szRelativePath, szRandom,
- gnuplot_black, gnuplot_pink, gnuplot_blue, gnuplot_red);
+ if (max_obs[i] < (*distributions)[k]->obs[i])
+ max_obs[i] = (*distributions)[k]->obs[i];
+ }
+ fprintf(fpTmp, "\n");
+ }
+ }
- pngfile4_ = plotModel(4, False, max_obs[3], range[3], szModelFileBasename, szModelDir,
- szTmpPlotFile, szTmpDataFile, szRelativePath, szRandom,
- gnuplot_black, gnuplot_pink, gnuplot_blue, gnuplot_red);
- //DDS: Zoom 4+
- pngZfile4_ = plotModel(4, True, max_pos[3], range[3], szModelFileBasename, szModelDir,
- szTmpPlotFile, szTmpDataFile, szRelativePath, szRandom,
- gnuplot_black, gnuplot_pink, gnuplot_blue, gnuplot_red);
+ fclose(fpTmp);
- pngfile5_ = plotModel(5, False, max_obs[4], range[4], szModelFileBasename, szModelDir,
- szTmpPlotFile, szTmpDataFile, szRelativePath, szRandom,
- gnuplot_black, gnuplot_pink, gnuplot_blue, gnuplot_red);
- //DDS: Zoom 5+
- pngZfile5_ = plotModel(5, True, max_pos[4], range[4], szModelFileBasename, szModelDir,
- szTmpPlotFile, szTmpDataFile, szRelativePath, szRandom,
- gnuplot_black, gnuplot_pink, gnuplot_blue, gnuplot_red);
+ //create png model files for all 7 charges
+ for(char i = 0; i != MAX_CHARGE; i++)
+ {
+ if(chargeModelData[i].hasData)
+ {
+ //testing new plot model
+ pngModel_[i] = plotModel(filePath, i + 1, false, max_obs[i], range[i], random,
+ gnuplotBlack, gnuplotPink, gnuplotBlue, gnuplotRed);
+ //Now the Zoom
+ pngModelZoom_[i] = plotModel(filePath, i + 1, true, max_pos[i], range[i], random,
+ gnuplotBlack, gnuplotPink, gnuplotBlue, gnuplotRed);
+ }
+ else
+ {
+ pngModel_[i] = NULL;
+ pngModelZoom_[i] = NULL;
+ }
+ }
- pngfile6_ = plotModel(6, False, max_obs[5], range[5], szModelFileBasename, szModelDir,
- szTmpPlotFile, szTmpDataFile, szRelativePath, szRandom,
- gnuplot_black, gnuplot_pink, gnuplot_blue, gnuplot_red);
- //DDS: Zoom 6+
- pngZfile6_ = plotModel(6, True, max_pos[5], range[5], szModelFileBasename, szModelDir,
- szTmpPlotFile, szTmpDataFile, szRelativePath, szRandom,
- gnuplot_black, gnuplot_pink, gnuplot_blue, gnuplot_red);
+ unlink(szTmpDataFile);
- pngfile7_ = plotModel(7, False, max_obs[6], range[6], szModelFileBasename, szModelDir,
- szTmpPlotFile, szTmpDataFile, szRelativePath, szRandom,
- gnuplot_black, gnuplot_pink, gnuplot_blue, gnuplot_red);
- //DDS: Zoom 7+
- pngZfile7_ = plotModel(7, True, max_pos[6], range[6], szModelFileBasename, szModelDir,
- szTmpPlotFile, szTmpDataFile, szRelativePath, szRandom,
- gnuplot_black, gnuplot_pink, gnuplot_blue, gnuplot_red);
+ //note: the image files are deleted as soon as they are viewed via the mechanism used by makeTmpPNGFileSrcRef
+ } //if write figs
- unlink(szTmpDataFile);
+ writeModelResults(cout, options, sensitivity, chargeModelData);
+}
- } // if write figs
+char* ModelParser::plotSensitivity(char* filePath, int charge, long random, char sensColor, char errColor)
+{
+ FILE* fpPlotCode;
- writeModelResults(cout, options, sensitivity);
+ char* pngFilePath = new char[SIZE_FILE];
+ char* dataFilePath = new char[SIZE_FILE]; //by this point data file exists and is populated, but it's file path is known
+ char* plotFilePath = new char[SIZE_FILE];
+ char plotCommand[4096];
+
+ if(charge)
+ sprintf(pngFilePath, "%s.%ld.s%d.ISB.png", filePath, random, charge);
+ else
+ sprintf(pngFilePath, "%s.%ld.ISB.png", filePath, random);
+
+ sprintf(plotFilePath, "%s.gp", filePath);
+ sprintf(dataFilePath, "%s.data", filePath);
+
+ if ((fpPlotCode = fopen(plotFilePath, "w")) == NULL)
+ printf("Error - cannot create gnuplot file %s.", plotFilePath);
+ else
+ {
+ //gnuplot code
+ fprintf(fpPlotCode, "set terminal png size %d, %d\n", SENS_IMG_W, SENS_IMG_H);
+ fprintf(fpPlotCode, "set output \"%s\"\n", pngFilePath);
+ fprintf(fpPlotCode, "set border\n");
+ fprintf(fpPlotCode, "set title \"Sensitivity & Error Rates\"\n");
+ fprintf(fpPlotCode, "set xlabel \"Min Probability Threshhold (MPT) To Accept\"\n");
+ fprintf(fpPlotCode, "set ylabel \"Sensitivity & Error\"\n");
+ fprintf(fpPlotCode, "set grid\n");
+ fprintf(fpPlotCode, "set xrange [0:1]\n");
+ fprintf(fpPlotCode, "set yrange [0:1]\n");
+ fprintf(fpPlotCode, "set key bottom right\n");
+ fprintf(fpPlotCode, "plot \"%s\" using 1:2 title 'sensitivity' with lines lc %d, \\\n", dataFilePath, sensColor);
+ fprintf(fpPlotCode, "\"%s\" using 1:3 title 'error' with lines lc %d\n", dataFilePath, errColor);
+
+ fprintf(fpPlotCode, "unset output\n");
+ fclose(fpPlotCode);
+
+ char* plotFileName = findRightmostPathSeperator(plotFilePath);
+ *plotFileName++ = '\0';
+
+ //write and call plot command
+ sprintf(plotCommand, "cd %s; %s %s; rm -f %s", plotFilePath, GNUPLOT_BINARY, plotFileName, plotFileName);
+ verified_system(plotCommand); //system() with verbose error check
+
+#ifdef USING_RELATIVE_WEBSERVER_PATH //fix up the image path if needed
+ pngFilePath = translate_relative_webserver_root_path_to_absolute_filesystem_path(pngFilePath);
+#endif
+ }
+
+ unlink(plotFilePath);
+
+ delete[] plotFilePath;
+ delete[] dataFilePath;
+
+ return pngFilePath;
}
-char* ModelParser::plotModel(int charge, Boolean isZoom, double maxpos, int range, char* szModelFileBasename, char* szModelDir,
- char* szTmpPlotFile, char* szTmpDataFile, char* szRelativePath, char* szRandom,
- char* color_black, char* color_pink, char* color_blue, char* color_red) {
- FILE *fpTmp;
- char szTmpImageFile[SIZE_FILE],
- szBuf[SIZE_BUFF],
- *pngFileName = new char[SIZE_FILE];
+char* ModelParser::plotModel(char* filePath, int charge, bool zoom, double maxpos, int range, long random,
+ char colorBlack, char colorPink, char colorBlue, char colorRed)
+{
+ FILE* fpPlotCode;
- const char *szZoom = isZoom ? "Zoom" : "";
+ char* pngFilePath = new char[SIZE_FILE];
+ char* dataFilePath = new char[SIZE_FILE]; //by this point data file exists and is populated, but it's file path is known
+ char* plotFilePath = new char[SIZE_FILE];
- int distrData = 3 * charge - 1;
- int posData = distrData + 1;
- int negData = distrData + 2;
+ char plotCommand[4096];
- sprintf(szTmpImageFile, "%s.%s.%d%s.ISB.png", szModelFileBasename, szRandom, charge, szZoom);
+ int distrData = 3 * charge - 1;
+ int posData = distrData + 1;
+ int negData = distrData + 2;
- if ( (fpTmp=fopen(szTmpPlotFile, "w"))==NULL) {
- printf("Error - cannot create %d+ image file %s.", charge, szTmpPlotFile);
- }
- else {
- fprintf(fpTmp, "set terminal png;\n");
- fprintf(fpTmp, "set output \"%s\";\n", szTmpImageFile);
- fprintf(fpTmp, "set title \"%d+ %s\";\n", charge, szZoom);
- fprintf(fpTmp, "set border;\n");
- fprintf(fpTmp, "set xlabel \"Discriminant Score (fval)\";\n");
- fprintf(fpTmp, "set ylabel \"# of Spectra\";\n");
- fprintf(fpTmp, "set grid;\n");
- fprintf(fpTmp, "set size 0.33, 0.41;\n");
+ //assume filePath = c:Inetpub/wwwroot/ISB/data/class/iProphet/xtandem/interact.iproph.pep.xml.a#####
- if(display_fval_ && charge_ == charge) {
- fprintf(fpTmp, "set parametric;\n");
- fprintf(fpTmp, "set trange [0:%d];\n", range/2);
- fprintf(fpTmp, "const=%0.4f;\n", fvalue_);
- }
+ if(zoom)
+ sprintf(pngFilePath, "%s.%ld.%dzoom.ISB.png", filePath, random, charge);
+ else
+ sprintf(pngFilePath, "%s.%ld.%d.ISB.png", filePath, random, charge);
- fprintf(fpTmp, "set yrange [0:%f];\n", maxpos*1.2);
- if (isZoom) {
+ sprintf(plotFilePath, "%s.gp", filePath);
+ sprintf(dataFilePath, "%s.data", filePath); //the data should already be at this location
- fprintf(fpTmp, "plot \"%s\" using 1:%d notitle with lines lc %s, \\\n",
- szTmpDataFile, distrData, color_black);
- fprintf(fpTmp, " \"%s\" using 1:%d notitle with lines lc %s, \\\n",
- szTmpDataFile, posData, color_pink);
+ //write gnuplot plotting file
+ if((fpPlotCode = fopen(plotFilePath, "w")) == NULL)
+ {
+ printf("Error - cannot create gnuplot file %s for %d+ charge.", plotFilePath, charge);
+ }
+ else
+ {
+ //working with gnuplot 4.4
+ fprintf(fpPlotCode, "set terminal png size %d, %d;\n", IMG_W, IMG_H);
+ fprintf(fpPlotCode, "set output \"%s\";\n", pngFilePath);
+ if (zoom)
+ fprintf(fpPlotCode, "set title \"%d+ Zoom\";\n", charge);
+ else
+ fprintf(fpPlotCode, "set title \"%d+\";\n", charge);
+ fprintf(fpPlotCode, "set border;\n");
+ fprintf(fpPlotCode, "set xlabel \"Discriminant Score (fval)\";\n");
+ fprintf(fpPlotCode, "set ylabel \"# of Spectra\";\n");
+ fprintf(fpPlotCode, "set grid;\n");
- if(display_fval_ && charge_ == charge) {
- fprintf(fpTmp, " \"%s\" using 1:%d notitle with lines lc %s,\\\n", szTmpDataFile, negData, color_blue);
- fprintf(fpTmp, " const,t notitle with lines lc %s\n", color_red);
- }
- else
- fprintf(fpTmp, " \"%s\" using 1:%d notitle with lines lc %s\n", szTmpDataFile, negData, color_blue);
+ if(display_fval_ && charge_ == charge)
+ {
+ fprintf(fpPlotCode, "set parametric;\n");
+ fprintf(fpPlotCode, "set trange [0:%d];\n", range / 2);
+ fprintf(fpPlotCode, "const = %0.4f;\n", fvalue_);
+ }
+ fprintf(fpPlotCode, "set yrange [0:%f];\n", maxpos * 1.2);
- }
- else {
- fprintf(fpTmp, "plot \"%s\" using 1:%d notitle with lines lc %s, \\\n",
- szTmpDataFile, distrData, color_black);
- fprintf(fpTmp, " \"%s\" using 1:%d notitle with lines lc %s, \\\n",
- szTmpDataFile, posData, color_pink);
+ if (zoom)
+ {
+ fprintf(fpPlotCode, "plot \"%s\" using 1:%d notitle with lines lc %d, \\\n", dataFilePath, distrData, colorBlack);
+ fprintf(fpPlotCode, "\"%s\" using 1:%d notitle with lines lc %d, \\\n", dataFilePath, posData, colorPink);
- if(display_fval_ && charge_ == charge) {
- fprintf(fpTmp, " \"%s\" using 1:%d notitle with lines lc %s,\\\n",
- szTmpDataFile, negData, color_blue);
- fprintf(fpTmp, " const,t title '%0.4f' with lines lc %s\n", fvalue_, color_red);
- }
- else
- fprintf(fpTmp, " \"%s\" using 1:%d notitle with lines lc %s\n",
- szTmpDataFile, negData, color_blue);
- }
+ if(display_fval_ && charge_ == charge)
+ {
+ fprintf(fpPlotCode, "\"%s\" using 1:%d notitle with lines lc %d,\\\n", dataFilePath, negData, colorBlue);
+ fprintf(fpPlotCode, "const,t notitle with lines lc %d\n", colorRed);
+ }
+ else
+ fprintf(fpPlotCode, "\"%s\" using 1:%d notitle with lines lc %d\n", dataFilePath, negData, colorBlue);
+ }
+ else
+ {
+ fprintf(fpPlotCode, "plot \"%s\" using 1:%d notitle with lines lc %d, \\\n", dataFilePath, distrData, colorBlack);
+ fprintf(fpPlotCode, "\"%s\" using 1:%d notitle with lines lc %d, \\\n", dataFilePath, posData, colorPink);
- fclose(fpTmp);
+ if(display_fval_ && charge_ == charge)
+ {
+ fprintf(fpPlotCode, "\"%s\" using 1:%d notitle with lines lc %d,\\\n", dataFilePath, negData, colorBlue);
+ fprintf(fpPlotCode, "const, t title '%0.4f' with lines lc %d\n", fvalue_, colorRed);
+ }
+ else
+ fprintf(fpPlotCode, "\"%s\" using 1:%d notitle with lines lc %d\n", dataFilePath, negData, colorBlue);
+ }
- sprintf(szBuf, "cd %s ; %s %s; rm -f %s", szModelDir, GNUPLOT_BINARY, szTmpPlotFile, szTmpPlotFile);
- sprintf(szTmpImageFile, "%s.%s.%d%s.ISB.png", szRelativePath, szRandom, charge, szZoom);
+ fclose(fpPlotCode);
- verified_system(szBuf); // system() with verbose error check
+ char* plotFileName = findRightmostPathSeperator(plotFilePath);
+ *plotFileName++ = '\0';
-#ifdef USING_RELATIVE_WEBSERVER_PATH // for example, in win32 understand /foo/bar as /Inetpub/wwwroot/foo/bar // fix up the image path
- pngFileName = translate_relative_webserver_root_path_to_absolute_filesystem_path(szTmpImageFile);
-#else
- pngFileName = strdup(szTmpImageFile);
+ //write and call plot command
+ sprintf(plotCommand, "cd %s; %s %s; rm -f %s", plotFilePath, GNUPLOT_BINARY, plotFileName, plotFileName);
+ verified_system(plotCommand); //system() with verbose error check
+
+#ifdef USING_RELATIVE_WEBSERVER_PATH //fix up the image path if needed
+ pngFilePath = translate_relative_webserver_root_path_to_absolute_filesystem_path(pngFilePath);
#endif
- }
+ }
- unlink(szTmpPlotFile);
+ unlink(plotFilePath);
- return pngFileName;
+ delete[] plotFilePath;
+ delete[] dataFilePath;
+
+ return pngFilePath;
}
-char* ModelParser::formatFiles(char* replace) {
- int num_spaces = inputfiles_->length()-1;
+//this correctly sets filePath and returns the path of the performance pngs to be loaded
+char* ModelParser::setFilePaths(char* filePath)
+{
+ const char* tmpRoot;
+ char* pngPath = new char[SIZE_FILE];
+ char webserverRoot[SIZE_FILE];
- if (num_spaces<0) {
- return strCopy("");
- }
+ tmpRoot = getWebserverRoot();
- int k, len = 0;
- for(k = 0; k < inputfiles_->length(); k++)
- len += (int)strlen((*inputfiles_)[k]);
+ if (tmpRoot == NULL)
+ {
+ printf("<PRE> Environment variable WEBSERVER_ROOT does not exist.\n\n");
+#ifdef WINDOWS_CYGWIN
+ printf(" For Windows users, you can set this environment variable\n");
+ printf(" through the Advanced tab under System Properties when you\n");
+ printf(" right-mouse-click on your My Computer icon.\n\n");
- /*
- for(int k = 0; k < strlen(inputfiles); k++)
- if(inputfiles[k] == ' ')
- num_spaces++;
- */
+ printf(" Set this environment variable to your webserver's document\n");
+ printf(" root directory such as c:\\inetpub\\wwwroot for IIS or\n");
+ printf(" c:\\website\\htdocs or WebSite Pro.\n\n");
+#endif
+ printf(" Exiting.\n");
+ exit(0);
+ }
+ else
+ {
+ //must first pass to cygpath program
+#ifdef WINDOWS_CYGWIN
+ char
+ szCommand[SIZE_FILE],
+ szNewRoot[SIZE_FILE];
- char* output = new char[len+(strlen(replace)*(num_spaces+1))+1];
- int index = 0;
- for(k = 0; k < inputfiles_->length(); k++) {
- for(int j = 0; (*inputfiles_)[k][j]; j++)
+ sprintf(szCommand, "cygpath '%s'", tmpRoot);
+ FILE* fp;
- output[index++] = ((*inputfiles_)[k])[j];
- if(k < inputfiles_->length() - 1)
- for(int j = 0; replace[j]; j++)
- output[index++] = replace[j];
- }
-
- /*
- for(int k = 0; k < strlen(inputfiles); k++)
- if(inputfiles[k] == ' ')
- for(int j = 0; j < strlen(replace); j++)
- output[index++] = replace[j];
- else
- output[index++] = inputfiles[k];
- */
- // end
- for(k = 0; replace[k]; k++)
- if(replace[k] != '\n' && replace[k] != ' ')
- output[index++] = replace[k];
- else {
- output[index] = 0;
- return output;
- }
- output[index] = 0;
- return output;
-}
+ if((fp = popen(szCommand, "r")) == NULL)
+ {
+ printf("cygpath error, exiting\n");
+ exit(1);
+ }
+ else
+ {
+ fgets(szNewRoot, TEXT_SIZE3, fp);
+ pclose(fp);
+ szBuf[strlen(szNewRoot) - 1] = 0;
+ strcpy(webServerRoot, szNewRoot);
+ }
+#else
+ strcpy(webserverRoot, tmpRoot);
+#endif
+ }
-void ModelParser::setFilter(Tag* tag) {
- if(tag == NULL)
- return;
+ //Check if webServerRoot is present
+ if (access(webserverRoot, F_OK))
+ {
+ printf(" Cannot access the webserver's root directory:\n");
+ printf(" %s\n", webserverRoot);
+ printf(" This was set as the environment variable WEBSERVER_ROOT\n\n");
- if(filter_memory_) {
- filter_memory_ = False;
- filter_ = False;
- }
- //tag->write(cout);
+ printf(" For Windows users, you can check this environment variable\n");
+ printf(" through the Advanced tab under System Properties when you\n");
+ printf(" right-mouse-click on your My Computer icon.\n\n");
+ printf(" Exiting.\n");
+ exit(1);
+ }
+ //set up correct pngPath
+ char* result = NULL;
- if(! strcmp(tag->getName(), "analysis_summary")) {
- if(tag->isEnd() && filter_)
- filter_memory_ = True;
- else if(tag->isStart() && ! strcmp(tag->getName(), "analysis_summary") &&
- ! strcmp(tag->getAttributeValue("analysis"), prophet_name_) &&
- (timestamp_ == NULL || ! strcmp(tag->getAttributeValue("time"), timestamp_))) {
- filter_ = True;
- if(timestamp_ == NULL) {
- timestamp_ = new char[strlen(tag->getAttributeValue("time"))+1];
- strcpy(timestamp_, tag->getAttributeValue("time"));
- }
- }
- }
+ result = strstri(filePath, webserverRoot);
+
+ if(result != NULL)
+ {
+ if(strlen(result) > strlen(webserverRoot) && result[strlen(webserverRoot)] != '/')
+ sprintf(pngPath, "/%s", result + strlen(webserverRoot));
+ else
+ strcpy(pngPath, result + strlen(webserverRoot));
+ }
+ else
+ strcpy(pngPath, filePath);
+
+ *strstr(pngPath, ".xml") = 0;
+
+ strcat(pngPath, "_");
+
+ //set up correct filePath
+ replace_path_with_webserver_tmp(filePath, sizeof(filePath)); //do this in designated tmpdir, if any
+
+ strcat(filePath, ".XXXXXX");
+ safe_fclose(FILE_mkstemp(filePath)); //create then close a uniquely named file
+
+ unlink(filePath); //we only wanted its name, we never actually use it
+
+ return pngPath;
}
-Boolean ModelParser::setFvalue(char* scores) {
- // fval=xxx
- //cout << "score: " << scores << endl;
- if(scores == NULL)
- return False;
- char prefix[] = "fval=";
- if(strlen(scores) <= strlen(prefix))
- return False;
- char* result = strstr(scores, prefix);
- if(result != NULL) {
- sscanf(result+strlen(prefix), "%lf", &fvalue_);
- //cout << "fval: " << fvalue_ << endl;
- return True;
- }
- //cout << "returning false" << endl;
- return False;
+void ModelParser::removeOldFiles(char* filePath)
+{
+ //remove any aging tmpfiles that may be around for any reason
+ std::string pngMask(filePath);
+ int rslash = findRightmostPathSeperator(pngMask);
+
+ if (rslash > 0)
+ pngMask = pngMask.substr(0, rslash + 1);
+
+ pngMask += "*.ISB.png";
+ remove_files_olderthan(pngMask, 600); //kill any png files more than 10 minutes old (600 seconds)
}
+/*unused function
+char* ModelParser::formatFiles(char* replace)
+{
+ int num_spaces = inputfiles_->length() - 1;
-void ModelParser::writeModelResults(ostream& os, char* options, Array<sens_err*>* sensitivity) {
- char *fp = new char[50000];
- int k;
+ if (num_spaces<0)
+ return strCopy("");
- sprintf(fp, "<HTML>\n<HEAD>\n<TITLE>%s (%s), %s</TITLE>\n\n", szVERSION, szTPPVersionInfo, szAUTHOR);
- os << fp;
+ int k, len = 0;
+ for(k = 0; k < inputfiles_->length(); k++)
+ len += (int)strlen((*inputfiles_)[k]);
- // style-sheet
- os << "<style type=\"text/css\">\n";
- os << ".hideit {display:none}\n";
- os << ".showit {display:table-row}\n";
- os << ".accepted {background: #87ff87; font-weight:bold;}\n";
- os << ".rejected {background: #ff8700;}\n";
- os << "body{font-family: Helvetica, sans-serif; }\n";
- os << "h1 {font-family: Helvetica, Arial, Verdana, sans-serif; font-size: 24pt; font-weight:bold; color:#0E207F}\n";
- os << "h2 {font-family: Helvetica, Arial, sans-serif; font-size: 20pt; font-weight: bold; color:#0E207F}\n";
- os << "h3 {font-family: Helvetica, Arial, sans-serif; font-size: 16pt; color:#FF8700}\n";
- os << "h4 {font-family: Helvetica, Arial, sans-serif; font-size: 14pt; color:#0E207F}\n";
- os << "h5 {font-family: Helvetica, Arial, sans-serif; font-size: 10pt; color:#AA2222}\n";
- os << "h6 {font-family: Helvetica, Arial, sans-serif; font-size: 8pt; color:#333333}\n";
- os << "table {border-collapse: collapse; border-color: #000000;}\n";
- os << "td {border-collapse: collapse; border-color: #000000;}\n";
- os << ".banner_cid {\n";
- os << " background: #0e207f;\n";
- os << " border: 2px solid #0e207f;\n";
- os << " color: #eeeeee;\n";
- os << " font-weight:bold;\n";
- os << " }\n";
- os << ".markSeq {\n";
- os << " color: #0000FF;\n";
- os << " font-weight:bold;\n";
- os << " }\n";
- os << ".markAA {\n";
- os << " color: #AA2222;\n";
- os << " font-weight:bold;\n";
- os << " }\n";
- os << ".glyco {\n";
- os << " background: #d0d0ff;\n";
- os << " border: 1px solid black;\n";
- os << " }\n";
- os << ".messages {\n";
- os << " background: #ffffff;\n";
- os << " border: 2px solid #FF8700;\n";
- os << " color: black;\n";
- os << " padding: 1em;\n";
- os << " }\n";
- os << ".formentry {\n";
- os << " background: #eeeeee;\n";
- os << " border: 2px solid #0e207f;\n";
- os << " color: black;\n";
- os << " padding: 1em;\n";
- os << " }\n";
- os << ".model {\n";
- os << " background: #ffffff;\n";
- os << " border: 2px solid #0e207f;\n";
- os << " color: black;\n";
- os << " padding: 1em;\n";
- os << " }\n";
- os << ".nav {\n";
- os << " background: #eeeeee;\n";
- os << " border: 2px solid #0e207f;\n";
- os << " font-family: Helvetica, Arial, Verdana, sans-serif;\n";
- os << " font-weight:bold;\n";
- os << " }\n";
- os << ".navselected {\n";
- os << " background: #dddddd;\n";
- os << " border: 2px solid #0e207f;\n";
- os << " font-family: Helvetica, Arial, Verdana, sans-serif;\n";
- os << " font-weight:bold;\n";
- os << " }\n";
- os << ".graybox {\n";
- os << " background: #dddddd;\n";
- os << " border: 1px solid black;\n";
- os << " font-weight:bold;\n";
- os << " }\n";
- os << ".seq {\n";
- os << " background: #ffaa33;\n";
- os << " border: 1px solid black;\n";
- os << " font-weight:bold;\n";
- os << " }\n";
- os << ".info {\n";
- os << " color: #333333;\n";
- os << " font-size: 10pt;\n";
- os << " }\n";
- os << ".infoplus {\n";
- os << " border-top: 1px solid black;\n";
- os << " color: #333333;\n";
- os << " font-size: 10pt;\n";
- os << " }\n";
- os << ".hist_valueL{\n";
- os << " height: 10px;\n";
- os << " float: left;\n";
- os << " background-color: #BBBBBB;\n";
- os << " border: 1px solid #999999;\n";
- os << " font-size: 1px;\n";
- os << " line-height: 0pt;\n";
- os << " display: inline;\n";
- os << " clear: both;\n";
- os << " margin: 0pt 0pt 0pt 0px;\n";
- os << "}\n";
- os << ".hist_valueR{\n";
- os << " height: 10px;\n";
- os << " float: right;\n";
- os << " background-color: #BBBBBB;\n";
- os << " border: 1px solid #999999;\n";
- os << " font-size: 1px;\n";
- os << " line-height: 0pt;\n";
- os << " display: inline;\n";
- os << " clear: both;\n";
- os << " margin: 0pt 0pt 0pt 0px;\n";
- os << "}\n";
- os << ".hist_full{\n";
- os << " width: 100px;\n";
- os << " height: 10px;\n";
- os << " border: 0px solid #999999;\n";
- os << " font-size: 1px;\n";
- os << " margin: 0px 0pt 0pt;\n";
- os << " line-height: 0px;\n";
- os << "}\n";
- os << "</style>\n";
+ // for(int k = 0; k < strlen(inputfiles); k++)
+ // if(inputfiles[k] == ' ')
+ // num_spaces++;
- //some javascript, for the kids...
- os << "<script language=\"JavaScript\">\n";
- os << " var showParams = true;\n";
- os << " function toggleParams(){\n";
- os << " var x;\n";
- os << " var new_state = 'hideit';\n";
- os << " if (showParams) {\n";
- os << " showParams = false;\n";
- os << " new_state = 'showit';\n";
- os << " document.getElementById('paramshead').innerHTML = ': [ - ]';\n";
- os << " } else {\n";
- os << " showParams = true;\n";
- os << " document.getElementById('paramshead').innerHTML = '... [ + ]';\n";
- os << " }\n";
- os << " for(var i=1; i<=3; i++) {\n";
- os << " document.getElementById(\"parameters\"+i).className = new_state;\n";
- os << " }\n";
- os << " }\n";
- os << " var charges = new Array()\n";
+ char* output = new char[len + (strlen(replace) * (num_spaces + 1)) + 1];
+ int index = 0;
+ for(k = 0; k < inputfiles_->length(); k++)
+ {
+ for(int j = 0; (*inputfiles_)[k][j]; j++)
+ output[index++] = ((*inputfiles_)[k])[j];
+ if(k < inputfiles_->length() - 1)
+ for(int j = 0; replace[j]; j++)
+ output[index++] = replace[j];
+ }
- for(k = 0; k < model_tags_->length(); k++) {
- sprintf(fp, " charges[%d] = \"plus%d\";\n", k, k+1);
- os << fp;
- }
+ // for(int k = 0; k < strlen(inputfiles); k++)
+ // if(inputfiles[k] == ' ')
+ // for(int j = 0; j < strlen(replace); j++)
+ // output[index++] = replace[j];
+ // else
+ // output[index++] = inputfiles[k];
- os << " function display(chargestate){\n";
- os << " var x;\n";
- os << " var new_state;\n";
- os << " var new_nav;\n";
- os << " for (x in charges) {\n";
- os << " if (charges[x] == chargestate) {\n";
- os << " new_state = 'showit';\n";
- os << " new_nav = 'nav';\n";
- os << " } else {\n";
- os << " new_state = 'hideit';\n";
- os << " new_nav = 'banner_cid';\n";
- os << " }\n";
- os << " document.getElementById(charges[x] + \"_tr\").className = new_state;\n";
- os << " document.getElementById(charges[x] + \"_nav\").className = new_nav;\n";
- os << " }\n";
- os << " }\n";
- os << " function displayAll(){\n";
- os << " for (x in charges) {\n";
- os << " docume...
[truncated message content] |