Esempio n. 1
0
  void TOPPASResources::load(const QString& file_name)
  {
    Param load_param;
    ParamXMLFile paramFile;
    paramFile.load(String(file_name), load_param);

    for (Param::ParamIterator it = load_param.begin(); it != load_param.end(); ++it)
    {
      StringList substrings;
      it.getName().split(':', substrings);
      if (substrings.size() != 2 ||
          substrings.back() != "url_list" ||
          (it->value).valueType() != DataValue::STRING_LIST)
      {
        std::cerr << "Invalid file format." << std::endl;
        return;
      }

      QString key = (substrings[0]).toQString();
      StringList url_list = (it->value);
      QList<TOPPASResource> resource_list;
      for (StringList::const_iterator it = url_list.begin(); it != url_list.end(); ++it)
      {
        resource_list << TOPPASResource(QUrl(it->toQString()));
      }

      add(key, resource_list);
    }
  }
Esempio n. 2
0
  StringList INIUpdater::getToolNamesFromINI(const Param & ini) const
  {
    StringList tool_names;

    for (Param::ParamIterator it = ini.begin(); it != ini.end(); ++it)
    {
      if (it.getName().toQString().count(':') == 1 && it.getName().hasSuffix(":version"))
      {
        tool_names.push_back(it.getName().prefix(':'));
      }
    }
    return tool_names;
  }
Esempio n. 3
0
  void ResidueDB::readResiduesFromFile_(const String& file_name)
  {
    String file = File::find(file_name);

    Param param;
    ParamXMLFile paramFile;
    paramFile.load(file, param);

    if (!param.begin().getName().hasPrefix("Residues"))
    {
      throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "", "");
    }

    try
    {
      vector<String> split;
      param.begin().getName().split(':', split);
      String prefix = split[0] + split[1];
      Residue* res_ptr = nullptr;

      Map<String, String> values;

      for (Param::ParamIterator it = param.begin(); it != param.end(); ++it)
      {
        it.getName().split(':', split);
        if (prefix != split[0] + split[1])
        {
          // add residue
          res_ptr = parseResidue_(values);
          values.clear();
          residues_.insert(res_ptr);
          const_residues_.insert(res_ptr);
          prefix = split[0] + split[1];
        }

        String value = it->value;
        String key = it.getName();
        values[key] = value;

      }

      // add last residue
      res_ptr = parseResidue_(values);
      residues_.insert(res_ptr);
      const_residues_.insert(res_ptr);
    }
    catch (Exception::BaseException& e)
    {
      throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, e.what(), "");
    }
  }
Esempio n. 4
0
  void EnzymesDB::readEnzymesFromFile_(const String& file_name)
  {
    String file = File::find(file_name);

    Param param;
    ParamXMLFile paramFile;
    paramFile.load(file, param);

    if (!param.begin().getName().hasPrefix("Enzymes"))
    {
      throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "", "");
    }

    try
    {
      vector<String> split;
      param.begin().getName().split(':', split);
      String prefix = split[0] + split[1];
 
      Map<String, String> values;

      for (Param::ParamIterator it = param.begin(); it != param.end(); ++it)
      {
        it.getName().split(':', split);
        if (prefix != split[0] + split[1])
        {
          // add enzyme
          addEnzyme_(parseEnzyme_(values));
          prefix = split[0] + split[1];
          values.clear();
        }
        values[it.getName()] = it->value;
      }

      // add last enzyme
      addEnzyme_(parseEnzyme_(values));
    }
    catch (Exception::BaseException& e)
    {
      throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, e.what(), "");
    }
  }
Esempio n. 5
0
 void DefaultParamHandler::defaultsToParam_()
 {
   //check if a description is given for all defaults
   bool description_missing = false;
   String missing_parameters;
   for (Param::ParamIterator it = defaults_.begin(); it != defaults_.end(); ++it)
   {
     //cout << "Name: " << it->getName() << endl;
     if (it->description == "")
     {
       description_missing = true;
       missing_parameters += it.getName() + ",";
       break;
     }
   }
   if (description_missing)
   {
     cerr << "Warning: no default parameter description for parameters '" << missing_parameters << "' of DefaultParameterHandler '" << error_name_ << "' given!" << endl;
   }
   param_.setDefaults(defaults_);
   updateMembers_();
 }
Esempio n. 6
0
  void ElementDB::readFromFile_(const String& file_name)
  {
    String file = File::find(file_name);

    // load elements into param object
    Param param;
    ParamXMLFile paramFile;
    paramFile.load(file, param);

    UInt an(0);
    String name, symbol;

    // determine prefix
    vector<String> split;
    param.begin().getName().split(':', split);
    String prefix("");
    for (Size i = 0; i < split.size() - 1; ++i)
    {
      prefix += split[i] + ":";
    }
    //cout << "first element prefix=" << prefix << endl;

    Map<UInt, double> Z_to_abundancy;
    Map<UInt, double> Z_to_mass;

    for (Param::ParamIterator it = param.begin(); it != param.end(); ++it)
    {
      // new element started?
      if (!it.getName().hasPrefix(prefix))
      {
        // update prefix
        it.getName().split(':', split);
        prefix = "";
        for (Size i = 0; i < split.size() - 1; ++i)
        {
          prefix += split[i] + ":";
        }
        // cout << "new element prefix=" << prefix << endl;

        // Parsing of previous element is finished. Now store data in Element object
        IsotopeDistribution isotopes = parseIsotopeDistribution_(Z_to_abundancy);
        double avg_weight = calculateAvgWeight_(Z_to_abundancy, Z_to_mass);
        double mono_weight = calculateMonoWeight_(Z_to_mass);

        /*
        // print information about elements
        cout << "Name: " << name << " AtomicNumber: " << an << " Symbol: " << symbol << " AvgWeight: " << avg_weight
             << " MonoWeight: " << mono_weight << " NIsotopes: " << isotopes.size() << endl;

        */
        Element* e = new Element(name, symbol, an, avg_weight, mono_weight, isotopes);
        names_[name] = e;
        symbols_[symbol] = e;
        atomic_numbers_[an] = e;

        // add all the individual isotopes as separat elements
        for (IsotopeDistribution::ConstIterator iit = isotopes.begin(); iit != isotopes.end(); ++iit)
        {
          String iso_name = "(" + String(iit->first) + ")" + name;
          String iso_symbol = "(" + String(iit->first) + ")" + symbol;

          // set avg and mono to same value for isotopes (old hack...)
          DoubleReal iso_avg_weight = Z_to_mass[(UInt) iit->first];
          DoubleReal iso_mono_weight = iso_avg_weight;
          IsotopeDistribution iso_isotopes;
          vector<pair<Size, double> > iso_container;
          iso_container.push_back(make_pair(iit->first, 1.0));
          iso_isotopes.set(iso_container);

          /*
          // print name, symbal and atomic mass of the current isotope
          cout << "Isotope Name: " << iso_name << " Symbol: " << iso_symbol << " AtomicMass: " << iso_mono_weight << endl;
          */

          Element* iso_e = new Element(iso_name, iso_symbol, an, iso_avg_weight, iso_mono_weight, iso_isotopes);
          names_[iso_name] = iso_e;
          names_[iso_symbol] = iso_e;
        }

        Z_to_abundancy.clear();
        Z_to_mass.clear();
      }

      // top level: read the contents of the element section
      it.getName().split(':', split);
      String key = split[2];
      String value = it->value;
      value.trim();

      // cout << "Key=" << key << endl;

      if (key == "AtomicNumber")
      {
        an = (UInt)value.toInt();
      }
      else
      {
        if (key == "Isotopes")
        {
          UInt Z = UInt(split[3].toInt());
          String item = split[4];
          if (item == "RelativeAbundance")
          {
            Z_to_abundancy[Z] = double(value.toDouble() / 100.0);
          }
          else if (item == "AtomicMass")
          {
            Z_to_mass[Z] = double(value.toDouble());
          }
          else
          {
            cerr << "read unknown item in Isotopes: " << item << endl;
          }
        }
        else
        {
          if (key == "Name")
          {
            name = value;
          }
          else
          {
            if (key == "Symbol")
            {
              symbol = value;
            }
            else
            {
              cerr << "read unknown tag: " << key << endl;
            }
          }
        }
      }
    }

    // build last element
    double avg_weight(0), mono_weight(0);
    IsotopeDistribution isotopes = parseIsotopeDistribution_(Z_to_abundancy);
    Element* e = new Element(name, symbol, an, avg_weight, mono_weight, isotopes);
    names_[name] = e;
    symbols_[symbol] = e;
    atomic_numbers_[an] = e;
  }
Esempio n. 7
0
  void ToolsDialog::loadINI_()
  {
    QString string;
    filename_ = QFileDialog::getOpenFileName(this, tr("Open ini file"), default_dir_.c_str(), tr("ini files (*.ini);; all files (*.*)"));
    //not file selected
    if (filename_.isEmpty())
    {
      return;
    }
    enable_();
    if (!arg_param_.empty())
    {
      arg_param_.clear();
      vis_param_.clear();
      editor_->clear();
      arg_map_.clear();
    }
    try
    {
      ParamXMLFile paramFile;
      paramFile.load(filename_.toStdString(), arg_param_);
    }
    catch (Exception::BaseException& e)
    {
      QMessageBox::critical(this, "Error", (String("Error loading INI file: ") + e.getMessage()).c_str());
      arg_param_.clear();
      return;
    }
    //set tool combo
    Param::ParamIterator iter = arg_param_.begin();
    String str;
    string = iter.getName().substr(0, iter.getName().find(":")).c_str();
    Int pos = tools_combo_->findText(string);
    if (pos == -1)
    {
      QMessageBox::critical(this, "Error", (String("Cannot apply '") + string + "' tool to this layer type. Aborting!").c_str());
      arg_param_.clear();
      return;
    }
    tools_combo_->setCurrentIndex(pos);
    //Extract the required parameters
    vis_param_ = arg_param_.copy(getTool() + ":1:", true);
    vis_param_.remove("log");
    vis_param_.remove("no_progress");
    vis_param_.remove("debug");
    //load data into editor
    editor_->load(vis_param_);

    QStringList arg_list;
    for (Param::ParamIterator iter = arg_param_.begin(); iter != arg_param_.end(); ++iter)
    {
      str = iter.getName().substr(iter.getName().rfind("1:") + 2, iter.getName().size());
      if (!str.empty() && str.find(":") == String::npos)
      {
        arg_map_.insert(make_pair(str, iter.getName()));
        arg_list << QStringList(str.c_str());
      }
    }
    arg_list.push_front("<select>");
    input_combo_->clear();
    output_combo_->clear();
    input_combo_->addItems(arg_list);
    pos = arg_list.indexOf("in");
    if (pos != -1)
    {
      input_combo_->setCurrentIndex(pos);
    }
    output_combo_->addItems(arg_list);
    pos = arg_list.indexOf("out");
    if (pos != -1 && getTool() != "FileInfo")
    {
      output_combo_->setCurrentIndex(pos);
    }
  }
Esempio n. 8
0
  void ToolsDialog::createINI_()
  {
    String call = String("\"") + File::findExecutable(getTool()) + "\"" + " -write_ini " + ini_file_ + " -log " + ini_file_ + ".log";

    if (system(call.c_str()) != 0)
    {
      QMessageBox::critical(this, "Error", (String("Could not execute '") + call + "'!\n\nMake sure the TOPP tools are present in '" + File::getExecutablePath() + "',  that you have permission to write to the temporary file path, and that there is space left in the temporary file path.").c_str());
    }
    else if (!File::exists(ini_file_))
    {
      QMessageBox::critical(this, "Error", (String("Could not open '") + ini_file_ + "'!").c_str());
    }
    else
    {
      enable_();
      if (!arg_param_.empty())
      {
        tool_desc_->clear();
        arg_param_.clear();
        vis_param_.clear();
        editor_->clear();
        arg_map_.clear();
      }

      ParamXMLFile paramFile;
      paramFile.load((ini_file_).c_str(), arg_param_);

      tool_desc_->setText(arg_param_.getSectionDescription(getTool()).toQString());
      vis_param_ = arg_param_.copy(getTool() + ":1:", true);
      vis_param_.remove("log");
      vis_param_.remove("no_progress");
      vis_param_.remove("debug");

      editor_->load(vis_param_);

      String str;
      QStringList arg_list;
      for (Param::ParamIterator iter = arg_param_.begin(); iter != arg_param_.end(); ++iter)
      {
        str = iter.getName().substr(iter.getName().rfind("1:") + 2, iter.getName().size());
        if (str.size() != 0 && str.find(":") == String::npos)
        {
          arg_map_.insert(make_pair(str, iter.getName()));
          arg_list << QStringList(str.c_str());
        }
      }

      arg_list.push_front("<select>");
      input_combo_->clear();
      output_combo_->clear();
      input_combo_->addItems(arg_list);
      Int pos = arg_list.indexOf("in");
      if (pos != -1)
      {
        input_combo_->setCurrentIndex(pos);
      }
      output_combo_->addItems(arg_list);
      pos = arg_list.indexOf("out");
      if (pos != -1 && getTool() != "FileInfo")
      {
        output_combo_->setCurrentIndex(pos);
      }
      editor_->setFocus(Qt::MouseFocusReason);
    }
  }
int main(int argc, const char** argv)
{
#if  defined(__APPLE__)
  // we do not want to load plugins as this leads to serious problems
  // when shipping on mac os x
  QApplication::setLibraryPaths(QStringList());
#endif

  // ensure correct encoding of paths
  QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));

  Map<String, String> option_lists;
  Map<String, String> options;
  options["-print"] = "print";
  Map<String, String> flags;
  flags["--help"] = "help";
  Param param;
  param.parseCommandLine(argc, argv, options, flags, option_lists);

  //catch command line errors
  if (param.exists("help") //help requested
     || argc > 3 //too many arguments
     || (argc == 3 && !param.exists("print")) //three argument but no -print
     || (param.exists("print") && param.getValue("print") == "") //-print but no file given
      )
  {
    cerr << endl
         << "INIFileEditor -- An editor for OpenMS configuration files." << endl
         << endl
         << "Usage:" << endl
         << " INIFileEditor [options] [file]" << endl
         << endl
         << "Options are:" << endl
         << " --help         Shows this help and exits" << endl
         << " -print <file>  Prints the content of the file to the command line and exits" << endl
         << endl;
    return 0;
  }

  //print a ini file as text
  if (param.exists("print"))
  {
    Param data;
    ParamXMLFile paramFile;
    try
    {
      paramFile.load(param.getValue("print"), data);
      for (Param::ParamIterator it = data.begin(); it != data.end(); ++it)
      {
        cout << it.getName() << " = " << it->value << endl;
      }
    }
    catch (Exception::BaseException& e)
    {
      LOG_ERROR << "Error while parsing file '" << param.getValue("print") << "'\n";
      LOG_ERROR << e << "\n";
    }

    return 0;
  }

  //Create window
  QApplicationTOPP app(argc, const_cast<char**>(argv));

  //set plastique style unless windows / mac style is available
  if (QStyleFactory::keys().contains("windowsxp", Qt::CaseInsensitive))
  {
    app.setStyle("windowsxp");
  }
  else if (QStyleFactory::keys().contains("macintosh", Qt::CaseInsensitive))
  {
    app.setStyle("macintosh");
  }
  else if (QStyleFactory::keys().contains("plastique", Qt::CaseInsensitive))
  {
    app.setStyle("plastique");
  }

  INIFileEditorWindow editor_window;

  //Open passed file
  if (argc == 2)
  {
    //cout << "OPEN: "  << argv[1] << endl;
    editor_window.openFile(argv[1]);
  }

#ifdef OPENMS_WINDOWSPLATFORM
  FreeConsole(); // get rid of console window at this point (we will not see any console output from this point on)
  AttachConsole(-1); // if the parent is a console, reattach to it - so we can see debug output - a normal user will usually not use cmd.exe to start a GUI)
#endif

  editor_window.show();
  return app.exec();
}
Esempio n. 10
0
void convertINI2HTML(const Param & p, ostream & os)
{
  // the .css file is included via the Header.html (see doc/doxygen/common/Header.html)
  os << "<div class=\"ini_global\">\n";
  os << "<div class=\"legend\">\n";
  os << "<b>Legend:</b><br>\n";
  os << " <div class=\"item item_required\">required parameter</div>\n";
  os << " <div class=\"item item_advanced\">advanced parameter</div>\n";
  os << "</div>\n";

  Param::ParamIterator it = p.begin();
  String indentation = "  ";

  while (it != p.end())
  {
    string key = it.getName();

    //write opened/closed nodes
    const std::vector<Param::ParamIterator::TraceInfo> & trace = it.getTrace();
    for (std::vector<Param::ParamIterator::TraceInfo>::const_iterator it2 = trace.begin(); it2 != trace.end(); ++it2)
    {
      if (it2->opened) //opened node
      {
        String d = it2->description;
        d.substitute("\n", "<br>");
        os << indentation  << "<div class=\"node\"><span class=\"node_name\">" << (String().fillLeft('+', (UInt) indentation.size() / 2) + it2->name) << "</span><span class=\"node_description\">" << (d) << "</span></div>" << "\n";
        indentation += "  ";
      }
      else //closed node
      {
        indentation.resize(indentation.size() - 2);
        //os << indentation << "</div>" << "\n";
      }
    }

    //write item
    String s_attr;
    String s_req;
    if (it->tags.find("advanced") != it->tags.end())
      s_attr += " item_advanced";                                                // optionally add advanced class
    if (it->tags.find("required") != it->tags.end())
      s_req += " item_required";                                                // optionally add required class
    DataValue::DataType value_type = it->value.valueType();
    //write opening tag
    os << indentation << "<div class=\"item" + s_attr + "\"><span class=\"item_name" + s_req + "\" style=\"padding-left:" << indentation.size() * 4 << "px;\">" << (it->name) << "</span><span class=\"item_value\">" << it->value.toString() << "</span>" << "\n";

    //replace all critical characters in description
    String d = it->description;
    d.substitute("\n", "<br>");
    os << "<span class=\"item_description\">" << (d) << "</span>";

    //tags
    String list;
    for (set<String>::const_iterator tag_it = it->tags.begin(); tag_it != it->tags.end(); ++tag_it)
    {
      if (*tag_it == "advanced")
        continue;                        // do not list "advanced" or "required" (this is done by color coding)
      if (*tag_it == "required")
        continue;
      if (!list.empty())
        list += ",";
      list += *tag_it;
    }
    os << "<span class=\"item_tags\">" << (list) << "</span>";

    //restrictions
    String restrictions = "";
    bool escape_restrictions(true);
    switch (value_type)
    {
    case DataValue::INT_VALUE:
    case DataValue::INT_LIST:
    {
      bool min_set = (it->min_int != -numeric_limits<Int>::max());
      bool max_set = (it->max_int != numeric_limits<Int>::max());
      if (max_set || min_set)
      {
        if (min_set)
          restrictions += String(it->min_int);
        else
          restrictions += "-&#8734;";        // infinity symbol
        restrictions += ':';
        if (max_set)
          restrictions += String(it->max_int);
        else
          restrictions += "&#8734;";
      }
      escape_restrictions = false;     // prevent html escape of infinity symbol
    }
    break;

    case DataValue::DOUBLE_VALUE:
    case DataValue::DOUBLE_LIST:
    {
      bool min_set = (it->min_float != -numeric_limits<DoubleReal>::max());
      bool max_set = (it->max_float != numeric_limits<DoubleReal>::max());
      if (max_set || min_set)
      {
        if (min_set)
          restrictions += String(it->min_float);
        else
          restrictions += "-&#8734;";        // infinity symbol
        restrictions += ':';
        if (max_set)
          restrictions += String(it->max_float);
        else
          restrictions += "&#8734;";
      }
      escape_restrictions = false;     // prevent html escape of infinity symbol
    }
    break;

    case DataValue::STRING_VALUE:
    case DataValue::STRING_LIST:
      if (it->valid_strings.size() != 0)
      {
        restrictions.concatenate(it->valid_strings.begin(), it->valid_strings.end(), ",");
      }
      break;

    default:
      break;
    }
    if (restrictions.empty())
      restrictions = " ";                       // create content, such that the cell gets an underline

    os << "<span class=\"item_restrictions\">" << restrictions << "</span>";

    os << "</div>"; // end div item

    ++it;
  }

  os << "</div>\n";  // end global div
}