Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

David@rustdf #17

Merged
merged 26 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions IMSJL/src/Data.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
28 changes: 7 additions & 21 deletions IMSJL/src/JuliaDataHandle.jl → IMSJL/src/DataHandle.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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
8 changes: 4 additions & 4 deletions IMSJL/src/IMSJL.jl
Original file line number Diff line number Diff line change
@@ -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
end
48 changes: 18 additions & 30 deletions IMSJL/src/RustCAPI.jl
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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,
Expand All @@ -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
5 changes: 2 additions & 3 deletions imsjl_connector/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
}

Expand Down Expand Up @@ -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)
}