diff --git a/IMSJL/src/Data.jl b/IMSJL/src/Data.jl index 366cf728..0f461788 100644 --- a/IMSJL/src/Data.jl +++ b/IMSJL/src/Data.jl @@ -1,22 +1,7 @@ -""" -# module Data - -- Julia version: -- Author: davidteschner -- Date: 2023-09-27 - -# Examples - -```jldoctest -julia> -``` -""" module Data import Base.show -export TimsFrame - struct TimsFrame frame_id::Int32 ms_type_numeric::Int32 @@ -29,8 +14,10 @@ struct TimsFrame end function show(io::IO, frame::TimsFrame) - num_peaks = length(frame.mz) # or whichever array represents peaks + num_peaks = length(frame.mz) print(io, "TimsFrame(frame_id=$(frame.frame_id), ms_type=$(frame.ms_type_numeric), num_peaks=$num_peaks)") end +export TimsFrame + end \ No newline at end of file diff --git a/IMSJL/src/JuliaDataHandle.jl b/IMSJL/src/DataHandle.jl similarity index 72% rename from IMSJL/src/JuliaDataHandle.jl rename to IMSJL/src/DataHandle.jl index f766bb96..884f3770 100644 --- a/IMSJL/src/JuliaDataHandle.jl +++ b/IMSJL/src/DataHandle.jl @@ -1,22 +1,6 @@ -""" -# module JuliaDataHandle +module DataHandle -- Julia version: -- Author: davidteschner -- Date: 2023-09-27 - -# Examples - -```jldoctest -julia> -``` -""" -module JuliaDataHandle - -include("RustCAPI.jl") -include("Data.jl") - -export TimsDataHandle, get_tims_frame +using IMSJL.Data, IMSJL.RustCAPI struct TimsDataHandle data_path::String @@ -30,7 +14,7 @@ struct TimsDataHandle bruker_binary_path = determine_bruker_binary_path() # Acquire the actual handle from the C-exposed Rust object - handle = RustcApi.TimsDataHandle_new(data_path, bruker_binary_path) + handle = RustCAPI.TimsDataHandle_new(data_path, bruker_binary_path) # Construct the instance new(data_path, bruker_binary_path, handle) @@ -46,8 +30,10 @@ function determine_imsjl_connector_path()::String end function get_tims_frame(handle::TimsDataHandle, frame_id::Number)::TimsFrame - ctims_frame = RustcApi.TimsDataHandle_get_frame(handle.handle, Int32(frame_id)) - return RustcApi.ctims_frame_to_julia_tims_frame(ctims_frame) + ctims_frame = RustCAPI.TimsDataHandle_get_frame(handle.handle, Int32(frame_id)) + return RustCAPI.ctims_frame_to_julia_tims_frame(ctims_frame) end +export TimsDataHandle, get_tims_frame + end \ No newline at end of file diff --git a/IMSJL/src/IMSJL.jl b/IMSJL/src/IMSJL.jl index 7b064b9d..7ef4b9e3 100644 --- a/IMSJL/src/IMSJL.jl +++ b/IMSJL/src/IMSJL.jl @@ -1,9 +1,9 @@ module IMSJL -include("RustCAPI.jl") -include("JuliaDataHandle.jl") include("Data.jl") +include("RustCAPI.jl") +include("DataHandle.jl") -export JuliaDataHandle.TimsDataHandle, JuliaDataHandle.get_tims_frame, Data.TimsFrame +export Data, RustCAPI, DataHandle -end # module IMSJL \ No newline at end of file +end \ No newline at end of file diff --git a/IMSJL/src/RustCAPI.jl b/IMSJL/src/RustCAPI.jl index 9dabe9b7..de6e0dd0 100644 --- a/IMSJL/src/RustCAPI.jl +++ b/IMSJL/src/RustCAPI.jl @@ -1,40 +1,26 @@ -""" -# module RustCAPI - -- Julia version: -- Author: davidteschner -- Date: 2023-09-27 - -# Examples - -```jldoctest -julia> -``` -""" -module RustcApi - -export TimsDataHandle_new, TimsDataHandle_get_data_path, TimsFrame_get_bruker_binary_path, TimsDataHandle_destroy, TimsDataHandle_get_frame_count, TimsDataHandle_get_frame, ctims_frame_to_julia_tims_frame +module RustCAPI +using IMSJL.Data struct CTimsFrame -frame_id::Int32 -ms_type::Int32 -retention_time::Float64 + frame_id::Int32 + ms_type::Int32 + retention_time::Float64 -scan::Ptr{Int32} -scan_size::UInt64 + scan::Ptr{Int32} + scan_size::UInt64 -inv_mobility::Ptr{Float64} -inv_mobility_size::UInt64 + inv_mobility::Ptr{Float64} + inv_mobility_size::UInt64 -tof::Ptr{Int32} -tof_size::UInt64 + tof::Ptr{Int32} + tof_size::UInt64 -mz::Ptr{Float64} -mz_size::UInt64 + mz::Ptr{Float64} + mz_size::UInt64 -intensity::Ptr{Float64} -intensity_size::UInt64 + intensity::Ptr{Float64} + intensity_size::UInt64 end const lib = "/home/administrator/Documents/promotion/rustims/imsjl_connector/target/release/libimsjl_connector.so" @@ -61,7 +47,7 @@ function ctims_frame_to_julia_tims_frame(ctims_frame::CTimsFrame)::TimsFrame TimsFrame( ctims_frame.frame_id, - ctims_frame.ms_type, # Note that I've changed ms_type_numeric to ms_type + ctims_frame.ms_type, ctims_frame.retention_time, julia_scan, julia_inv_mobility, @@ -71,4 +57,6 @@ function ctims_frame_to_julia_tims_frame(ctims_frame::CTimsFrame)::TimsFrame ) end +export TimsDataHandle_new, TimsDataHandle_get_data_path, TimsDataHandle_get_bruker_binary_path, TimsDataHandle_destroy, TimsDataHandle_get_frame_count, TimsDataHandle_get_frame, ctims_frame_to_julia_tims_frame + end \ No newline at end of file diff --git a/imsjl_connector/src/handle.rs b/imsjl_connector/src/handle.rs index 10744177..b1b90d6f 100644 --- a/imsjl_connector/src/handle.rs +++ b/imsjl_connector/src/handle.rs @@ -20,10 +20,9 @@ pub extern "C" fn tims_data_handle_new(data_path: *const c_char, bruker_lib_path let data_path = unsafe { std::ffi::CStr::from_ptr(data_path) }.to_str().unwrap(); let bruker_lib_path = unsafe { std::ffi::CStr::from_ptr(bruker_lib_path) }.to_str().unwrap(); - // Create your structure let handle = TimsDataHandle::new(bruker_lib_path, data_path).unwrap(); - // Box the structure to keep it on the heap and return a pointer + // Box structure to keep it on heap and return pointer Box::into_raw(Box::new(CTimsDataHandle { inner: handle })) } @@ -55,6 +54,6 @@ pub extern "C" fn tims_data_handle_destroy(handle: *mut CTimsDataHandle) { #[no_mangle] pub extern "C" fn tims_data_handle_get_frame(handle: &TimsDataHandle, frame_id: i32) -> CTimsFrame { - let frame = handle.get_frame(frame_id as u32).unwrap(); // Ensure proper error handling if get_frame can fail + let frame = handle.get_frame(frame_id as u32).unwrap(); convert_to_ctims_frame(frame) }