Skip to content

Commit 36f537d

Browse files
committed
feat: more varian metadata + test
1 parent 34c5b86 commit 36f537d

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

R/attach_metadata.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ attach_metadata <- function(x, meta, format_in, format_out, data_format,
7575
x$end_time}),
7676
no_scans = meta$n_scan,
7777
ms_params = meta[c("ion_time","emission_current", "max_ric_scan",
78-
"max_ric_val", "max_ionization_time")],
78+
"max_ric_val", "max_ionization_time",
79+
"temp_trap", "temp_manifold", "temp_transferline",
80+
"axial_modulation")],
7981
time_interval = NA,
8082
time_interval_unit = NA,
8183
time_unit = NA,

R/read_varian_sms.R

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,56 @@ read_varian_sms <- function(path, what = c("chrom", "MS1"),
8383
dat <- collapse_list(dat)
8484
if (read_metadata){
8585
offsets <- read_varian_offsets(f)
86+
8687
prep_offset <- offsets[grep("SamplePrep", offsets$name), "start"]
8788
seek(f, prep_offset)
8889
meta$sample_name <- readBin(f,"character")
89-
mod_offset <- offsets[grep("ModAttr", offsets$name), "start"]
90-
seek(f, mod_offset)
91-
readBin(f, "raw", n = 2)
92-
meta$software <- readBin(f,"character")
93-
skip_null_bytes(f)
94-
meta$version <- readBin(f,"character")
90+
91+
meta <- read_mod_metadata(f, offsets, meta)
92+
9593
dat <- attach_metadata(dat, meta, format_in = "varian_sms",
9694
format_out = format_out, data_format = data_format,
9795
source_file = path)
9896
}
9997
dat
10098
}
10199

100+
#' @noRd
101+
read_mod_metadata <- function(f, offsets, meta){
102+
mod_offset <- offsets[grep("ModAttr", offsets$name), "start"]
103+
seek(f, mod_offset)
104+
readBin(f, "raw", n = 2)
105+
meta$software <- readBin(f,"character")
106+
skip_null_bytes(f)
107+
108+
meta$version <- readBin(f,"character")
109+
skip_null_bytes(f)
110+
111+
readBin(f, "raw", n = 3) # skip
112+
skip_null_bytes(f)
113+
114+
meta$temp_trap <- readBin(f, "integer", size=2,
115+
signed = FALSE, endian = "little")
116+
117+
meta$temp_manifold <- readBin(f, "integer", size=2,
118+
signed = FALSE, endian = "little")
119+
120+
meta$temp_transferline <- readBin(f, "integer", size=2,
121+
signed = FALSE, endian = "little")
122+
123+
readBin(f, "integer", size=2,
124+
signed = FALSE, endian = "little")
125+
126+
meta$axial_modulation <- readBin(f, "integer", size=2,
127+
signed = FALSE, endian = "little")/10
128+
# unknown date
129+
# meta$date <- as.POSIXct(readBin(f, "integer", size=4, endian = "little"))
130+
131+
# seek(f, 12, origin = "current") # skip 12 bytes
132+
# readBin(f, "double", size=8) #air water check
133+
meta
134+
}
135+
102136
#' Read 'Varian Workstation' Chromatograms
103137
#' @author Ethan Bass
104138
#' @noRd
@@ -292,9 +326,9 @@ read_varian_msdata_header <- function(f){
292326

293327
u5 <- readBin(f, what = "integer", size = 2, endian = "little",
294328
signed = FALSE)
295-
readBin(f, what = "integer", size = 2, endian = "little") #skip
296329

297-
readBin(f, what = "raw", n=12) #skip
330+
readBin(f, what = "integer", size = 2, endian = "little") #skip
331+
readBin(f, what = "raw", n = 12) #skip
298332

299333
# reader segment headers
300334
seg_no <- readBin(f, what="integer", size = 2)

tests/testthat/test-extra.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,5 +663,9 @@ test_that("read_chroms can read 'Varian' SMS", {
663663
expect_equal(attr(x, "ms_params")$max_ric_scan, 1445)
664664
expect_equal(attr(x, "ms_params")$max_ric_val, 39285)
665665
expect_equal(attr(x, "ms_params")$max_ionization_time, c(0,25000))
666+
expect_equal(attr(x, "ms_params")$temp_trap, 150)
667+
expect_equal(attr(x, "ms_params")$temp_manifold, 50)
668+
expect_equal(attr(x, "ms_params")$temp_transferline, 250)
669+
expect_equal(attr(x, "ms_params")$axial_modulation, 4)
666670
})
667671

0 commit comments

Comments
 (0)