Exemplo n.º 1
0
//-----------------------------------------------------------------------------
string getProjPath(const ParameterList & pl, const string & addPath)
{
  string projDir = pl.getValue("PROJECT_DIR", "");
  bool relDir = pl.getValueBool("RELATIVE_DIR", true);

  return getPath(projDir, addPath, relDir);
}
bool MSMSFragmentation::getScoreValue ( const ParameterList& params, const string& name, ScoreType& value )
{
	double dvalue;
	bool flag = params.getValue ( name, dvalue );
	if ( flag ) {
		dvalue *= SCORE_TYPE_MULTIPLIER;
		value = static_cast <ScoreType> ( dvalue );
	}
	return flag;
}
Exemplo n.º 3
0
int SpecCheckInterface::processOptions(int argc, char **argv)
{
  //--------------------------------------------------------------------------------------------
  // Initialize directories used
  //--------------------------------------------------------------------------------------------


  //--------------------------------------------------------------------------------------------
  // Parse the command line parameters
  //--------------------------------------------------------------------------------------------
  vector<CommandLineParser::Option> listOptions;

  //  c++ instruction                            cmd line option    parameter name    takes value?

  listOptions.push_back(CommandLineParser::Option("-help",            "help",             false));
  listOptions.push_back(CommandLineParser::Option("-version",         "VERSION",          false));

  listOptions.push_back(CommandLineParser::Option("-input-list",      "INPUT_LIST",       true));
  listOptions.push_back(CommandLineParser::Option("-inputspectra",    "INPUT_SPECS_MS",   true));

  // parameter file
  listOptions.push_back(CommandLineParser::Option("-p",               "PARAMETER_FILE",   true));


  ////////////////////////////////////////////////////////////////////////////////
  // Execute the command line parser
  CommandLineParser clp(argc, argv, 0, listOptions);

  ////////////////////////////////////////////////////////////////////////////////
  // Checking for errors
  string parser_error;
  if (!clp.validate(parser_error)) {
    ERROR_MSG(parser_error);
    return -1;
  }


  ////////////////////////////////////////////////////////////////////////////////
  // The parameters' values
  ParameterList commandLineParams;
  clp.getOptionsAsParameterList(commandLineParams);

  ////////////////////////////////////////////////////////////////////////////////
  // Parameter file
  ////////////////////////////////////////////////////////////////////////////////

  if (commandLineParams.exists("PARAMETER_FILE")) {

    string parameterFilename = commandLineParams.getValue("PARAMETER_FILE");

    ParameterList ip;
    ip.readFromFile(parameterFilename);
    // Combine the command line parameters to the file ones
    //   Command line parameters take precedence (hence the overwrite flag not set)
    commandLineParams.addList(ip, false);
  }

  ////////////////////////////////////////////////////////////////////////////////
  // "help" prints help and exits
  if (commandLineParams.exists("VERSION"))
    return version(cout);

  ////////////////////////////////////////////////////////////////////////////////
  // the same for "version"
  if (commandLineParams.exists("help"))
    return help(cout);



  ////////////////////////////////////////////////////////////////////////////////
  // File load section

  // input spectra file to load
  if (commandLineParams.exists("INPUT_LIST")) {
    inputFilesNames = commandLineParams.getValue("INPUT_LIST").c_str();

    // load input files names
    if(!loadStringVector(inputFilesNames, inputFiles)) {
      cerr << "Unable to load file: " << inputFilesNames << endl;
      exit(0);
    }
  }


  if (commandLineParams.exists("INPUT_SPECS_MS")) {
    string aux = commandLineParams.getValue("INPUT_SPECS_MS").c_str();
    splitText(aux.c_str(), inputFiles, ";|");
  }


  // Keep record of loaded files
  int filesLoaded = 0;

  cout  << "Loading " << inputFiles.size() << " files." << endl;

  for(int i = 0 ; i < inputFiles.size() ; i++) {
    SpecSet spec;
    if(loadSpecset(inputFiles[i], spec)) {
      inputData.push_back(spec);
      filesLoaded++;
    }
  }

  cout <<  filesLoaded << " files loaded." << endl;

  // exit if no file was loaded
  if(!filesLoaded) {
    cerr << "No file loaded." << endl;
    return 0;
  }


  ////////////////////////////////////////////////////////////////////////////////
  //  Processing section

  // check for zero PM

  cout << "Checking " << inputData.size() << " specsets." << endl;
  for(int i = 0 ; i < inputData.size() ; i++) {
    cout << "  #" << i << " Checking " << inputData[i].size() << " spectra." << endl;
    vector<int> aux;
    for(int j = 0 ; j < inputData[i].size() ; j++) {
      if(inputData[i][j].parentMass < 2.0) {
        aux.push_back(j);
        cout << "found: " << i << " ; " << j << " -> " << inputData[i][j].parentMass << endl;
      } //else
      //  cout << "value: " << i << " ; " << j << " -> " << inputData[i][j].parentMass << " - " << inputData[i][j].parentMZ << endl;
    }
    if(aux.size())
      invalid.insert(pair<int, vector<int> >(i, aux));
  }


  ////////////////////////////////////////////////////////////////////////////////
  //  output section

  map<int, vector<int> >::iterator it;
  for(it = invalid.begin() ; it != invalid.end() ; it++) {
    int fileIdx = it->first;
    string fn = inputFiles[fileIdx];

    cout << "------- " << fn << " -------" << endl;

    for(int i = 0 ; i > it->second.size() ; i++) {
      if(!i) cout << " ; ";
      cout << it->second[i];
    }
    cout << endl;
  }


   // return status ok
  return 0;
}
Exemplo n.º 4
0
void batchSubmission ( ostream& os, ParameterList& paramList )
{
	init_html ( os, "Batch Submission" );
	if ( paramList.empty () ) {
		ErrorHandler::genError ()->error ( "No parameters passed to Prospector program.\n" );
	}
	string user = paramList.getStringValue ( "user" );
	os << "<p>Creating Prospector files.</p>" << endl;
	string searchKey = genRandomString ( 16 );			// Selects a unique string for the search
	string searchName = paramList.getStringValue ( "search_name" );					// Program (eg batchtag)
	string uploadFpath = paramList.getStringValue ( "upload_data_filepath" );	// This is the full path name of the uploaded file as named by PP
	string resultsName = paramList.getStringValue ( "output_filename" );
	bool searchKeyProblem;
	try {
		checkConstantAndVariableModCompatibility ( &paramList );
	}
	catch ( runtime_error e ) {		// Catch database login problems
		genUnlink ( uploadFpath );
		ErrorHandler::genError ()->error ( e );
	}
	try {
		searchKeyProblem = MySQLPPSDDBase::instance ().checkSearchKey ( searchKey );// Checks it is unique
	}
	catch ( runtime_error e ) {		// Catch database login problems
		genUnlink ( uploadFpath );
		ErrorHandler::genError ()->error ( e );
	}
	if ( searchKeyProblem ) {
		genUnlink ( uploadFpath );
		ErrorHandler::genError ()->error ( "Search key not unique.\n" );// The search key has to be unique to carry on.
	}
	if ( resultsName.empty () ) {
		genUnlink ( uploadFpath );
		ErrorHandler::genError ()->error ( "No results name has been chosen.\n" );
	}
	string password;
	bool passwordFlag = paramList.getValue ( "password", password );
	UserInfo* userInfo = MySQLPPSDDBase::instance ().getUserInfo ( user );
	if ( !userInfo || ( passwordFlag && userInfo->getPassword () != password ) ) {													// Get the user information
		genUnlink ( uploadFpath );
		ErrorHandler::genError ()->error ( "Unknown user and/or password.\n" );
	}
	if ( user == "root" ) {													// Get the user information
		genUnlink ( uploadFpath );
		ErrorHandler::genError ()->error ( "Root user can't do searches.\n" );
	}
	if ( userInfo->getIsGuest () ) {
		genUnlink ( uploadFpath );
		ErrorHandler::genError ()->error ( "Guest users can't do searches.\n" );
	}
	if ( !InfoParams::instance ().getBoolValue ( "btag_daemon_remote" ) ) {
		try {
			startDaemonIfNecessary ();
		}
		catch ( runtime_error e ) {
			genUnlink ( uploadFpath );
			ErrorHandler::genError ()->error ( e );
		}
	}
	string userID = userInfo->getUserID ();
	Repository* reposit = new UserRepository ( searchName, userInfo->getDirectoryName () );	// Where to put files given a user. Also creates the directories.
	string projectName;
	if ( uploadFpath.empty () ) {		// The project already exists
		projectName = paramList.getStringValue ( "project_name" );	// From a form with a project name option.
	}
	else {
		string uploadFname = paramList.getStringValue ( "upload_data_filename" );	// This is the original file name.
		string instrument = paramList.getStringValue ( "instrument_name" );
		uploadFname = genFilenameFromPath ( uploadFname );						// IE gives the full path whereas Mozilla give the filename (what we want)
		projectName = getProjectName ( uploadFname );	// The project is named after the uploaded file. This has to be unique.
		if ( projectName.length () > 58 ) {
			genUnlink ( uploadFpath );
			ErrorHandler::genError ()->error ( "The project name " + projectName + " is too long.\n" );
		}
		if ( MySQLPPSDDBase::instance ().checkProject ( userID, projectName ) ) {
			genUnlink ( uploadFpath );
			ErrorHandler::genError ()->error ( "Project already exists.\n" );
		}
		paramList.setValue ( "data_source", "List of Files" );
		paramList.setValue ( "project_name", projectName );
		paramList.removeName ( "upload_data_filename" );
		paramList.removeName ( "upload_data_filepath" );
		string uploadName = genPreprocessFile ( uploadFpath );
		if ( uploadName == uploadFpath || isCompressedUpload ( uploadName ) ) {		// If the file hasn't been preprocessed or it has just been uncompressed it must be a single file
			string shortName = genShortFilenameFromPath ( uploadName );
			string newDir = genDirectoryFromPath ( uploadName ) + SLASH + shortName;
			if ( newDir == uploadName ) {
				newDir += "_1";
			}
			genCreateDirectory ( newDir );
			string newUploadName;
			if ( isCompressedUpload ( uploadName ) )
				newUploadName = newDir + SLASH + genShortFilenameFromPath ( uploadFname );
			else
				newUploadName = newDir + SLASH + uploadFname;
			genRename ( uploadName, newUploadName );
			uploadName = newDir;
		}
		PPProject ppp ( userInfo->getMaxMSMSSpectra (), userInfo->getAllowRaw (), projectName, uploadName, searchKey, reposit, MSMSDataSetInfo::setChargeRange ( &paramList ) );
		if ( ppp.initialised () ) {
			int err = genRename ( uploadName, reposit->getFullDataPath () + SLASH + searchKey );
			if ( err ) {
				genUnlink ( uploadName );
				string e = gen_itoa ( err );
				ErrorHandler::genError ()->error ( "Failed to move uploaded file to repository.\nError code = " + e + "\n" );
			}
			ppp.createProjectFile ( reposit->getFullProjectPath () + SLASH + projectName + ".xml" );
			string projectPath = reposit->getProjectPath ();
			MySQLPPSDDBase::instance ().submitProject ( userID, projectName, projectName + ".xml", reposit->getProjectPath (), instrument );
		}
		else {
			string err = ppp.getErrMessage ();
			if ( ppp.getDeleteFlag () ) {		// Known error - delete the upload directory
				genUnlinkDirectory ( uploadName );
			}
			if ( err.empty () )
				ErrorHandler::genError ()->error ( "Upload file has an invalid format.\n" );
			else
				ErrorHandler::genError ()->error ( err + "\n" );
		}
	}
	paramList.removeName ( "user" );
	paramList.removeName ( "password" );
	paramList.removeName ( "project_name" );
	paramList.removeName ( "output_filename" );					// Search results file.
	paramList.removeName ( "msms_mod_AA_list" );				// These options are used to load the variable mods
	paramList.removeName ( "msms_mod_AA_types" );				// and shouldn't be saved.
	paramList.removeName ( "mod_AA_limit" );
	paramList.removeName ( "mod_AA_file" );
	paramList.removeName ( "motif_offset" );
	paramList.removeName ( "motif" );
	string projectID = MySQLPPSDDBase::instance ().getProjectID ( userID, projectName );
	if ( projectID.empty () ) {
		genUnlink ( uploadFpath );
		ErrorHandler::genError ()->error ( "Project doesn't exist.\n" );
	}
	if ( MySQLPPSDDBase::instance ().checkResults ( userID, projectID, resultsName ) ) {
		genUnlink ( uploadFpath );
		ErrorHandler::genError ()->error ( "Results file of this name already exists for this project.\n" );
	}
	paramList.XMLParameterFile ( reposit->getFullResultsPath () + SLASH + searchKey + ".xml" );	// This is the search parameter file
	MySQLPPSDDBase::instance ().submitSearch ( searchKey, projectID, resultsName, searchKey + ".xml", reposit->getResultsPath () );
	MySQLPPSDDBase::instance ().updateProjectRecordUpdated ( projectID );

	genSleep ( 5000 );
	ParameterList pList ( "jobStatus", false, false, false, false, false );
	pList.addName ( "search_key", searchKey );
	refreshJavascript ( os, 0, pList.getURL (), true );
}
Exemplo n.º 5
0
// -------------------------------------------------------------------------
int main(int argc, char ** argv)
{
  Logger::setDefaultLogger(Logger::getLogger(0));

  if (argc < 3)
  {
    cerr << "Usage: main_execmodule moduleName parametersFileName [options]" << endl;
    return -1;
  }

  // Parse the command line parameters
  vector<CommandLineParser::Option> listOptions;
  listOptions.push_back(CommandLineParser::Option("t", "NUM_THREADS", true));
  listOptions.push_back(CommandLineParser::Option("lf", "LOG_FILE_NAME", true));
  listOptions.push_back(CommandLineParser::Option("ll", "LOG_LEVEL", true));

  // Command line parameters for ExecSpectraExtraction for CCMS Workflows
  listOptions.push_back(CommandLineParser::Option("ccms_output_library", "OUTPUT_MGF", true));
  listOptions.push_back(CommandLineParser::Option("ccms_input_library", "EXISTING_LIBRARY_MGF", true));
  listOptions.push_back(CommandLineParser::Option("ccms_input_spectradir", "SPECTRA_DIR", true));
  listOptions.push_back(CommandLineParser::Option("ccms_results_dir", "RESULTS_DIR", true));
  listOptions.push_back(CommandLineParser::Option("ccms_newresults_dir", "NEWLIBRARYRESULTS_DIR", true));
  listOptions.push_back(CommandLineParser::Option("ccms_input_spectradatafile", "INPUTSPECTRA_DATAFILE", true));
  listOptions.push_back(CommandLineParser::Option("ccms", "CCMS", true));

  CommandLineParser clp(argc, argv, 2, listOptions);
  string parser_error;
  if (!clp.validate(parser_error))
  {
    ERROR_MSG(parser_error);
    return -2;
  }

  ParameterList commandLineParams;
  clp.getOptionsAsParameterList(commandLineParams);

  // Load the parameter file
  ParameterList ip;
  std::string paramsFileName = argv[2];
  std::string::size_type idx = paramsFileName.rfind(".");
  if( idx != std::string::npos &&
      paramsFileName.substr(idx + 1) == "xml"){
    if (!ip.readFromProteosafeXMLFile(argv[2]))
    {
        ERROR_MSG("Can not read parameter file [" << argv[2] << "].");
        return -3;
    }
  }
  else{
    if (!ip.readFromFile(argv[2]))
    {
        ERROR_MSG("Can not read parameter file [" << argv[2] << "].");
        return -3;
    }
  }

  // Combine the command line parameters to the file ones
  //   Command line parameters take precedence (hence the overwrite flag set)
  ip.addList(commandLineParams, true);

  int logLevel = ip.getValueInt("LOG_LEVEL", 0);
  if (ip.exists("LOG_FILE_NAME"))
  {
    string logFileName = ip.getValue("LOG_FILE_NAME");
    Logger::setDefaultLogger(Logger::getLogger(logFileName, logLevel));
  }
  else
  {
    Logger::setDefaultLogger(Logger::getLogger(logLevel));
  }

  DEBUG_TRACE;
  // Fill the factory with all known module types
  ExecModuleFactoryLP::RegisterAllModules();

  DEBUG_TRACE;
  // Get the exemplar from the factory
  ExecBase * moduleExemplar = ExecModuleFactoryLP::getModule(argv[1]);

  if (moduleExemplar == 0)
  {
    ERROR_MSG("Module name [" << argv[1] << "] not found in factory.");
    ExecModuleFactoryLP::cleanup();
    return -4;
  }

  DEBUG_TRACE;
  // Clone the exemplar and create a real module with the desired parameters
  ExecBase * moduleReal = moduleExemplar->clone(ip);

  string jobDoneFile(moduleReal->getName());
  jobDoneFile += "_";
  string numNode = moduleReal->m_params.getValue("NUM_SPLIT");
  jobDoneFile += numNode;
  jobDoneFile += "_results.param";

  DEBUG_VAR(jobDoneFile);

  // Validate all the parameters before invoking
  std::string errorString;
  if (!moduleReal->validateParams(errorString))
  {
    ERROR_MSG(errorString);
    string errorString2("Invalid parameters [");
    errorString2 += argv[2];
    errorString2 += "] to module of type [";
    errorString2 += argv[1];
    errorString2 += "]";
    ERROR_MSG("Invalid parameters [" << argv[2] << "] to module of type ["
        << argv[1] << "].");
    delete moduleReal;
    ExecModuleFactoryLP::cleanup();
    return -3;
  }

  DEBUG_TRACE;
  // Load all the input data from the specified files
  if (!moduleReal->loadInputData())
  {
    ERROR_MSG("Loading input data for module of type [" << argv[1] << "]");
    delete moduleReal;
    ExecModuleFactoryLP::cleanup();
    return -4;
  }

  DEBUG_TRACE;
  
  bool returnStatus;
  if(!ip.exists("NUM_THREADS") || ip.getValueInt("NUM_THREADS") <= 1)
  {
    DEBUG_TRACE;
    returnStatus = moduleReal->invoke();
    DEBUG_VAR(returnStatus);
  }
  else
  {
    int numThreads = ip.getValueInt("NUM_THREADS");
    DEBUG_VAR(numThreads);
    //returnStatus = moduleReal->invoke();
    ParallelThreadedExecution exec(moduleReal);
    returnStatus = exec.invoke(numThreads);
    DEBUG_VAR(returnStatus);
  }
    
  if (!returnStatus)
  {
    ERROR_MSG("Invoking module of type [" << argv[1] << "]");
    delete moduleReal;
    ExecModuleFactoryLP::cleanup();
    return -5;
  }

  DEBUG_TRACE;
  // Save any result data
  if (!moduleReal->saveOutputData())
  {
    ERROR_MSG("Saving output data for module of type [" << argv[1] << "]");
    delete moduleReal;
    ExecModuleFactoryLP::cleanup();
    return -6;
  }

  DEBUG_TRACE;

  delete moduleReal;
  ExecModuleFactoryLP::cleanup();
  return 0;
}
Exemplo n.º 6
0
// -------------------------------------------------------------------------
int main(int argc, char ** argv)
{
  int logLevel = 5;
  Logger::setDefaultLogger(Logger::getLogger(logLevel));

  string initialStageString("");
  string finalStageString("");
  string statusFileName("status.txt");

  bool resumeFlag = false;
  bool gridExecutionFlag = false;
  bool runGenoMSFlag = false;
  bool runMergedFlag = false;

  bool showHelp = false;
  for (size_t i = 0; i < argc; i++)
  {
    string arg(argv[i]);
    if (arg.compare("--help") == 0)
    {
      showHelp = true;
    }
  }

  if (argc < 2 || showHelp)
  {
    if (showHelp)
    {
      cout << "Usage: main_flr [PARAM FILE] [OPTION]..." << endl << endl;
      cout << "Optional arguments are listed below " << endl;
      cout << "  -i  <intialstage>   begin processing at specified stage:"
          << endl;
      cout << "                         begin,pairspectra,lpsolver,flr" << endl;
      cout
          << "  -f  <finalstage>   end processing after completing specified stage:"
          << endl;
      cout << "                        lpsolver,flr" << endl;

      cout << "  -g                  execution is on a grid" << endl;
      cout << "  -lf <filename>      name of log file for output" << endl;
      cout << "  -ll <loglevel>      log level for debug/warn/error output:"
          << endl;
      cout << "                         9 for errors only" << endl;
      cout << "                         5 for warnings and errors" << endl;
      cout << "                         0 for all debug output" << endl;
      cout << "  -s                   execute a single step then exit" << endl;
    }
    else
    {
      cerr << "main_specnets: insufficient arguments" << endl;
      cerr << "Try \'main_specnets --help\' for more information." << endl
          << endl;
    }

    cout << PROGRAM_NAME << endl;
    cout << "main_specnets 3.0." << XSTR(SPS_VERSION) << endl;
    cout << endl;

    cout << COPYRIGHT1 << endl;
    cout << COPYRIGHT2 << endl;
    cout << endl;

    return -1;
  }
  // Parse the command line parameters
  vector<CommandLineParser::Option> listOptions;
  listOptions.push_back(CommandLineParser::Option("i", "INITIAL_STAGE", 1));
  listOptions.push_back(CommandLineParser::Option("f", "FINAL_STAGE", 1));
  listOptions.push_back(CommandLineParser::Option("g", "GRID_EXECUTION", 0));
  listOptions.push_back(CommandLineParser::Option("lf", "LOG_FILE_NAME", 1));
  listOptions.push_back(CommandLineParser::Option("ll", "LOG_LEVEL", 1));
  listOptions.push_back(CommandLineParser::Option("s", "SINGLE_STEP", 0));

  CommandLineParser clp(argc, argv, 1, listOptions);
  string parser_error;
  if (!clp.validate(parser_error))
  {
    ERROR_MSG(parser_error);
    return -2;
  }

  ParameterList commandLineParams;
  clp.getOptionsAsParameterList(commandLineParams);

  ParameterList ip;
  ip.readFromFile(argv[1]);
  ip.writeToFile("debug_sps.params");

  // Combine the command line parameters to the file ones
  //   Command line parameters take precedence (hence the overwrite flag set)
  ip.addList(commandLineParams, true);
  ip.writeToFile("debug_wcommand.params");

  logLevel = ip.getValueInt("LOG_LEVEL", 5);
  if (ip.exists("LOG_FILE_NAME"))
  {
    string logFileName = ip.getValue("LOG_FILE_NAME");
    Logger::setDefaultLogger(Logger::getLogger(logFileName, logLevel));
  }
  else
  {
    Logger::setDefaultLogger(Logger::getLogger(logLevel));
  }

  // add divert for segfault
  addSegFaultDivert();

  DEBUG_TRACE;

  if (!ip.exists("EXE_DIR"))
  {

    // extract EXE_DIR from command line
    string exeDir(argv[0]);

    // find last /, and remove from that point on
    size_t found = exeDir.find_last_of("/\\");
    string aux = exeDir.substr(0, found);

    //string mainSpecnetsStr = "/main_specnets";
    //exeDir.erase(exeDir.length() - mainSpecnetsStr.length(), mainSpecnetsStr.length());

    // remove /ExecFramework, if it exists
    ip.setValue("EXE_DIR", aux);
  }

  if (ip.exists("INITIAL_STAGE"))
  {
    initialStageString = commandLineParams.getValue("INITIAL_STAGE");
  }
  DEBUG_VAR(initialStageString);

  if (ip.exists("FINAL_STAGE"))
  {
    finalStageString = commandLineParams.getValue("FINAL_STAGE");
  }
  DEBUG_VAR(finalStageString);

  addDefaultParameterValues(ip);
  ip.writeToFile("debug_default.params");

  if (ip.exists("EXE_DIR"))
  {
    string exeDir = ip.getValue("EXE_DIR");

    // if path begins with '~', exit program.
    if (exeDir[0] == '~')
    {
      cout
          << "EXE_DIR path begins with tilde (~). Paths beginning with tilde are not supported."
          << endl;
      exit(0);
    }

    // In case there is a "/" at the end of EXE_DIR.. remove it
    if (exeDir.length() > 2 && exeDir[exeDir.length() - 1] == '/')
    {
      exeDir = exeDir.substr(0, exeDir.length() - 1);
      ip.setValue("EXE_DIR", exeDir);
    }
  }

  if (ip.exists("GRID_EXE_DIR"))
  {
    // In case there is a "/" at the end of EXE_DIR.. remove it
    string gridExeDir = ip.getValue("GRID_EXE_DIR");
    if (gridExeDir.length() > 2 && gridExeDir[gridExeDir.length() - 1] == '/')
    {
      gridExeDir = gridExeDir.substr(0, gridExeDir.length() - 1);
      ip.setValue("GRID_EXE_DIR", gridExeDir);
    }
  }

  if (ip.exists("GRID_SGE_EXE_DIR"))
  {
    // In case there is a "/" at the end of GRID_SGE_EXE_DIR.. remove it
    string gridSgeExeDir = ip.getValue("GRID_SGE_EXE_DIR");
    if (gridSgeExeDir.length() > 2
        && gridSgeExeDir[gridSgeExeDir.length() - 1] == '/')
    {
      gridSgeExeDir = gridSgeExeDir.substr(0, gridSgeExeDir.length() - 1);
      ip.setValue("GRID_SGE_EXE_DIR", gridSgeExeDir);
    }
  }

  if (ip.exists("INITIAL_STAGE"))
  {
    initialStageString = ip.getValue("INITIAL_STAGE");
  }
  DEBUG_VAR(initialStageString);
  if (initialStageString.empty())
  {
    initialStageString = "begin";
  }
  DEBUG_VAR(initialStageString);

  if (ip.exists("FINAL_STAGE"))
  {
    finalStageString = ip.getValue("FINAL_STAGE");
  }
  DEBUG_VAR(finalStageString);
  if (finalStageString.empty())
  {
    finalStageString = "flr";
  }
  DEBUG_VAR(finalStageString);

  map<string, Stage> map_stage;
  map_stage["begin"] = STAGE_BEGIN;
  map_stage["pairspectra"] = STAGE_PAIRSPECTRA;
  map_stage["lpsolver"] = STAGE_LPSOLVER;
  map_stage["flr"] = STAGE_FLR;

  if (map_stage.find(initialStageString) == map_stage.end())
  {
    ERROR_MSG("Unknown starting stage [" << initialStageString << "]");
    return -1;
  }

  if (map_stage.find(finalStageString) == map_stage.end())
  {
    ERROR_MSG("Unknown final stage [" << finalStageString << "]");
    return -1;
  }

  //Start the status as "running" and write itout
  writeStatusFile(statusFileName, "Running");

  int initialStage = map_stage[initialStageString];
  DEBUG_VAR(initialStage);
  int finalStage = map_stage[finalStageString];
  DEBUG_VAR(finalStage);

  bool res;
  res = mkdir_if_not_exist("spectra");
  if (res)
  {
    DEBUG_MSG("Made directory \'spectra\'");
  }

  // get LD_LIBRARY_PATH from system
  char *curLibPath = getenv("LD_LIBRARY_PATH");

  // Build the needed library path
  string libPath;
  libPath = ip.getValue("EXE_DIR");
  // set LD_LIBRARY_PATH to EXE_DIR + /libs.
  libPath += "/libs";

  string fullLibPath;
  // check if LD_LIBRARY_PATH is already defined.
  if (curLibPath)
  {
    // if it is, check if it contains the path we want.
    fullLibPath = curLibPath;
    // if the library path IS NOT contained in the path variable, add it, and set the environment variable.
    if (fullLibPath.find(libPath) == string::npos)
    {
      fullLibPath += ':';
      fullLibPath += libPath;
      mysetenv("LD_LIBRARY_PATH", fullLibPath.c_str());
    }
  }
  else
  {
    // if LD_LIBRARY_PATH is not defined,, define it with what we want.
    mysetenv("LD_LIBRARY_PATH", libPath.c_str());
  }

  if (commandLineParams.exists("GRID_EXECUTION"))
  {
    gridExecutionFlag = true;
  }
  DEBUG_VAR(gridExecutionFlag);

  //---------------------------------
  // Load amino acid masses
  //---------------------------------
  AAJumps jumps(1); // Amino acid masses
  if (ip.exists("AMINO_ACID_MASSES"))
  {
    DEBUG_MSG("Loading amino acid masses from [" << ip.getValue("AMINO_ACID_MASSES") << "]");
    if (!jumps.loadJumps(ip.getValue("AMINO_ACID_MASSES").c_str(), true))
    {
      ERROR_MSG("Unable to load amino acid jumps");
      ERROR_MSG("Aborting!");
      exit(-1);
    }
  }
  else
  {
    DEBUG_MSG("No amino acid masses loaded. Using defaults");
  }

  string exeDir = ip.getValue("EXE_DIR");
  string convertCmd = exeDir + "/convert ";

  PeptideSpectrumMatchSet peptideResults;
  SpecSet filteredSpectra;

  if (initialStage == STAGE_BEGIN)
  {
    DEBUG_TRACE;

    //load results
    if (!loadPsmResults(ip, peptideResults))
    {
      return false;
    }

    if (!loadResultSpectrum(ip,
            ip.getValue("INPUT_SPECTRA_FILE_LIST").c_str(),
            peptideResults,
            filteredSpectra,
            ip.getValueBool("REINDEX_SCANS")))
    {
      return false;
    }

    if (commandLineParams.exists("SINGLE_STEP"))
    {
      DEBUG_MSG("Option -s given. Exiting after single step.");
      writeStatusFile(statusFileName, "Finished");
      exit(0);
    }
  }
  else
  {
    if (initialStage == STAGE_PAIRSPECTRA)
    {
      //load results
      if (!loadPsmResults(ip, peptideResults))
      {
        return false;
      }

      if (!loadSpecsMS(ip.getValue("EXE_DIR"), DEFAULT_INPUT_FILES_LIST, filteredSpectra))
      {
        ERROR_MSG("loadSpecsMS() exited in error. Exiting program");
        exit(0);
      }
      filteredSpectra.index();
      peptideResults.addSpectraByFilename(&filteredSpectra,false);
    }
  }

  DEBUG_VAR(peptideResults.size());
  DEBUG_VAR(filteredSpectra.size());

  if (finalStage == STAGE_BEGIN)
  {
    DEBUG_MSG("Option -f given. Exiting after step: " << finalStageString);
    writeStatusFile(statusFileName, "Finished");
    exit(0);
  }

  if (initialStage <= STAGE_PAIRSPECTRA)
  {
    DEBUG_TRACE;

    if (!performPairSpectra(ip,
            peptideResults,
            filteredSpectra,
            ip.getValueBool("GRID_EXECUTION")))
    {
      exit(0);
    }

    if (commandLineParams.exists("SINGLE_STEP"))
    {
      DEBUG_MSG("Option -s given. Exiting after single step.");
      writeStatusFile(statusFileName, "Finished");
      exit(0);
    }
  }

  if (finalStage == STAGE_PAIRSPECTRA)
  {
    DEBUG_MSG("Option -f given. Exiting after step: " << finalStageString);
    writeStatusFile(statusFileName, "Finished");
    exit(0);
  }

  if (initialStage <= STAGE_LPSOLVER)
  {
    DEBUG_TRACE;
    if (!performLpSolver(ip,
            ip.getValueBool("GRID_EXECUTION")))
    {
      exit(0);
    }

    if (commandLineParams.exists("SINGLE_STEP"))
    {
      DEBUG_MSG("Option -s given. Exiting after single step.");
      writeStatusFile(statusFileName, "Finished");
      exit(0);
    }
  }

  if (finalStage == STAGE_LPSOLVER)
  {
    DEBUG_MSG("Option -f given. Exiting after step: " << finalStageString);
    writeStatusFile(statusFileName, "Finished");
    exit(0);
  }

  if (initialStage <= STAGE_FLR)
  {
    DEBUG_TRACE;
    if (!performLpSolver(ip,
            ip.getValueBool("GRID_EXECUTION")))
    {
      exit(0);
    }

    if (commandLineParams.exists("SINGLE_STEP"))
    {
      DEBUG_MSG("Option -s given. Exiting after single step.");
      writeStatusFile(statusFileName, "Finished");
      exit(0);
    }
  }

  if (finalStage == STAGE_FLR)
  {
    DEBUG_MSG("Option -f given. Exiting after step: " << finalStageString);
    writeStatusFile(statusFileName, "Finished");
    exit(0);
  }

}
Exemplo n.º 7
0
// -------------------------------------------------------------------------
bool performFlr(ParameterList & ip, bool gridExecutionFlag)
{
  DEBUG_TRACE;
  ExecFlr moduleFlr(ip);
  DEBUG_TRACE;

  string errorString;
  bool isValid = moduleFlr.validateParams(errorString);
  DEBUG_VAR(isValid);
  if (!isValid)
  {
    ERROR_MSG(errorString);
    return false;
  }

  isValid = moduleFlr.loadInputData();
  DEBUG_VAR(isValid);
  if (!isValid)
  {
    ERROR_MSG(errorString);
    return false;
  }

  bool returnStatus;

  if (!ip.exists("GRID_NUMNODES") || ip.getValueInt("GRID_NUMNODES") <= 0)
  {
    returnStatus = moduleFlr.invoke();
  }
  else
  {
    DEBUG_TRACE;
    int numNodes = ip.getValueInt("GRID_NUMNODES");

    string gridType = ip.getValue("GRID_TYPE");
    if (gridType == "pbs")
    {
      ParallelPbsExecution exec(&moduleFlr,
          gridExecutionFlag,
          !gridExecutionFlag,
          false);
      returnStatus = exec.invoke(numNodes);
    }
    else if (gridType == "sge")
    {
      ParallelSgeExecution exec(&moduleFlr,
          gridExecutionFlag,
          !gridExecutionFlag,
          false);
      returnStatus = exec.invoke(numNodes);
    }
  }
  // Test for return status
  DEBUG_VAR( returnStatus);
  if (!returnStatus)
  {
    ERROR_MSG("invoking moduleFlr exited in error.");
    return false;
  }

  DEBUG_TRACE;

  moduleFlr.saveOutputData();
  return true;
}
MSMSFragmentation::MSMSFragmentation ( const string& fragName ) :
	fragName		( fragName ),
	ammoniaLoss		( "RKNQ" ),
	waterLoss		( "STED" ),
	posChargeBearing( "RHK" ),
	dIonExclude		( "FHPWY" ),
	vIonExclude		( "GP" ),
	wIonExclude		( "FHWY" ),

	unmatchedScore ( DEFAULT_MISS_SCORE ),

	immoniumScore ( DEFAULT_HIT_SCORE ),
	relatedIonScore ( DEFAULT_HIT_SCORE ),
	mScore ( DEFAULT_HIT_SCORE ),

	aScore ( DEFAULT_HIT_SCORE ),
	aLossScore ( DEFAULT_HIT_SCORE ),
	aPhosLossScore ( DEFAULT_HIT_SCORE ),
	bScore ( DEFAULT_HIT_SCORE ),
	bPlusH2OScore ( DEFAULT_HIT_SCORE ),
	bLossScore ( DEFAULT_HIT_SCORE ),
	bPhosLossScore ( DEFAULT_HIT_SCORE ),
	cLadderScore ( DEFAULT_HIT_SCORE ),
	cPlus2DaScore ( DEFAULT_HIT_SCORE ),
	cPlus1DaScore ( DEFAULT_HIT_SCORE ),
	cScore ( DEFAULT_HIT_SCORE ),
	cMinus1DaScore ( DEFAULT_HIT_SCORE ),
	dScore ( DEFAULT_HIT_SCORE ),

	vScore ( DEFAULT_HIT_SCORE ),
	wScore ( DEFAULT_HIT_SCORE ),
	xScore ( DEFAULT_HIT_SCORE ),
	nLadderScore ( DEFAULT_HIT_SCORE ),
	yScore ( DEFAULT_HIT_SCORE ),
	yLossScore ( DEFAULT_HIT_SCORE ),
	yPhosLossScore ( DEFAULT_HIT_SCORE ),
	bigYScore ( DEFAULT_HIT_SCORE ),
	zScore ( DEFAULT_HIT_SCORE ),
	zPlus1DaScore ( DEFAULT_HIT_SCORE ),
	zPlus2DaScore ( DEFAULT_HIT_SCORE ),
	zPlus3DaScore ( DEFAULT_HIT_SCORE ),

	bp2Score ( DEFAULT_HIT_SCORE ),
	bp2LossScore ( DEFAULT_HIT_SCORE ),
	bp2PhosLossScore ( DEFAULT_HIT_SCORE ),

	yp2Score ( DEFAULT_HIT_SCORE ),
	yp2LossScore ( DEFAULT_HIT_SCORE ),
	yp2PhosLossScore ( DEFAULT_HIT_SCORE ),

	internalAScore ( DEFAULT_HIT_SCORE ),
	internalBScore ( DEFAULT_HIT_SCORE ),
	internalLossScore ( DEFAULT_HIT_SCORE ),

	MH3PO4Score ( DEFAULT_HIT_SCORE ),
	MSOCH4Score ( DEFAULT_HIT_SCORE ),

	scoring ( false ),
	maximumInternalIonMass ( 700.0 ),
	chargeReducedFragmentation ( false )
{
	if ( !fragName.empty () ) {
		GenIFStream fromFile ( MsparamsDir::instance ().getParamPath ( "fragmentation.txt" ) );
		string line;
		bool flag = false;
		while ( getline ( fromFile, line ) ) {
			if ( line == fragName ) {
				ParameterList params ( fromFile );
				params.getValue ( "nh3_loss", ammoniaLoss );
				params.getValue ( "h2o_loss", waterLoss );
				params.getValue ( "pos_charge", posChargeBearing );
				params.getValue ( "d_ion_exclude", dIonExclude );
				params.getValue ( "v_ion_exclude", vIonExclude );
				params.getValue ( "w_ion_exclude", wIonExclude );
				params.getValue ( "it", ionTypes );
				params.getValue ( "max_internal_ion_mass", maximumInternalIonMass );
				params.getValue ( "charge_reduced_fragmentation", chargeReducedFragmentation );

				scoring = getScoreValue ( params, "unmatched_score", unmatchedScore );

				scoring = getScoreValue ( params, "immonium_score", immoniumScore );
				scoring = getScoreValue ( params, "related_ion_score", relatedIonScore );
				scoring = getScoreValue ( params, "m_score", mScore );

				scoring = getScoreValue ( params, "a_score", aScore );
				scoring = getScoreValue ( params, "a_loss_score", aLossScore );
				scoring = getScoreValue ( params, "a_phos_loss_score", aPhosLossScore );
				scoring = getScoreValue ( params, "b_score", bScore );
				scoring = getScoreValue ( params, "b_plus_h2o_score", bPlusH2OScore );
				scoring = getScoreValue ( params, "b_loss_score", bLossScore );
				scoring = getScoreValue ( params, "b_phos_loss_score", bPhosLossScore );
				scoring = getScoreValue ( params, "c_ladder_score", cLadderScore );
				scoring = getScoreValue ( params, "c_plus_2_score", cPlus2DaScore );
				scoring = getScoreValue ( params, "c_plus_1_score", cPlus1DaScore );
				scoring = getScoreValue ( params, "c_score", cScore );
				scoring = getScoreValue ( params, "c_minus_1_score", cMinus1DaScore );
				scoring = getScoreValue ( params, "d_score", dScore );

				scoring = getScoreValue ( params, "v_score", vScore );
				scoring = getScoreValue ( params, "w_score", wScore );
				scoring = getScoreValue ( params, "x_score", xScore );
				scoring = getScoreValue ( params, "n_ladder_score", nLadderScore );
				scoring = getScoreValue ( params, "y_score", yScore );
				scoring = getScoreValue ( params, "y_loss_score", yLossScore );
				scoring = getScoreValue ( params, "y_phos_loss_score", yPhosLossScore );
				scoring = getScoreValue ( params, "Y_score", bigYScore );
				scoring = getScoreValue ( params, "z_score", zScore );
				scoring = getScoreValue ( params, "z_plus_1_score", zPlus1DaScore );
				scoring = getScoreValue ( params, "z_plus_2_score", zPlus2DaScore );
				scoring = getScoreValue ( params, "z_plus_3_score", zPlus3DaScore );

				scoring = getScoreValue ( params, "bp2_score", bp2Score );
				scoring = getScoreValue ( params, "bp2_loss_score", bp2LossScore );
				scoring = getScoreValue ( params, "bp2_phos_loss_score", bp2PhosLossScore );

				scoring = getScoreValue ( params, "yp2_score", yp2Score );
				scoring = getScoreValue ( params, "yp2_loss_score", yp2LossScore );
				scoring = getScoreValue ( params, "yp2_phos_loss_score", yp2PhosLossScore );

				scoring = getScoreValue ( params, "internal_a_score", internalAScore );
				scoring = getScoreValue ( params, "internal_b_score", internalBScore );
				scoring = getScoreValue ( params, "internal_loss_score", internalLossScore );

				scoring = getScoreValue ( params, "mh3po4_score", MH3PO4Score );
				scoring = getScoreValue ( params, "msoch4_score", MSOCH4Score );
				flag = true;
				break;
			}
		}
		if ( !flag ) ErrorHandler::genError ()->error ( "Invalid or unspecified fragmentation name (file: fragmentation.txt).\nFunction: DiscriminantScore.\n" );
	}
	setMasks ();
}