Ejemplo 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);
}
Ejemplo n.º 2
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);
  }

}