-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKM1605_UvOx_Expt_analysis.R
More file actions
2213 lines (1541 loc) · 92.2 KB
/
KM1605_UvOx_Expt_analysis.R
File metadata and controls
2213 lines (1541 loc) · 92.2 KB
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
# KM1605_UvOx_Expt_analysis.R
# Analysis of an ultraviolet radiation oxiation experiment conducted with large-volume whole seawater samples during a SCOPE cruise (KM1605) aboard the R/V Kilo Moana
# Created 11/29/16 by J.R.C.
# Follows same general initial path as PAL1314_PAL1516_environmental_samples.R
### workspace preparation ####
# load necessary libraries
library(LOBSTAHS)
library(chemCal)
library(stats)
library(stringr)
# set wd
setwd("/Users/jrcollins/Code/LipidPhotoOxBox/")
### load some necessary metadata; define functions ###
# some chemical data
DNPPE_mg_mL_BD_extracts_2016 = 0.051 # concentration of the DNPPE added during B&D extractions
# in Van Mooy Lab in 2016
DNPPE_MW = 875.081 # MW DNPPE, g/mol
### functions for general lookup and computation ###
# define a two-step function "splitpred" to compute pmol o.c. from raw values for PC and DNPPE, using one of two linear standard curves depending on magnitude of concentration (defined by cutoff value)
splitpred = function(x,linfit_low,linfit_hi,cutoff) {
input = x
if (!is.na(x)) {
if (input > cutoff) {
predval = inverse.predict(linfit_hi, newdata = x)
} else if (input <= cutoff) {
predval = inverse.predict(linfit_low, newdata = x)
}
predval$Prediction
} else {
NA
}
}
# define function for TAG concentration calculation
TAGconcCalc= function(x,numC,numDB,TAGfitFunction,linDNPPEfit_low,linDNPPEfit_hi,DNPPEfit.cutoff) {
# calculate ECN (equivalent carbon number)
ECN = numC-2*numDB
# create data frame for lookup
ECN.lookup = as.data.frame(ECN)
colnames(ECN.lookup) = "x"
# retrieve RRF
this.RRF = predict(TAGfitFunction, newdata = ECN.lookup)
# calculate RRF-adjusted peak area
adj.peakarea = this.RRF*x
# calculate pmol o.c. of TAG (by way of DNPPE standard curve, since the TAG RRFs were calculated relative to DNPPE)
TAGpmol.oc = splitpred(adj.peakarea,
linfit_low = linDNPPEfit_low,
linfit_hi = linDNPPEfit_hi,
cutoff = DNPPEfit.cutoff)
return(TAGpmol.oc)
}
# define function allow "easy" retrieval of sample metadata based on sample ID in filename
getMetDat = function(fn,metadat.raw,whichdat) {
# fn is sample descriptor (from verbose file name) from which sample ID will be extracted and then matched
# whichdat is a list of metadata to be retrieved (corresponding to name of column in the metadat.raw table)
match_ind = grepl(sub("^.*_","\\1",fn),metadat.raw$Orbi.sequence.ID) # get index of matching metadata
this.metdat = metadat.raw[match_ind,whichdat] # extract called-for metadata
this.metdat # return extracted data
}
### functions for evaluation of fragmentation spectra ###
# necessary functions that will allow us to extract the correct ms2 spectra, evaluate transitions, etc
get.ms2Peaklist = function (precursor.index,sample_ID,xcmsRaw.list) {
ms2data.start = xcmsRaw.list[[sample_ID]]@msnScanindex[precursor.index]
ms2data.end = xcmsRaw.list[[sample_ID]]@msnScanindex[precursor.index+1]-1
scandata =
data.frame(xcmsRaw.list[[sample_ID]]@env$msnMz[ms2data.start:ms2data.end],
xcmsRaw.list[[sample_ID]]@env$msnIntensity[ms2data.start:ms2data.end])
colnames(scandata) = c("mz","Intensity")
return(scandata)
}
get.topN = function(peaklist,N) {
ordered.peaklist = peaklist[order(peaklist$Intensity, decreasing = TRUE),]
topN.peaklist = ordered.peaklist[1:N,]
return(topN.peaklist)
}
eval.PIspecies = function(peaklist,species,ppm,ms2.lookupClasses) {
# check to make sure there are no blank values in the peaklist; if so, excise them
peaklist = peaklist[!is.na(peaklist$mz),]
# retrieve product ion m/z
prod.ion = ms2.lookupClasses$mz_value[
rownames(ms2.lookupClasses)==species]
if (any(abs((prod.ion-peaklist[,1])/prod.ion*1000000)<ppm)) {
# it's a match
return(1)
} else {
return(0)
}
}
eval.CNLspecies = function(peaklist,species,sample_ID,ppm,ms2.lookupClasses) {
# check to make sure there are no blank values in the peaklist; if so, excise them
peaklist = peaklist[!is.na(peaklist$mz),]
# calculate theoretical m/z of the ion that would be produced via the neutral loss
# throwing in a mean() here in case xcms associated more than one peak with the group in this particular sample
CNL_product_mz = mean(xcms.peakdata_thisgroup_pos[xcms.peakdata_thisgroup_pos$sample==sample_ID,1])-
ms2.lookupClasses$mz_value[
rownames(ms2.lookupClasses)==this.IDclass]
# perform comparison
if (any(abs((CNL_product_mz-peaklist[,1])/CNL_product_mz*1000000)<ppm)) {
# it's a match
return(1)
} else {
return(0)
}
}
sumfrag = function(x) {
if (all(is.na(x))) {
NA
} else {
sum(x, na.rm = T)
}
}
#### standards ####
### + mode standards ###
### standards from 20161107 ####
# QE003063-QE003073
# standards from 20161107, for PAL1314 & LMG1401 particulate data
# these didn't include any betaine standards
load("data/nice/Orbi_MS_data/LOBSTAHS_processed/6IPL_Standards_20161107_pos.RData") # load processed standard data
IPLstd_pos_20161107.raw = getLOBpeaklist(x6IPL_Standards_20161107_pos) # generate peaklist
# extract standards for each species, and DNPPE
# **** need to extract more than one species for DGDG, SQDG, MGDG since these were not pure standards of one species, and some of the "secondary" (less abundant) species are still abundant enough that they contribute to the overall mass of the lipid
Std_peakareas.20161107 = IPLstd_pos_20161107.raw[
IPLstd_pos_20161107.raw$compound_name %in% c("PG 32:0","PE 32:0","PC 32:0",
"MGDG 36:0","MGDG 34:0","SQDG 34:3",
"SQDG 34:2","SQDG 36:6","SQDG 32:0",
"SQDG 32:3","SQDG 36:5","SQDG 34:1",
"SQDG 36:4",
"DGDG 36:4","DGDG 34:2","DGDG 36:3",
"DNPPE"),]
rownames(Std_peakareas.20161107) = Std_peakareas.20161107$compound_name
Std_peakareas.20161107 = Std_peakareas.20161107[,14:25]
Std_peakareas.20161107 = Std_peakareas.20161107[order(colnames(Std_peakareas.20161107))]
# separate a QC from the standards
Std_peakareas.20161107_QC = Std_peakareas.20161107[,c(ncol(Std_peakareas.20161107))]
Std_peakareas.20161107 = Std_peakareas.20161107[,-c(ncol(Std_peakareas.20161107))]
# define quantities on column for standards (in pmol), assuming 20 uL injection,
# per HFF spreadsheet for current VML standards: 4/12/16, with DNPPE from 3/31/16
# will iterate so I don't make a mistake
# assumes user followed VML protocol for serial dilution of standards; molar
# quantities in the vectors below should be listed from lowest to highest
# DNPPE: 4k standard at 0.051 mg/mL
# MGDG: 16k pmol/mL in highest concentration standard
# create df, populate first row (and rows 2-3, for DNPPE)
Stds_20161107_oc = as.data.frame(matrix(NA,11,8))
colnames(Stds_20161107_oc) = c("pmol_mL_MGDG","pmol_oc_PG","pmol_oc_PE",
"pmol_oc_PC","pmol_oc_MGDG","pmol_oc_SQDG",
"pmol_oc_DGDG","pmol_oc_DNPPE")
Stds_20161107_oc[1,] = c(16000,250.130,252.326,252.326,318.839,501.626,254.179,0.000)
Stds_20161107_oc$pmol_oc_DNPPE[2:3] = c(0,116.56)
# fill out the rest of the matrix
for (i in 2:nrow(Stds_20161107_oc)) {
Stds_20161107_oc[i,1:7] = Stds_20161107_oc[i-1,1:7]/2
if (i>3) {
Stds_20161107_oc[i,8] = Stds_20161107_oc[i-1,8]/2
}
}
# fit standard curves using standard data, define breakpoints in cases where we will need two prediction ranges
# because the MS response was different
# PG
# curve fitting & diagnostics
y = Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="PG 32:0",1:9]
x = rev(Stds_20161107_oc$pmol_oc_PG)[1:9]
linfit_low.PG.20161107 = lm(as.numeric(y)~x-1) # fit a linear model for the first 9 standard levels
plot(rev(Stds_20161107_oc$pmol_oc_PG),
Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="PG 32:0",],
pch="+",
ylab = "Peak area, PG 32:0",
xlab = "pmol o.c., PG 32:0")
points(rev(Stds_20161107_oc$pmol_oc_PG)[1:9],fitted(linfit_low.PG.20161107),col="red",pch="+")
# the second-highest standard appears to be messed up, will need to develop a
# different approach for response of highest peak areas
y = Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="PG 32:0",c(9,11)]
x = rev(Stds_20161107_oc$pmol_oc_PG)[c(9,11)]
linfit_hi.PG.20161107 = lm(as.numeric(y)~x)
points(rev(Stds_20161107_oc$pmol_oc_PG)[c(9,11)],fitted(linfit_hi.PG.20161107),col="blue",pch="+")
PG_std_breakpoint.20161107 = Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="PG 32:0",9]
# PE
# curve fitting & diagnostics
y = Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="PE 32:0",1:9]
x = rev(Stds_20161107_oc$pmol_oc_PE)[1:9]
linfit_low.PE.20161107 = lm(as.numeric(y)~x-1) # fit a linear model for the first 9 standard levels
plot(rev(Stds_20161107_oc$pmol_oc_PE),
Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="PE 32:0",],
pch="+",
ylab = "Peak area, PE 32:0",
xlab = "pmol o.c., PE 32:0")
points(rev(Stds_20161107_oc$pmol_oc_PE)[1:9],fitted(linfit_low.PE.20161107),col="red",pch="+")
# the second-highest standard appears to be messed up, will need to develop a
# different approach for response of highest peak areas
y = Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="PE 32:0",c(9,11)]
x = rev(Stds_20161107_oc$pmol_oc_PE)[c(9,11)]
linfit_hi.PE.20161107 = lm(as.numeric(y)~x)
points(rev(Stds_20161107_oc$pmol_oc_PE)[c(9,11)],fitted(linfit_hi.PE.20161107),col="blue",pch="+")
PE_std_breakpoint.20161107 = Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="PE 32:0",9]
# PC
# curve fitting & diagnostics
y = Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="PC 32:0",1:10]
x = rev(Stds_20161107_oc$pmol_oc_PC)[1:10]
linfit_low.PC.20161107 = lm(as.numeric(y)~x-1) # fit a linear model for the first 10 standard levels
plot(rev(Stds_20161107_oc$pmol_oc_PC),
Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="PC 32:0",],
pch="+",
ylab = "Peak area, PC 32:0",
xlab = "pmol o.c., PC 32:0")
points(rev(Stds_20161107_oc$pmol_oc_PC)[1:10],fitted(linfit_low.PC.20161107),col="red",pch="+")
# we will need some other fit for levels higher than ~ 125 pmol o.c.
y = Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="PC 32:0",10:11]
x = rev(Stds_20161107_oc$pmol_oc_PC)[10:11]
linfit_hi.PC.20161107 = lm(as.numeric(y)~x)
points(rev(Stds_20161107_oc$pmol_oc_PC)[10:11],fitted(linfit_hi.PC.20161107),col="blue",pch="+")
PC_std_breakpoint.20161107 = Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="PC 32:0",10]
# MGDG
# curve fitting & diagnostics
MGDG.stdareas.20161107 = apply(Std_peakareas.20161107[grep("^MGDG",rownames(Std_peakareas.20161107)),],2,sum,na.rm = T)
y = MGDG.stdareas.20161107[1:9]
x = rev(Stds_20161107_oc$pmol_oc_MGDG)[1:9]
linfit_low.MGDG.20161107 = lm(as.numeric(y)~x-1) # fit a linear model for the first 10 standard levels
plot(rev(Stds_20161107_oc$pmol_oc_MGDG),
MGDG.stdareas.20161107,
pch="+",
ylab = "Peak area, total MGDG",
xlab = "pmol o.c., total MGDG")
points(rev(Stds_20161107_oc$pmol_oc_MGDG)[1:9],fitted(linfit_low.MGDG.20161107),col="red",pch="+")
# we will need some other fit for levels higher than ~ 155 pmol o.c.
y = MGDG.stdareas.20161107[10:11]
x = rev(Stds_20161107_oc$pmol_oc_MGDG)[10:11]
linfit_hi.MGDG.20161107 = lm(as.numeric(y)~x)
points(rev(Stds_20161107_oc$pmol_oc_MGDG)[10:11],fitted(linfit_hi.MGDG.20161107),col="blue",pch="+")
MGDG_std_breakpoint.20161107 = MGDG.stdareas.20161107[10]
# SQDG
# curve fitting & diagnostics
SQDG.stdareas.20161107 = apply(Std_peakareas.20161107[grep("^SQDG",rownames(Std_peakareas.20161107)),],2,sum,na.rm = T)
y = SQDG.stdareas.20161107[1:9]
x = rev(Stds_20161107_oc$pmol_oc_SQDG)[1:9]
linfit_low.SQDG.20161107 = lm(as.numeric(y)~x-1) # fit a linear model for the first 9 standard levels
plot(rev(Stds_20161107_oc$pmol_oc_SQDG),
SQDG.stdareas.20161107,
pch="+",
ylab = "Peak area, total SQDG",
xlab = "pmol o.c., total SQDG")
points(rev(Stds_20161107_oc$pmol_oc_SQDG)[1:9],fitted(linfit_low.SQDG.20161107),col="red",pch="+")
# the second-highest standard appears to be messed up, will need to develop a
# different approach for response of highest peak areas
y = SQDG.stdareas.20161107[c(9,11)]
x = rev(Stds_20161107_oc$pmol_oc_SQDG)[c(9,11)]
linfit_hi.SQDG.20161107 = lm(as.numeric(y)~x)
points(rev(Stds_20161107_oc$pmol_oc_SQDG)[c(9,11)],fitted(linfit_hi.SQDG.20161107),col="blue",pch="+")
SQDG_std_breakpoint.20161107 = SQDG.stdareas.20161107[9]
# DGDG
DGDG.stdareas.20161107 = apply(Std_peakareas.20161107[grep("^DGDG",rownames(Std_peakareas.20161107)),],2,sum,na.rm = T)
# curve fitting & diagnostics
# just need one curve here, as long as we omit the second-highest level
y = DGDG.stdareas.20161107[c(1:9,11)]
x = rev(Stds_20161107_oc$pmol_oc_DGDG)[c(1:9,11)]
linfit_low.DGDG.20161107 = lm(as.numeric(y)~x-1) # fit a linear model for the first 9 standard levels
plot(rev(Stds_20161107_oc$pmol_oc_DGDG),
DGDG.stdareas.20161107,
pch="+",
ylab = "Peak area, DGDG 36:4",
xlab = "pmol o.c., DGDG 36:4")
points(rev(Stds_20161107_oc$pmol_oc_DGDG)[c(1:9,11)],fitted(linfit_low.DGDG.20161107),col="red",pch="+")
# can define the high-range curve to be the same as the low-range curve, in this case
linfit_hi.DGDG.20161107 = linfit_low.DGDG.20161107
DGDG_std_breakpoint.20161107 = DGDG.stdareas.20161107[9]
# # DNPPE
# # no DNPPE added at two highest standard levels, per VML lab SOP
#
# # curve fitting & diagnostics
#
# y = Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="DNPPE",1:9]
# x = 1/(4 + (rev(Stds_20161107_oc$pmol_oc_DNPPE)[1:9])*.025)
# polyfit_low.DNPPE.20161107 = lm(as.numeric(y)~x) # fit a first-degee inverse polynomial model
# plot(rev(Stds_20161107_oc$pmol_oc_DNPPE),
# Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="DNPPE",],
# pch="+",
# ylab = "Peak area, DNPPE",
# xlab = "pmol o.c., DNPPE",
# ylim = c(0,3.5e+09))
# points(rev(Stds_20161107_oc$pmol_oc_DNPPE)[1:9],fitted(polyfit_low.DNPPE.20161107),col="red",pch="+")
#
# # can define the high-range curve to be the same as the low-range curve, in this case
#
# polyfit_hi.DNPPE.20161107 = polyfit_low.DNPPE.20161107
# DNPPE_std_breakpoint.20161107 = Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="DNPPE",8]
# DNPPE
# no DNPPE added at two highest standard levels, per VML lab SOP
# curve fitting & diagnostics
y = Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="DNPPE",1:8]
x = rev(Stds_20161107_oc$pmol_oc_DNPPE)[1:8]
linfit_low.DNPPE.20161107 = lm(as.numeric(y)~x-1) # fit a linear model to first 8 points
plot(rev(Stds_20161107_oc$pmol_oc_DNPPE),
Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="DNPPE",],
pch="+",
ylab = "Peak area, DNPPE",
xlab = "pmol o.c., DNPPE",
ylim = c(0,3.5e+09))
points(rev(Stds_20161107_oc$pmol_oc_DNPPE)[1:8],fitted(linfit_low.DNPPE.20161107),col="red",pch="+")
# can define the high-range curve to be the same as the low-range curve, in this case
y = Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="DNPPE",c(8,9)]
x = rev(Stds_20161107_oc$pmol_oc_DNPPE)[c(8,9)]
linfit_hi.DNPPE.20161107 = lm(as.numeric(y)~x)
points(rev(Stds_20161107_oc$pmol_oc_DNPPE)[c(8,9)],fitted(linfit_hi.DNPPE.20161107),col="blue",pch="+")
DNPPE_std_breakpoint.20161107 = Std_peakareas.20161107[rownames(Std_peakareas.20161107)=="DNPPE",8]
### standards from 20160421 ####
# QE001265-QE001276
# maybe not needed for environmental samples
# these were really run for the main batch of the liposome experiment data
### standards from 20161005 ####
# QE002850-QE002859
# these were the closest set of standards (temporally) to PAL1314 and LMG1401
# dissolved phase environmental samples, the Marchetti Antarctic diatom extracts,
# the KM1605 UV-ox experiment, and all the PAL1516 particulate samples, including
# all SPE prefilters
# these standards contain DGTS 16:0, 16:0 (from Avanti), but the DGTS has a
# crazy low response factor
# per HFF, DGTS was added to 4000 pmol/mL MGDG standard to achieve 4000 pmol/mL
# concentration
# Kevin Becker also ran TAG standards around the same time, will use them later
# TAG standards are QE002840-QE002847
load("data/nice/Orbi_MS_data/LOBSTAHS_processed/6IPL_plus_DGTS_Standards_20161005_pos.RData") # load processed standard data
IPLstd_pos_20161005.raw = getLOBpeaklist(IPL_plus_DGTS_Standards_20161005) # generate peaklist
# **** need to extract more than one species for DGDG, SQDG, MGDG since these were not pure standards of one species, and some of the "secondary" (less abundant) species are still abundant enough that they contribute to the overall mass of the lipid
Std_peakareas.20161005 = IPLstd_pos_20161005.raw[
IPLstd_pos_20161005.raw$compound_name %in% c("PG 32:0","PE 32:0","PC 32:0",
"MGDG 36:0","MGDG 34:0","SQDG 34:3",
"SQDG 34:2","SQDG 36:6","SQDG 32:0",
"SQDG 32:3","SQDG 36:5","SQDG 34:1",
"SQDG 36:4",
"DGDG 36:4","DGDG 34:2","DGDG 36:3",
"DNPPE",
"DGTS_DGTA 32:0","DGTS_DGTA 34:0"),]
rownames(Std_peakareas.20161005) = Std_peakareas.20161005$compound_name
Std_peakareas.20161005 = Std_peakareas.20161005[,13:23]
Std_peakareas.20161005 = Std_peakareas.20161005[order(colnames(Std_peakareas.20161005))]
# separate a QC from the standards
Std_peakareas.20161005_QC = Std_peakareas.20161005[,c(ncol(Std_peakareas.20161005))]
Std_peakareas.20161005 = Std_peakareas.20161005[,-c(ncol(Std_peakareas.20161005))]
# define quantities on column for standards (in pmol), assuming 20 uL injection,
# per HFF spreadsheet for current VML standards: 4/12/16, with DNPPE from 3/31/16
# will iterate so I don't make a mistake
# assumes user followed VML protocol for serial dilution of standards; molar
# quantities in the vectors below should be listed from lowest to highest
# these standards only went up to 8k pmol/mL MGDG
# DNPPE: 4k standard at 0.051 mg/mL
# MGDG: 8k pmol/mL in highest concentration standard
# create df, populate first row (and row 2, for DNPPE and DGTS)
Stds_20161005_oc = as.data.frame(matrix(NA,10,9))
colnames(Stds_20161005_oc) = c("pmol_mL_MGDG","pmol_oc_PG","pmol_oc_PE",
"pmol_oc_PC","pmol_oc_MGDG","pmol_oc_SQDG",
"pmol_oc_DGDG","pmol_oc_DNPPE","pmol_oc_DGTS")
Stds_20161005_oc[1,] = c(8000,125.0650,126.1630,126.1630,159.4195,250.8130,127.0895,0.000,0.000)
Stds_20161005_oc$pmol_oc_DNPPE[2] = c(116.56)
Stds_20161005_oc$pmol_oc_DGTS[2] = c(79.7097500)
# fill out the rest of the matrix
for (i in 2:nrow(Stds_20161005_oc)) {
Stds_20161005_oc[i,c(1:7)] = Stds_20161005_oc[i-1,c(1:7)]/2
if (i>2) {
Stds_20161005_oc[i,8:9] = Stds_20161005_oc[i-1,8:9]/2
}
}
# fit standard curves using standard data, define breakpoints in cases where we
# will need two prediction ranges because the MS response was different
# PG
# curve fitting & diagnostics
y = Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="PG 32:0",c(1:7)]
#x = rev(Stds_20161005_oc$pmol_oc_PG)[c(1:8,10)]/(20+0.1*rev(Stds_20161005_oc$pmol_oc_PG)[c(1:8,10)])
#x = (rev(Stds_20161005_oc$pmol_oc_PG)[c(1:8,10)]^0.8)
#x = 8*(1-exp(-0.008*rev(Stds_20161005_oc$pmol_oc_PG)[c(1:8,10)])^1)
x = rev(Stds_20161005_oc$pmol_oc_PG)[c(1:7)]
linfit_low.PG.20161005 = lm(as.numeric(y)~x) # fit a linear model for the first 9 standard levels
plot(rev(Stds_20161005_oc$pmol_oc_PG),
Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="PG 32:0",],
pch="+",
ylab = "Peak area, PG 32:0",
xlab = "pmol o.c., PG 32:0")
points(rev(Stds_20161005_oc$pmol_oc_PG)[c(1:7)],fitted(linfit_low.PG.20161005),col="red",pch="+")
# the second-highest standard appears to be messed up, will need to develop a
# different approach for response of highest peak areas
y = Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="PG 32:0",c(7,8,10)]
x = rev(Stds_20161005_oc$pmol_oc_PG)[c(7,8,10)]
linfit_hi.PG.20161005 = lm(as.numeric(y)~x)
points(rev(Stds_20161005_oc$pmol_oc_PG)[c(7,8,10)],fitted(linfit_hi.PG.20161005),col="blue",pch="+")
PG_std_breakpoint.20161005 = Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="PG 32:0",7]
# PE
# curve fitting & diagnostics
y = Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="PE 32:0",c(1:8)]
x = rev(Stds_20161005_oc$pmol_oc_PE)[c(1:8)]
linfit_low.PE.20161005 = lm(as.numeric(y)~x) # fit a linear model for the first 9 standard levels
plot(rev(Stds_20161005_oc$pmol_oc_PE),
Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="PE 32:0",],
pch="+",
ylab = "Peak area, PE 32:0",
xlab = "pmol o.c., PE 32:0")
points(rev(Stds_20161005_oc$pmol_oc_PE)[c(1:8)],fitted(linfit_low.PE.20161005),col="red",pch="+")
# the second-highest standard appears to be messed up, will need to develop a
# different approach for response of highest peak areas
y = Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="PE 32:0",c(8,10)]
x = rev(Stds_20161005_oc$pmol_oc_PE)[c(8,10)]
linfit_hi.PE.20161005 = lm(as.numeric(y)~x)
points(rev(Stds_20161005_oc$pmol_oc_PE)[c(8,10)],fitted(linfit_hi.PE.20161005),col="blue",pch="+")
PE_std_breakpoint.20161005 = Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="PE 32:0",8]
# PC
# curve fitting & diagnostics
y = Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="PC 32:0",c(1:8)]
x = rev(Stds_20161005_oc$pmol_oc_PC)[c(1:8)]
linfit_low.PC.20161005 = lm(as.numeric(y)~x) # fit a linear model for the entire range,
# while skipping the 9th standard because something was wonky with it
plot(rev(Stds_20161005_oc$pmol_oc_PC),
Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="PC 32:0",],
pch="+",
ylab = "Peak area, PC 32:0",
xlab = "pmol o.c., PC 32:0")
points(rev(Stds_20161005_oc$pmol_oc_PC)[c(1:8)],fitted(linfit_low.PC.20161005),col="red",pch="+")
# high range
y = Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="PC 32:0",c(8,10)]
x = rev(Stds_20161005_oc$pmol_oc_PC)[c(8,10)]
linfit_hi.PC.20161005 = lm(as.numeric(y)~x)
points(rev(Stds_20161005_oc$pmol_oc_PC)[c(8,10)],fitted(linfit_hi.PC.20161005),col="blue",pch="+")
PC_std_breakpoint.20161005 = Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="PC 32:0",8]
# MGDG
MGDG.stdareas.20161005 = apply(Std_peakareas.20161005[grep("^MGDG",rownames(Std_peakareas.20161005)),],2,sum,na.rm = T)
# curve fitting & diagnostics
y = MGDG.stdareas.20161005[1:8]
x = rev(Stds_20161005_oc$pmol_oc_MGDG)[1:8]
linfit_low.MGDG.20161005 = lm(as.numeric(y)~x) # fit a linear model for the first 10 standard levels
plot(rev(Stds_20161005_oc$pmol_oc_MGDG),
MGDG.stdareas.20161005,
pch="+",
ylab = "Peak area, total MGDG",
xlab = "pmol o.c., total MGDG")
points(rev(Stds_20161005_oc$pmol_oc_MGDG)[1:8],fitted(linfit_low.MGDG.20161005),col="red",pch="+")
# we will need some other fit for levels higher than ~ 40 pmol o.c.
y = MGDG.stdareas.20161005[8:10]
x = rev(Stds_20161005_oc$pmol_oc_MGDG)[8:10]
linfit_hi.MGDG.20161005 = lm(as.numeric(y)~x)
points(rev(Stds_20161005_oc$pmol_oc_MGDG)[8:10],fitted(linfit_hi.MGDG.20161005),col="blue",pch="+")
MGDG_std_breakpoint.20161005 = MGDG.stdareas.20161005[8]
# SQDG
SQDG.stdareas.20161005 = apply(Std_peakareas.20161005[grep("^SQDG",rownames(Std_peakareas.20161005)),],2,sum,na.rm = T)
# curve fitting & diagnostics
# something appears to be very weird with the SQDG in these standards
# will generate one curve while ommitting the 8th and 9th points
y = SQDG.stdareas.20161005[1:7]
# x = rev(Stds_20161005_oc$pmol_oc_SQDG)[c(1:7,10)]
x = rev(Stds_20161005_oc$pmol_oc_SQDG)[c(1:7)]
linfit_low.SQDG.20161005 = lm(as.numeric(y)~x) # fit a linear model for the first 7 standard levels
plot(rev(Stds_20161005_oc$pmol_oc_SQDG),
SQDG.stdareas.20161005,
pch="+",
ylab = "Peak area, total SQDG",
xlab = "pmol o.c., total SQDG")
points(rev(Stds_20161005_oc$pmol_oc_SQDG)[c(1:7)],fitted(linfit_low.SQDG.20161005),col="red",pch="+")
# we will need some other fit for levels higher than ~ 40 pmol o.c.
y = SQDG.stdareas.20161005[c(7,10)]
x = rev(Stds_20161005_oc$pmol_oc_SQDG)[c(7,10)]
linfit_hi.SQDG.20161005 = lm(as.numeric(y)~x)
points(rev(Stds_20161005_oc$pmol_oc_SQDG)[c(7,10)],fitted(linfit_hi.SQDG.20161005),col="blue",pch="+")
SQDG_std_breakpoint.20161005 = SQDG.stdareas.20161005[7]
# # SQDG
#
# # curve fitting & diagnostics
# # something appears to be very weird with the SQDG in these standards
# # will generate one curve while ommitting the 8th and 9th points
#
# y = Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",c(1:7,10)]
# # x = rev(Stds_20161005_oc$pmol_oc_SQDG)[c(1:7,10)]
# x = rev(Stds_20161005_oc$pmol_oc_SQDG)[c(1:7,10)]*1/(4 + (rev(Stds_20161005_oc$pmol_oc_SQDG)[c(1:7,10)])*.01)
# hyperfit_low.SQDG.20161005 = lm(as.numeric(y)~x) # fit a linear model for the first 9 standard levels
# plot(rev(Stds_20161005_oc$pmol_oc_SQDG),
# Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",],
# pch="+",
# ylab = "Peak area, SQDG 34:3",
# xlab = "pmol o.c., SQDG 34:3")
# points(rev(Stds_20161005_oc$pmol_oc_SQDG)[c(1:7,10)],fitted(hyperfit_low.SQDG.20161005),col="red",pch="+")
#
# # can define the high-range curve to be the same as the low-range curve, in this case
#
# hyperfit_hi.SQDG.20161005 = hyperfit_low.SQDG.20161005
# SQDG_std_breakpoint.20161005 = Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",9]
# xhat=c((4*as.numeric(inverse.predict(hyperfit_low.SQDG.20161005,Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",c(1)])[c("Prediction")]))/
# (1-as.numeric(inverse.predict(hyperfit_low.SQDG.20161005,Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",c(1)])[c("Prediction")])*0.01),
# (4*as.numeric(inverse.predict(hyperfit_low.SQDG.20161005,Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",c(2)])[c("Prediction")]))/
# (1-as.numeric(inverse.predict(hyperfit_low.SQDG.20161005,Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",c(3)])[c("Prediction")])*0.01),
# (4*as.numeric(inverse.predict(hyperfit_low.SQDG.20161005,Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",c(3)])[c("Prediction")]))/
# (1-as.numeric(inverse.predict(hyperfit_low.SQDG.20161005,Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",c(3)])[c("Prediction")])*0.01),
# (4*as.numeric(inverse.predict(hyperfit_low.SQDG.20161005,Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",c(4)])[c("Prediction")]))/
# (1-as.numeric(inverse.predict(hyperfit_low.SQDG.20161005,Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",c(4)])[c("Prediction")])*0.01),
# (4*as.numeric(inverse.predict(hyperfit_low.SQDG.20161005,Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",c(5)])[c("Prediction")]))/
# (1-as.numeric(inverse.predict(hyperfit_low.SQDG.20161005,Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",c(5)])[c("Prediction")])*0.01),
# (4*as.numeric(inverse.predict(hyperfit_low.SQDG.20161005,Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",c(6)])[c("Prediction")]))/
# (1-as.numeric(inverse.predict(hyperfit_low.SQDG.20161005,Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",c(6)])[c("Prediction")])*0.01),
# (4*as.numeric(inverse.predict(hyperfit_low.SQDG.20161005,Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",c(7)])[c("Prediction")]))/
# (1-as.numeric(inverse.predict(hyperfit_low.SQDG.20161005,Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",c(7)])[c("Prediction")])*0.01),
# (4*as.numeric(inverse.predict(hyperfit_low.SQDG.20161005,Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",c(10)])[c("Prediction")]))/
# (1-as.numeric(inverse.predict(hyperfit_low.SQDG.20161005,Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="SQDG 34:3",c(10)])[c("Prediction")])*0.01))
# points(xhat,fitted(hyperfit_low.SQDG.20161005),col="green",pch="o")
# # DGDG
#
# # curve fitting & diagnostics
# # just need one curve here, as long as we omit the second-highest level
#
# y = Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="DGDG 36:4",c(1:8,10)]
# x = rev(Stds_20161005_oc$pmol_oc_DGDG)[c(1:8,10)]*1/(4 + (rev(Stds_20161005_oc$pmol_oc_DGDG)[c(1:8,10)])*.01)
# hyperfit_low.DGDG.20161005 = lm(as.numeric(y)~x) # fit a linear model for the first 9 standard levels
# plot(rev(Stds_20161005_oc$pmol_oc_DGDG),
# Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="DGDG 36:4",],
# pch="+",
# ylab = "Peak area, DGDG 36:4",
# xlab = "pmol o.c., DGDG 36:4")
# points(rev(Stds_20161005_oc$pmol_oc_DGDG)[c(1:8,10)],fitted(hyperfit_low.DGDG.20161005),col="red",pch="+")
#
# # can define the high-range curve to be the same as the low-range curve, in this case
#
# hyperfit_hi.DGDG.20161005 = hyperfit_low.DGDG.20161005
# DGDG_std_breakpoint.20161005 = Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="DGDG 36:4",9]
# DGDG
DGDG.stdareas.20161005 = apply(Std_peakareas.20161005[grep("^DGDG",rownames(Std_peakareas.20161005)),],2,sum,na.rm = T)
# curve fitting & diagnostics
y = DGDG.stdareas.20161005[1:8]
x = rev(Stds_20161005_oc$pmol_oc_DGDG)[c(1:8)]
linfit_low.DGDG.20161005 = lm(as.numeric(y)~x) # fit a linear model for the first 7 standard levels
plot(rev(Stds_20161005_oc$pmol_oc_DGDG),
DGDG.stdareas.20161005,
pch="+",
ylab = "Peak area, total DGDG",
xlab = "pmol o.c., total DGDG")
points(rev(Stds_20161005_oc$pmol_oc_DGDG)[c(1:8)],fitted(linfit_low.DGDG.20161005),col="red",pch="+")
# we will need some other fit for levels higher than ~ 40 pmol o.c.
y = DGDG.stdareas.20161005[c(8,10)]
x = rev(Stds_20161005_oc$pmol_oc_DGDG)[c(8,10)]
linfit_hi.DGDG.20161005 = lm(as.numeric(y)~x)
points(rev(Stds_20161005_oc$pmol_oc_DGDG)[c(8,10)],fitted(linfit_hi.DGDG.20161005),col="blue",pch="+")
DGDG_std_breakpoint.20161005 = DGDG.stdareas.20161005[8]
# DNPPE
# no DNPPE added at highest standard level, per VML lab SOP
# curve fitting & diagnostics
# will proceed with single linear fit after omitting 8th and 9th points
y = Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="DNPPE",c(1:7,9)]
x = rev(Stds_20161005_oc$pmol_oc_DNPPE)[c(1:7,9)]
linfit_low.DNPPE.20161005 = lm(as.numeric(y)~x) # fit linear model
plot(rev(Stds_20161005_oc$pmol_oc_DNPPE),
Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="DNPPE",],
pch="+",
ylab = "Peak area, DNPPE",
xlab = "pmol o.c., DNPPE",
ylim = c(0,12e+08))
points(rev(Stds_20161005_oc$pmol_oc_DNPPE)[c(1:7,9)],fitted(linfit_low.DNPPE.20161005),col="red",pch="+")
# can define the high-range curve to be the same as the low-range curve, in this case
linfit_hi.DNPPE.20161005= linfit_low.DNPPE.20161005
DNPPE_std_breakpoint.20161005 = Std_peakareas.20161005[rownames(Std_peakareas.20161005)=="DNPPE",8]
# DGTS
DGTS_DGTA.stdareas.20161005 = apply(Std_peakareas.20161005[grep("^DGTS_DGTA",rownames(Std_peakareas.20161005)),],2,sum,na.rm = T)
# curve fitting & diagnostics
y = DGTS_DGTA.stdareas.20161005[1:8]
x = rev(Stds_20161005_oc$pmol_oc_DGTS)[c(1:8)]
linfit_low.DGTS_DGTA.20161005 = lm(as.numeric(y)~x) # fit a model for the first 8 standard levels
plot(rev(Stds_20161005_oc$pmol_oc_DGTS),
DGTS_DGTA.stdareas.20161005,
pch="+",
ylab = "Peak area, DGTS_DGTA 32:0 + 34:0",
xlab = "pmol o.c., DGTS_DGTA 32:0 + 34:0")
points(rev(Stds_20161005_oc$pmol_oc_DGTS)[c(1:8)],fitted(linfit_low.DGTS_DGTA.20161005),col="red",pch="+")
# we will need some other fit for levels higher than ~ 40 pmol o.c.
y = DGTS_DGTA.stdareas.20161005[8:9]
x = rev(Stds_20161005_oc$pmol_oc_DGTS)[8:9]
linfit_hi.DGTS_DGTA.20161005 = lm(as.numeric(y)~x)
points(rev(Stds_20161005_oc$pmol_oc_DGTS)[8:9],fitted(linfit_hi.DGTS_DGTA.20161005),col="blue",pch="+")
DGTS_DGTA_std_breakpoint.20161005 = DGTS_DGTA.stdareas.20161005[8]
### TAG standards from 20161004 ####
# run by Kevin Becker, QE002840-QE002847
# the standard mix includes odd fatty acid TAGs as well, so re-ran the dataset
# in LOBSTAHS with exclude.oddFA = F
# standards were run in duplicate, will take averages
load("data/nice/Orbi_MS_data/LOBSTAHS_processed/TAG_Standards_20161004_pos.RData") # load processed standard data
TAGstd_pos_20161004.raw = getLOBpeaklist(TAG_Standards_20161004_pos) # generate peaklist
# extract standards for each TAG in the mix, and DNPPE
TAGstd_peakareas.20161004 = TAGstd_pos_20161004.raw[
TAGstd_pos_20161004.raw$compound_name %in% c("TAG 24:0","TAG 27:0","TAG 30:0",
"TAG 33:0","TAG 36:0","TAG 39:0",
"TAG 42:0","TAG 45:0","TAG 48:0",
"TAG 51:0","TAG 54:0","TAG 57:0",
"TAG 48:3","TAG 54:9","TAG 60:15",
"TAG 66:18","DNPPE"),]
# three of these (24:0, 27:0, 57:0) aren't in the current LOBSTAHS DB, not going
# to worry about them
rownames(TAGstd_peakareas.20161004) = TAGstd_peakareas.20161004$compound_name
TAGstd_peakareas.20161004 = TAGstd_peakareas.20161004[,13:20]
TAGstd_peakareas.20161004 = TAGstd_peakareas.20161004[order(colnames(TAGstd_peakareas.20161004))]
# # separate a QC from the standards
# no QC's in these standards, skipping...
# TAGstd_peakareas.20161004_QC = TAGstd_peakareas.20161004[,c(ncol(TAGstd_peakareas.20161004))]
# TAGstd_peakareas.20161004 = TAGstd_peakareas.20161004[,-c(ncol(TAGstd_peakareas.20161004))]
# average the respective duplicates
TAGstd_peakareas.20161004.means = as.data.frame(matrix(NA,nrow(TAGstd_peakareas.20161004),4))
colnames(TAGstd_peakareas.20161004.means) = c("ng_oc_0.5","ng_oc_4","ng_oc_15","ng_oc_40")
rownames(TAGstd_peakareas.20161004.means) = rownames(TAGstd_peakareas.20161004)
TAGstd_peakareas.20161004.means[,1] = apply(TAGstd_peakareas.20161004[,1:2],1,mean)
TAGstd_peakareas.20161004.means[,2] = apply(TAGstd_peakareas.20161004[,3:4],1,mean)
TAGstd_peakareas.20161004.means[,3] = apply(TAGstd_peakareas.20161004[,5:6],1,mean)
TAGstd_peakareas.20161004.means[,4] = apply(TAGstd_peakareas.20161004[,7:8],1,mean)
# put in more logical order
TAGstd_peakareas.20161004.means =
TAGstd_peakareas.20161004.means[order(rownames(TAGstd_peakareas.20161004.means)),]
# define quantities on column for standards (in pmol), per Kevin's notes, with
# DNPPE from 3/31/16
# specify molecular weights for each species, in order of species as they appear
# in TAGstd_peakareas.20161004.means after reordering, just above
TAG.mws_20161004 = c(857.51666,554.45464,596.50159,638.54854,680.59549,722.64244,
764.68939,806.73634,800.68939,848.78329,890.83024,872.68939,
944.68939,1022.73634)
# DNPPE: assumed added at same concentration (ng) as the TAGs
# calculate pmol o.c. for each of the four standard levels, populate data frame
TAGstds_20161004_pmol_oc = as.data.frame(matrix(NA,ncol(TAGstd_peakareas.20161004.means),
nrow(TAGstd_peakareas.20161004.means)))
colnames(TAGstds_20161004_pmol_oc) = apply(expand.grid(c("pmol_oc_"),rownames(TAGstd_peakareas.20161004.means)),1,paste,collapse="")
colnames(TAGstds_20161004_pmol_oc) = gsub(" ","_",colnames(TAGstds_20161004_pmol_oc))
colnames(TAGstds_20161004_pmol_oc) = gsub(":","_",colnames(TAGstds_20161004_pmol_oc))
rownames(TAGstds_20161004_pmol_oc) = colnames(TAGstd_peakareas.20161004.means)
TAGstds_20161004_pmol_oc[1,] = 0.5/TAG.mws_20161004*1000
TAGstds_20161004_pmol_oc[2,] = 4/TAG.mws_20161004*1000
TAGstds_20161004_pmol_oc[3,] = 15/TAG.mws_20161004*1000
TAGstds_20161004_pmol_oc[4,] = 40/TAG.mws_20161004*1000
# now, build standard curves for each TAG, and DNPPE
# preallocate a list object to hold results of the curve fits, set correct element names
TAGstdlist.names = rownames(TAGstd_peakareas.20161004.means)
TAGstdlist.names = gsub(" ","_",TAGstdlist.names)
TAGstdlist.names = gsub(":","_",TAGstdlist.names)
TAGstds_20161004_linfits = vector("list",length(TAGstdlist.names))
names(TAGstds_20161004_linfits) = TAGstdlist.names
# apply linear fit to each of these, then plot, then store
for (i in 1:length(TAGstds_20161004_linfits)) {
# for a few species, want to omit some bad data points in the standards
if (rownames(TAGstd_peakareas.20161004.means)[i] %in% c("TAG 48:0","TAG 51:0")) {
y = TAGstd_peakareas.20161004.means[i,c(1,3,4)]
x = TAGstds_20161004_pmol_oc[c(1,3,4),i]
} else if (rownames(TAGstd_peakareas.20161004.means)[i]=="TAG 54:0") {
y = TAGstd_peakareas.20161004.means[i,c(1,2,4)]
x = TAGstds_20161004_pmol_oc[c(1,2,4),i]
} else {
y = TAGstd_peakareas.20161004.means[i,]
x = TAGstds_20161004_pmol_oc[,i]
}
linfit = lm(as.numeric(y)~x-1) # fit a linear model, force through origin
plot(TAGstds_20161004_pmol_oc[,i],
TAGstd_peakareas.20161004.means[i,],
pch="+",
ylab = paste0("Peak area, ",rownames(TAGstd_peakareas.20161004.means)[i]),
xlab = paste0("pmol o.c., ",rownames(TAGstd_peakareas.20161004.means)[i]))
points(x,fitted(linfit),col="red",pch="+")
TAGstds_20161004_linfits[[i]] = linfit
}
# can generate some relative response factors
RRFs = vector("numeric",length(TAGstds_20161004_linfits)) # preallocate
names(RRFs) = rownames(TAGstd_peakareas.20161004.means)
for (i in 1:length(RRFs)) {
RRFs[i] = TAGstds_20161004_linfits[[i]]$coefficients[1]/
TAGstds_20161004_linfits[[1]]$coefficients[1]
}
# calculate some equivalent carbon #s for the TAGs, then plot with RRFs
ECNs = vector("numeric",nrow(TAGstd_peakareas.20161004.means)-1) # preallocate
names(ECNs) = rownames(TAGstd_peakareas.20161004.means)[2:nrow(TAGstd_peakareas.20161004.means)]
for (i in 1:length(ECNs)) {
# get no. of C, DB
num_C = TAGstd_pos_20161004.raw$FA_total_no_C[TAGstd_pos_20161004.raw$compound_name==names(ECNs)[i]]
num_DB = TAGstd_pos_20161004.raw$FA_total_no_DB[TAGstd_pos_20161004.raw$compound_name==names(ECNs)[i]]
ECNs[i] = num_C-2*num_DB
}
plot(ECNs,RRFs[2:length(RRFs)])
text(ECNs, RRFs[2:length(RRFs)], labels=names(ECNs), pos = 4, cex = 0.5)
# maybe a plot of the reciprocals
plot(ECNs,1/RRFs[2:length(RRFs)])
text(ECNs, 1/RRFs[2:length(RRFs)], labels=names(ECNs), pos = 4, cex = 0.5)
# x = ECNs
# y = 1/RRFs[2:length(RRFs)]
# excluding 30:0, 33:0
x = ECNs[3:length(ECNs)]
y = 1/RRFs[4:length(RRFs)]
# fit a non-linear model of form
# y = a*b^x-c
nls.fit.TAG20161004 = nls(y~a*b^x-c,list(x,y),c(a=0.5,b=1.25,c=30), nls.control(maxiter=5000),
lower = c(0.000001,0.5,-1000), algorithm = "port",
upper = c(6,3,500))
points(x,fitted(nls.fit.TAG20161004),col="red",pch="+")
text(ECNs[1:2],1/RRFs[2:3],c("EXCLUDED","EXCLUDED"), cex = 0.5, pos = 1, col = "red")
### pull in data ####
# will use the 20161107 standards for these data, with the 20161005 standards for DGTS & DGTA
load("data/nice/Orbi_MS_data/LOBSTAHS_processed/KM1605_UvOX_Expt_pos_withoddFA_LOBSet.RData")
KM1605_UvOX_Expt_pos_withoddFA_particulate = getLOBpeaklist(KM1605_UvOX_Expt_pos_withoddFA_LOBSet) # generate peaklist
# # get rid of the two QC's
# KM1605_UvOX_Expt_pos_withoddFA_particulate = KM1605_UvOX_Expt_pos_withoddFA_particulate[,-c(21:22)]
### ***** experimental trial of use of msn data using series of xcmsRaw objects ***** ####
# now, use fragmentation spectra for basic confirmation of putative LOBSTAHS IDs
# requires several additional files: (1) annotated xcmsSet object for data in positive ion mode, (2) LOBSet object in positive ion mode, and (3) list containing positive-mode xcmsRaw objects for all samples generated using:
# xraw <- xcmsRaw("yourfile.mzXML", includeMSn=TRUE)
# the routine below assumes the xcmsRaw objects are stored in the list in the order in which they appear in the xsAnnotate and LOBSet objects