-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMTopPeps.cpp
174 lines (153 loc) · 3.86 KB
/
MTopPeps.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
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
#include "MTopPeps.h"
MTopPeps::MTopPeps(){
peptideCount = 0;
peptideFirst = NULL;
peptideLast = NULL;
peptideMax = 0;
//singletList = NULL;
//singletBins = 0;
}
MTopPeps::MTopPeps(const MTopPeps& c){
peptideCount = c.peptideCount;
peptideMax = c.peptideMax;
peptideFirst = NULL;
peptideLast = NULL;
mScoreCard* sc = NULL;
mScoreCard* tmp = c.peptideFirst;
if (tmp != NULL) {
peptideFirst = new mScoreCard(*tmp);
sc = peptideFirst;
tmp = tmp->next;
while (tmp != NULL){
sc->next = new mScoreCard(*tmp);
sc->next->prev = sc;
sc = sc->next;
tmp = tmp->next;
}
peptideLast = sc;
}
/*
singletBins = c.singletBins;
if (singletBins == 0) singletList = NULL;
else {
singletList = new list<mSingletScoreCard*>*[singletBins];
for (size_t j = 0; j<singletBins; j++){
if (c.singletList[j] == NULL) singletList[j] = NULL;
else {
singletList[j] = new list<mSingletScoreCard*>;
list<mSingletScoreCard*>::iterator it = c.singletList[j]->begin();
while (it != c.singletList[j]->end()){
singletList[j]->emplace_back(*it);
it++;
}
}
}
}
*/
}
MTopPeps::~MTopPeps(){
while (peptideFirst != NULL){
mScoreCard* tmp = peptideFirst;
peptideFirst = peptideFirst->next;
delete tmp;
}
peptideLast = NULL;
}
MTopPeps& MTopPeps::operator=(const MTopPeps& c){
if(this!=&c){
peptideCount = c.peptideCount;
peptideMax = c.peptideMax;
while (peptideFirst != NULL){
mScoreCard* tmp = peptideFirst;
peptideFirst = peptideFirst->next;
delete tmp;
}
peptideLast = NULL;
mScoreCard* sc = NULL;
mScoreCard* tmp = c.peptideFirst;
if (tmp != NULL) {
peptideFirst = new mScoreCard(*tmp);
sc = peptideFirst;
tmp = tmp->next;
while (tmp != NULL){
sc->next = new mScoreCard(*tmp);
sc->next->prev = sc;
sc = sc->next;
tmp = tmp->next;
}
peptideLast = sc;
}
}
return *this;
}
void MTopPeps::checkPeptideScore(mScoreCard& s){
mScoreCard* sc;
mScoreCard* cur;
//If list is empty, add the score card
if (peptideCount == 0){
peptideFirst = new mScoreCard(s);
peptideLast = peptideFirst;
peptideCount++;
return;
}
//check if we can just add to the end
if (s.simpleScore<peptideLast->simpleScore){
//check if we need to store the singlet
if (peptideCount == peptideMax) return;
peptideLast->next = new mScoreCard(s);
peptideLast->next->prev = peptideLast;
peptideLast = peptideLast->next;
peptideCount++;
return;
}
//check if it goes in the front
if (s.simpleScore >= peptideFirst->simpleScore){
peptideFirst->prev = new mScoreCard(s);
peptideFirst->prev->next = peptideFirst;
peptideFirst = peptideFirst->prev;
if (peptideCount<peptideMax) {
peptideCount++;
} else {
cur = peptideLast;
peptideLast = peptideLast->prev;
peptideLast->next = NULL;
delete cur;
}
return;
}
//scan to find insertion point
cur = peptideFirst->next;
int i = 1;
while (s.simpleScore < cur->simpleScore){
i++;
cur = cur->next;
}
sc = new mScoreCard(s);
sc->prev = cur->prev;
sc->next = cur;
cur->prev->next = sc;
cur->prev = sc;
if (sc->prev == NULL) peptideFirst = sc;
if (peptideCount<peptideMax) {
peptideCount++;
} else {
cur = peptideLast;
peptideLast = peptideLast->prev;
peptideLast->next = NULL;
delete cur;
}
}
//void MTopPeps::resetSingletList(double mass){
/*
size_t j;
if (singletList != NULL){
for (j = 0; j<singletBins; j++){
if (singletList[j] != NULL) delete singletList[j];
}
delete[] singletList;
}
singletBins = (int)(mass / 10 + 1);
singletList = new list<mSingletScoreCard*>*[singletBins];
for (j = 0; j<singletBins; j++) singletList[j] = NULL;
*/
//}