/
BiSpectrum.aspx.cs
1480 lines (1343 loc) · 57.5 KB
/
BiSpectrum.aspx.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Drawing;
using System.Collections;
using System.Drawing.Drawing2D;
using ZJU.COPLib;
using System.Web.Configuration;
using System.Text.RegularExpressions;
using ZJU.COPDB;
using System.Data;
public partial class BiSpectrum : System.Web.UI.Page
{
struct MZintensitiy
{
public float mz;
public float intensity;
}
Color PreforColor = System.Drawing.Color.DarkGray ;
Color NoiseModeColor = System.Drawing.Color.White;
ArrayList SpectrumData, GuestSpectrumData;
float MaxIntensitiy = 0.0F;
float GuestMaxIntensitiy = 0.0F;
float MinX = 20000.0F;
float MaxX = 0.0F;
float GuestMinX = 20000.0F;
float GuestMaxX = 0.0F;
int DisplayMinX = 0;
int DisplayMaxX = 10000;
int DisplayMaxY = 100;
int HEIGHT = 510;
int WIDTH = 720;
int WHITEMARGIN = 14;
int NETAREALEFTMARGIN = 50;
int NETAREABOTTOMMARGIN = 32;
int NETAREATOPMARGIN = 24;
int XBIGSEG = 100;
int YBIGSEG = 25;
int XAxisScaleLength = 6;
bool bZoomOut = false;
bool bShowTheory = false;
bool bShowNoise = false;
bool bShowLabel = true;
string PeptideSequence = "";
string AdditionalSequence = "";
string ChargeState = "";
string SearchType = "DTA";
float PrecursorMZ = 0.0F;
float mzTolerance = 2.0F;
string GuestSpectrums = "";
string SessionID;
string TaskID;
protected void Page_Load(object sender, EventArgs e)
{
SpectrumData = new ArrayList();
GuestSpectrumData = new ArrayList();
SessionID = Request.QueryString["SessionID"];
TaskID = Request.QueryString["TaskID"];
if (Request.QueryString["file"] != null)
{
string file_path = Request.QueryString["file"];
if (Request.QueryString["mode"] != null)
{
if (Request.QueryString["mode"] == "ZoomOut")
{
//get the param how to show the spectrum
string displayMin = Request.QueryString["xmin"];
string displayMax = Request.QueryString["xmax"];
string displayYMax = Request.QueryString["ymax"];
try
{
if (displayMin == null)
DisplayMinX = -1;
else
{
DisplayMinX = int.Parse(displayMin);
if (DisplayMinX < 0)
DisplayMinX = -1;
}
if (displayMax == null)
DisplayMaxX = -1;
else
{
DisplayMaxX = int.Parse(displayMax);
if (DisplayMaxX < 0 || DisplayMaxX <= DisplayMinX)
DisplayMaxX = -1;
}
}
catch
{
DisplayMaxX = -1;
DisplayMinX = -1;
}
//use the params to decide the seg distance will show on the axial
if (DisplayMaxX != -1 && DisplayMinX != -1)
{
int Length = DisplayMaxX - DisplayMinX;
if (Length > 1000)
XBIGSEG = 100;
else if (Length > 500)
XBIGSEG = 50;
else if (Length > 200)
XBIGSEG = 25;
else if (Length > 100)
XBIGSEG = 15;
else if (Length > 50)
XBIGSEG = 10;
else if (Length > 20)
XBIGSEG = 5;
else if (Length > 10)
XBIGSEG = 2;
else
XBIGSEG = 1;
}
try
{
if (displayYMax == null)
DisplayMaxY = 100;
else
{
DisplayMaxY = int.Parse(displayYMax);
if (DisplayMaxY < 75 && DisplayMaxY > 30)
{
YBIGSEG = 10;
}
else if (DisplayMaxY <= 30 && DisplayMaxY > 20)
{
YBIGSEG = 5;
}
else if (DisplayMaxY >= 0 && DisplayMaxY <= 20)
{
YBIGSEG = 2;
}
else if (DisplayMaxY <= 100 && DisplayMaxY >= 75)
{
YBIGSEG = 25;
}
else
{
DisplayMaxY = 100;
YBIGSEG = 25;
}
}
}
catch (Exception ex)
{
DisplayMaxY = 100; ;
}
bZoomOut = true;
}
else
{
bZoomOut = false;
}
}
if (Request.QueryString["Printable"] != null)
{
if (Request.QueryString["Printable"] == "True")
WIDTH = 580;
else
WIDTH = 800;
}
if (Request.QueryString["ShowTheory"] != null)
{
if (Request.QueryString["ShowTheory"] == "True")
{
bShowTheory = true;
}
else
bShowTheory = false;
}
if (Request.QueryString["Noise"] != null)
{
if (Request.QueryString["Noise"] == "True")
bShowNoise = true;
else
bShowNoise = false;
}
if (Request.QueryString["Label"] != null)
{
if (Request.QueryString["Label"] == "True")
bShowLabel = true;
else
bShowLabel = false;
}
AdditionalSequence = Request.QueryString["SEQ"];
ChargeState = Request.QueryString["CS"];
SearchType = Request.QueryString["ST"];
PrecursorMZ = float.Parse(Request.QueryString["pmz"]);
mzTolerance = float.Parse(WebConfigurationManager.ConnectionStrings["mzTolerance"].ConnectionString);
// get the library spectrum data
if (true)//File.Exists(file_path))
{
//multiuser-fridendly streamreader
//FileInfo fiLibSpectra = new FileInfo(file_path);
//if (!fiLibSpectra.Exists)
// return;
//FileStream fs = File.Open(file_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
//StreamReader sr = new StreamReader(fs);
string lines = "";
String strSQL = string.Format("select spectrum,ptm_sequence from spectrum_tbl where spectrum_seq={0}", file_path);
DataSet result = DBInterface.QuerySQL2(strSQL);
if (result != null)
{
if (result.Tables[0].Rows.Count > 0)
{
lines = result.Tables[0].Rows[0].ItemArray[0].ToString();
PeptideSequence = result.Tables[0].Rows[0].ItemArray[1].ToString();
}
}
String[] dtaLines = lines.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
if (bZoomOut && DisplayMaxX != -1 && DisplayMinX != -1)
{
MinX = DisplayMinX;
MaxX = DisplayMaxX;
}
foreach (String line in dtaLines)
{
if (char.IsDigit(line, 0))
{
string[] tokens = line.Split (new string[]{" ","\t"},StringSplitOptions.RemoveEmptyEntries );
string mz = tokens[0];
string intensity = tokens [1];
MZintensitiy mzi = new MZintensitiy();
try
{
mzi.mz = float.Parse(mz);
if (bZoomOut && DisplayMaxX != -1 && DisplayMinX != -1)
{
if (mzi.mz < DisplayMaxX && mzi.mz > DisplayMinX)
{
//if (mzi.mz < MinX)
// MinX = mzi.mz;
//if (mzi.mz > MaxX)
// MaxX = mzi.mz;
mzi.intensity = float.Parse(intensity);
if (mzi.intensity > MaxIntensitiy)
MaxIntensitiy = mzi.intensity;
SpectrumData.Add(mzi);
}
}
else
{
if (mzi.mz < MinX)
MinX = mzi.mz;
if (mzi.mz > MaxX)
MaxX = mzi.mz;
mzi.intensity = float.Parse(intensity);
if (mzi.intensity > MaxIntensitiy)
MaxIntensitiy = mzi.intensity;
SpectrumData.Add(mzi);
}
}
catch
{ }
}
}
//sr.Close();
if (SearchType == "DTA")
{
////get the guest spectrum data
//if (GuestSpectrums == "")
// GuestSpectrums = (string)(Session[SessionID]);
//string[] lines = GuestSpectrums.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
//foreach (string pair in lines)
//{
// if (char.IsDigit(pair, 0))
// {
// int sperator = pair.IndexOf(" ");
// string mz = pair.Substring(0, sperator);
// string intensity = pair.Substring(sperator);
// MZintensitiy mzi = new MZintensitiy();
// try
// {
// mzi.mz = float.Parse(mz);
// if (bZoomOut && DisplayMaxX != -1 && DisplayMinX != -1)
// {
// // if mz in the zoom view
// if (mzi.mz < DisplayMaxX && mzi.mz > DisplayMinX)
// {
// if (mzi.mz < GuestMinX)
// GuestMinX = mzi.mz;
// if (mzi.mz > GuestMaxX)
// GuestMaxX = mzi.mz;
// mzi.intensity = float.Parse(intensity);
// if (mzi.intensity > GuestMaxIntensitiy)
// GuestMaxIntensitiy = mzi.intensity;
// GuestSpectrumData.Add(mzi);
// }
// }
// else
// {
// if (mzi.mz < GuestMinX)
// GuestMinX = mzi.mz;
// if (mzi.mz > GuestMaxX)
// GuestMaxX = mzi.mz;
// mzi.intensity = float.Parse(intensity);
// if (mzi.intensity > GuestMaxIntensitiy)
// GuestMaxIntensitiy = mzi.intensity;
// GuestSpectrumData.Add(mzi);
// }
// }
// catch (Exception ex)
// { }
// }
//}
}
else
{
string msFile = Request.QueryString["MSFile"];
string dtaFilePath = WebConfigurationManager.ConnectionStrings["UploadPath"].ConnectionString + TaskID + string.Format ("\\{0}_dta\\",msFile ) + SessionID + ".dta";
FileInfo fiDta = new FileInfo(dtaFilePath);
if (!fiDta.Exists)
return;
// get from the generated dta file
FileStream gfs = File.Open(dtaFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite );
StreamReader gsr = new StreamReader(gfs);
if (bZoomOut && DisplayMaxX != -1 && DisplayMinX != -1)
{
GuestMinX = DisplayMinX;
GuestMaxX = DisplayMaxX;
}
string line;
while ((line = gsr.ReadLine()) != null)
{
if (char.IsDigit(line, 0))
{
int sperator = line.IndexOf(" ");
string mz = line.Substring(0, sperator);
string intensity = line.Substring(sperator);
MZintensitiy mzi = new MZintensitiy();
try
{
mzi.mz = float.Parse(mz);
if (bZoomOut && DisplayMaxX != -1 && DisplayMinX != -1)
{
if (mzi.mz < DisplayMaxX && mzi.mz > DisplayMinX)
{
//if (mzi.mz < GuestMinX)
// GuestMinX = mzi.mz;
//if (mzi.mz > GuestMaxX)
// GuestMaxX = mzi.mz;
mzi.intensity = float.Parse(intensity);
if (mzi.intensity > GuestMaxIntensitiy)
GuestMaxIntensitiy = mzi.intensity;
GuestSpectrumData.Add(mzi);
}
}
else
{
if (mzi.mz < GuestMinX)
GuestMinX = mzi.mz;
if (mzi.mz > GuestMaxX)
GuestMaxX = mzi.mz;
mzi.intensity = float.Parse(intensity);
if (mzi.intensity > GuestMaxIntensitiy)
GuestMaxIntensitiy = mzi.intensity;
GuestSpectrumData.Add(mzi);
}
}
catch
{ }
}
}
gsr.Close();
}
DrawSpectrum();
}
}
}
private void DrawSpectrum()
{
Bitmap image = new Bitmap(WIDTH, HEIGHT);
Graphics g = Graphics.FromImage(image);
g.FillRectangle(Brushes.White, 0, 0, WIDTH, HEIGHT);
DrawAxis(g);
image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
g.Dispose();
image.Dispose();
Response.ContentType = "image/gif";
}
int XLinePos;
private void DrawAxis(Graphics g)
{
Font Numberfont = new Font("Arial", 9, FontStyle.Regular);
Font WordFont = new Font("Arial", 9, FontStyle.Bold);
Font smallwordFont = new Font("Arial", 9, FontStyle.Bold);
Rectangle YtitleRect = new Rectangle(0, NETAREABOTTOMMARGIN, NETAREALEFTMARGIN - XAxisScaleLength, HEIGHT - NETAREABOTTOMMARGIN - NETAREATOPMARGIN);
StringFormat format2 = new StringFormat(StringFormatFlags.DirectionVertical);
format2.LineAlignment = StringAlignment.Near;
format2.Alignment = StringAlignment.Center;
g.DrawString("Relative Abundance", WordFont , new SolidBrush(PreforColor ), YtitleRect, format2);
Rectangle XtitleRect = new Rectangle(WIDTH - NETAREALEFTMARGIN, NETAREATOPMARGIN/2, NETAREALEFTMARGIN, HEIGHT - NETAREABOTTOMMARGIN - NETAREATOPMARGIN );
StringFormat format3 = new StringFormat(StringFormatFlags.NoClip);
format3.LineAlignment = StringAlignment.Center;
format3.Alignment = StringAlignment.Center;
g.DrawString("m/z", smallwordFont, new SolidBrush(PreforColor), XtitleRect, format3);
//draw the axis main line
//Y axis
g.DrawLine(new Pen(PreforColor), new Point(NETAREALEFTMARGIN, NETAREATOPMARGIN), new Point(NETAREALEFTMARGIN, HEIGHT - NETAREABOTTOMMARGIN));
//X axis
XLinePos = HEIGHT - NETAREABOTTOMMARGIN - (HEIGHT - NETAREABOTTOMMARGIN - NETAREATOPMARGIN) / 2;
g.DrawLine(new Pen(PreforColor), new Point(NETAREALEFTMARGIN, XLinePos), new Point(WIDTH - WHITEMARGIN, XLinePos));
int StartX = (int)(MinX / XBIGSEG) * XBIGSEG;
int EndX = (int)(MaxX / XBIGSEG + 1) * XBIGSEG;
float XUnit = (float)(WIDTH - WHITEMARGIN - NETAREALEFTMARGIN) / (EndX - StartX);
float XStepValue = XUnit * XBIGSEG;
int stepNum = (EndX - StartX) / XBIGSEG;
//draw the top scale
g.DrawLine(new Pen (PreforColor ), new Point(NETAREALEFTMARGIN, NETAREATOPMARGIN ), new Point(WIDTH - WHITEMARGIN, NETAREATOPMARGIN ));
//draw the bottom scale
g.DrawLine(new Pen(PreforColor), new Point(NETAREALEFTMARGIN, HEIGHT - NETAREABOTTOMMARGIN), new Point(WIDTH - WHITEMARGIN, HEIGHT - NETAREABOTTOMMARGIN));
for (int i = 0; i <= stepNum; i++)
{
float x1 = NETAREALEFTMARGIN + i * XStepValue;
g.DrawLine(new Pen(PreforColor), x1, NETAREATOPMARGIN, x1, NETAREATOPMARGIN + XAxisScaleLength);
g.DrawLine(new Pen(PreforColor), x1, HEIGHT - NETAREABOTTOMMARGIN - XAxisScaleLength, x1, HEIGHT - NETAREABOTTOMMARGIN);
Rectangle stringrect = new Rectangle((int)x1 - 32, NETAREATOPMARGIN - 16, 64, 16);
Rectangle stringrect2 = new Rectangle((int)x1 - 32, HEIGHT - NETAREABOTTOMMARGIN+2 , 64, 16);
StringFormat format1 = new StringFormat(StringFormatFlags.NoClip);
format1.LineAlignment = StringAlignment.Center;
format1.Alignment = StringAlignment.Center;
g.DrawString(string.Format("{0:F0}", StartX + i * XBIGSEG), Numberfont, new SolidBrush(PreforColor ) , stringrect, format1);
g.DrawString(string.Format("{0:F0}", StartX + i * XBIGSEG), Numberfont, new SolidBrush(PreforColor), stringrect2, format1);
}
int TotalY = 100;
if (bZoomOut)
{
TotalY = DisplayMaxY;
}
float YUnit = (XLinePos - NETAREATOPMARGIN) / (float)TotalY;
float YStepValue = YUnit * YBIGSEG;
int yStepNum = TotalY / YBIGSEG;
for (int i = 0; i <= yStepNum; i++)
{
float y1 = XLinePos - i * YStepValue;
g.DrawLine(new Pen(PreforColor), NETAREALEFTMARGIN - XAxisScaleLength, y1, NETAREALEFTMARGIN, y1);
Rectangle stringrect = new Rectangle(WHITEMARGIN, (int)y1-5, NETAREALEFTMARGIN - XAxisScaleLength - WHITEMARGIN, 16);
StringFormat format1 = new StringFormat(StringFormatFlags.NoClip);
format1.LineAlignment = StringAlignment.Far;
format1.Alignment = StringAlignment.Center;
g.DrawString(string.Format("{0:F0}", i * YBIGSEG), Numberfont, new SolidBrush(PreforColor), stringrect, format1);
}
Font titleFont = new Font("Arial", 16, FontStyle.Bold);
g.DrawString("Library", titleFont, new SolidBrush(PreforColor), new PointF(WIDTH - 86, NETAREATOPMARGIN));
g.DrawString(PeptideSequence, titleFont, new SolidBrush(Color.LightGray), new PointF(NETAREALEFTMARGIN + 5, NETAREATOPMARGIN + 25));
g.DrawString("Query", titleFont, new SolidBrush(PreforColor), new PointF(WIDTH - 80, HEIGHT - NETAREABOTTOMMARGIN - 30));
g.DrawString(AdditionalSequence, titleFont, new SolidBrush(Color.LightGray), new PointF(NETAREALEFTMARGIN + 5, HEIGHT - NETAREABOTTOMMARGIN - 50));
for (int i = 0; i <= yStepNum; i++)
{
float y1 = XLinePos + i * YStepValue;
g.DrawLine(Pens.Gray, NETAREALEFTMARGIN - XAxisScaleLength, y1, NETAREALEFTMARGIN, y1);
Rectangle stringrect = new Rectangle(WHITEMARGIN, (int)y1-5, NETAREALEFTMARGIN - XAxisScaleLength - WHITEMARGIN, 16);
StringFormat format1 = new StringFormat(StringFormatFlags.NoClip);
format1.LineAlignment = StringAlignment.Far;
format1.Alignment = StringAlignment.Center;
g.DrawString(string.Format("{0:F0}", i * YBIGSEG), Numberfont, new SolidBrush(PreforColor), stringrect, format1);
}
DrawDiffMap(g, XUnit, YUnit,StartX);
DrawData(g, XUnit, YUnit, StartX);
if (bShowTheory)
{
if (PeptideSequence == AdditionalSequence)
DrawTheoryData(g, XUnit, StartX);
else
{
DrawTheoryData2(g, XUnit, StartX);
DrawUserTheoryData(g, XUnit, StartX);
}
}
}
private string ValidePepSeq(string Src_seq)
{
string newSeq = "";
Regex reg = new Regex("[ACDEFGHIKLMNPQRSTVWY]");
MatchCollection matchMade = reg.Matches(Src_seq);
for (int i = 0; i < matchMade.Count; i++)
{
newSeq += matchMade[i].Value;
}
return newSeq;
}
bool HadModifed(int site, string mModifiedSequence, ref float ModifiedWeight)
{
Regex reg = new Regex("[ACDEFGHIKLMNPQRSTVWY]");
int iCurrent = 0;
int iSite = 1;
if (site == 0)
{
if (mModifiedSequence.StartsWith("("))
{
string mod = mModifiedSequence.Substring(1, mModifiedSequence.IndexOf(")") - 1);
ModifiedWeight = float.Parse(mod);
return true;
}
return false;
}
while (true)
{
if (reg.IsMatch(mModifiedSequence.Substring(iCurrent, 1)))
{
if (iSite == site)
{
if (reg.IsMatch(mModifiedSequence.Substring(iCurrent + 1, 1)))
{
return false;
}
else
{
string mod = mModifiedSequence.Substring(iCurrent + 2, mModifiedSequence.IndexOf(")", iCurrent) - iCurrent - 2);
ModifiedWeight = float.Parse(mod);
return true;
}
}
iSite++;
}
iCurrent++;
if (iCurrent >= mModifiedSequence.Length - 1)
break;
}
return false;
}
private void DrawUserTheoryData(Graphics g, float XUnit, int xstart)
{
PeptideMW PMW = new PeptideMW(this.AdditionalSequence);
float[] Bs = PMW.GetPepFragmentBValues();
float[] Ys = PMW.GetPepFragmentYValues();
Pen dataPen = new Pen(Brushes.Blue, 1);
dataPen.DashStyle = DashStyle.Dash;
Pen dataPen2 = new Pen(Brushes.Red, 1);
dataPen2.DashStyle = DashStyle.Dash;
Font Numberfont = new Font("Times New Roman", 10, FontStyle.Regular);
//int charge = int.Parse(ChargeState);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
int axisline = HEIGHT - NETAREABOTTOMMARGIN - (HEIGHT - NETAREABOTTOMMARGIN - NETAREATOPMARGIN) / 2;
for (int i = 0; i < Bs.Length; i++)
{
if (Bs[i] > xstart)
{
float x = (Bs[i] - xstart) * XUnit + NETAREALEFTMARGIN;
float previousAA = 0.0F;
if (i == 0)
previousAA = NETAREALEFTMARGIN;
else
{
if (Bs[i - 1] > xstart)
previousAA = (Bs[i - 1] - xstart) * XUnit + NETAREALEFTMARGIN;
else
previousAA = NETAREALEFTMARGIN;
}
g.DrawLine(dataPen, x, (float)axisline, x, (float)HEIGHT - NETAREABOTTOMMARGIN);
string neatSequence = ValidePepSeq(this.AdditionalSequence);
float modified = 0.0F;
string AA = "";
if (HadModifed(i+1, AdditionalSequence, ref modified))
AA = string.Format("{0}+{1:F2}", neatSequence.Substring(i, 1), modified);
else
AA = neatSequence.Substring(i, 1);
g.DrawString(AA, Numberfont, Brushes.Blue, new RectangleF(previousAA, HEIGHT - NETAREABOTTOMMARGIN - 25, x - previousAA, 25), sf);
}
}
for (int i = 0; i < Ys.Length; i++)
{
if (Ys[i] > xstart)
{
float x = (Ys[i] - xstart) * XUnit + NETAREALEFTMARGIN;
float previousAA = 0.0F;
if (i == 0)
previousAA = NETAREALEFTMARGIN;
else
{
if (Ys[i - 1] > xstart)
previousAA = (Ys[i - 1] - xstart) * XUnit + NETAREALEFTMARGIN;
else
previousAA = NETAREALEFTMARGIN;
}
g.DrawLine(dataPen2, x, (float)axisline , x, (float)HEIGHT-NETAREABOTTOMMARGIN -25);
string neatSequence = ValidePepSeq(AdditionalSequence);
int iSite = neatSequence.Length -1- i;
float modified = 0.0F;
string AA = "";
if (HadModifed(iSite+1, AdditionalSequence, ref modified))
AA = string.Format("{0}+{1:F2}", neatSequence.Substring(iSite, 1), modified);
else
AA = neatSequence.Substring(iSite, 1);
g.DrawString(AA, Numberfont, Brushes.Red, new RectangleF(previousAA, HEIGHT - NETAREABOTTOMMARGIN - 50, x - previousAA, 25), sf);
}
//if (Ys[i] / 2 > xstart)
//{
// float x = (Ys[i] / 2 - xstart) * XUnit + NETAREALEFTMARGIN;
// g.DrawLine(dataPen, x, (float)NETAREATOPMARGIN, x, (float)HEIGHT - NETAREABOTTOMMARGIN);
// g.DrawString(string.Format("Y{0:D}:2+", i + 1), Numberfont, Brushes.Red, new PointF(x, NETAREATOPMARGIN + 12));
//}
}
}
private void DrawTheoryData2(Graphics g, float XUnit, int xstart)
{
PeptideMW PMW = new PeptideMW(this.PeptideSequence);
float[] Bs = PMW.GetPepFragmentBValues();
float[] Ys = PMW.GetPepFragmentYValues();
Pen dataPen = new Pen(Brushes.Blue, 1);
dataPen.DashStyle = DashStyle.Dash;
Pen dataPen2 = new Pen(Brushes.Red, 1);
dataPen2.DashStyle = DashStyle.Dash;
Font Numberfont = new Font("Times New Roman", 10, FontStyle.Regular);
//int charge = int.Parse(ChargeState);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
int axisline = HEIGHT - NETAREABOTTOMMARGIN - (HEIGHT - NETAREABOTTOMMARGIN - NETAREATOPMARGIN) / 2;
for (int i = 0; i < Bs.Length; i++)
{
if (Bs[i] > xstart)
{
float x = (Bs[i] - xstart) * XUnit + NETAREALEFTMARGIN;
float previousAA = 0.0F;
if (i == 0)
previousAA = NETAREALEFTMARGIN;
else
{
if (Bs[i - 1] > xstart)
previousAA = (Bs[i - 1] - xstart) * XUnit + NETAREALEFTMARGIN;
else
previousAA = NETAREALEFTMARGIN;
}
g.DrawLine(dataPen, x, (float)NETAREATOPMARGIN, x, (float)axisline );
string neatSequence = ValidePepSeq(this.AdditionalSequence);
float modified = 0.0F;
string AA = "";
if (HadModifed(i + 1, this.PeptideSequence, ref modified))
AA = string.Format("{0}+{1:F2}", neatSequence.Substring(i, 1), modified);
else
AA = neatSequence.Substring(i, 1);
g.DrawString(AA, Numberfont, Brushes.Blue, new RectangleF(previousAA, NETAREATOPMARGIN, x - previousAA, 25), sf);
}
}
for (int i = 0; i < Ys.Length; i++)
{
if (Ys[i] > xstart)
{
float x = (Ys[i] - xstart) * XUnit + NETAREALEFTMARGIN;
float previousAA = 0.0F;
if (i == 0)
previousAA = NETAREALEFTMARGIN;
else
{
if (Ys[i - 1] > xstart)
previousAA = (Ys[i - 1] - xstart) * XUnit + NETAREALEFTMARGIN;
else
previousAA = NETAREALEFTMARGIN;
}
g.DrawLine(dataPen2, x, (float)NETAREATOPMARGIN + 25, x, (float)axisline );
string neatSequence = ValidePepSeq(AdditionalSequence);
int iSite = neatSequence.Length - 1 - i;
float modified = 0.0F;
string AA = "";
if (HadModifed(iSite + 1, this.PeptideSequence, ref modified))
AA = string.Format("{0}+{1:F2}", neatSequence.Substring(iSite, 1), modified);
else
AA = neatSequence.Substring(iSite, 1);
g.DrawString(AA, Numberfont, Brushes.Red, new RectangleF(previousAA, NETAREATOPMARGIN + 25, x - previousAA, 25), sf);
}
//if (Ys[i] / 2 > xstart)
//{
// float x = (Ys[i] / 2 - xstart) * XUnit + NETAREALEFTMARGIN;
// g.DrawLine(dataPen, x, (float)NETAREATOPMARGIN, x, (float)HEIGHT - NETAREABOTTOMMARGIN);
// g.DrawString(string.Format("Y{0:D}:2+", i + 1), Numberfont, Brushes.Red, new PointF(x, NETAREATOPMARGIN + 12));
//}
}
}
private void DrawTheoryData(Graphics g, float XUnit, int xstart)
{
PeptideMW PMW = new PeptideMW(this.PeptideSequence);
float[] Bs = PMW.GetPepFragmentBValues();
float[] Ys = PMW.GetPepFragmentYValues();
Pen dataPen = new Pen(Brushes.Blue, 1);
dataPen.DashStyle = DashStyle.Dash;
Pen dataPen2 = new Pen(Brushes.Red, 1);
dataPen2.DashStyle = DashStyle.Dash;
Font Numberfont = new Font("Times New Roman", 10, FontStyle.Regular);
//int charge = int.Parse(ChargeState);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
for (int i = 0; i < Bs.Length; i++)
{
if (Bs[i] > xstart)
{
float x = (Bs[i] - xstart) * XUnit + NETAREALEFTMARGIN;
float previousAA =0.0F;
if (i==0)
previousAA = NETAREALEFTMARGIN ;
else
{
if (Bs[i-1] > xstart )
previousAA = (Bs[i-1]-xstart )* XUnit + NETAREALEFTMARGIN;
else
previousAA = NETAREALEFTMARGIN ;
}
g.DrawLine(dataPen, x, (float)NETAREATOPMARGIN, x, (float)HEIGHT - NETAREABOTTOMMARGIN-25);
string neatSequence = ValidePepSeq(this.AdditionalSequence);
float modified = 0.0F;
string AA = "";
if (HadModifed(i+1, AdditionalSequence, ref modified))
AA = string.Format("{0}+{1:F2}", neatSequence.Substring(i, 1), modified);
else
AA = neatSequence.Substring(i, 1);
g.DrawString(AA, Numberfont, Brushes.Blue, new RectangleF (previousAA , NETAREATOPMARGIN ,x-previousAA ,25),sf);
}
}
for (int i = 0; i < Ys.Length; i++)
{
if (Ys[i] > xstart)
{
float x = (Ys[i] - xstart) * XUnit + NETAREALEFTMARGIN;
float previousAA = 0.0F;
if (i == 0)
previousAA = NETAREALEFTMARGIN;
else
{
if (Ys[i - 1] > xstart)
previousAA = (Ys[i - 1] - xstart) * XUnit + NETAREALEFTMARGIN;
else
previousAA = NETAREALEFTMARGIN;
}
g.DrawLine(dataPen2, x, (float)NETAREATOPMARGIN+25, x, (float)HEIGHT - NETAREABOTTOMMARGIN);
string neatSequence = ValidePepSeq(AdditionalSequence);
int iSite = neatSequence.Length-1 - i;
float modified = 0.0F;
string AA = "";
if (HadModifed(iSite+1, AdditionalSequence, ref modified))
AA = string.Format("{0}+{1:F2}", neatSequence.Substring(iSite, 1), modified);
else
AA = neatSequence.Substring(iSite, 1);
g.DrawString(AA, Numberfont, Brushes.Red, new RectangleF(previousAA, HEIGHT - NETAREABOTTOMMARGIN-25, x - previousAA, 25), sf);
}
//if (Ys[i] / 2 > xstart)
//{
// float x = (Ys[i] / 2 - xstart) * XUnit + NETAREALEFTMARGIN;
// g.DrawLine(dataPen, x, (float)NETAREATOPMARGIN, x, (float)HEIGHT - NETAREABOTTOMMARGIN);
// g.DrawString(string.Format("Y{0:D}:2+", i + 1), Numberfont, Brushes.Red, new PointF(x, NETAREATOPMARGIN + 12));
//}
}
}
const float OH = 17.00274F;
const float H2O = 18.01057F;
const float HPO3 = 79.966391F;
const float H3PO4 = 97.976961F;
const float Aion = 28.0F;
private string GetAnnotation(ArrayList Spectra, int pos, float[] Bs, float[] Ys, bool NoiseMode, float PreMZ, int charge, bool bPhosphorylation)
{
if (!IsPeak(Spectra,pos)&&!NoiseMode)
return "";
float mz = ((MZintensitiy)Spectra[pos]).mz;
return GetAnnotation(mz, Bs, Ys, PreMZ, charge, bPhosphorylation);
}
private bool IsPeak(ArrayList Spectra, int pos)
{
bool result = true ;
float posmz = ((MZintensitiy)Spectra[pos]).mz;
float posintensity = ((MZintensitiy)Spectra[pos]).intensity ;
int i = pos-1;
int j = pos+1;
while (i > 0 && j < Spectra.Count)
{
float ipos = ((MZintensitiy)Spectra[i]).mz;
float jpos = ((MZintensitiy)Spectra[j]).mz;
if (posmz - ipos > 0.9 && jpos - posmz > 0.9)
break;
float jintensity = ((MZintensitiy)Spectra[j]).intensity ;
float iintensity = ((MZintensitiy)Spectra[i]).intensity;
if (posmz - ipos <= 0.9 && iintensity > posintensity)
{
result = false;
break;
}
if (jpos - posmz <= 0.9 && jintensity > posintensity)
{
result = false;
break;
}
i = i - 1;
j = j + 1;
}
return result;
}
Boolean IsMatch(float i, Hashtable ions, ref string annotation)
{
float Prioritymindif = 100;
string Priorityannotation = "";
float othermindif = 100;
string otherannotation = "";
foreach (float v in ions.Keys)
{
string ionsname = (string)ions[v];
if (ionsname.Contains ("NH") || ionsname.Contains ("H2O"))
{
if (Math.Abs(i - v) < othermindif)
{
othermindif = Math.Abs(i - v);
otherannotation = ionsname;
}
}
else
{
if (Math.Abs(i - v) < Prioritymindif)
{
Prioritymindif = Math.Abs(i - v);
Priorityannotation = (string)ions[v];
}
}
}
if (Prioritymindif < mzTolerance)
{
annotation = Priorityannotation;
return true;
}
if (othermindif < mzTolerance)
{
annotation = otherannotation;
return true;
}
return false;
}
private string GetAnnotation(float mz, float[] B, float[] Y, float precursor, int charge, bool bPhosphorylation)
{
Hashtable Ions = new Hashtable();
Ions.Add(precursor, string.Format("M+{0}", charge));
Ions.Add(precursor - OH / charge, string.Format("(M-NH3)+{0}", charge));
Ions.Add(precursor - H2O / charge, string.Format("(M-H2O)+{0}", charge));
Ions.Add(precursor - 2 * OH / charge, string.Format("(M-2*NH3)+{0}", charge));
Ions.Add(precursor - 2 * H2O / charge, string.Format("(M-2*H2O)+{0}", charge));
Ions.Add(precursor - (OH + H2O) / charge, string.Format("(M-NH3-H2O)+{0}", charge));
if (bPhosphorylation)
{
Ions.Add(precursor - HPO3 / charge, string.Format("(M-HPO3)+{0}", charge));
Ions.Add(precursor - H3PO4 / charge, string.Format("(M-H3PO4)+{0}", charge));
}
for (int i = 0; i < B.Length; i++)
{
for (int z = 1; z <= charge; z++)
{
if (!Ions.Contains((B[i] + z - 1) / z))
Ions.Add((B[i] + z - 1) / z, string.Format("(b{0})+{1}", i+1, z));
if (!Ions.Contains((B[i] - OH + z - 1) / z))
Ions.Add((B[i] - OH + z - 1) / z, string.Format("(b{0}-NH)+{1}", i+1, z));
if (!Ions.Contains((B[i] - H2O + z - 1) / z))
Ions.Add((B[i] - H2O + z - 1) / z, string.Format("(b{0}-H2O)+{1}", i+1, z));
//if (!Ions.Contains((B[i] - 2 * OH + z - 1) / z))
// Ions.Add((B[i] - 2 * OH + z - 1) / z, string.Format("B{0}:{1}:-2NH", i, z));
//if (!Ions.Contains((B[i] - 2 * H2O + z - 1) / z))
// Ions.Add((B[i] - 2 * H2O + z - 1) / z, string.Format("B{0}:{1}:-2H2O", i, z));
if (!Ions.Contains((B[i] - Aion + z - 1) / z))
Ions.Add((B[i] - Aion + z - 1) / z, string.Format("(a{0})+{1}", i+1, z));
}
//float B2 = (B[i] + 1) / 2;
//Fragments.Add(B2);
//Fragments.Add (B2-OH/2 );
//Fragments.Add (B2-H2O/2);
//float A = B[i] - Aion;
//Fragments.Add(A);
//float A2 = (A + 1) / 2;
//Fragments.Add(A);
}
for (int i = 0; i < Y.Length; i++)
{
for (int z = 1; z <= charge; z++)
{
if (!Ions.Contains((Y[i] + z - 1) / z))
Ions.Add((Y[i] + z - 1) / z, string.Format("(y{0})+{1}", i+1, z));
if (!Ions.Contains((Y[i] - OH + z - 1) / z))
Ions.Add((Y[i] - OH + z - 1) / z, string.Format("(y{0}-NH)+{1}", i+1, z));
if (!Ions.Contains((Y[i] - H2O + z - 1) / z))
Ions.Add((Y[i] - H2O + z - 1) / z, string.Format("(y{0}-H2O)+{1}", i+1, z));
//if (!Ions.Contains((Y[i] - 2 * OH + z - 1) / z))
//Ions.Add((Y[i] - 2 * OH + z - 1) / z, string.Format("Y{0}:{1}", i, z));
//if (!Ions.Contains((Y[i] - 2 * H2O + z - 1) / z))
//Ions.Add((Y[i] - 2 * H2O + z - 1) / z, string.Format("Y{0}:{1}", i, z));
}
//float Y2 = (Y[i] + 1) / 2;
//Fragments.Add(Y2);
//Fragments.Add(Y2 - OH);
//Fragments.Add(Y2 - H2O);
}
string annotation = "";
IsMatch(mz, Ions, ref annotation);
return annotation;
}
private string GetAnnotation(float mz, float[] Bs, float[] Ys)
{
string strAnnotation = "";
string LossFlag1 = "";
int b1 = -1;
string bCharge = "";
string yCharge = "";
string aCharge = "";
float minBDiff = 1000.0f;
for (int i = 0; i < Bs.Length; i++)
{
float diff1 = Math.Abs(mz - Bs[i]);
float diff2 = Math.Abs(mz - (Bs[i] + 1) / 2);
float diff = Math.Min(diff1, diff2);
if (diff < minBDiff)