Skip to content

Commit

Permalink
v1.2.2 number format bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
kuwisdelu committed Oct 25, 2024
1 parent 01a688e commit 13baf2d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: CardinalIO
Type: Package
Title: Read and write mass spectrometry imaging files
Version: 1.2.1
Version: 1.2.2
Date: 2023-8-29
Authors@R: person("Kylie Ariel", "Bemis",
email = "[email protected]",
Expand Down
8 changes: 8 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

CHANGES IN VERSION 1.2.2 [2024-10-24]
------------------------------------

BUG FIXES

o Fix writing scientific notation to imzML output
(note: only affected parsing, not precision)

CHANGES IN VERSION 1.2.1 [2024-5-7]
------------------------------------

Expand Down
10 changes: 7 additions & 3 deletions R/writeImzML.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ setMethod("writeImzML", "ImzMeta",
# process positions
if ( !is.null(positions) )
{
positions <- as.data.frame(apply(positions, 2L, as.character))
positions <- as.data.frame(apply(positions, 2L, .format_values))
if ( ncol(positions) == 2L ) {
names(positions) <- c("position x", "position y")
} else if ( ncol(positions) == 3L ) {
Expand Down Expand Up @@ -212,7 +212,7 @@ setMethod("writeImzML", "ImzMeta",
mzArrays[["external array length"]] <- rep_len(mza$extent, n)
mzArrays[["external encoded length"]] <- rep_len(xlen, n)
mzArrays[["binary data type"]] <- rep_len(mza$type, n)
mzArrays[] <- lapply(mzArrays, as.character)
mzArrays[] <- lapply(mzArrays, .format_values)
# get intensity metadata
intensityArrays <- data.frame(row.names=seq_len(n))
ia <- as.data.frame(atomdata(intensity))
Expand All @@ -221,7 +221,7 @@ setMethod("writeImzML", "ImzMeta",
intensityArrays[["external array length"]] <- ia$extent
intensityArrays[["external encoded length"]] <- xlen
intensityArrays[["binary data type"]] <- ia$type
intensityArrays[] <- lapply(intensityArrays, as.character)
intensityArrays[] <- lapply(intensityArrays, .format_values)
# get checksum and uuid as 8-4-4-4-12 formatted string
path <- path(mz)
checksum <- checksum(path, algo=algo)
Expand Down Expand Up @@ -271,6 +271,10 @@ setMethod("writeImzML", "ImzMeta",
metadata
}

.format_values <- function(x) {
ifelse(is.na(x), NA_character_, format(x, scientific=FALSE))
}

#### Deparse generic imzML tags ####
## ----------------------------------

Expand Down

0 comments on commit 13baf2d

Please sign in to comment.