Example #1
0
 Param getSubsectionDefaults_(const String& /*section*/) const
 {
   Param p = AccurateMassSearchEngine().getDefaults();
   // remove params which are already registered at top level (see registerOptionsAndFlags_())
   p.remove("db:mapping");
   p.remove("db:struct");
   p.remove("positive_adducts_file");
   p.remove("negative_adducts_file");
   return p;
 }
 //there is only one parameter at the moment
 Param getSubsectionDefaults_(const String& /*section*/) const
 {
   Param p = PosteriorErrorProbabilityModel().getParameters();
   if (p.exists("out_plot"))
   { // hide from user -- we have a top-level param for that
     p.remove("out_plot");
   }
   else 
   {
     throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "INTERNAL ERROR: Param 'out_plot' was removed from fit-algorithm. Please update param handling internally!");
   }
   return p;
 }
  Param getSubsectionDefaults_(const String& section) const
  {
    if (section == "Mascot_server")
    {
      MascotRemoteQuery mascot_query;
      return mascot_query.getParameters();
    }

    if (section == "Mascot_parameters")
    {
      MascotGenericFile mgf_file;
      Param p = mgf_file.getParameters();
      p.remove("internal:");
      return p;
    }

    return Param();
  }
Example #4
0
  void MSSim::syncParams_(Param& p, bool to_outer)
  {
    vector<StringList> globals;
    // here the globals params are listed that require to be in sync across several modules
    // - first the global param name and following that the module names where this param occurs
    // - Warning: the module params must have unchanged names and restrictions! (descriptions can differ though)
    globals.push_back(ListUtils::create<String>("ionization_type,Ionization,RawSignal,RawTandemSignal"));

    String global_prefix = "Global";
    // remove or add local params
    if (to_outer) // remove local params and merge to global
    {
      for (Size i = 0; i < globals.size(); ++i)
      {
        // set the global param:
        OPENMS_PRECONDITION(globals[i].size() >= 2, "Param synchronisation aborting due to missing local parameters!");
        p.insert(global_prefix + ":" + globals[i][0], p.copy(globals[i][1] + ":" + globals[i][0], true));
        // remove local params
        for (Size i_local = 1; i_local < globals[i].size(); ++i_local)
        {
          p.remove(globals[i][i_local] + ":" + globals[i][0]);
        }
      }
    }
    else // restore local params from global one
    {
      for (Size i = 0; i < globals.size(); ++i)
      {
        // get the global param:
        OPENMS_PRECONDITION(globals[i].size() >= 2, "Param synchronisation aborting due to missing local parameters!");

        Param p_global = p.copy(global_prefix + ":" + globals[i][0], true);
        // insert into local params
        for (Size i_local = 1; i_local < globals[i].size(); ++i_local)
        {
          p.insert(globals[i][i_local] + ":" + globals[i][0], p_global);
        }
      }
    }

  }
Example #5
0
  void updateINI(const String& infile, const String& outfile)
  {
    Int this_instance = getIntOption_("instance");
    INIUpdater updater;
    String tmp_ini_file = File::getTempDirectory() + "/" + File::getUniqueName() + "_INIUpdater.ini";
    tmp_files_.push_back(tmp_ini_file);

    String path = File::getExecutablePath();

    Param p;
    ParamXMLFile paramFile;
    paramFile.load(infile, p);
    // get sections (usually there is only one - or the user has merged INI files manually)
    StringList sections = updater.getToolNamesFromINI(p);

    if (sections.empty())
    {
      writeLog_("Update for file " + infile + " failed because tool section does not exist. Check INI file for corruption!");
      failed_.push_back(infile);
      return;
    }

    // get version of first section
    String version_old = "Unknown";
    if (!p.exists(sections[0] + ":version"))
    {
      writeLog_("No OpenMS version information found in file " + infile + "! Cannot update!");
      failed_.push_back(infile);
      return;
    }
    else
    {
      version_old = p.getValue(sections[0] + ":version");
      // TODO: return on newer version?!
    }


    // update sections
    writeDebug_("Section names: " + ListUtils::concatenate(sections, ", "), 1);
    bool update_success = true;
    for (Size s = 0; s < sections.size(); ++s)
    {
      String sec_inst = sections[s] + ":" + String(this_instance) + ":";
      // check for default instance
      if (!p.exists(sec_inst + "debug"))
      {
        writeLog_("Update for file '" + infile + "' failed because the instance section '" + sec_inst + "' does not exist. Use -instance or check INI file for corruption!");
        update_success = false;
        break;
      }
      String new_tool;
      String ttype;
      // find mapping to new tool (might be the same name)
      if (p.exists(sec_inst + "type")) ttype = p.getValue(sec_inst + "type");
      if (!updater.getNewToolName(sections[s], ttype, new_tool))
      {
        String type_text = ((ttype == "") ? "" : " with type '" + ttype + "' ");
        writeLog_("Update for file '" + infile + "' failed because the tool '" + sections[s] + "'" + type_text + "is unknown. TOPPAS file seems to be corrupted!");
        update_success = false;
        break;
      }
      // get defaults of new tool by calling it
      QProcess pr;
      QStringList arguments;
      arguments << "-write_ini";
      arguments << tmp_ini_file.toQString();
      arguments << "-instance";
      arguments << String(this_instance).toQString();
      pr.start((path + "/" + new_tool).toQString(), arguments);
      if (!pr.waitForFinished(-1))
      {
        writeLog_("Update for file '" + infile + "' failed because the tool '" + new_tool + "' returned with an error! Check if the tool works properly.");
        update_success = false;
        break;
      }

      // update defaults with old values
      Param new_param;
      paramFile.load(tmp_ini_file, new_param);
      new_param = new_param.copy(new_tool, true);
      Param old_param = p.copy(sections[s], true);
      new_param.update(old_param);
      // push back changes
      p.remove(sections[s] + ":");
      p.insert(new_tool, new_param);
    }

    if (!update_success)
    {
      failed_.push_back(infile);
      return;
    }

    // STORE
    if (outfile.empty()) // create a backup
    {
      QFileInfo fi(infile.toQString());
      String backup_filename = String(fi.path()) + "/" + fi.completeBaseName() + "_v" + version_old + ".ini";
      QFile::rename(infile.toQString(), backup_filename.toQString());
      std::cout << "Backup of input file created: " << backup_filename << std::endl;
      // write updated/new file
      paramFile.store(infile, p);
    }
    else
    {
      paramFile.store(outfile, p);
    }
  }
Example #6
0
  void updateTOPPAS(const String& infile, const String& outfile)
  {
    Int this_instance = getIntOption_("instance");
    INIUpdater updater;
    String tmp_ini_file = File::getTempDirectory() + "/" + File::getUniqueName() + "_INIUpdater.ini";
    tmp_files_.push_back(tmp_ini_file);

    String path = File::getExecutablePath();

    ParamXMLFile paramFile;
    Param p;
    paramFile.load(infile, p);

    // get version of TOPPAS file
    String version = "Unknown";
    if (!p.exists("info:version"))
    {
      writeLog_("No OpenMS version information found in file " + infile + "! Assuming OpenMS 1.8 and below.");
      version = "1.8.0";
    }
    else
    {
      version = p.getValue("info:version");
      // TODO: return on newer version?!
    }

    Int vertices = p.getValue("info:num_vertices");

    // update sections
    writeDebug_("#Vertices: " + String(vertices), 1);
    bool update_success = true;
    for (Int v = 0; v < vertices; ++v)
    {
      String sec_inst = "vertices:" + String(v) + ":";
      // check for default instance
      if (!p.exists(sec_inst + "toppas_type"))
      {
        writeLog_("Update for file " + infile + " failed because the vertex #" + String(v) + " does not have a 'toppas_type' node. Check INI file for corruption!");
        update_success = false;
        break;
      }

      if (p.getValue(sec_inst + "toppas_type") != "tool") // not a tool (but input/output/merge node)
      {
        continue;
      }

      if (!p.exists(sec_inst + "tool_name"))
      {
        writeLog_("Update for file " + infile + " failed because the vertex #" + String(v) + " does not have a 'tool_name' node. Check INI file for corruption!");
        update_success = false;
        break;
      }

      String old_name = p.getValue(sec_inst + "tool_name");
      String new_tool;
      String ttype;
      // find mapping to new tool (might be the same name)
      if (p.exists(sec_inst + "tool_type")) ttype = p.getValue(sec_inst + "tool_type");
      if (!updater.getNewToolName(old_name, ttype, new_tool))
      {
        String type_text = ((ttype == "") ? "" : " with type '" + ttype + "' ");
        writeLog_("Update for file " + infile + " failed because the tool '" + old_name + "'" + type_text + "is unknown. TOPPAS file seems to be corrupted!");
        update_success = false;
        break;
      }

      // set new tool name
      p.setValue(sec_inst + "tool_name", new_tool);
      // delete TOPPAS type
      if (new_tool != "GenericWrapper")
      {
        p.setValue(sec_inst + "tool_type", "");
      }

      // get defaults of new tool by calling it
      QProcess pr;
      QStringList arguments;
      arguments << "-write_ini";
      arguments << tmp_ini_file.toQString();
      arguments << "-instance";
      arguments << String(this_instance).toQString();
      pr.start((path + "/" + new_tool).toQString(), arguments);
      if (!pr.waitForFinished(-1))
      {
        writeLog_("Update for file " + infile + " failed because the tool '" + new_tool + "' returned with an error! Check if the tool works properly.");
        update_success = false;
        break;
      }

      // update defaults with old values
      Param new_param;
      paramFile.load(tmp_ini_file, new_param);
      new_param = new_param.copy(new_tool + ":1", true);
      Param old_param = p.copy(sec_inst + "parameters", true);
      new_param.update(old_param);
      // push back changes
      p.remove(sec_inst + "parameters:");
      p.insert(sec_inst + "parameters", new_param);
    }

    if (!update_success)
    {
      failed_.push_back(infile);
      return;
    }

    paramFile.store(tmp_ini_file, p);

    // update internal structure (e.g. edges format changed from 1.8 to 1.9)
    int argc = 1;
    const char* c = "IniUpdater";
    const char** argv = &c;

    QApplication app(argc, const_cast<char**>(argv), false);
    String tmp_dir = File::getTempDirectory() + "/" + File::getUniqueName();
    QDir d;
    d.mkpath(tmp_dir.toQString());
    TOPPASScene ts(nullptr, tmp_dir.toQString(), false);
    paramFile.store(tmp_ini_file, p);
    ts.load(tmp_ini_file);
    ts.store(tmp_ini_file);
    paramFile.load(tmp_ini_file, p);

    // STORE
    if (outfile.empty()) // create a backup
    {
      QFileInfo fi(infile.toQString());
      String new_name = String(fi.path()) + "/" + fi.completeBaseName() + "_v" + version + ".toppas";
      QFile::rename(infile.toQString(), new_name.toQString());
      // write new file
      paramFile.store(infile, p);
    }
    else
    {
      paramFile.store(outfile, p);
    }
  }
 Param getSubsectionDefaults_(const String & /* section*/) const
 {
   Param tmp = SvmTheoreticalSpectrumGeneratorTrainer().getDefaults();
   tmp.remove("write_training_files");
   return tmp;
 }