-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspectra.cpp
More file actions
58 lines (53 loc) · 1.41 KB
/
spectra.cpp
File metadata and controls
58 lines (53 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <math.h>
#include <iostream>
#include <vector>
#include "spectra.h"
using namespace std;
bool comp_inten(const peak & p1, const peak & p2)
{
return p1.intensity > p2.intensity;
}
void spectra::append_peak(peak new_ion)
{
ions.push_back(new_ion);
return;
}
void spectra::select_peaks()
{
//cout << "\t\t in select_peaks. before select: " << this->ions.size();
// cout << "\t\t precursor_mz : " << this->precursor_mz;
int k = this->precursor_mz / 50;
sort(this->ions.begin(), this->ions.end(), comp_inten);
// cout << "\t\t in select_peaks. after sort: " << this->ions.size();
// sort(data_rho.begin(), data_rho.end(), comp_rho);
/*
int num_erase = this->ions.size() - k;
for (int i = 0; i < num_erase; ++i)
{
this->ions.pop_back();
}
*/
if (k < this->ions.size())
{
this->ions.resize(k);
}
// this->ions.erase(this->ions.end() - num_erase, this->ions.end());
//cout << "\t\t in select_peaks. after select: " << this->ions.size();
return;
}
void spectra::normalize_spectra()
{
/* make the sum of intensity to 1000 */
double sum_inten = 0.0;
for (int i = 0; i < this->ions.size(); ++i)
{
sum_inten += (this->ions[i].intensity);
}
double scale_magnin = 1000.0 / sum_inten;
for (int i = 0; i < this->ions.size(); ++i)
{
this->ions[i].intensity *= scale_magnin;
this->ions[i].intensity = 1 + log(this->ions[i].intensity);
}
return;
}