fixed docker Julia issues, tested reproductability across all scripts through the docker
This commit is contained in:
@@ -1,53 +1,42 @@
|
||||
# This script is part of the hybrid Julia-Python workflow for MSI analysis.
|
||||
# It uses JuliaMSI for high-performance data ingestion and TrIQ normalization.
|
||||
|
||||
# 1. SETUP ENVIRONMENT
|
||||
# We add the JuliaMSI directory to the load path
|
||||
using Pkg
|
||||
juliamsi_path = joinpath(@__DIR__, "..", "JuliaMSI")
|
||||
if isdir(juliamsi_path)
|
||||
push!(LOAD_PATH, juliamsi_path)
|
||||
end
|
||||
|
||||
using MSI_src
|
||||
using Statistics, Images, Interpolations
|
||||
|
||||
# 2. CONFIGURATION
|
||||
data_path = joinpath(@__DIR__, "..", "data", "Leaf.imzML")
|
||||
mask_path = joinpath(@__DIR__, "..", "data", "region_of_interest.png")
|
||||
output_folder = joinpath(@__DIR__, "..", "datos_para_ai")
|
||||
img_size = (224, 224)
|
||||
# 1. Configuration
|
||||
data_path = "Leaf.imzML"
|
||||
mask_path = "region_of_interest.png"
|
||||
output_folder = "datos_para_ai"
|
||||
img_size = (224, 224) # Standard size for CNN
|
||||
mkpath(output_folder)
|
||||
|
||||
# 3. DATA LOADING (Using JuliaMSI core logic)
|
||||
# Note: In a headless Docker environment, we would use:
|
||||
# julia -J /app/JuliaMSI/sys_msi_headless.so scripts_julia/prepare_data_simclr.jl
|
||||
try
|
||||
# JuliaMSI core loading (based on documentation analysis)
|
||||
# We include the core logic directly if the module isn't exported as a package
|
||||
include(joinpath(juliamsi_path, "src", "julia_mzML_imzML.jl"))
|
||||
include(joinpath(juliamsi_path, "src", "mask.jl"))
|
||||
catch e
|
||||
println("Warning: Could not find JuliaMSI core files. Falling back to local MSI_src if available.")
|
||||
# Fallback to user's existing MSI_src if present in LOAD_PATH
|
||||
end
|
||||
# 2. Data loading
|
||||
data = OpenMSIData(data_path)
|
||||
|
||||
# Placeholder for OpenMSIData if not loaded via include
|
||||
if !@isdefined(OpenMSIData)
|
||||
# Fallback to basic imzML loading logic if framework is missing
|
||||
println("Using basic loading logic...")
|
||||
end
|
||||
# 3. Get important peaks (you can use your previous logic)
|
||||
mzs, avg_ints = MSI_src.get_average_spectrum(data, mask_path=mask_path)
|
||||
threshold = maximum(avg_ints) * 0.02
|
||||
peak_indices = findall(x -> x > threshold, avg_ints)
|
||||
|
||||
# 4. PROCESSING LOGIC
|
||||
# (The user's original logic using OpenMSIData and TrIQ)
|
||||
# This assumes OpenMSIData returns a structure compatible with the framework
|
||||
function process_msi()
|
||||
println("Loading data: $data_path")
|
||||
# data = OpenMSIData(data_path)
|
||||
println("Exporting $(length(peak_indices)) ions...")
|
||||
|
||||
for idx in peak_indices
|
||||
mz_val = mzs[idx]
|
||||
if mz_val < 50.0 || mz_val > 700.0 continue end
|
||||
|
||||
# A. Extract slice (raw, no plots)
|
||||
raw_slice = MSI_src.get_mz_slice(data, mz_val, 0.05, mask_path=mask_path)
|
||||
|
||||
# ... (Actual implementation would call JuliaMSI functions)
|
||||
println("Preprocessing step would run here using JuliaMSI backend.")
|
||||
end
|
||||
# B. TrIQ Normalization (as in your script)
|
||||
vals = filter(x -> x > 0 && isfinite(x), raw_slice)
|
||||
if isempty(vals) continue end
|
||||
q = quantile(vals, 0.98)
|
||||
q = q == 0 ? maximum(vals) : q
|
||||
enhanced = clamp.(raw_slice ./ q, 0.0, 1.0)
|
||||
|
||||
if abspath(PROGRAM_FILE) == @__FILE__
|
||||
process_msi()
|
||||
# C. Rescale to 224x224 (Crucial for CNN)
|
||||
# We use imresize from Images.jl
|
||||
img_resized = imresize(enhanced, img_size)
|
||||
|
||||
# D. Save as raw PNG (Grayscale, no axes)
|
||||
filename = "ion_$(round(mz_val, digits=2)).png"
|
||||
save(joinpath(output_folder, filename), Gray.(img_resized))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user