-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMAnalysis.cpp
1696 lines (1516 loc) · 72.8 KB
/
MAnalysis.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
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
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright 2018, Michael R. Hoopmann, Institute for Systems Biology
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 "MAnalysis.h"
using namespace std;
bool* MAnalysis::bKIonsManager;
MDatabase* MAnalysis::db;
MIons* MAnalysis::ions;
double MAnalysis::maxMass;
double MAnalysis::minMass;
Mutex MAnalysis::mutexKIonsManager;
Mutex* MAnalysis::mutexSpecScore;
Mutex** MAnalysis::mutexSingletScore;
mParams MAnalysis::params;
MData* MAnalysis::spec;
bool* MAnalysis::adductSites;
bool** MAnalysis::scanBuffer;
int MAnalysis::numIonSeries;
int* MAnalysis::pepMassSize;
double** MAnalysis::pepMass;
bool** MAnalysis::pepBin;
int* MAnalysis::pepBinSize;
int MAnalysis::skipCount;
int MAnalysis::nonSkipCount;
MDecoys MAnalysis::decoys;
double MAnalysis::dummy[10]{};
int MAnalysis::dummyM[10]{};
int* MAnalysis::maxZ2;
size_t* MAnalysis::bufSize2;
//bool MAnalysis::bEcho;
//int MAnalysis::sCounter;
/*============================
Constructors & Destructors
============================*/
MAnalysis::MAnalysis(mParams& p, MDatabase* d, MData* dat){
unsigned int i;
int j,k;
//bEcho=false;
//Assign pointers and structures
params=p;
db=d;
spec=dat;
adductSites = spec->getAdductSites();
//Do memory allocations and initialization
bKIonsManager=NULL;
ions=NULL;
allocateMemory(params.threads);
for(j=0;j<params.threads;j++){
for(i=0;i<params.fMods.size();i++) ions[j].addFixedMod((char)params.fMods[i].index,params.fMods[i].mass);
for(i=0;i<params.mods.size();i++) ions[j].addMod((char)params.mods[i].index,params.mods[i].xl,params.mods[i].mass);
for(i=0;i<params.aaMass.size();i++) ions[j].setAAMass((char)params.aaMass[i].index, params.aaMass[i].mass);
ions[j].setMaxModCount(params.maxMods);
}
//Initalize variables
maxMass = spec->getMaxMass()+0.25;
minMass = spec->getMinMass()-0.25;
numIonSeries=0;
for(i=0;i<6;i++){
if(params.ionSeries[i]) numIonSeries++;
}
//Create mutexes
Threading::CreateMutex(&mutexKIonsManager);
mutexSingletScore = new Mutex*[spec->size()];
mutexSpecScore = new Mutex[spec->size()];
for(j=0;j<spec->size();j++){
Threading::CreateMutex(&mutexSpecScore[j]);
mutexSingletScore[j] = new Mutex[spec->at(j).sizePrecursor()];
for(k=0;k<spec->at(j).sizePrecursor();k++){
Threading::CreateMutex(&mutexSingletScore[j][k]);
}
}
//xCorrCount=0;
}
MAnalysis::~MAnalysis(){
int i,j;
//Destroy mutexes
Threading::DestroyMutex(mutexKIonsManager);
for(i=0;i<spec->size();i++){
Threading::DestroyMutex(mutexSpecScore[i]);
for(j=0;j<spec->at(i).sizePrecursor();j++){
Threading::DestroyMutex(mutexSingletScore[i][j]);
}
delete [] mutexSingletScore[i];
}
delete [] mutexSingletScore;
delete [] mutexSpecScore;
//Deallocate memory and release pointers
deallocateMemory(params.threads);
db=NULL;
spec=NULL;
adductSites=NULL;
}
//============================
// Public Functions
//============================
bool MAnalysis::doPeptideAnalysis(){
size_t i;
int iPercent;
int iTmp;
vector<mPeptide>* p;
vector<int> index;
vector<mPepMod> mods;
//mScoreCard sc;
ThreadPool<mAnalysisStruct*>* threadPool = new ThreadPool<mAnalysisStruct*>(analyzePeptideProc,params.threads,params.threads,1);
//Set progress meter
iPercent=0;
printf("%2d%%",iPercent);
fflush(stdout);
//Set which list of peptides to search (with and without internal lysine)
p=db->getPeptideList();
//Iterate the peptide for the first pass
for(i=0;i<p->size();i++){
threadPool->WaitForQueuedParams();
mAnalysisStruct* a = new mAnalysisStruct(&mutexKIonsManager,&p->at(i),(int)i);
threadPool->Launch(a);
//Update progress meter
iTmp=(int)((double)i/p->size()*100);
if(iTmp>iPercent){
iPercent=iTmp;
printf("\b\b\b%2d%%",iPercent);
fflush(stdout);
}
}
threadPool->WaitForQueuedParams();
threadPool->WaitForThreads();
//Finalize progress meter
printf("\b\b\b100%%");
cout << endl;
//clean up memory & release pointers
delete threadPool;
threadPool=NULL;
p=NULL;
return true;
}
bool MAnalysis::doEValuePrecalc(){
int i;
int iPercent;
int iTmp;
ThreadPool<MSpectrum*>* threadPool = new ThreadPool<MSpectrum*>(analyzeEValuePrecalcProc, params.threads, params.threads, 1);
//Set progress meter
iPercent = 0;
printf("%2d%%", iPercent);
fflush(stdout);
//Iterate the peptide for the first pass
for (i = 0; i<spec->size(); i++){
threadPool->WaitForQueuedParams();
MSpectrum* a = &spec->at(i);
threadPool->Launch(a);
//Update progress meter
iTmp = (int)((double)i / spec->size() * 100);
if (iTmp>iPercent){
iPercent = iTmp;
printf("\b\b\b%2d%%", iPercent);
fflush(stdout);
}
}
threadPool->WaitForQueuedParams();
threadPool->WaitForThreads();
//Finalize progress meter
printf("\b\b\b100%%");
cout << endl;
//clean up memory & release pointers
delete threadPool;
threadPool = NULL;
return true;
}
//============================
// Private Functions
//============================
//============================
// Thread-Start Functions
//============================
//These functions fire off when a thread starts. They pass the variables to for
//each thread-specific analysis to the appropriate function.
void MAnalysis::analyzePeptideProc(mAnalysisStruct* s){
int i;
Threading::LockMutex(mutexKIonsManager);
for(i=0;i<params.threads;i++){
if(!bKIonsManager[i]){
bKIonsManager[i]=true;
break;
}
}
Threading::UnlockMutex(mutexKIonsManager);
if(i==params.threads){
cout << "Error in KAnalysis::analyzePeptidesProc" << endl;
exit(-1);
}
s->bKIonsMem = &bKIonsManager[i];
analyzePeptide(s->pep,s->pepIndex,i);
delete s;
s=NULL;
}
void MAnalysis::analyzeEValuePrecalcProc(MSpectrum* s){
s->generateXcorrDecoys3(params.minPepLen, db->getMaxPepLen(s->bigMonoMass),params.eValDepth);
s = NULL;
}
//============================
// Analysis Functions
//============================
//Analyzes all single peptides. Also analyzes cross-linked peptides when in full search mode,
//or stage 1 of relaxed mode analysis
bool MAnalysis::analyzePeptide(mPeptide* p, int pepIndex, int iIndex){
vector<int> index;
vector<mPepMod> mods;
//char str[256];
//db->getPeptideSeq(p->map->at(0).index,p->map->at(0).start,p->map->at(0).stop,str);
//if(strcmp(str,"EFNAETFTFHADICTLSEK")==0) cout <<"Peptide: " << pepIndex << "." << endl;
//cout << str << "\t" << p->mass << "\t" << pepIndex << endl;
//Set the peptide, calc the ions, and score it against the spectra
int len = (p->map->at(0).stop - p->map->at(0).start) + 1;
//skip peptide if its smallest possible mass with modifications is more than largest precursor.
if(p->mass>spec->getMaxMass()+1) {
//cout << "Too big. Next" << endl;
return true;
}
ions[iIndex].setPeptide(&db->at(p->map->at(0).index).sequence[p->map->at(0).start],p->map->at(0).stop-p->map->at(0).start+1,p->mass,p->nTerm,p->cTerm);
ions[iIndex].buildModIons2(false); //having this here is bad if there are lots of mods and few spectra
/*if(pepIndex==635){
cout <<"Bions-normal:" << endl;
vector<sNode2>* peaks=ions[iIndex].peaks;
for (size_t a = 0; a < peaks->size(); a++) {
cout << a << " " << peaks->at(a).id << "\t" << peaks->at(a).mass << "\t" << peaks->at(a).next.size() << endl;
for (size_t b = 0; b < peaks->at(a).next.size(); b++) {
cout << " N\t" << b << "\t" << peaks->at(a).next[b].nextIndex << "\t" << peaks->at(a).next[b].nextNode << "\t" << peaks->at(a).next[b].pepNum << endl;
}
for (size_t b = 0; b < peaks->at(a).start.size(); b++) {
cout << " S\t" << b << "\t" << peaks->at(a).start[b].nextIndex << "\t" << peaks->at(a).start[b].nextNode << "\t" << peaks->at(a).start[b].pepNum << endl;
}
}
cout << "Yions-normal:" <<endl;
vector<sNode2>* peaksRev = ions[iIndex].peaksRev;
for (size_t a = 0; a < peaksRev->size(); a++) {
cout << a << " " << peaksRev->at(a).id << "\t" << peaksRev->at(a).mass << "\t" << peaksRev->at(a).next.size() << endl;
for (size_t b = 0; b < peaksRev->at(a).next.size(); b++) {
cout << " N\t" << b << "\tNindex: " << peaksRev->at(a).next[b].nextIndex << "\tNnode: " << peaksRev->at(a).next[b].nextNode << "\tPep: " << peaksRev->at(a).next[b].pepNum << endl;
}
for (size_t b = 0; b < peaksRev->at(a).start.size(); b++) {
cout << " S\t" << b << "\tSindex: " << peaksRev->at(a).start[b].nextIndex << "\tSnode: " << peaksRev->at(a).start[b].nextNode << "\tPep: " << peaksRev->at(a).start[b].pepNum << "\tParentPep: " << peaksRev->at(a).start[b].parentPepNum << endl;
}
}
}*/
//Check peptide without open modifications
double lastMass=0;
for(size_t j=0;j<ions[iIndex].pepCount;j++){
if(ions[iIndex].pepMass[j]<=lastMass) continue; //skip peptide variants already searched
if(spec->getBoundaries2(ions[iIndex].pepMass[j],params.ppmPrecursor,index,scanBuffer[iIndex])){
scoreSpectra2(index, ions[iIndex].pepMass[j], len, pepIndex, iIndex);
}
lastMass= ions[iIndex].pepMass[j];
}
if (p->xlSites == 0) {
//cout << "No sites" << endl;
return true;
}
//Search for open modifications on peptide as well if it has sites where modification can bind
analyzeSinglets(*p, pepIndex, iIndex);
//cout << "Done: " << str << endl;
return true;
//
//ions[iIndex].buildIons();
//ions[iIndex].modIonsRec2(0,-1,0,0,false);
//for(j=0;j<ions[iIndex].size();j++){
// bt= spec->getBoundaries2(ions[iIndex][j].mass, params.ppmPrecursor, index, scanBuffer[iIndex]);
// if(bt) scoreSpectra(index,j,len,ions[iIndex][j].difMass,pepIndex,-1,-1,-1,-1,iIndex);
// }
//if(p->xlSites==0) return true;
////Search for open modifications on peptide as well if it has sites where modification can bind
//analyzeSinglets(*p,pepIndex,iIndex);
//return true;
}
bool MAnalysis::analyzeSinglets(mPeptide& pep, int index, int iIndex){
//get the peptide sequence
//string pepSeq;
//db->getPeptideSeq(pep,pepSeq);
//cout << "analyzeSinglets(): " << pepSeq << endl;
//if(index!=903) return false;
//Build our peptide
int len=(pep.map->at(0).stop-pep.map->at(0).start)+1;
ions[iIndex].setPeptide(&db->at(pep.map->at(0).index).sequence[pep.map->at(0).start], len, pep.mass, pep.nTerm, pep.cTerm);
ions[iIndex].buildModIons2(); //It would be more efficient to do this after spec->getBoundaries below. Must use alternative way to compute min and max peptides.
//cout << "BUILD DONE: " << ions[iIndex].pepCount << endl;
/*if (index == 103) {
cout << "Bions:" << endl;
vector<sNode2>* peaks = ions[iIndex].peaks;
for (size_t a = 0; a < peaks->size(); a++) {
cout << a << " " << peaks->at(a).id << "\t" << peaks->at(a).mass << "\t" << peaks->at(a).next.size() << endl;
for (size_t b = 0; b < peaks->at(a).next.size(); b++) {
cout << " N\t" << b << "\t" << peaks->at(a).next[b].nextIndex << "\t" << peaks->at(a).next[b].nextNode << "\t" << peaks->at(a).next[b].pepNum << endl;
}
for (size_t b = 0; b < peaks->at(a).start.size(); b++) {
cout << " S\t" << b << "\t" << peaks->at(a).start[b].nextIndex << "\t" << peaks->at(a).start[b].nextNode << "\t" << peaks->at(a).start[b].pepNum << endl;
}
}
cout << "Yions:"<<endl;
vector<sNode2>* peaksRev=ions[iIndex].peaksRev;
for (size_t a = 0; a < peaksRev->size(); a++) {
cout << a << " " << peaksRev->at(a).id << "\t" << peaksRev->at(a).mass << "\t" << peaksRev->at(a).next.size() << endl;
for (size_t b = 0; b < peaksRev->at(a).next.size(); b++) {
cout << " N\t" << b << "\tNindex: " << peaksRev->at(a).next[b].nextIndex << "\tNnode: " << peaksRev->at(a).next[b].nextNode << "\tPep: " << peaksRev->at(a).next[b].pepNum << endl;
}
for (size_t b = 0; b < peaksRev->at(a).start.size(); b++) {
cout << " S\t" << b << "\tSindex: " << peaksRev->at(a).start[b].nextIndex << "\tSnode: " << peaksRev->at(a).start[b].nextNode << "\tPep: " << peaksRev->at(a).start[b].pepNum << "\tParentPep: " << peaksRev->at(a).start[b].parentPepNum << endl;
}
}
}*/
/*cout << endl;
for(size_t a=0;a<ions[iIndex].peaks->size();a++){
cout << ions[iIndex].peaks->at(a).mass << "\t" << ions[iIndex].peaks->at(a).next.size() << "\t" << ions[iIndex].peaks->at(a).start.size() << endl;
}*/
//get all spectra that might contain this peptide and adduct
//Set Mass boundaries
double minMass = ions[iIndex].pepMassMin + params.minAdductMass;
double maxMass = ions[iIndex].pepMassMax + params.maxAdductMass;
minMass-=(minMass/1000000*params.ppmPrecursor); //is this necessary because all adduct results end in 0ppm error?
maxMass+=(maxMass/1000000*params.ppmPrecursor);
vector<int> scanIndex;
//cout << "Boundaries" << endl;
if (!spec->getBoundaries(minMass, maxMass, scanIndex, scanBuffer[iIndex])) return true;
//cout << "onward" << endl;
for (size_t j = 0; j<scanIndex.size(); j++){
if(j>0){
for(size_t a=0;a<ions[iIndex].peaks->size();a++) ions[iIndex].peaks->at(a).visit=false; //reset for the next analysis
for (size_t a = 0; a < ions[iIndex].peaksRev->size(); a++) ions[iIndex].peaksRev->at(a).visit = false;
}
scoreSingletSpectra2(scanIndex[j], pep.mass, len, index, minMass, maxMass, iIndex);
}
//cout << "Done Singlets" << endl;
return true;
}
/*============================
Private Functions
============================*/
bool MAnalysis::allocateMemory(int threads){
bKIonsManager = new bool[threads];
ions = new MIons[threads];
scanBuffer = new bool*[threads];
for(int i=0;i<threads;i++) {
bKIonsManager[i]=false;
scanBuffer[i] = new bool[spec->size()];
for(int j=0;j<128;j++){
ions[i].site[j]=adductSites[j];
}
}
maxZ2=new int[threads];
bufSize2=new size_t[threads];
return true;
}
void MAnalysis::deallocateMemory(int threads){
delete [] bKIonsManager;
delete [] ions;
for (int i = 0; i < threads; i++){
delete[] scanBuffer[i];
}
delete[] scanBuffer;
delete[] maxZ2;
delete[] bufSize2;
}
//This function is way out of date. Particularly the mutexes and how to deal with multiple precursors.
//void MAnalysis::scoreSingletSpectra(int index, int sIndex, double mass, int len, int pep, char k, double minMass, double maxMass, int iIndex, bool bSiteless){
// //cout << "scoreSingletSpectra()" << endl;
// mScoreCard sc;
// MIonSet* iset;
// mPepMod mod;
// double score=0;
// int i,j;
// int precI;
// int match;
// int conFrag;
//
// MSpectrum* s=spec->getSpectrum(index);
// mPrecursor* p=NULL;
// MTopPeps* tp;
// int sz=s->sizePrecursor();
// double topScore=0;
// int topMatch=0;
// int topConFrag=0;
//
// int code;
// for(i=0;i<sz;i++){
// p=s->getPrecursor2(i);
// if (p->corr<-4) code = 2;
// else if (p->corr<0)code = 3;
// else if (p->corr == 0)code = 2;
// else code = 1;
// if(code==1) break;
//
// }
// if(i==sz) {
// i=0;
// p = s->getPrecursor2(i);
// }
//
// if((p->monoMass-mass)<params.minAdductMass) score=0; //this could be narrowed down to user-defined precursor tolerance.
// else if((p->monoMass-mass)>params.maxAdductMass) score=0;
// else if(bSiteless) score = magnumScoring(index, 0, sIndex, iIndex, match, conFrag, p->charge); //score peptide without open mod (i.e. scores peptide without localization)
//
// if(score>0){
// topScore = score;
// topMatch = match;
// topConFrag = conFrag;
// precI = i;
// sc.simpleScore = (float)score;
// sc.pep = pep;
// sc.mass = mass;
// sc.massA = p->monoMass - mass;
// sc.precursor = i;
// sc.site = -99;
// sc.mods->clear();
// iset = ions[iIndex].at(sIndex);
// if (iset->difMass != 0){
// for (j = 0; j<ions[iIndex].getIonCount(); j++) {
// if (iset->mods[j] != 0){
// if (j == 0 && iset->modNTerm) mod.term = true;
// else if (j == ions[iIndex].getIonCount() - 1 && iset->modCTerm) mod.term = true;
// else mod.term = false;
// mod.pos = (char)j;
// mod.mass = iset->mods[j];
// sc.mods->push_back(mod);
// }
// }
// }
// }
//
// for(i=0;i<sz;i++){
// p=s->getPrecursor2(i);
// //cout << i << " of " << sz << "\t" << p->monoMass << "\t" << minMass << "\t" << maxMass << "\t" << mass << endl;
// if(p->monoMass<minMass) continue;
// if(p->monoMass>maxMass) continue;
// if ((p->monoMass - mass)>params.maxAdductMass) continue;
// if ((p->monoMass - mass)<params.minAdductMass) continue;
// //cout << "Before magnumScoring" << endl;
// score=magnumScoring(index,p->monoMass-mass,sIndex,iIndex,match,conFrag,p->charge); //open mod with localization
// //cout << score << endl;
// if(score==0) continue;
// else if(score>topScore) { //replace the previous peptide scores, if this version of the peptide scores better.
// topScore=score;
// topMatch=match;
// topConFrag=conFrag;
// precI=i;
// sc.simpleScore = (float)score;
// sc.pep = pep;
// sc.mass = mass;
// sc.massA = p->monoMass - mass;
// sc.precursor = i;
// sc.site = k;
// sc.mods->clear();
// iset = ions[iIndex].at(sIndex);
// if (iset->difMass != 0){
// for (j = 0; j<ions[iIndex].getIonCount(); j++) {
// if (iset->mods[j] != 0){
// if (j == 0 && iset->modNTerm) mod.term = true;
// else if (j == ions[iIndex].getIonCount() - 1 && iset->modCTerm) mod.term = true;
// else mod.term = false;
// mod.pos = (char)j;
// mod.mass = iset->mods[j];
// sc.mods->push_back(mod);
// }
// }
// }
// }
// }
//
// if(topScore>0){
// //cout << "Topper " << topScore << endl;
// double ev = 1000;
// Threading::LockMutex(mutexSpecScore[index]);
// ev = s->computeE(topScore, len);
//
// //** temporary
// //s->tHistogram(topScore, len);
// //**
//
// //cout << "DoneE " << ev << endl;
// Threading::UnlockMutex(mutexSpecScore[index]);
// sc.eVal=ev;
// sc.match=topMatch;
// sc.conFrag=topConFrag;
//
// tp = s->getTopPeps(precI);
// //cout << "GotTopPeps" << endl;
// Threading::LockMutex(mutexSingletScore[index][precI]);
// tp->checkPeptideScore(sc);
// //cout << "CheckPepScore" << endl;
// Threading::UnlockMutex(mutexSingletScore[index][precI]);
//
// Threading::LockMutex(mutexSpecScore[index]);
// s->checkScore(sc,iIndex);
// //cout << "CheckScore" << endl;
// Threading::UnlockMutex(mutexSpecScore[index]);
// }
//
// //** temporary
// //else {
// // Threading::LockMutex(mutexSpecScore[index]);
// // s->tHistogram(0, len);
// // Threading::UnlockMutex(mutexSpecScore[index]);
// //}
// //**
//
//}
void MAnalysis::scoreSingletSpectra2(int index, double mass, int len, int pep, double minMass, double maxMass, int iIndex){
mScoreCard sc;
double score = 0;
int precI;
int match=0;
int conFrag=0;
MSpectrum* s = spec->getSpectrum(index);
mPrecursor* p;
MTopPeps* tp;
int sz = s->sizePrecursor();
double topScore = 0;
int topMatch = 0;
int topConFrag = 0;
//score all peptides against all appropriate precursors
vector<sPrecursor> pre;
maxZ2[iIndex] = 1;
//double maxPre=0;
//double minPre=100000;
//cout << "scoreSingletSpectra2 " << s->getScanNumber() << "\t" << sz << endl;
//bEcho=true; //comment this out
if(sz>MAX_PRECURSOR){
cout << "WARNING: " << s->getScanNumber() << " has too many candidate precursor ions. Analysis limited to " << MAX_PRECURSOR << " precursors." << endl;
}
for(int i=0;i<sz;i++){
p = s->getPrecursor2(i);
if (p->monoMass<minMass) continue;
if (p->monoMass>maxMass) continue;
//if ((p->monoMass - mass)>params.maxAdductMass) continue; //Not sure here, peptides have multiple masses
//if ((p->monoMass - mass)<params.minAdductMass) continue;
sPrecursor pr;
pr.index=i;
pr.monomass=p->monoMass;
pr.maxZ=p->charge-1;
if(pr.maxZ<1) pr.maxZ=1;
if(pr.maxZ>3) pr.maxZ=3;
if (pr.maxZ>maxZ2[iIndex]) maxZ2[iIndex] = pr.maxZ;
//if(pr.monomass>maxPre) maxPre=pr.monomass; //adjust later for ppm error?
//if(pr.monomass<minPre) minPre=pr.monomass;
pre.push_back(pr);
if(pre.size()==MAX_PRECURSOR) break;
}
if(pre.size()==0) {
cout << "WTF" << endl;
exit(1);
}
bufSize2[iIndex] = sizeof(double)*pre.size();
size_t pepCount=ions[iIndex].pepCount;
//cout << "First pepCount: " << pepCount << "\t" << sizeof(double) * pre.size() << "\t" << pre.size() << endl;
//for(size_t a=0;a<pre.size();a++){
// cout << pre[a].monomass << "\t" << pre[a].maxZ << "\t" << pre[a].index << endl;
//}
size_t preCount=pre.size();
sScoreSet* pScores = new sScoreSet[pepCount];
vector<sNode2>* peaks=ions[iIndex].peaks;
//cout << "\n\nBions:" << endl;
for (size_t a = 0; a<peaks->at(0).start.size(); a++){
//sCounter=0;
//score7(s, peaks, &peaks->at(peaks->at(0).start[a].nextNode), &peaks->at(peaks->at(0).start[a].nextNode).next[peaks->at(0).start[a].nextIndex], dummy, dummy, 0, pScores, &pre, iIndex /*,minPre-params.maxAdductMass,maxPre-params.minAdductMass*/);
score8(s, peaks, &peaks->at(peaks->at(0).start[a].nextNode), &peaks->at(peaks->at(0).start[a].nextNode).next[peaks->at(0).start[a].nextIndex], pScores, &pre, iIndex);
//cout << "Final counter: " << sCounter << endl;
//score6(s, &peaks->at(peaks->at(0).start[a].nextNode), &peaks->at(peaks->at(0).start[a].nextNode).next[peaks->at(0).start[a].nextIndex], dummy, dummy, dummyM, dummyM, 0, pScores, &pre, iIndex, maxZ, sizeof(double)*pre.size(), sizeof(int)*pre.size()/*,minPre-params.maxAdductMass,maxPre-params.minAdductMass*/);
}
//diagnostics
/*cout << "PepCount: " << pepCount << endl;
for (size_t a = 0; a < pepCount; a++) {
for (size_t b = 0; b < preCount; b++) {
cout << "Peptide: " << a << " Precursor: " << b << "\tPepMass: " << ions[iIndex].pepMass[a] << "\tpepLinks: " << ions[iIndex].pepLinks[a] << "\tModCount: " << ions[iIndex].pepMods[a].mods.size() << "\tScore: " << pScores[a].scores[b] << endl;
}
}*/
//cout << "\n\nScore7: " << endl;
//delete pScores;
sScoreSet* pScores2 = new sScoreSet[pepCount];
peaks = ions[iIndex].peaksRev;
//cout << "\nYions:" << endl;
//if(pep==103 && s->getScanNumber()==55157) bEcho=true;
//cout << s->getScanNumber() << endl;
//bEcho=true;
//cout << "start: " << peaks->at(0).start.size() << endl;
for (size_t a = 0; a < peaks->at(0).start.size(); a++) {
//sCounter=0;
//score7(s, peaks, &peaks->at(peaks->at(0).start[a].nextNode), &peaks->at(peaks->at(0).start[a].nextNode).next[peaks->at(0).start[a].nextIndex], dummy, dummy, 0, pScores2, &pre, iIndex /*,minPre-params.maxAdductMass,maxPre-params.minAdductMass*/);
score8(s,peaks, &peaks->at(peaks->at(0).start[a].nextNode), &peaks->at(peaks->at(0).start[a].nextNode).next[peaks->at(0).start[a].nextIndex],pScores2,&pre,iIndex);
//cout << "Final counter: " << sCounter << endl;
}
//bEcho=false;
//cout << endl;
//diagnostics
/*cout << "PepCount: " << pepCount << endl;
for(size_t a=0;a<pepCount;a++){
for (size_t b = 0; b < preCount; b++) {
cout << "Peptide: " << a << " Precursor: " << b << "\tPepMass: " << ions[iIndex].pepMass[a] << "\tpepLinks: " << ions[iIndex].pepLinks[a] << "\tModCount: " << ions[iIndex].pepMods[a].mods.size() << "\tScore: " << pScores2[a].scores[b] << "\t" << pScores[a].scores[b]+pScores2[a].scores[b] << endl;
}
}
cout << pre.size() << "\t" << preCount << endl;
for(size_t a=0;a<peaks->size();a++){
cout << a << "\t" << peaks->at(a).visit << "\t" << peaks->at(a).mass;
if(peaks->at(a).mass>0) cout << "[" << peaks->at(a).mass + 1.007276466 << " = " << (int)magnumScoring2(s,peaks->at(a).mass+1.007276466) <<"]";
else cout << "[" << -peaks->at(a).mass + 1.007276466 << " = "<< (int)magnumScoring2(s, -peaks->at(a).mass+1.007276466) << "]";
cout << "\t" << peaks->at(a).score[0] << "," << peaks->at(a).score[1] << "," << peaks->at(a).score[2];
if(peaks->at(a).mass<0) cout << "\t" << pre[0].monomass+ peaks->at(a).mass << "," << peaks->at(a).scoreAlt[0][1] << "," << peaks->at(a).scoreAlt[0][2] << "\t" << pre[1].monomass + peaks->at(a).mass << "," << peaks->at(a).scoreAlt[1][1] << "," << peaks->at(a).scoreAlt[1][2] << endl;
else cout << "\t" << peaks->at(a).scoreAltNL[0] << "," << peaks->at(a).scoreAltNL[1] << "," << peaks->at(a).scoreAltNL[2] << endl;
}
for(size_t c=0;c<pepCount;c++){
cout << "C: " << c << endl;
int tally=0;
for (size_t a = 0; a < peaks->size(); a++) {
for(size_t b=0;b<peaks->at(a).start.size();b++){
sLink2* l=&peaks->at(a).start[b];
if(l->pepNum==c) {
cout << "start " << c << " at " << a << "," << b << "\t" << l->nextNode << "\t" << l->nextIndex << endl;
size_t nn= l->nextNode;
while(true){
double mz= peaks->at(nn).mass+1.007276466;
if(peaks->at(nn).mass<0) mz= -peaks->at(nn).mass + pre[preCount - 1].monomass - ions[iIndex].pepMass[c]+1.007276466;
double mz2= (peaks->at(nn).mass + 1.007276466*2)/2;
if (peaks->at(nn).mass < 0) mz2 = (-peaks->at(nn).mass + pre[preCount - 1].monomass - ions[iIndex].pepMass[c] + 1.007276466*2)/2;
tally+= (int)magnumScoring2(s, mz);
tally += (int)magnumScoring2(s, mz2);
cout << "\t" << nn << "\t" << mz << "\t" << (int)magnumScoring2(s,mz) << "\t" << (int)magnumScoring2(s, mz2) << "\t" << peaks->at(nn).score[2]+peaks->at(nn).scoreAlt[preCount-1][2] << endl;
size_t d;
for(d=0;d<peaks->at(nn).next.size();d++){
if(peaks->at(nn).next[d].pepNum==c) break;
}
if(d== peaks->at(nn).next.size()) break;
nn=peaks->at(nn).next[d].nextNode;
if(nn==SIZE_MAX) {
cout << "\tTally: " << tally << "\t" << (double)tally*0.005 << endl;
break;
}
}
}
}
}
}*/
//Sanity check score diagnostics
//int isize=14;
//double b[14]={ 156.1011115,319.1644395,447.2594025,518.2965165,589.3336305,736.4020445,837.4497225,966.4923155,1126.522965,1286.553613,1414.612191,1485.649305,1556.686419,1671.713362};
//double y[14]={ 1661.717778,1498.65445,1370.559487,1299.522373,1228.485259,1081.416845,980.3691665,851.3265725,691.2959245,531.2652755,403.2066985,332.1695845,261.1324705,146.1055275};
//int isize=18;
//double b[18]={ 103.0091845,206.0183685,334.1133325,463.1559255,562.2243395,709.2927535,780.3298665,851.3669805,998.4353945,1113.462338,1228.489281,1359.529766,1458.59818,1529.635294,1772.562057,1885.646121,2013.704698,2142.747291};
//double y[18]={ 2185.843635,2082.83445,1954.739487,1825.696894,1726.62848,1579.560066,1508.522952,1437.485838,1290.417424,1175.390481,1060.363538,929.3230535,830.2546395,759.2175255,516.2907625,403.2066985,275.1481205,146.1055275 };
/*int isize = 18;
double b[18] = { 129.0425935,276.1110075,390.1539345,461.1910485,590.2336415,691.2813195,838.3497335,939.3974125,1086.465827,1223.524739,1294.561853,1409.588796,1522.67286,1682.703508,1783.751187,1896.835251,1983.867279,2112.909872 };
double y[18] = { 2129.972807,1982.904393,1868.861465,1797.824352,1668.781758,1567.73408,1420.665666,1319.617988,1172.549574,1035.490662,964.4535475,849.4266045,736.3425405,576.3118915,475.2642135,362.1801495,275.1481205,146.1055275 };
float sum=0;
for(int q=0;q<isize;q++){
for(int z=1;z<=1;z++){
double mz=(b[q]+1.007276466*z)/z;
float scor= magnumScoring2(s, mz);
sum+=scor;
cout << "\t" << mz << " " << scor;
}
for (int z = 1; z <= 1; z++) {
double mz = (y[q] + 1.007276466 * z) / z;
float scor = magnumScoring2(s, mz);
sum+=scor;
cout << "\t" << mz << " " << scor;
}
cout << "\t" << sum << endl;
}
cout << "Final: " << sum << "\t" << sum*0.005 << endl;*/
//keep only the best score(s).
vector<sDIndex> vTop;
topScore=0;
size_t minMods=100;
for (size_t a = 0; a<pepCount; a++){
//cout << "Peptide: " << a << "\t" << ions[iIndex].pepMass[a] << "\t" << ions[iIndex].pepLinks[a] << "\t" << ions[iIndex].pepMods[a].mods.size() << "\t" << pScores[a].scores << endl;
double topPreScore=0;
size_t topPreIndex=0;
for (size_t b = 0; b<preCount; b++){
//if(pep==103 && s->getScanNumber()==55157) cout << "Peptide: " << a << "\tmass: " << ions[iIndex].pepMass[a] << "\tmod: " << pre[b].monomass - ions[iIndex].pepMass[a] << "\tsite: " << ions[iIndex].pepLinks[a] << "\tdiffmods: " << ions[iIndex].pepMods[a].mods.size() << "\tTscore: " << (pScores[a].scores[b]+pScores2[a].scores[b])*0.005 << "\tB: " <<pScores[a].scores[b] << "\tY: " << pScores2[a].scores[b] << "\tprecursor:" <<b << endl;
//cout << pScores[a].scored << endl;
/*if (s->getScanNumber()==55157){
if(a==6 && b==0){
float sum=0;
float pb1,pb2,py1,py2;
pb1= magnumScoring2(s, 157.108388); pb2= magnumScoring2(s, 79.057832); py1= magnumScoring2(s, 147.112804); py2 = magnumScoring2(s, 74.060040);
sum+=(pb1+pb2+py1+py2);
cout << 157.108388 << "\t" << pb1 << "\t" << pb2 << "\t" << py1 << "\t" << py2 << "\t" << sum << endl;
pb1 = magnumScoring2(s, 320.171716); pb2 = magnumScoring2(s, 160.589496); py1 = magnumScoring2(s, 262.139747); py2 = magnumScoring2(s, 131.573512);
sum += (pb1 + pb2 + py1 + py2);
cout << 320.171716 << "\t" << pb1 << "\t" << pb2 << "\t" << py1 << "\t" << py2 << "\t" << sum << endl;
pb1 = magnumScoring2(s, 448.266679); pb2 = magnumScoring2(s, 224.636978); py1 = magnumScoring2(s, 333.176861); py2 = magnumScoring2(s, 167.092069);
sum += (pb1 + pb2 + py1 + py2);
cout << 448.266679 << "\t" << pb1 << "\t" << pb2 << "\t" << py1 << "\t" << py2 << "\t" << sum << endl;
pb1 = magnumScoring2(s, 519.303793); pb2 = magnumScoring2(s, 260.155535); py1 = magnumScoring2(s, 404.213975); py2 = magnumScoring2(s, 202.610626);
sum += (pb1 + pb2 + py1 + py2);
cout << 519.303793 << "\t" << pb1 << "\t" << pb2 << "\t" << py1 << "\t" << py2 << "\t" << sum << endl;
pb1 = magnumScoring2(s, 590.340907); pb2 = magnumScoring2(s, 295.674092); py1 = magnumScoring2(s, 532.272552); py2 = magnumScoring2(s, 266.639914);
sum += (pb1 + pb2 + py1 + py2);
cout << 590.340907 << "\t" << pb1 << "\t" << pb2 << "\t" << py1 << "\t" << py2 << "\t" << sum << endl;
pb1 = magnumScoring2(s, 737.409321); pb2 = magnumScoring2(s, 369.208299); py1 = magnumScoring2(s, 692.303201); py2 = magnumScoring2(s, 346.655239);
sum += (pb1 + pb2 + py1 + py2);
cout << 737.409321 << "\t" << pb1 << "\t" << pb2 << "\t" << py1 << "\t" << py2 << "\t" << sum << endl;
pb1 = magnumScoring2(s, 838.456999); pb2 = magnumScoring2(s, 419.732138); py1 = magnumScoring2(s, 852.333849); py2 = magnumScoring2(s, 426.670563);
sum += (pb1 + pb2 + py1 + py2);
cout << 838.456999 << "\t" << pb1 << "\t" << pb2 << "\t" << py1 << "\t" << py2 << "\t" << sum << endl;
pb1 = magnumScoring2(s, 967.499592); pb2 = magnumScoring2(s, 484.253434); py1 = magnumScoring2(s, 981.376443); py2 = magnumScoring2(s, 491.191860);
sum += (pb1 + pb2 + py1 + py2);
cout << 967.499592 << "\t" << pb1 << "\t" << pb2 << "\t" << py1 << "\t" << py2 << "\t" << sum << endl;
pb1 = magnumScoring2(s, 1127.530241); pb2 = magnumScoring2(s, 564.268759); py1 = magnumScoring2(s, 1082.424121); py2 = magnumScoring2(s, 541.715699);
sum += (pb1 + pb2 + py1 + py2);
cout << 1127.530241 << "\t" << pb1 << "\t" << pb2 << "\t" << py1 << "\t" << py2 << "\t" << sum << endl;
pb1 = magnumScoring2(s, 1287.560889); pb2 = magnumScoring2(s, 644.284083); py1 = magnumScoring2(s, 1229.492535); py2 = magnumScoring2(s, 615.249906);
sum += (pb1 + pb2 + py1 + py2);
cout << 1287.560889 << "\t" << pb1 << "\t" << pb2 << "\t" << py1 << "\t" << py2 << "\t" << sum << endl;
pb1 = magnumScoring2(s, 1415.619467); pb2 = magnumScoring2(s, 708.313372); py1 = magnumScoring2(s, 1300.529649); py2 = magnumScoring2(s, 650.768463);
sum += (pb1 + pb2 + py1 + py2);
cout << 1415.619467 << "\t" << pb1 << "\t" << pb2 << "\t" << py1 << "\t" << py2 << "\t" << sum << endl;
pb1 = magnumScoring2(s, 1486.656581); pb2 = magnumScoring2(s, 743.831929); py1 = magnumScoring2(s, 1371.566763); py2 = magnumScoring2(s, 686.287020);
sum += (pb1 + pb2 + py1 + py2);
cout << 1486.656581 << "\t" << pb1 << "\t" << pb2 << "\t" << py1 << "\t" << py2 << "\t" << sum << endl;
pb1 = magnumScoring2(s, 1557.693695); pb2 = magnumScoring2(s, 779.350485); py1 = magnumScoring2(s, 1499.661726); py2 = magnumScoring2(s, 750.334501);
sum += (pb1 + pb2 + py1 + py2);
cout << 1557.693695 << "\t" << pb1 << "\t" << pb2 << "\t" << py1 << "\t" << py2 << "\t" << sum << endl;
pb1 = magnumScoring2(s, 1672.720638); pb2 = magnumScoring2(s, 836.863957); py1 = magnumScoring2(s, 1662.725054); py2 = magnumScoring2(s, 831.866165);
sum += (pb1 + pb2 + py1 + py2);
cout << 1672.720638 << "\t" << pb1 << "\t" << pb2 << "\t" << py1 << "\t" << py2 << "\t" << sum << endl;
cout << sum*0.005 << endl;
}
}*/
double massA = pre[b].monomass - ions[iIndex].pepMass[a];
if(massA<params.minAdductMass || massA>params.maxAdductMass) continue; //skip adducts outside our bounds
if (pScores[a].scores[b]+pScores2[a].scores[b] > topPreScore){
topPreScore=pScores[a].scores[b] + pScores2[a].scores[b];
topPreIndex=b;
}
}
if (topPreScore > topScore){
topScore = pScores[a].scores[topPreIndex]+pScores2[a].scores[topPreIndex];
vTop.clear();
sDIndex di;
di.a=a;
di.b = topPreIndex;
vTop.push_back(di);
minMods = ions[iIndex].pepMods[a].mods.size();
} else if (topPreScore == topScore){
sDIndex di;
di.a = a;
di.b = topPreIndex;
vTop.push_back(di);
if (ions[iIndex].pepMods[a].mods.size()<minMods) minMods = ions[iIndex].pepMods[a].mods.size();
}
}
//TODO: Combine all ambiguous localizations here
if(topScore>0){
for(size_t a=0;a<vTop.size();a++){
double score = (pScores[vTop[a].a].scores[vTop[a].b]+ pScores2[vTop[a].a].scores[vTop[a].b]) *0.005;
if (ions[iIndex].pepMods[vTop[a].a].mods.size()>minMods) continue; //skip modified peptides that are explained with fewer modifications
topScore = score;
//topMatch = pScores[vTop[a].a].match[vTop[a].b];
topConFrag = conFrag;
precI = pre[vTop[a].b].index;
sc.simpleScore = (float)score;
sc.pep = pep;
sc.mass = ions[iIndex].pepMass[vTop[a].a];
sc.massA = pre[vTop[a].b].monomass - ions[iIndex].pepMass[vTop[a].a];
sc.precursor = pre[vTop[a].b].index;
sc.site = ions[iIndex].pepLinks[vTop[a].a];
sc.mods->clear();
for (size_t c = 0; c<ions[iIndex].pepMods[vTop[a].a].mods.size(); c++){
sc.mods->push_back(ions[iIndex].pepMods[vTop[a].a][c]);
}
double ev = 1000;
Threading::LockMutex(mutexSpecScore[index]);
ev = s->computeE(topScore, len);
Threading::UnlockMutex(mutexSpecScore[index]);
sc.eVal = ev;
sc.match = 0;//topMatch;
sc.conFrag = topConFrag;
tp = s->getTopPeps(precI);
Threading::LockMutex(mutexSingletScore[index][precI]);
tp->checkPeptideScore(sc);
Threading::UnlockMutex(mutexSingletScore[index][precI]);
Threading::LockMutex(mutexSpecScore[index]);
s->checkScore(sc, iIndex);
Threading::UnlockMutex(mutexSpecScore[index]);
}
}
delete [] pScores;
delete [] pScores2;
peaks=NULL;
}
//could speed up this function significantly (>5%) by replacing the calls to magnumScoring2 with the code inside magnumScoring2
void MAnalysis::score6(MSpectrum* s, sNode2* node, sLink2* link, double* score, double* scoreNL, int depth, sScoreSet* v, vector<sPrecursor>* pre, int iIndex/*, double minMass, double maxMass*/) {
cout << "Peptide: " << link->pepNum << "\tNode: " << node->id << "\tmass: " << node->mass << "\tsite: " << ions[iIndex].pepLinks[link->pepNum];
if (node->mass > 0) {
if (!node->visit) {
for (int b = 1; b <= maxZ2[iIndex]; b++){
double mz = (node->mass + 1.007276466*b)/b;
node->score[b] = node->score[b - 1] + magnumScoring2(s, mz);//score forward
//cout << "ScoreA: " << mz << " " << b << "\t" << (int)magnumScoring2(s, mz) << "\t" << node->score[b] << endl;
mz = (ions[iIndex].pepMass[link->pepNum] - node->mass + 1.007276466*b)/ b;
node->scoreAltNL[b] = node->scoreAltNL[b - 1] + magnumScoring2(s, mz);//score reverse without link
//cout << "ScoreA-ALtNL: " << mz << " " << b << "\t" << (int)magnumScoring2(s, mz) << "\t" << node->scoreAltNL[b] << endl;
}
cout << "\tScore: " << node->mass + 1.007276466 << "," << node->score[1] << "," << node->score[2];
cout << "\tScoreAltNL: " << ions[iIndex].pepMass[link->pepNum] - node->mass + 1.007276466 << "," << node->scoreAltNL[1] << "," << node->scoreAltNL[2];
} else {
cout << "\tCarryover-Score: " << node->mass + 1.007276466 << "," << node->score[1] << "," << node->score[2];
cout << "\tCarryover-ScoreAltNL: " << ions[iIndex].pepMass[link->pepNum] - node->mass + 1.007276466 << "," << node->scoreAltNL[1] << "," << node->scoreAltNL[2];
}
for (size_t a = 0; a<pre->size(); a++){
link->score[a] = score[a] + node->score[pre->at(a).maxZ];
link->scoreNL[a] = scoreNL[a] + node->score[pre->at(a).maxZ] + node->scoreAltNL[pre->at(a).maxZ];
cout << "\tDepth: " << depth << "," << ions[iIndex].maxLink;
if (depth < ions[iIndex].maxLink) {
if (!node->visit) {
for (int b = 1; b <= maxZ2[iIndex]; b++) {
double mz = (pre->at(a).monomass - node->mass + 1.007276466*b) / b;
node->scoreAlt[a][b] = node->scoreAlt[a][b - 1] + magnumScoring2(s, mz); //score reverse after precursor subtraction
//cout << "Pre: " << a << "\tScoreA-Alt: " << mz << " " << b << "\t" << (int)magnumScoring2(s, mz) << "\t" << node->scoreAlt[a][b] << endl;
}
cout << "\tScoreAlt: " << pre->at(a).monomass - node->mass + 1.007276466 << "," << node->scoreAlt[a][1] << "," << node->scoreAlt[a][2];
} else {
cout << "\tCarryover-Alt: " << pre->at(a).monomass - node->mass + 1.007276466 << "," << node->scoreAlt[a][1] << "," << node->scoreAlt[a][2];
}
link->score[a] += node->scoreAlt[a][pre->at(a).maxZ];
//cout << "Pre: " << a << " scoreA final: " << link->score[a] << endl;
}
}
cout << "\tLinkScore: " << link->score[0] << "," << link->score[1];
cout << "\tLinkScoreNL: " << link->scoreNL[0] << "," << link->scoreNL[1];
} else {
if (!node->visit) {
for (int b = 1; b <= maxZ2[iIndex]; b++) {
double mz = (ions[iIndex].pepMass[link->pepNum] + node->mass + 1.007276466*b) / b;
node->score[b] = node->score[b - 1] + magnumScoring2(s, mz);//score forward
//cout << "ScoreB: " << mz << " " << b << "\t" << (int)magnumScoring2(s, mz) << "\t" << node->score[b] << endl;
}
cout << "\tScore: " << ions[iIndex].pepMass[link->pepNum] + node->mass + 1.007276466 << "," << node->score[1] << "," << node->score[2];
} else {
cout << "\tCarryover-Score: " << ions[iIndex].pepMass[link->pepNum] + node->mass + 1.007276466 << "," << node->score[1] << "," << node->score[2];
}
for (size_t a = 0; a < pre->size(); a++) {
if (!node->visit) {
for (int b = 1; b <= maxZ2[iIndex]; b++) {
double mz = (pre->at(a).monomass - ions[iIndex].pepMass[link->pepNum] - node->mass + 1.007276466*b) / b;
node->scoreAlt[a][b] = node->scoreAlt[a][b - 1] + magnumScoring2(s, mz); //score after precursor subtraction
//cout << "ScoreB-Alt: " << mz << " " << b << "\t" << (int)magnumScoring2(s, mz) << "\t" << node->scoreAlt[a][b] << "\t" << ions[iIndex].pepMass[link->pepNum] << "\t" << link->pepNum << "\t" << pre->at(a).monomass << "\t" << node->mass << endl;
}
cout << "\tScoreAlt: " << pre->at(a).monomass - ions[iIndex].pepMass[link->pepNum] - node->mass + 1.007276466 << "," << node->scoreAlt[a][1] << "," << node->scoreAlt[a][2];
} else {
cout << "\tCarryover-Alt: " << pre->at(a).monomass - ions[iIndex].pepMass[link->pepNum] - node->mass + 1.007276466 << "," << node->scoreAlt[a][1] << "," << node->scoreAlt[a][2];
}
link->score[a] = score[a] + node->scoreAlt[a][pre->at(a).maxZ] + node->score[pre->at(a).maxZ];
link->scoreNL[a] = scoreNL[a] + node->scoreAlt[a][pre->at(a).maxZ];
}
cout << "\tLinkScore: " << link->score[0] << "," << link->score[1];
cout << "\tLinkScoreNL: " << link->scoreNL[0] << "," << link->scoreNL[1];
}
node->visit = true;
cout << endl;
if (link->nextNode == SIZE_MAX) {
//cout << "In memswap" << endl;
if (ions[iIndex].pepLinks[link->pepNum] < 0) {
//cout << ions[iIndex].pepLinks[link->pepNum] << " no localization" << endl;
memcpy(v[link->pepNum].scores, link->scoreNL, bufSize2[iIndex]);
cout << link->pepNum << " scores now " << v[link->pepNum].scores[0] << "," << v[link->pepNum].scores[1] << endl;
//cout << "Copy NL scores for: " << link->pepNum << "\t" << bufSize2[iIndex] << endl;
} else {
memcpy(v[link->pepNum].scores, link->score, bufSize2[iIndex]);
cout << link->pepNum << " scores now " << v[link->pepNum].scores[0] << "," << v[link->pepNum].scores[1] << endl;
}
} else score6(s, &ions[iIndex].peaks->at(link->nextNode), &ions[iIndex].peaks->at(link->nextNode).next[link->nextIndex], link->score, link->scoreNL, depth + 1, v, pre, iIndex/*, minMass, maxMass*/);
for (size_t a = 0; a < node->start.size(); a++) {
//cout << "Iterate from " << link->nextNode << "\t" << a << "\t" << node->start[a].pepNum << "\t" << link->pepNum << "\tScored: " << v[node->start[a].pepNum].scored << endl;
if (v[node->start[a].pepNum].scored) continue; //maybe create a structure and flag instead?
if (node->start[a].pepNum < link->pepNum) continue;