~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to source/TRANSFORMATIONS/FEATUREFINDER/EmgModel.C

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2012-11-12 15:58:12 UTC
  • Revision ID: package-import@ubuntu.com-20121112155812-vr15wtg9b50cuesg
Tags: upstream-1.9.0
ImportĀ upstreamĀ versionĀ 1.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: C++; tab-width: 2; -*-
 
2
// vi: set ts=2:
 
3
//
 
4
// --------------------------------------------------------------------------
 
5
//                   OpenMS Mass Spectrometry Framework
 
6
// --------------------------------------------------------------------------
 
7
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
 
8
//
 
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.
 
13
//
 
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.
 
18
//
 
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
 
22
//
 
23
// --------------------------------------------------------------------------
 
24
// $Maintainer: Clemens Groepl $
 
25
// $Authors: $
 
26
// --------------------------------------------------------------------------
 
27
 
 
28
#include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/EmgModel.h>
 
29
#include <numeric>
 
30
#include <OpenMS/CONCEPT/Constants.h>
 
31
 
 
32
namespace OpenMS
 
33
{
 
34
    EmgModel::EmgModel()
 
35
                : InterpolationModel()
 
36
    {
 
37
      setName(getProductName());
 
38
      
 
39
      defaults_.setValue("bounding_box:min",0.0f,"Lower end of bounding box enclosing the data used to fit the model.", StringList::create("advanced"));
 
40
      defaults_.setValue("bounding_box:max",1.0f,"Upper end of bounding box enclosing the data used to fit the model.", StringList::create("advanced"));
 
41
      defaults_.setValue("statistics:mean",0.0f,"Centroid position of the model.", StringList::create("advanced"));
 
42
      defaults_.setValue("statistics:variance",1.0f,"The variance of the model.", StringList::create("advanced"));
 
43
      defaults_.setValue("emg:height",100000.0f,"Height of the exponentially modified Gaussian.", StringList::create("advanced"));
 
44
      defaults_.setValue("emg:width",5.0f,"Width of the exponentially modified Gaussian.", StringList::create("advanced"));
 
45
      defaults_.setValue("emg:symmetry",5.0f,"Symmetry of the exponentially modified Gaussian.", StringList::create("advanced"));
 
46
      defaults_.setValue("emg:retention",1200.0f,"Retention time of the exponentially modified Gaussian.", StringList::create("advanced"));
 
47
      
 
48
      defaultsToParam_();
 
49
    }
 
50
 
 
51
    EmgModel::EmgModel(const EmgModel& source)
 
52
    : InterpolationModel(source)
 
53
    {
 
54
      setParameters( source.getParameters() );
 
55
      updateMembers_();
 
56
    }
 
57
  
 
58
    EmgModel::~EmgModel()
 
59
    {   
 
60
    }
 
61
  
 
62
    EmgModel& EmgModel::operator = (const EmgModel& source)
 
63
    {
 
64
      if (&source == this) return *this;
 
65
      
 
66
      InterpolationModel::operator = (source);
 
67
      setParameters( source.getParameters() );
 
68
      updateMembers_();
 
69
      
 
70
      return *this;
 
71
    }
 
72
 
 
73
    void EmgModel::setSamples()
 
74
    {
 
75
      LinearInterpolation::container_type& data = interpolation_.getData();
 
76
      data.clear();
 
77
      if (max_==min_) return;
 
78
      data.reserve( UInt ( (max_-min_) / interpolation_step_ + 1 ) );
 
79
      CoordinateType pos = min_;
 
80
  
 
81
      DoubleReal sqrt_2pi = sqrt(2*Constants::PI);
 
82
      DoubleReal term_sq2 = (-2.4055/sqrt(2.0));
 
83
      DoubleReal part1    = (height_*width_/symmetry_);
 
84
      DoubleReal part2    = pow(width_,2)/(2*pow(symmetry_,2));
 
85
      DoubleReal part3    = width_/symmetry_;
 
86
  
 
87
      for ( UInt i = 0; pos< max_; ++i)
 
88
      {
 
89
        pos = min_ + i * interpolation_step_;
 
90
        DoubleReal tmp = pos - retention_;
 
91
        
 
92
        // data.push_back (Simplified EMG)
 
93
        data.push_back((part1*sqrt_2pi*exp(part2-(tmp/symmetry_))/(1+exp(term_sq2*((tmp/width_)-part3)))));
 
94
      }
 
95
  
 
96
      interpolation_.setScale  ( interpolation_step_ );
 
97
      interpolation_.setOffset ( min_ );
 
98
    }
 
99
 
 
100
    void EmgModel::setOffset(CoordinateType offset)
 
101
    {
 
102
      DoubleReal diff = offset - getInterpolation().getOffset();
 
103
      min_ += diff;
 
104
      max_ += diff;
 
105
      statistics_.setMean(statistics_.mean() + diff);
 
106
  
 
107
      InterpolationModel::setOffset(offset);
 
108
  
 
109
      param_.setValue("bounding_box:min", min_);
 
110
      param_.setValue("bounding_box:max", max_);
 
111
      param_.setValue("statistics:mean", statistics_.mean());
 
112
    }
 
113
 
 
114
    EmgModel::CoordinateType EmgModel::getCenter() const
 
115
    {
 
116
      return statistics_.mean();
 
117
    }
 
118
    
 
119
    void EmgModel::updateMembers_()
 
120
    {
 
121
      InterpolationModel::updateMembers_();
 
122
  
 
123
      min_ = param_.getValue("bounding_box:min");
 
124
      max_ = param_.getValue("bounding_box:max");
 
125
      statistics_.setMean( param_.getValue("statistics:mean") );
 
126
      statistics_.setVariance(param_.getValue("statistics:variance"));
 
127
      height_ = param_.getValue("emg:height");
 
128
      width_ = param_.getValue("emg:width");
 
129
      symmetry_ = param_.getValue("emg:symmetry");
 
130
      retention_ = param_.getValue("emg:retention");
 
131
      
 
132
      setSamples();
 
133
    }
 
134
        
 
135
}