-
Notifications
You must be signed in to change notification settings - Fork 1
/
CKronik.h
441 lines (380 loc) · 10.2 KB
/
CKronik.h
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
/*
Copyright 2007-2015, Michael R. Hoopmann, 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.
*/
#ifndef _CKRONIK_H
#define _CKRONIK_H
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;
#define FWHMCONST 2.3548200450309493820231386529194
#define SQRTTWO 1.4142135623730950488016887242097
typedef struct sPep{
char charge;
char mods;
float intensity;
double monoMass;
double basePeak;
double xCorr;
} sPep;
typedef struct sScan {
char file;
int scanNum;
float rTime;
vector<sPep> *vPep;
//Constructors & Destructor
sScan(){vPep = new vector<sPep>;}
sScan(const sScan& s){
vPep = new vector<sPep>;
for(unsigned int i=0;i<s.vPep->size();i++) vPep->push_back(s.vPep->at(i));
scanNum = s.scanNum;
file = s.file;
rTime=s.rTime;
}
~sScan(){delete vPep;}
//Copy operator
sScan& operator=(const sScan& s){
if(this!=&s){
delete vPep;
vPep = new vector<sPep>;
for(unsigned int i=0;i<s.vPep->size();i++) vPep->push_back(s.vPep->at(i));
scanNum = s.scanNum;
file = s.file;
rTime=s.rTime;
}
return *this;
}
//Clear
void clear(){
delete vPep;
vPep = new vector<sPep>;
}
static int compareIntRev1(const void *p1, const void *p2){
const sPep d1 = *(sPep *)p1;
const sPep d2 = *(sPep *)p2;
if(d1.intensity>d2.intensity) return -1;
else if(d1.intensity<d2.intensity) return 1;
else return 0;
}
static int compareMonoMass1(const void *p1, const void *p2){
const sPep d1 = *(sPep *)p1;
const sPep d2 = *(sPep *)p2;
if(d1.monoMass<d2.monoMass) return -1;
else if(d1.monoMass>d2.monoMass) return 1;
else return 0;
}
void sortIntRev(){
if(vPep->size()==0) return;
qsort(&vPep->at(0),vPep->size(),sizeof(sPep),compareIntRev1);
}
void sortMonoMass(){
if(vPep->size()==0) return;
qsort(&vPep->at(0),vPep->size(),sizeof(sPep),compareMonoMass1);
}
} sScan;
typedef struct sProfileData {
bool interpolated;
int scanNum;
float intensity;
float rTime;
double monoMass;
double xCorr;
//Constructor
sProfileData(){
interpolated=false;
scanNum=0;
intensity=0.0f;
rTime=0.0f;
monoMass=0.0;
xCorr=0.0;
}
} sProfileData;
typedef struct sPepProfile {
char charge;
char mods;
int lowScan;
int highScan;
int bestScan;
int MS2Events;
size_t datapoints;
float rTime;
float firstRTime;
float lastRTime;
float intensity;
float sumIntensity;
double monoMass;
double basePeak;
double xCorr;
double gaussian[4];
double gaussR2;
//string gene;
//string sequence;
//char* gene;
//char* sequence;
char gene[32];
char sequence[64];
sProfileData* profile;
//Constructors
sPepProfile() {
profile = new sProfileData[1];
sProfileData d;
profile[0]=d;
datapoints=1;
lowScan=0;
highScan=0;
bestScan=0;
MS2Events=0;
charge=0;
rTime=0.0f;
firstRTime=0.0f;
lastRTime=0.0f;
intensity=0.0f;
sumIntensity=0.0f;
monoMass=0.0;
basePeak=0.0;
xCorr=0.0;
gaussian[0]=gaussian[1]=gaussian[2]=gaussian[3]=0.0;
gaussR2=0.0;
mods=0;
//sequence=new char[1];
//gene=new char[1];
sequence[0]='\0';
gene[0]='\0';
}
sPepProfile(const unsigned int i) {
profile = new sProfileData[i];
sProfileData d;
unsigned int j;
for(j=0;j<i;j++) profile[j]=d;
datapoints=i;
lowScan=0;
highScan=0;
bestScan=0;
charge=0;
MS2Events=0;
rTime=0.0f;
firstRTime=0.0f;
lastRTime=0.0f;
intensity=0.0f;
sumIntensity=0.0f;
monoMass=0.0;
basePeak=0.0;
xCorr=0.0;
gaussian[0]=gaussian[1]=gaussian[2]=gaussian[3]=0.0;
gaussR2=0.0;
mods=0;
//sequence=new char[1];
//gene=new char[1];
sequence[0]='\0';
gene[0]='\0';
}
sPepProfile(const sPepProfile& p){
unsigned int i;
profile = new sProfileData[p.datapoints];
for(i=0;i<p.datapoints;i++) profile[i]=p.profile[i];
lowScan = p.lowScan;
highScan = p.highScan;
bestScan = p.bestScan;
charge = p.charge;
MS2Events = p.MS2Events;
datapoints = p.datapoints;
rTime = p.rTime;
firstRTime = p.firstRTime;
lastRTime = p.lastRTime;
intensity = p.intensity;
sumIntensity = p.sumIntensity;
monoMass = p.monoMass;
basePeak = p.basePeak;
xCorr = p.xCorr;
gaussian[0]=p.gaussian[0];
gaussian[1]=p.gaussian[1];
gaussian[2]=p.gaussian[2];
gaussian[3]=p.gaussian[3];
gaussR2=p.gaussR2;
mods=p.mods;
//delete [] sequence;
//sequence = new char[strlen(p.sequence)+1];
strcpy(sequence,p.sequence);
//delete [] gene;
//gene = new char[strlen(p.gene)+1];
strcpy(gene,p.gene);
}
//Destructor
~sPepProfile(){
//delete [] gene;
//delete [] sequence;
delete [] profile;
}
//Copy operator
sPepProfile& operator=(const sPepProfile& p){
if(this!=&p){
unsigned int i;
delete [] profile;
profile = new sProfileData[p.datapoints];
for(i=0;i<p.datapoints;i++) profile[i]=p.profile[i];
lowScan = p.lowScan;
highScan = p.highScan;
bestScan = p.bestScan;
MS2Events = p.MS2Events;
charge = p.charge;
datapoints = p.datapoints;
rTime = p.rTime;
firstRTime = p.firstRTime;
lastRTime = p.lastRTime;
intensity = p.intensity;
sumIntensity = p.sumIntensity;
monoMass = p.monoMass;
basePeak = p.basePeak;
xCorr = p.xCorr;
gaussian[0]=p.gaussian[0];
gaussian[1]=p.gaussian[1];
gaussian[2]=p.gaussian[2];
gaussian[3]=p.gaussian[3];
gaussR2=p.gaussR2;
mods=p.mods;
//delete [] sequence;
//sequence = new char[strlen(p.sequence)+1];
strcpy(sequence,p.sequence);
//delete [] gene;
//gene = new char[strlen(p.gene)+1];
strcpy(gene,p.gene);
}
return *this;
}
void setPoints(const size_t& i){
delete [] profile;
profile = new sProfileData[i];
datapoints=i;
sProfileData d;
for(unsigned int j=0;j<i;j++) profile[j]=d;
}
static int compareMonoMass2(const void *p1, const void *p2){
const sProfileData d1 = *(sProfileData *)p1;
const sProfileData d2 = *(sProfileData *)p2;
if(d1.monoMass<d2.monoMass) return -1;
else if(d1.monoMass>d2.monoMass) return 1;
else return 0;
}
static int compareScanNum2(const void *p1, const void *p2){
const sProfileData d1 = *(sProfileData *)p1;
const sProfileData d2 = *(sProfileData *)p2;
if(d1.scanNum<d2.scanNum) return -1;
else if(d1.scanNum>d2.scanNum) return 1;
else return 0;
}
static int compareIntRev2(const void *p1, const void *p2){
const sProfileData d1 = *(sProfileData *)p1;
const sProfileData d2 = *(sProfileData *)p2;
if(d1.intensity>d2.intensity) return -1;
else if(d1.intensity<d2.intensity) return 1;
else return 0;
}
void sortIntRev(){
if(datapoints==0) return;
qsort(profile,datapoints,sizeof(sProfileData),compareIntRev2);
}
void sortMonoMass(){
if(datapoints==0) return;
qsort(profile,datapoints,sizeof(sProfileData),compareMonoMass2);
}
void sortScanNum(){
if(datapoints==0) return;
qsort(profile,datapoints,sizeof(sProfileData),compareScanNum2);
}
} sPepProfile;
typedef struct iTwo{
int scan;
int pep;
} iTwo;
typedef struct intenIndex{
float intensity;
int scan;
int pep;
} intenIndex;
class CKronik {
public:
//Constructors and destructors
CKronik();
CKronik(const CKronik& c);
~CKronik();
//Operator overrides
CKronik& operator=(const CKronik& c);
sPepProfile& operator[ ](const unsigned int& i);
//Statistics and math functions
bool pearson(int i1, int i2, bool byScan, bool interpolate, double& rval, double& pval, double& slope, double& intercept, float& sum1, float& sum2);
double polynomialBestFit(sProfileData* profile, size_t sz, float max, double* coeff, int degree=2);
//Parameter accessors and modifiers
void setGaussFit(bool b);
void setPPMTol(double d);
void setMatchTol(int i);
void setGapTol(int i);
//Automation
int getPercent();
bool loadHK(const char* in);
bool processHK(const char* in, const char* out="\0");
//Tools
bool getRT(int scanNum, float& rt);
//Filters
void filterRT(float rt1, float rt2);
void removeContaminants(float rt);
void removeMass(double m1, double m2);
//Data manipulation functions
sPepProfile& at(unsigned int i);
void add(sPepProfile& p);
void clear();
void clearHK();
void erase(unsigned int i);
size_t size();
//Sorting functions
void sortBasePeak();
void sortBestScan();
void sortMonoMass();
void sortFirstRTime();
void sortIntensityRev();
void sortRTime();
void sortSumIntensityRev();
//Unsorted
vector<string> vFile;
vector<string> vMods;
protected:
private:
int binarySearch(vector<sScan>& v, int index, double mass, int charge);
bool findMax(vector<sScan>& v, int& s, int& p);
double interpolate(int x1, int x2, double y1, double y2, int x);
//Statistics functions
double betai(double a, double b, double x);
double betacf(double a, double b, double x);
double gammaln(double xx);
//Data Members: data analysis
vector<sPepProfile> vPeps;
vector<sScan> hkData;
//Data Members: parameters
bool bGaussFit; //default false
double dPPMTol; //default 10.0
int iGapTol; //default 1
int iMatchTol; //Default 3
int iPercent;
//Sorting Functions
void sortPeptide();
static int compareBP3(const void *p1, const void *p2);
static int compareBS3(const void *p1, const void *p2);
static int compareMM3(const void *p1, const void *p2);
static int compareRT3(const void *p1, const void *p2);
static int compareFRT3(const void *p1, const void *p2);
static int compareIntRev3(const void *p1, const void *p2);
static int compareIRev3(const void *p1, const void *p2);
static int compareSumIRev3(const void *p1, const void *p2);
};
#endif