# test/synthetic.jl # --------------------------------------------------------------------------- # Minimal, valid imzML + ibd generator used by the integration tests. # # Layout: `width` × `height` spectra, Float32, uncompressed, centroided, five # peaks per spectrum. One pixel is given a very strong peak at 300.0 Da so the # tests can assert that ion-image extraction actually finds signal. # --------------------------------------------------------------------------- function write_synthetic_imzml(dir::AbstractString; width::Int=4, height::Int=3, mzs::Vector{Float64}=[100.0, 200.0, 300.0, 400.0, 500.0]) mkpath(dir) base = joinpath(dir, "synthetic") imzml_path = base * ".imzML" ibd_path = base * ".ibd" n = width * height offsets = Vector{Tuple{Int64,Int64,Int64,Int64}}(undef, n) # mz_off, mz_len, int_off, int_len open(ibd_path, "w") do io # JuliaMSI's parser ignores arrays whose external offset is 0 (it uses 0 # as the "unset" sentinel), so keep a small pad at the start of the ibd. write(io, zeros(UInt8, 16)) for k in 1:n x = ((k - 1) % width) + 1 y = ((k - 1) ÷ width) + 1 intensities = Float64[10.0 + x, 20.0 + y, 30.0, 40.0, 50.0] if (x, y) == (2, 2) intensities[3] = 1000.0 elseif (x, y) == (4, 3) intensities[1] = 2000.0 end mz_bytes = reinterpret(UInt8, Float32.(mzs)) int_bytes = reinterpret(UInt8, Float32.(intensities)) mz_off = position(io) write(io, mz_bytes) int_off = position(io) write(io, int_bytes) offsets[k] = (Int64(mz_off), Int64(length(mzs)), Int64(int_off), Int64(length(mzs))) end end open(imzml_path, "w") do io write(io, """ """) for k in 1:n x = ((k - 1) % width) + 1 y = ((k - 1) ÷ width) + 1 mz_off, mz_len, int_off, int_len = offsets[k] write(io, """ """) end write(io, """ """) end return imzml_path end