@@ -15,6 +15,7 @@ test_that("read_chroms can read 'Agilent' MS files", {
15
15
expect_equal(class(x )[1 ], " matrix" )
16
16
expect_equal(dim(x ), c(95471 , 3 ))
17
17
expect_equal(attr(x , " parser" ), " entab" )
18
+ expect_equal(attr(x , " data_format" ), " long" )
18
19
expect_equal(colnames(x ), c(" rt" , " mz" , " intensity" ))
19
20
20
21
# export as mzML
@@ -23,40 +24,55 @@ test_that("read_chroms can read 'Agilent' MS files", {
23
24
ext = " mzML" )
24
25
on.exit(unlink(path_mzml ))
25
26
26
- x1 <- read_chroms(path , parser = " chromconverter" , what = " MS1" ,
27
- format_out = " data.table" ,
27
+ # chromConverter can read Agilent MS data and write to mzml
28
+ x1 <- read_chroms(path , parser = " chromconverter" ,
29
+ format_out = " data.frame" , data_format = " wide" ,
28
30
progress_bar = FALSE ,
29
- export_format = " mzML" , path_out = tmp )[[1 ]]
30
- expect_s3_class(x1 , " data.table" )
31
- expect_equal(attr(x1 , " format_out" ), " data.table" )
31
+ export_format = " mzML" , path_out = tmp , force = TRUE )[[1 ]]
32
+ expect_s3_class(x1 $ MS1 , " data.frame" )
33
+ expect_equal(attr(x1 $ MS1 , " format_out" ), " data.frame" )
34
+ expect_equal(attr(x1 $ MS1 , " data_format" ), " long" )
35
+ expect_equal(attr(x1 $ TIC , " data_format" ), " wide" )
36
+ expect_equal(attr(x1 $ BPC , " data_format" ), " long" )
32
37
33
38
xx <- read_mzml(path_mzml )
34
- expect_equal(x1 , xx $ MS1 [,- 4 ], ignore_attr = TRUE )
35
- expect_equal(x1 , as.data.frame(x ), ignore_attr = TRUE )
36
- expect_equal(attr(x1 ," sample_name" ), attr(x1 ," sample_name" ))
37
- expect_equal(attr(x1 ," source_sha1" ), attr(x1 ," source_sha1" ))
38
- expect_equal(attr(x1 ," time_unit" ), attr(x1 ," time_unit" ))
39
- expect_equal(attr(x1 ," run_datetime" ), attr(x1 ," run_datetime" ))
40
- expect_equal(attr(x1 ," operator" ), attr(x1 ," operator" ))
41
- expect_equal(attr(x1 ," method" ), attr(x1 ," method" ))
42
- expect_equal(attr(x1 ," detector" ), attr(x1 ," detector" ))
39
+ expect_equal(xx $ MS1 [,- 4 ], x1 $ MS1 , ignore_attr = TRUE )
40
+ expect_equal(as.data.frame(xx $ TIC ), x1 $ TIC , ignore_attr = TRUE )
41
+ expect_equal(rownames(xx $ TIC ), rownames(x1 $ TIC ))
42
+ expect_equal(xx $ BPC [,1 ], x1 $ BPC [,3 ], ignore_attr = TRUE )
43
+ expect_equal(as.numeric(rownames(xx $ BPC )), x1 $ BPC $ rt , tolerance = 0.00001 )
44
+
45
+ expect_equal(x1 $ MS1 , as.data.frame(x ), ignore_attr = TRUE )
46
+ expect_equal(attr(x1 $ MS1 ," sample_name" ), attr(x ," sample_name" ))
47
+ expect_equal(attr(x1 $ MS1 ," source_sha1" ), attr(x ," source_sha1" ))
48
+ expect_equal(attr(x1 $ MS1 , " time_unit" ), attr(x , " time_unit" ))
49
+ expect_equal(attr(x1 $ MS1 ," run_datetime" ), attr(x ," run_datetime" ))
50
+ expect_equal(attr(x1 $ MS1 ," operator" ), attr(x ," operator" ))
51
+ expect_equal(attr(x1 $ MS1 ," method" ), attr(x ," method" ))
52
+ expect_equal(attr(x1 $ MS1 ," detector" ), attr(x ," detector" ))
53
+ expect_equal(attr(x1 $ MS1 , " data_format" ), " long" )
43
54
44
55
# rainbow
45
- x1 <- read_chroms(path , parser = " rainbow" ,
46
- progress_bar = FALSE , precision = 0 )[[1 ]]
47
- expect_equal(class(x1 )[1 ], " matrix" )
48
- expect_equal(dim(x1 ), c(2534 , 841 ))
49
- expect_equal(attr(x1 ," run_datetime" ), attr(x1 ," run_datetime" ))
50
- expect_equal(attr(x1 ," method" ), attr(x1 ," method" ))
51
- expect_equal(attr(x1 ," detector" ), attr(x1 ," detector" ))
52
-
53
56
x2 <- read_chroms(path , parser = " rainbow" ,
57
+ progress_bar = FALSE , precision = 0 )[[1 ]]
58
+ expect_equal(class(x2 )[1 ], " matrix" )
59
+ expect_equal(dim(x2 ), c(2534 , 841 ))
60
+ # date time stamp appears to be wrong in rainbow
61
+ # expect_equal(attr(x2,"run_datetime"), attr(x,"run_datetime"))
62
+ expect_equal(attr(x2 , " method" ), attr(x1 $ MS1 , " method" ))
63
+ expect_equal(attr(x2 , " detector" ), attr(x1 $ MS1 , " detector" ))
64
+ expect_equal(attr(x2 , " data_format" ), " wide" )
65
+
66
+ x3 <- read_chroms(path , parser = " rainbow" ,
54
67
progress_bar = FALSE , data_format = " long" ,
55
68
format_out = " data.table" ,
56
69
precision = 0 )[[1 ]]
57
- expect_s3_class(x2 , " data.table" )
58
- expect_equal(dim(x2 ), c(2131094 , 3 ))
59
- expect_equal(colnames(x2 ), c(" rt" , " mz" , " intensity" ))
70
+ expect_s3_class(x3 , " data.table" )
71
+ expect_equal(dim(x3 ), c(2131094 , 3 ))
72
+ expect_equal(colnames(x3 ), c(" rt" , " mz" , " intensity" ))
73
+ expect_equal(attr(x3 , " method" ), attr(x2 , " method" ))
74
+ expect_equal(attr(x3 , " detector" ), attr(x2 , " detector" ))
75
+ expect_equal(attr(x3 , " data_format" ), " long" )
60
76
})
61
77
62
78
test_that(" read_chroms can read 'Agilent ChemStation' version 30 files" , {
@@ -80,6 +96,7 @@ test_that("read_chroms can read 'Agilent ChemStation' version 30 files", {
80
96
expect_equal(attr(x , " detector_y_unit" ), " mAU" )
81
97
expect_equal(attr(x , " method" ), " JCMONO1.M" )
82
98
expect_equal(attr(x , " time_unit" ), " Minutes" )
99
+ expect_equal(attr(x , " data_format" ), " wide" )
83
100
84
101
x1 <- read_chroms(path , parser = " chromconverter" , format_out = " data.frame" ,
85
102
data_format = " long" , progress_bar = FALSE )[[1 ]]
@@ -89,6 +106,7 @@ test_that("read_chroms can read 'Agilent ChemStation' version 30 files", {
89
106
expect_equal(x [,1 ], x1 [,2 ], ignore_attr = TRUE )
90
107
expect_equal(head(x1 $ rt , 1 ), - .00133333333333333 , tolerance = .00001 )
91
108
expect_equal(tail(x1 $ rt , 1 ), 32.002 , tolerance = .00001 )
109
+ expect_equal(attr(x1 , " data_format" ), " long" )
92
110
})
93
111
94
112
test_that(" read_chroms can read 'Agilent ChemStation' 31 files" , {
@@ -133,6 +151,9 @@ test_that("read_chroms can read 'Agilent ChemStation' 31 files", {
133
151
134
152
expect_equal(attr(x , " time_unit" ), " Minutes" )
135
153
expect_equal(attr(x , " time_unit" ), attr(x1 , " time_unit" ))
154
+
155
+ expect_equal(attr(x , " data_format" ), " wide" )
156
+ expect_equal(attr(x , " data_format" ), attr(x1 , " data_format" ))
136
157
})
137
158
138
159
test_that(" read_chroms can read 'Agilent ChemStation' version 81 files" , {
@@ -157,6 +178,7 @@ test_that("read_chroms can read 'Agilent ChemStation' version 81 files", {
157
178
expect_equal(attr(x , " detector_id" ), " HP G1530A" )
158
179
expect_equal(attr(x , " sample_name" ), " 5970 mix 10nG" )
159
180
expect_equal(attr(x , " time_unit" ), " Minutes" )
181
+ expect_equal(attr(x , " data_format" ), " wide" )
160
182
161
183
# long format
162
184
x1 <- read_chroms(path , progress_bar = FALSE ,
@@ -168,6 +190,7 @@ test_that("read_chroms can read 'Agilent ChemStation' version 81 files", {
168
190
expect_equal(x [,1 ], x1 [[2 ]], ignore_attr = TRUE )
169
191
expect_equal(head(x1 $ rt , 1 ), 3.00044479166667 , tolerance = .00001 )
170
192
expect_equal(tail(x1 $ rt , 1 ), 11.9971114583333 , tolerance = .00001 )
193
+ expect_equal(attr(x1 , " data_format" ), " long" )
171
194
})
172
195
173
196
test_that(" read_chroms can read 'Agilent ChemStation' version 130 files" , {
@@ -190,6 +213,7 @@ test_that("read_chroms can read 'Agilent ChemStation' version 130 files", {
190
213
expect_equal(attr(x , " detector_y_unit" ), " mAU" )
191
214
expect_equal(attr(x , " method" ), " Phenolics_new2.M" )
192
215
expect_equal(attr(x , " time_unit" ), " Minutes" )
216
+ expect_equal(attr(x , " data_format" ), " wide" )
193
217
194
218
# long format
195
219
x1 <- read_chroms(path , data_format = " long" , format_out = " data.table" ,
@@ -206,7 +230,7 @@ test_that("read_chroms can read 'Agilent ChemStation' version 130 files", {
206
230
expect_equal(attr(x1 , " detector_y_unit" ), " mAU" )
207
231
expect_equal(attr(x1 , " method" ), " Phenolics_new2.M" )
208
232
expect_equal(attr(x1 , " time_unit" ), " Minutes" )
209
-
233
+ expect_equal(attr( x1 , " data_format " ), " long " )
210
234
})
211
235
212
236
@@ -229,6 +253,7 @@ test_that("read_chroms can read 'Agilent OpenLab' 179 files", {
229
253
expect_equal(attr(x , " sample_name" ), " STD_1_1mM-1MKHCO3" )
230
254
expect_equal(attr(x , " detector_y_unit" ), " nRIU" )
231
255
expect_equal(attr(x , " time_unit" ), " Minutes" )
256
+ expect_equal(attr(x , " data_format" ), " wide" )
232
257
233
258
# long format
234
259
x1 <- read_chroms(path , progress_bar = FALSE ,
@@ -241,6 +266,7 @@ test_that("read_chroms can read 'Agilent OpenLab' 179 files", {
241
266
expect_equal(x [,1 ], x1 [,2 ], ignore_attr = TRUE )
242
267
expect_equal(head(x1 $ rt ,1 ), 0.001125 , tolerance = .00001 )
243
268
expect_equal(tail(x1 $ rt ,1 ), 36 , tolerance = .00001 )
269
+ expect_equal(attr(x1 , " data_format" ), " long" )
244
270
})
245
271
246
272
test_that(" read_chroms can read 'Agilent ChemStation' 179 files (8-byte format)" , {
@@ -265,6 +291,7 @@ test_that("read_chroms can read 'Agilent ChemStation' 179 files (8-byte format)"
265
291
expect_equal(attr(x , " software" ), " Mustang ChemStation" )
266
292
expect_equal(attr(x , " method" ), " NGS Default Edit.M" )
267
293
expect_equal(attr(x , " time_unit" ), " Minutes" )
294
+ expect_equal(attr(x , " data_format" ), " wide" )
268
295
269
296
# test scale argument
270
297
x1 <- read_chroms(path , progress_bar = FALSE , scale = FALSE )[[1 ]]
@@ -284,6 +311,7 @@ test_that("read_chroms can read 'Agilent ChemStation' 179 (4-byte format)", {
284
311
expect_equal(dim(x ), c(22800 , 1 ))
285
312
expect_equal(head(get_times(x ), 1 ), 0.00083331667582194 , tolerance = .00001 )
286
313
expect_equal(tail(get_times(x ), 1 ), 19 , tolerance = .00001 )
314
+ expect_equal(attr(x , " data_format" ), " wide" )
287
315
288
316
# check metadata
289
317
expect_equal(attr(x , " parser" ), " chromconverter" )
@@ -304,15 +332,17 @@ test_that("read_chroms can read 'Agilent MassHunter' dad files", {
304
332
skip_if_not(file.exists(path ))
305
333
306
334
x <- read_chroms(path , format_in = " masshunter_dad" , parser = " entab" ,
307
- progress_bar = FALSE )
335
+ progress_bar = FALSE )[[ 1 ]]
308
336
x1 <- read_chroms(path , format_in = " masshunter_dad" , parser = " aston" ,
309
- progress_bar = FALSE )
337
+ progress_bar = FALSE )[[ 1 ]]
310
338
311
- expect_equal(dim(x [[1 ]]), c(240 , 276 ))
312
- expect_equal(class(x [[1 ]])[1 ], " matrix" )
313
- expect_equal(x [[1 ]], x1 [[1 ]], ignore_attr = TRUE )
314
- expect_equal(attr(x [[1 ]], " parser" ), " entab" )
315
- expect_equal(attr(x1 [[1 ]], " parser" ), " aston" )
339
+ expect_equal(dim(x ), c(240 , 276 ))
340
+ expect_equal(class(x )[1 ], " matrix" )
341
+ expect_equal(x , x1 , ignore_attr = TRUE )
342
+ expect_equal(attr(x , " parser" ), " entab" )
343
+ expect_equal(attr(x1 , " parser" ), " aston" )
344
+ expect_equal(attr(x , " data_format" ), " wide" )
345
+ expect_equal(attr(x1 , " data_format" ), " wide" )
316
346
317
347
x <- read_chroms(path , format_in = " masshunter_dad" , parser = " entab" ,
318
348
data_format = " long" , format_out = " data.frame" ,
@@ -327,6 +357,8 @@ test_that("read_chroms can read 'Agilent MassHunter' dad files", {
327
357
328
358
expect_equal(attr(x1 , " parser" ), " aston" )
329
359
expect_equal(colnames(x1 ), c(" rt" , " lambda" , " intensity" ))
360
+ expect_equal(attr(x , " data_format" ), " long" )
361
+ expect_equal(attr(x1 , " data_format" ), " long" )
330
362
})
331
363
332
364
@@ -356,6 +388,7 @@ test_that("read_chroms can read 'Agilent ChemStation' version 181 files", {
356
388
expect_equal(attr(x [[1 ]], " run_datetime" ), as.POSIXct(" 2022-8-23 12:16:25" ,
357
389
tz = " UTC" ))
358
390
expect_equal(attr(x [[1 ]], " time_unit" ), " Minutes" )
391
+ expect_equal(attr(x [[1 ]], " data_format" ), " wide" )
359
392
360
393
expect_equal(attr(x [[2 ]], " sample_name" ), " 140+H" )
361
394
expect_equal(attr(x [[2 ]], " file_version" ), " 181" )
@@ -379,9 +412,10 @@ test_that("read_chroms can read 'Agilent ChemStation' version 181 files", {
379
412
expect_equal(tail(x1 $ FID1A $ rt , 1 ), 19.7048479166667 , tolerance = .00001 )
380
413
381
414
expect_equal(extract_metadata(x )[,c(1 : 8 )], extract_metadata(x1 )[,c(1 : 8 )])
415
+ expect_equal(attr(x1 [[1 ]], " data_format" ), " long" )
382
416
383
417
expect_warning(read_chroms(path , format_in = " agilent_d" , what = " dad" ,
384
- progress_bar = FALSE ))
418
+ progress_bar = FALSE ))
385
419
expect_error(read_agilent_d(path , what = " dad" ))
386
420
387
421
})
@@ -419,10 +453,10 @@ test_that("read_chroms can read 'Agilent' .dx files", {
419
453
expect_true(all(round(x $ instrument $ `THM1B,Right Temperature` ) == 45 ))
420
454
421
455
expect_equal(head(names(x $ instrument ),5 ), c(" RID1G,Board Temperature" ,
422
- " RID1F,Diode 2" ,
423
- " RID1E,Diode 1" ,
424
- " RID1D,Polarity" ,
425
- " RID1C,Diode Balance" ))
456
+ " RID1F,Diode 2" ,
457
+ " RID1E,Diode 1" ,
458
+ " RID1D,Polarity" ,
459
+ " RID1C,Diode Balance" ))
426
460
427
461
expect_equal(sapply(x $ instrument , function (xx ) attr(xx , " detector_y_unit" )),
428
462
c(" \u 00b0C" ," counts" ," counts" ," " ," " ," \u 00b0C" , " \u 00b0C" ,
@@ -437,14 +471,15 @@ test_that("read_chroms can read 'Agilent' .dx files", {
437
471
expect_true(all(
438
472
sapply(x $ instrument , function (xx ){
439
473
attr(xx , " run_datetime" )
440
- }) == 1636717143 ))
474
+ }) == 1636717143 ))
441
475
442
476
x1 <- read_chroms(path , format_in = " agilent_dx" , what = c(" chroms" ," instrument" ),
443
477
progress_bar = FALSE , data_format = " long" ,
444
478
format_out = " data.frame" )[[1 ]]
445
479
expect_s3_class(x1 $ chroms [1 ], " data.frame" )
446
480
expect_equal(dim(x1 $ chroms ), c(10000 , 2 ))
447
- expect_equal(dim(x1 $ instrument $ `PMP1C,Solvent Ratio A` ), c(43253 , 2 ))
481
+ expect_equal(dim(x1 $ instrument [[" PMP1C,Solvent Ratio A" ]]), c(43253 , 2 ))
482
+ expect_equal(attr(x1 $ chroms ," data_format" )," long" )
448
483
449
484
expect_warning(read_chroms(path , format_in = " agilent_dx" , what = " dad" ,
450
485
progress_bar = FALSE ))
0 commit comments