//Load a trained Svm and Prob. models
void SvmTheoreticalSpectrumGeneratorSet::load(String filename)
{
    if (!File::readable(filename)) // look in OPENMS_DATA_PATH
    {
        filename = File::find(filename);
    }

    Param sim_param = SvmTheoreticalSpectrumGenerator().getDefaults();

    TextFile file(filename);
    TextFile::ConstIterator it = file.begin();

    if (it == file.end()) return; // no data to load

    // skip header line
    ++it;
    // process content
    for (; it != file.end(); ++it)
    {
        std::vector<String> spl;
        it->split(":", spl);
        Int precursor_charge = spl[0].toInt();

        if (spl.size() != 2 || precursor_charge < 1)
        {
            throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, *it, " Invalid entry in SVM model File");
        }

        //load the model into the map
        sim_param.setValue("model_file_name", File::path(filename) + "/" + spl[1]);
        simulators_[precursor_charge].setParameters(sim_param);
        simulators_[precursor_charge].load();
    }
}
예제 #2
0
  ExitCodes main_(int, const char**)
  {

    //-------------------------------------------------------------
    // parameter handling
    //-------------------------------------------------------------

    String in = getStringOption_("in");
    String out = getStringOption_("out");
    String in_calib = getStringOption_("ext_calibrants");
    String ref = getStringOption_("ref_masses");
    String conv = getStringOption_("tof_const");
    //-------------------------------------------------------------
    // init TOFCalibration
    //-------------------------------------------------------------

    TOFCalibration calib;
    calib.setLogType(log_type_);
    Param param = getParam_().copy("algorithm:", true);
    calib.setParameters(param);
    //-------------------------------------------------------------
    // loading input
    //-------------------------------------------------------------
    MSExperiment<Peak1D> ms_exp_calib, ms_exp_raw;
    MzMLFile mz_data_file;
    mz_data_file.setLogType(log_type_);
    mz_data_file.load(in_calib, ms_exp_calib);
    mz_data_file.load(in, ms_exp_raw);

    vector<double> ref_masses;
    TextFile ref_file;
    ref_file.load(ref, true);

    for (TextFile::ConstIterator iter = ref_file.begin(); iter != ref_file.end(); ++iter)
    {
      ref_masses.push_back(String(iter->c_str()).toDouble());
    }
    TextFile const_file;
    const_file.load(conv, true);
    std::vector<String> vec;
    TextFile::ConstIterator iter = const_file.begin();
    iter->split('\t', vec);

    std::vector<double> ml1, ml2, ml3;
    ml1.push_back(String(vec[0].c_str()).toDouble());
    ml2.push_back(String(vec[1].c_str()).toDouble());
    if (vec.size() == 3)
    {
      ml3.push_back(String(vec[2].c_str()).toDouble());
    }
    ++iter;

    for (; iter != const_file.end(); ++iter)
    {
      iter->split('\t', vec);
      ml1.push_back(String(vec[0].c_str()).toDouble());
      ml2.push_back(String(vec[1].c_str()).toDouble());
      if (vec.size() == 3)
      {
        ml3.push_back(String(vec[2].c_str()).toDouble());
      }
    }

    if (ml1.size() != 1 &&  ml1.size() != ms_exp_calib.size())
    {
      writeLog_("Incorrect number of calibration constants given. Aborting!");
      return INPUT_FILE_CORRUPT;
    }
    calib.setML1s(ml1);
    calib.setML2s(ml2);
    if (!ml3.empty()) calib.setML3s(ml3);

    //-------------------------------------------------------------
    // perform calibration
    //-------------------------------------------------------------
    if (getFlag_("peak_data"))
    {
      calib.calibrate(ms_exp_calib, ms_exp_raw, ref_masses);
    }
    else
    {
      calib.pickAndCalibrate(ms_exp_calib, ms_exp_raw, ref_masses);
    }

    //-------------------------------------------------------------
    // writing output
    //-------------------------------------------------------------

    //annotate output with data processing info
    addDataProcessing_(ms_exp_raw, getProcessingInfo_(DataProcessing::CALIBRATION));

    mz_data_file.store(out, ms_exp_raw);

    return EXECUTION_OK;
  }