first commit, migrated repository to contain the scripts only
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using MSI_src
|
||||
using Statistics, Plots, Images
|
||||
|
||||
# 1. Definir función de contraste (si no la tienes ya en la sesión)
|
||||
# 1. Define the contrast function (if you do not already have it in the session)
|
||||
function apply_triq(img_matrix)
|
||||
vals = filter(x -> x > 0 && isfinite(x), img_matrix)
|
||||
if isempty(vals) return img_matrix end
|
||||
@@ -10,45 +10,45 @@ function apply_triq(img_matrix)
|
||||
return clamp.(img_matrix ./ q, 0.0, 1.0)
|
||||
end
|
||||
|
||||
# 2. Configuración de rutas
|
||||
path_data = "Hoja.imzML"
|
||||
path_mask = "region_interes.png"
|
||||
output_folder = "resultados_expertos/batch_triq"
|
||||
# 2. Path configuration
|
||||
path_data = "Leaf.imzML"
|
||||
path_mask = "region_of_interest.png"
|
||||
output_folder = "expert_results/batch_triq"
|
||||
mkpath(output_folder)
|
||||
|
||||
# 3. Carga de datos
|
||||
# 3. Data loading
|
||||
data = OpenMSIData(path_data)
|
||||
|
||||
# 4. Obtener espectro promedio SOLO de la zona de la máscara (ROI)
|
||||
println("Calculando espectro promedio en la ROI...")
|
||||
# Nota: Usamos la función de MSI_src para obtener el promedio filtrado
|
||||
# 4. Get the average spectrum ONLY for the mask region (ROI)
|
||||
println("Computing average spectrum over the ROI...")
|
||||
# Note: We use the MSI_src function to obtain the filtered average
|
||||
mzs, avg_ints = MSI_src.get_average_spectrum(data, mask_path=path_mask)
|
||||
|
||||
# 5. Identificar picos importantes (ej. > 2% del pico base)
|
||||
# 5. Identify important peaks (e.g. > 2% of the base peak)
|
||||
max_int = maximum(avg_ints)
|
||||
umbral = max_int * 0.02 # Ajusta este valor (0.01 para 1%, 0.05 para 5%)
|
||||
indices_picos = findall(x -> x > umbral, avg_ints)
|
||||
threshold = max_int * 0.02 # Adjust this value (0.01 for 1%, 0.05 for 5%)
|
||||
peak_indices = findall(x -> x > threshold, avg_ints)
|
||||
|
||||
println("Se encontraron $(length(indices_picos)) iones que superan el umbral.")
|
||||
println("Found $(length(peak_indices)) ions above the threshold.")
|
||||
|
||||
# 6. Bucle para generar imágenes con TrIQ
|
||||
for idx in indices_picos
|
||||
# 6. Loop to generate images with TrIQ
|
||||
for idx in peak_indices
|
||||
mz_val = mzs[idx]
|
||||
|
||||
# Validar rango (ejemplo: m/z 50 a 700)
|
||||
# Validate range (example: m/z 50 to 700)
|
||||
if mz_val < 50.0 || mz_val > 700.0
|
||||
continue
|
||||
end
|
||||
|
||||
println("Procesando m/z: $(round(mz_val, digits=2))")
|
||||
println("Processing m/z: $(round(mz_val, digits=2))")
|
||||
|
||||
# A. Extraer los datos crudos con la máscara aplicada
|
||||
# A. Extract the raw data with the mask applied
|
||||
raw_slice = MSI_src.get_mz_slice(data, mz_val, 0.05, mask_path=path_mask)
|
||||
|
||||
# B. Aplicar contraste TrIQ
|
||||
# B. Apply TrIQ contrast
|
||||
enhanced_slice = apply_triq(raw_slice)
|
||||
|
||||
# C. Crear el mapa de calor (Heatmap)
|
||||
# C. Create the heatmap
|
||||
p = heatmap(enhanced_slice,
|
||||
title="Ion m/z: $(round(mz_val, digits=2))",
|
||||
color=:viridis,
|
||||
@@ -56,9 +56,9 @@ for idx in indices_picos
|
||||
yflip=true,
|
||||
xaxis=false, yaxis=false)
|
||||
|
||||
# D. Guardar
|
||||
nombre_archivo = "ion_$(round(mz_val, digits=2))_triq.png"
|
||||
savefig(p, joinpath(output_folder, nombre_archivo))
|
||||
# D. Save
|
||||
filename = "ion_$(round(mz_val, digits=2))_triq.png"
|
||||
savefig(p, joinpath(output_folder, filename))
|
||||
end
|
||||
|
||||
println("--- Proceso completado. Revisa la carpeta: $output_folder ---")
|
||||
println("--- Process completed. Check the folder: $output_folder ---")
|
||||
|
||||
@@ -4,7 +4,7 @@ using Statistics, Images, Interpolations
|
||||
# 1. Configuration
|
||||
data_path = "Leaf.imzML"
|
||||
mask_path = "region_of_interest.png"
|
||||
output_folder = "datos_para_ai"
|
||||
output_folder = "ai_data"
|
||||
img_size = (224, 224) # Standard size for CNN
|
||||
mkpath(output_folder)
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ using Plots.Measures
|
||||
|
||||
dataset_name = length(ARGS) >= 1 ? ARGS[1] : "leaf"
|
||||
# Second positional arg (optional) overrides the dataset directory, e.g.
|
||||
# `julia plot_mass_spectra.jl Datura_leaf /path/to/datos_para_ai/Datura_leaf`.
|
||||
data_dir = length(ARGS) >= 2 ? ARGS[2] : joinpath(project_root, "datos_para_ai", dataset_name)
|
||||
# `julia plot_mass_spectra.jl Datura_leaf /path/to/ai_data/Datura_leaf`.
|
||||
data_dir = length(ARGS) >= 2 ? ARGS[2] : joinpath(project_root, "ai_data", dataset_name)
|
||||
output_dir = joinpath(project_root, "outputs", dataset_name)
|
||||
figures_dir = joinpath(output_dir, "figures")
|
||||
cluster_csv = joinpath(output_dir, "msi_clusters_results.csv")
|
||||
|
||||
Reference in New Issue
Block a user