ProteoWizard
convert2dense.hpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Witold Wolski <wewolski@gmail.com>
6//
7// Copyright : ETH Zurich
8//
9// Licensed under the Apache License, Version 2.0 (the "License");
10// you may not use this file except in compliance with the License.
11// You may obtain a copy of the License at
12//
13// http://www.apache.org/licenses/LICENSE-2.0
14//
15// Unless required by applicable law or agreed to in writing, software
16// distributed under the License is distributed on an "AS IS" BASIS,
17// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18// See the License for the specific language governing permissions and
19// limitations under the License.
20//
21
22#ifndef CONVERT2DENSE_H
23#define CONVERT2DENSE_H
24
25#include <vector>
26#include <iostream>
27#include <numeric>
28#include <boost/assert.hpp>
29#include <boost/cstdint.hpp>
33
34
35namespace ralab
36{
37 namespace base
38 {
39 namespace resample
40 {
41 typedef boost::int32_t int32_t;
43 {
45 std::vector<int32_t> idx_;//small workder vecs
46 std::vector<double> weight_;
47 double am_; //parameter describing the sampling width
48 Convert2Dense(double am = 0.1):bin_(),idx_(),weight_(),am_(){
49 }
50
51 /// computes split points of an map.
52 std::size_t defBreak(std::pair<double, double> & mzrange, double ppm ){
54 ralab::base::resample::breaks( mzrange.first - 1. , mzrange.second + 1. , ppmf , bin_.breaks_ );
55 bin_.reset();
56 return bin_.breaks_.size();
57 }
58
59 /// Converts a sparse spec to a dense spec
60 template<typename Tmass, typename Tintens, typename Tout >
61 void convert2dense(Tmass beginMass, Tmass endMass, Tintens intens,
62 Tout ass
63 )
64 {
65
66 for( ; beginMass != (endMass -1) ; ++beginMass, ++intens ){
67 double mass1 = *beginMass;
68 double mass2 = *(beginMass+1);
69 double predmass2 = mass1 + (am_* sqrt(mass1))*1.01;
70 if(mass2 > predmass2){
71 mass2 = predmass2;
72 }
73
74 double deltamass = mass2-mass1;
75 double deltamasshalf;
76 if(true){
77 deltamasshalf= deltamass/2.;
78 }
79 else{
80 deltamasshalf = deltamass;
81 }
82
83 bin_(mass1-deltamasshalf,mass2-deltamasshalf,idx_,weight_);
84
85 double intensd = static_cast<double>(*intens);
86 double sum = std::accumulate(weight_.begin(),weight_.end(),0.);
87 BOOST_ASSERT(fabs(deltamass- sum) < 1e-11);
88
89 double check = 0.;
90 for(std::size_t i = 0 ; i < idx_.size();++i){
91 if((idx_[i]>=0) &(idx_[i] < static_cast<int32_t>(bin_.breaks_.size() - 1)))
92 {
93 double bb= intensd * weight_[i]/deltamass;
94 *(ass + idx_[i]) += bb;
95 check += bb;
96 }
97 }
98 BOOST_ASSERT( fabs(check - intensd) < 1e-3 );
99 }
100 }//convert2dense
101
102 void getMids(std::vector<double> & mids)
103 {
105 }
106
107 /// Converts a sparse spec to a dense spec
108 template<typename Tmass, typename Tintens >
109 void convert2dense(Tmass beginMass, Tmass endMass, Tintens intens,
110 std::vector<typename std::iterator_traits<Tintens>::value_type > & gg
111 ){
112 gg.resize(bin_.breaks_.size() - 1);
113 convert2dense(beginMass,endMass, intens, gg.begin());
114 }
115 };
116
117
118 }
119 }
120}
121#endif // CONVERT2DENSE_H
TOutputIterator getMids(TInputIterator breaksBeg, TInputIterator breaksEnd, TOutputIterator midsBeg)
Definition breakspec.hpp:79
void breaks(double minMass, double maxMass, TMassComparator tmassComp, std::vector< double > &breaks, bool exact=false)
Segment mass range according to Mass Compare functor could be used to histogram a dataset or to compu...
Definition breakspec.hpp:41
boost::int32_t int32_t
Definition bin1d.hpp:40
EQUISPACEINTERPOL Interpolation on a equidistantly spaced grid.
Definition base.hpp:40
std::vector< double > breaks_
Definition bin1d.hpp:46
ralab::base::resample::Bin1D bin_
std::size_t defBreak(std::pair< double, double > &mzrange, double ppm)
computes split points of an map.
void getMids(std::vector< double > &mids)
void convert2dense(Tmass beginMass, Tmass endMass, Tintens intens, Tout ass)
Converts a sparse spec to a dense spec.
void convert2dense(Tmass beginMass, Tmass endMass, Tintens intens, std::vector< typename std::iterator_traits< Tintens >::value_type > &gg)
Converts a sparse spec to a dense spec.
TODO Do checking on TReal thats a real.