1
// -*- mode: C++; tab-width: 2; -*-
4
// --------------------------------------------------------------------------
5
// OpenMS Mass Spectrometry Framework
6
// --------------------------------------------------------------------------
7
// Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Lesser General Public
11
// License as published by the Free Software Foundation; either
12
// version 2.1 of the License, or (at your option) any later version.
14
// This library is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
// Lesser General Public License for more details.
19
// You should have received a copy of the GNU Lesser General Public
20
// License along with this library; if not, write to the Free Software
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
// --------------------------------------------------------------------------
24
// $Maintainer: Sandro Andreotti $
25
// $Authors: Sandro Andreotti $
26
// --------------------------------------------------------------------------
28
#include<OpenMS/CHEMISTRY/SvmTheoreticalSpectrumGeneratorSet.h>
29
#include <OpenMS/FORMAT/TextFile.h>
30
#include <OpenMS/SYSTEM/File.h>
37
// Default constructor
38
SvmTheoreticalSpectrumGeneratorSet::SvmTheoreticalSpectrumGeneratorSet(){}
41
SvmTheoreticalSpectrumGeneratorSet::SvmTheoreticalSpectrumGeneratorSet(const SvmTheoreticalSpectrumGeneratorSet& source):
42
simulators_(source.simulators_)
46
SvmTheoreticalSpectrumGeneratorSet::~SvmTheoreticalSpectrumGeneratorSet()
49
// Assignment operator
50
SvmTheoreticalSpectrumGeneratorSet& SvmTheoreticalSpectrumGeneratorSet::operator =(const SvmTheoreticalSpectrumGeneratorSet& rhs)
54
simulators_=rhs.simulators_;
59
// Generate the MS/MS according to the given probabilistic model
60
void SvmTheoreticalSpectrumGeneratorSet::simulate(RichPeakSpectrum &spectrum, const AASequence &peptide, const gsl_rng *rng, Size precursor_charge)
62
std::map<Size, SvmTheoreticalSpectrumGenerator>::iterator it=simulators_.find(precursor_charge);
63
if(it!=simulators_.end())
65
it->second.simulate(spectrum, peptide, rng, precursor_charge);
69
throw OpenMS::Exception::InvalidValue(__FILE__, __LINE__, __PRETTY_FUNCTION__, "Invalid Precursor charge, no Model available", String(precursor_charge));
73
//Load a trained Svm and Prob. models
74
void SvmTheoreticalSpectrumGeneratorSet::load(String filename)
76
if (! File::readable( filename ) )
77
{ // look in OPENMS_DATA_PATH
78
filename = File::find( filename );
80
TextFile file(filename);
82
Param sim_param = SvmTheoreticalSpectrumGenerator().getDefaults();
83
for(Size line_num=1; line_num<file.size(); ++line_num)
85
String line(file[line_num]);
86
std::vector<String>spl;
88
Int precursor_charge=spl[0].toInt();
90
if(spl.size()!=2 || precursor_charge<1)
92
OpenMS::Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, file[line_num]," Invalid entry in SVM model File");
95
//load the model into the map
96
sim_param.setValue("model_file_name", File::path(filename)+"/"+spl[1]);
97
simulators_[precursor_charge].setParameters(sim_param);
98
simulators_[precursor_charge].load();
102
//Return precursor charges for which a model is contained in the set
103
void SvmTheoreticalSpectrumGeneratorSet::getSupportedCharges(std::set<Size>&charges)
106
std::map<Size, SvmTheoreticalSpectrumGenerator>::const_iterator it;
107
for(it=simulators_.begin(); it!=simulators_.end(); ++it)
109
charges.insert(it->first);
113
//return a modifiable reference to the SVM model with given charge. If charge is not supported throw exception
114
SvmTheoreticalSpectrumGenerator & SvmTheoreticalSpectrumGeneratorSet::getSvmModel(Size prec_charge)
116
std::map<Size, SvmTheoreticalSpectrumGenerator>::iterator it = simulators_.find(prec_charge);
117
if(it==simulators_.end())
119
throw OpenMS::Exception::InvalidValue(__FILE__, __LINE__, __PRETTY_FUNCTION__, "Invalid Precursor charge, no Model available", String(prec_charge));