Beispiel #1
0
bool IDEvaluationBase::addSearchFile(const String& file_name)
{
    MSSpectrum<> points;
    if (!loadCurve(file_name, points)) return false;

    data_.addSpectrum(points);

    MSExperiment<>* exp = new MSExperiment<>();
    exp->addSpectrum(points);
    spec_1d_->canvas()->addLayer(SpectrumCanvas::ExperimentSharedPtrType(exp));
    spec_1d_->canvas()->setLayerName(spec_1d_->canvas()->getLayerCount() - 1, points.getMetaValue("search_engine"));
    // set intensity mode (after spectrum has been added!)
    setIntensityMode((int) SpectrumCanvas::IM_SNAP);

    return true;
}
Beispiel #2
0
  ExitCodes main_(int, const char**)
  {
    //----------------------------------------------------------------
    // load data
    //----------------------------------------------------------------
    StringList in_list = getStringList_("in");
    String out = getStringOption_("out");
    String out_csv = getStringOption_("out_csv");
    String format = getStringOption_("out_type");

    if (out.empty() && out_csv.empty())
    {
      LOG_ERROR << "Neither 'out' nor 'out_csv' were provided. Please assign at least one of them." << std::endl;
      return ILLEGAL_PARAMETERS;
    }

    if (!out.empty() && format == "") // get from filename
    {
      try
      {
        format = out.suffix('.');
      }
      catch (Exception::ElementNotFound& /*e*/)
      {
        format = "nosuffix";
      }
      // check if format is valid:
      if (!ListUtils::contains(out_formats_, format.toLower()))
      {
        LOG_ERROR << "No explicit image output format was provided via 'out_type', and the suffix ('" << format << "') does not resemble a valid type. Please fix one of them." << std::endl;
        return ILLEGAL_PARAMETERS;
      }
    }

    double q_min = getDoubleOption_("q_min");
    double q_max = getDoubleOption_("q_max");
    if (q_min >= q_max)
    {
      LOG_ERROR << "The parameter 'q_min' must be smaller than 'q_max'. Quitting..." << std::endl;
      return ILLEGAL_PARAMETERS;
    }


    IDEvaluationBase* mw = new IDEvaluationBase();
    Param alg_param = mw->getParameters();
    alg_param.insert("", getParam_().copy("algorithm:", true));
    mw->setParameters(alg_param);

    if (!mw->loadFiles(in_list))
    {
      LOG_ERROR << "Tool failed. See above." << std::endl;
      return INCOMPATIBLE_INPUT_DATA;
    }
    mw->setVisibleArea(q_min, q_max);

    if (!out.empty()) // save as image and exit
    {
      String error;
      bool r = mw->exportAsImage(out.toQString(), error, format.toQString());
      if (r) return EXECUTION_OK;
      else
      {
        LOG_ERROR << error << std::endl;
        return ILLEGAL_PARAMETERS;
      }
    }

    if (!out_csv.empty())
    {
      TextFile tf;
      for (Size i = 0; i < mw->getPoints().size(); ++i)
      {
        MSSpectrum s = mw->getPoints()[i];
        StringList sl1;
        StringList sl2;
        for (Size j = 0; j < s.size(); ++j)
        {
          sl1.push_back(s[j].getMZ());
          sl2.push_back(s[j].getIntensity());
        }
        tf.addLine(String("# ") + String(s.getMetaValue("search_engine")));
        tf.addLine(ListUtils::concatenate(sl1, ","));
        tf.addLine(ListUtils::concatenate(sl2, ","));
      }
      tf.store(out_csv);
    }

    delete(mw);
    return EXECUTION_OK;
  }
  tmp.getInstrumentSettings().getScanWindows().resize(1);
  tmp.setMetaValue("label",5.0);
  tmp.setMSLevel(17);
  tmp.setRT(7.0);
  tmp.setDriftTime(8.0);
  tmp.setName("bla");
  //peaks
  MSSpectrum::PeakType peak;
  peak.getPosition()[0] = 47.11;
  tmp.push_back(peak);

  //normal assignment
  MSSpectrum tmp2;
  tmp2 = tmp;
  TEST_EQUAL(tmp2.getInstrumentSettings().getScanWindows().size(),1);
  TEST_REAL_SIMILAR(tmp2.getMetaValue("label"), 5.0)
  TEST_EQUAL(tmp2.getMSLevel(), 17)
  TEST_REAL_SIMILAR(tmp2.getRT(), 7.0)
  TEST_REAL_SIMILAR(tmp2.getDriftTime(), 8.0)
  TEST_EQUAL(tmp2.getName(),"bla")
  TEST_EQUAL(tmp2.size(),1);
  TEST_REAL_SIMILAR(tmp2[0].getPosition()[0],47.11);

  //Assignment of empty object
  //normal assignment
  tmp2 = MSSpectrum();
  TEST_EQUAL(tmp2.getInstrumentSettings().getScanWindows().size(),0);
  TEST_EQUAL(tmp2.metaValueExists("label"), false)
  TEST_EQUAL(tmp2.getMSLevel(),1)
  TEST_REAL_SIMILAR(tmp2.getRT(), -1.0)
  TEST_REAL_SIMILAR(tmp2.getDriftTime(), -1.0)