本文整理汇总了C++中ParamXMLFile::load方法的典型用法代码示例。如果您正苦于以下问题:C++ ParamXMLFile::load方法的具体用法?C++ ParamXMLFile::load怎么用?C++ ParamXMLFile::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParamXMLFile
的用法示例。
在下文中一共展示了ParamXMLFile::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load
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);
}
}
示例2: getSystemParameters
Param File::getSystemParameters()
{
String filename = String(QDir::homePath()) + "/.OpenMS/OpenMS.ini";
Param p;
if (!File::readable(filename)) // create file
{
p = getSystemParameterDefaults_();
String dirname = String(QDir::homePath()) + "/.OpenMS";
QDir dir(dirname.toQString());
if (!dir.exists())
{
if (!File::writable(dirname))
{
LOG_WARN << "Warning: Cannot create folder '.OpenMS' in user home directory. Please check your environment!" << std::endl;
LOG_WARN << " Home directory determined is: " << QDir::homePath().toStdString() << "." << std::endl;
return p;
}
dir.mkpath(".");
}
if (!File::writable(filename))
{
LOG_WARN << "Warning: Cannot create '.OpenMS/OpenMS.ini' in user home directory. Please check your environment!" << std::endl;
LOG_WARN << " Home directory determined is: " << QDir::homePath().toStdString() << "." << std::endl;
return p;
}
ParamXMLFile paramFile;
paramFile.store(filename, p);
}
else
{
ParamXMLFile paramFile;
paramFile.load(filename, p);
// check version
if (!p.exists("version") || (p.getValue("version") != VersionInfo::getVersion()))
{
if (!p.exists("version"))
{
LOG_WARN << "Broken file '" << filename << "' discovered. The 'version' tag is missing." << std::endl;
}
else // old version
{
LOG_WARN << "File '" << filename << "' is deprecated." << std::endl;
}
LOG_WARN << "Updating missing/wrong entries in '" << filename << "' with defaults!" << std::endl;
Param p_new = getSystemParameterDefaults_();
p.setValue("version", VersionInfo::getVersion()); // update old version, such that p_new:version does not get overwritten during update()
p_new.update(p);
paramFile.store(filename, p_new);
}
}
return p;
}
示例3: readResiduesFromFile_
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(), "");
}
}
示例4: readEnzymesFromFile_
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(), "");
}
}
示例5: openFile
bool INIFileEditorWindow::openFile(const String& filename)
{
if (filename == "")
{
filename_ = QFileDialog::getOpenFileName(this, tr("Open ini file"), current_path_.toQString(), tr("ini files (*.ini);; all files (*.*)"));
}
else
{
filename_ = filename.c_str();
}
if (!filename_.isEmpty())
{
if (File::readable(filename_.toStdString()))
{
param_.clear();
ParamXMLFile paramFile;
try
{
paramFile.load(filename_.toStdString(), param_);
editor_->load(param_);
updateWindowTitle(editor_->isModified());
return true;
}
catch (Exception::BaseException& e)
{
LOG_ERROR << "Error while parsing file '" << filename_.toStdString() << "'\n";
LOG_ERROR << e << "\n";
}
}
QMessageBox::critical(this, "Error opening file", ("The file '" + filename_.toStdString() + "' does not exist, is not readable or not a proper INI file!").c_str());
}
return false;
}
示例6: main
Int main(int argc, const char** argv)
{
if (argc < 2) return 1;
// the path to the data should be given on the command line
String tutorial_data_path(argv[1]);
QApplication app(argc, const_cast<char**>(argv));
Param param;
ParamXMLFile paramFile;
paramFile.load(tutorial_data_path + "/data/Tutorial_ParamEditor.ini", param);
ParamEditor* editor = new ParamEditor(0);
editor->load(param);
editor->show();
app.exec();
editor->store();
paramFile.store("Tutorial_ParamEditor_out.ini", param);
return 0;
} //end of main
示例7: updateINI
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;
//.........这里部分代码省略.........
示例8: updateTOPPAS
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);
}
//.........这里部分代码省略.........
示例9: readFromFile_
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());
//.........这里部分代码省略.........
示例10: loadINI_
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);
}
}
示例11: createINI_
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);
}
}
示例12: wrapSVM
void RTSimulation::wrapSVM(std::vector<AASequence>& peptide_sequences, std::vector<DoubleReal>& predicted_retention_times)
{
String allowed_amino_acid_characters = "ACDEFGHIKLMNPQRSTVWY";
SVMWrapper svm;
LibSVMEncoder encoder;
svm_problem* training_data = NULL;
SVMData prediction_samples;
SVMData training_samples;
UInt k_mer_length = 0;
DoubleReal sigma = 0.0;
UInt border_length = 0;
Size max_number_of_peptides(2000); // hard coding pediction bins; larger values only take more memory, result is not affected
LOG_INFO << "Predicting RT ... ";
svm.loadModel(rt_model_file_);
// load additional parameters
if (svm.getIntParameter(SVMWrapper::KERNEL_TYPE) == SVMWrapper::OLIGO)
{
String add_paramfile = rt_model_file_ + "_additional_parameters";
if (!File::readable(add_paramfile))
{
throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__, "RTSimulation: SVM parameter file " + add_paramfile + " is not readable");
}
Param additional_parameters;
ParamXMLFile paramFile;
paramFile.load(add_paramfile, additional_parameters);
if (additional_parameters.getValue("border_length") == DataValue::EMPTY
&& svm.getIntParameter(SVMWrapper::KERNEL_TYPE) == SVMWrapper::OLIGO)
{
throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__, "RTSimulation: No border length defined in additional parameters file.");
}
border_length = ((String)additional_parameters.getValue("border_length")).toInt();
if (additional_parameters.getValue("k_mer_length") == DataValue::EMPTY
&& svm.getIntParameter(SVMWrapper::KERNEL_TYPE) == SVMWrapper::OLIGO)
{
throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__, "RTSimulation: No k-mer length defined in additional parameters file.");
}
k_mer_length = ((String)additional_parameters.getValue("k_mer_length")).toInt();
if (additional_parameters.getValue("sigma") == DataValue::EMPTY
&& svm.getIntParameter(SVMWrapper::KERNEL_TYPE) == SVMWrapper::OLIGO)
{
throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__, "RTSimulation: No sigma defined in additional parameters file.");
}
sigma = ((String)additional_parameters.getValue("sigma")).toFloat();
}
svm.setParameter(SVMWrapper::BORDER_LENGTH, (Int) border_length);
svm.setParameter(SVMWrapper::SIGMA, sigma);
// loading model data
String sample_file = rt_model_file_ + "_samples";
if (!File::readable(sample_file))
{
throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__, "RTSimulation: SVM sample file " + sample_file + " is not readable");
}
training_samples.load(sample_file);
svm.setTrainingSample(training_samples);
svm.setTrainingSample(training_data);
// use maximally max_number_of_peptides peptide sequence at once
Size tmp_count = 0;
Size count = 0;
std::vector<AASequence>::iterator pep_iter_start = peptide_sequences.begin();
std::vector<AASequence>::iterator pep_iter_stop = peptide_sequences.begin();
while (count < peptide_sequences.size())
{
while (pep_iter_stop != peptide_sequences.end() && tmp_count < max_number_of_peptides)
{
++tmp_count;
++pep_iter_stop;
}
std::vector<AASequence> tmp_peptide_seqs;
tmp_peptide_seqs.insert(tmp_peptide_seqs.end(), pep_iter_start, pep_iter_stop);
std::vector<DoubleReal> tmp_rts(tmp_peptide_seqs.size(), 0);
std::vector<DoubleReal> tmp_pred_rts;
// Encoding test data
encoder.encodeProblemWithOligoBorderVectors(tmp_peptide_seqs, k_mer_length, allowed_amino_acid_characters, border_length, prediction_samples.sequences);
prediction_samples.labels = tmp_rts;
svm.predict(prediction_samples, tmp_pred_rts);
predicted_retention_times.insert(predicted_retention_times.end(), tmp_pred_rts.begin(), tmp_pred_rts.end());
pep_iter_start = pep_iter_stop;
count += tmp_count;
tmp_count = 0;
}
LibSVMEncoder::destroyProblem(training_data);
LOG_INFO << "done" << endl;
}
示例13: initParam_
bool TOPPASToolVertex::initParam_(const QString& old_ini_file)
{
Param tmp_param;
// this is the only exception for writing directly to the tmpDir, instead of a subdir of tmpDir, as scene()->getTempDir() might not be available yet
QString ini_file = File::getTempDirectory().toQString() + QDir::separator() + "TOPPAS_" + name_.toQString() + "_";
if (type_ != "")
{
ini_file += type_.toQString() + "_";
}
ini_file += File::getUniqueName().toQString() + "_tmp.ini";
ini_file = QDir::toNativeSeparators(ini_file);
QString program = File::findExecutable(name_).toQString();
QStringList arguments;
arguments << "-write_ini";
arguments << ini_file;
if (type_ != "")
{
arguments << "-type";
arguments << type_.toQString();
}
// allow for update using old parameters
if (old_ini_file != "")
{
if (!File::exists(old_ini_file))
{
String msg = String("Could not open old INI file '") + old_ini_file + "'! File does not exist!";
if (getScene_()->isGUIMode()) QMessageBox::critical(0, "Error", msg.c_str());
else LOG_ERROR << msg << std::endl;
tool_ready_ = false;
return false;
}
arguments << "-ini";
arguments << old_ini_file;
}
// actually request the INI
QProcess p;
p.start(program, arguments);
if (!p.waitForFinished(-1) || p.exitStatus() != 0 || p.exitCode() != 0)
{
String msg = String("Error! Call to '") + program + "' '" + String(arguments.join("' '")) +
" returned with exit code (" + String(p.exitCode()) + "), exit status (" + String(p.exitStatus()) + ")." +
"\noutput:\n" + String(QString(p.readAll())) +
"\n";
if (getScene_()->isGUIMode()) QMessageBox::critical(0, "Error", msg.c_str());
else LOG_ERROR << msg << std::endl;
tool_ready_ = false;
return false;
}
if (!File::exists(ini_file))
{ // it would be weird to get here, since the TOPP tool ran successfully above, so INI file should exist, but nevertheless:
String msg = String("Could not open '") + ini_file + "'! It does not exist!";
if (getScene_()->isGUIMode()) QMessageBox::critical(0, "Error", msg.c_str());
else LOG_ERROR << msg << std::endl;
tool_ready_ = false;
return false;
}
ParamXMLFile paramFile;
paramFile.load(String(ini_file).c_str(), tmp_param);
// remember the parameters of this tool
param_ = tmp_param.copy(name_ + ":1:", true); // get first instance (we never use more -- this is a legacy layer in paramXML)
param_.setValue("no_progress", "true"); // by default, we do not want each tool to report loading/status statistics (would clutter the log window)
// the user is free however, to re-enable it for individual nodes
// write to disk to see if anything has changed
writeParam_(param_, ini_file);
bool changed = false;
if (old_ini_file != "")
{
//check if INI file has changed (quick & dirty by file size)
QFile q_ini(ini_file);
QFile q_old_ini(old_ini_file);
changed = q_ini.size() != q_old_ini.size();
}
QFile::remove(ini_file);
setToolTip(param_.getSectionDescription(name_).toQString());
return changed;
}
示例14: main
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();
}
示例15: generate
bool generate(const ToolListType & tools, const String & prefix, const String & binary_directory)
{
bool errors_occured = false;
for (ToolListType::const_iterator it = tools.begin(); it != tools.end(); ++it)
{
//start process
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
QStringList env = QProcess::systemEnvironment();
env << String("COLUMNS=110").toQString(); // Add an environment variable (used by each TOPP tool to determine width of help text (see TOPPBase))
process.setEnvironment(env);
String command = binary_directory + it->first;
#if defined(__APPLE__)
if (it->first == "TOPPView" || it->first == "TOPPAS")
{
command = binary_directory + it->first + ".app/Contents/MacOS/" + it->first;
}
#endif
#ifdef OPENMS_WINDOWSPLATFORM
command += ".exe"; // otherwise File::exists() will fail
#endif
ofstream f((String("output/") + prefix + it->first + ".cli").c_str());
if (!File::exists(command))
{
stringstream ss;
ss << "Errors occurred while generating the command line documentation for " << it->first << "!" << endl;
ss << "Tool could not be found at '" << command << "'\n " << command << endl;
f << ss.str();
cerr << ss.str();
errors_occured = true;
f.close();
continue;
}
else
{
process.start(String(command + " --help").toQString());
process.waitForFinished();
std::string lines = QString(process.readAll()).toStdString();
if (process.error() != QProcess::UnknownError)
{
// error while generation cli docu
stringstream ss;
f << "Errors occurred while generating the command line documentation for " << it->first << "!" << endl;
f << "Output was: \n" << lines << endl;
f << "Command line was: \n " << command << endl;
f << ss.str();
cerr << ss.str();
errors_occured = true;
f.close();
continue;
}
else
{
// write output
f << lines;
}
}
f.close();
//////
// get the INI file and convert it into HTML
//////
if (it->first == "GenericWrapper")
continue; // does not support -write_ini without a type
if (it->first == "TOPPView")
continue; // does not support -write_ini
if (it->first == "TOPPAS")
continue; // does not support -write_ini
String tmp_file = File::getTempDirectory() + "/" + File::getUniqueName() + "_" + it->first + ".ini";
process.start((command + " -write_ini " + tmp_file).toQString());
process.waitForFinished();
Param p;
ParamXMLFile pf;
pf.load(tmp_file, p);
File::remove(tmp_file);
ofstream f_html((String("output/") + prefix + it->first + ".html").c_str());
convertINI2HTML(p, f_html);
f_html.close();
}
return errors_occured;
}