-
Notifications
You must be signed in to change notification settings - Fork 3
/
CModelLibrary.cpp
149 lines (117 loc) · 3.84 KB
/
CModelLibrary.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
Copyright 2007-2016, Michael R. Hoopmann, Institute for Systems Biology
Michael J. MacCoss, University of Washington
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "CModelLibrary.h"
using namespace std;
using namespace MSToolkit;
CModelLibrary::CModelLibrary(CAveragine* avg, CMercury8* mer){
averagine=avg;
mercury=mer;
libModel=NULL;
chargeMin=0;
chargeCount=0;
varCount=0;
merCount=0;
}
CModelLibrary::~CModelLibrary(){
averagine=NULL;
mercury=NULL;
if(libModel!=NULL) {
eraseLibrary();
libModel=NULL;
}
}
bool CModelLibrary::buildLibrary(int lowCharge, int highCharge, vector<CHardklorVariant>& pepVariants){
int i,j,k;
unsigned int n;
vector<Peak_T> vMR;
Peak_T p;
float da;
double mass;
char av[64];
if(libModel!=NULL) {
cout << "library memory already in use." << endl;
return false;
}
//Fill in boundaries; Note Nov11_2019: This needs dynamic updating, perhaps drawn from a new parameter.
chargeMin=lowCharge;
chargeCount=highCharge+1;
varCount=(int)pepVariants.size();
if(merCount==0) merCount=1000;
libModel = new mercuryModel**[chargeCount];
for(i=chargeMin;i<chargeCount;i++){
libModel[i] = new mercuryModel*[varCount];
for(j=0;j<varCount;j++){
libModel[i][j] = new mercuryModel[merCount];
libModel[i][j][0].area=0.0f;
libModel[i][j][0].size=0;
libModel[i][j][0].zeroMass=0.0;
libModel[i][j][0].peaks=NULL;
for(k=1;k<merCount;k++){
mass=k*5*i-(1.007276466*i);
averagine->clear();
averagine->calcAveragine(mass,pepVariants[j]);
averagine->getAveragine(&av[0]);
//cout << mass << "\t" << pepVariants[j].sizeAtom() << "\t" << pepVariants[j].sizeEnrich() << "\t" << av << endl;
for(n=0;n<(unsigned int)pepVariants[j].sizeEnrich();n++){
mercury->Enrich(pepVariants[j].atEnrich(n).atomNum,pepVariants[j].atEnrich(n).isotope,pepVariants[j].atEnrich(n).ape);
}
mercury->GoMercury(&av[0],i);
vMR.clear();
da=0.0f;
for(n=0; n<mercury->FixedData.size(); n++) {
if(mercury->FixedData[n].data<1.0) continue;
p.intensity=(float)mercury->FixedData[n].data;
p.mz=mercury->FixedData[n].mass;
da+=p.intensity;
vMR.push_back(p);
}
da/=100.0f;
libModel[i][j][k].area = da;
libModel[i][j][k].size = (int)vMR.size();
libModel[i][j][k].peaks = new Peak_T[vMR.size()];
libModel[i][j][k].zeroMass = mercury->getZeroMass();
for(n=0;n<vMR.size();n++) libModel[i][j][k].peaks[n]=vMR[n];
}
}
}
return true;
}
void CModelLibrary::eraseLibrary(){
int i,j,k;
if(libModel==NULL) return;
for(i=chargeMin;i<chargeCount;i++){
for(j=0;j<varCount;j++){
for(k=0;k<merCount;k++){
delete [] libModel[i][j][k].peaks;
}
delete [] libModel[i][j];
}
delete [] libModel[i];
}
delete [] libModel;
libModel=NULL;
merCount=0;
}
mercuryModel* CModelLibrary::getModel(int charge, int var, double mz){
int intMZ=(int)(mz/5);
//punting this for now. A better solution needs to be made, but will wait until necessary.
if(intMZ>=merCount) {
cout << "Spectrum feature beyond molecule_max_mz. Hard boundary encountered. Please increase molecule_max_mz." << endl;
exit(-47);
}
return &libModel[charge][var][intMZ];
}
void CModelLibrary::setSize(double mz){
merCount=(int)(mz/5)+1;
}