Optimized memory cleaning, Improved UX/UI design

This commit is contained in:
José Julián Sierra Álvarez 2024-09-13 17:11:32 -06:00 committed by GitHub
parent 026b43daee
commit 2aaa53ee42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 50 additions and 30 deletions

68
app.jl
View File

@ -21,8 +21,7 @@ using Statistics
# @out variables can only be modified by the backend # @out variables can only be modified by the backend
# @in variables can be modified by both the backend and the browser # @in variables can be modified by both the backend and the browser
# variables must be initialized with constant values, or variables defined outside of the @app block # variables must be initialized with constant values, or variables defined outside of the @app block
#@out test = "/test.bmp"#slash means it's getting the info from 'public' folder #@out test = "/test.bmp" #slash means it's getting the info from 'public' folder
#mkdir("new_folder")
@in file_route = "" @in file_route = ""
@in file_name = "" @in file_name = ""
@out warning_fr = "" @out warning_fr = ""
@ -48,6 +47,7 @@ using Statistics
@in msgtriq = "" @in msgtriq = ""
@out full_route = "" @out full_route = ""
@out full_routeMz = "" @out full_routeMz = ""
@out full_routeMz2 = ""
layoutSpectra = PlotlyBase.Layout( layoutSpectra = PlotlyBase.Layout(
title = "Spectra Plot", title = "Spectra Plot",
xaxis = PlotlyBase.attr( xaxis = PlotlyBase.attr(
@ -58,9 +58,10 @@ using Statistics
title = "Intensity", title = "Intensity",
showgrid = true showgrid = true
), ),
height = 700 width = 900,
height = 500
) )
traceSpectra = PlotlyBase.scatter(x=[], y=[], mode="lines+markers") traceSpectra = PlotlyBase.scatter(x=[], y=[], mode="lines")
@out plotdata = [traceSpectra] @out plotdata = [traceSpectra]
@out plotlayout = layoutSpectra @out plotlayout = layoutSpectra
@ -79,32 +80,37 @@ using Statistics
full_route = joinpath( file_route, file_name ) full_route = joinpath( file_route, file_name )
if isfile(full_route) # check if the file exists if isfile(full_route) # check if the file exists
full_routeMz = split( full_route, "." )[1] * ".mzML" # Splitting the route from imzml to mzml so the plotting can work full_routeMz = split( full_route, "." )[1] * ".mzML" # Splitting the route from imzml to mzml so the plotting can work
if isfile(full_routeMz) # check if there is an mzML file around if isfile(full_routeMz) && (full_routeMz2 == "" || full_routeMz2 != full_routeMz) # check if there is an mzML file around
spectraMz = LoadMzml(full_routeMz) Disab_btn = true
# dims = size(spectraMz) warning_fr = "Loading plot..."
# scansMax = dims[2] # we get the total of scansMax spectraMz = LoadMzml(full_routeMz)
# traceSpectra = PlotlyBase.scatter(x = spectraMz[1, 1], y = spectraMz[2, 1], mode="lines") # dims = size(spectraMz)
traceSpectra = PlotlyBase.scatter(x = mean(spectraMz[1,:]), y = mean(spectraMz[2,:]), mode="lines") # scansMax = dims[2] # we get the total of scansMax
plotdata = [traceSpectra] # we add the data of spectra to the plot # traceSpectra = PlotlyBase.scatter(x = spectraMz[1, 1], y = spectraMz[2, 1], mode="lines")
spectraMz = nothing # Important for memory cleaning traceSpectra = PlotlyBase.scatter(x = mean(spectraMz[1,:]), y = mean(spectraMz[2,:]), mode="lines")
GC.gc() # Trigger garbage collection plotdata = [traceSpectra] # we add the data of spectra to the plot
end spectraMz = nothing # Important for memory cleaning
GC.gc() # Trigger garbage collection
ccall(:malloc_trim, Int32, (Int32,), 0) # Ensure julia returns the freed memory to OS
warning_fr = "Plot loaded."
Disab_btn = false
full_routeMz2 = full_routeMz # to avoid creating the plot if its the same file read as before
end
end end
else else
warning_fr = "is not an imzML file" warning_fr = "is not an imzML file"
end end
end end
@onchange Nmass begin @onchange Nmass begin
indeximg = Nmass indeximg = floor(Int, Nmass)
indeximgTriq = Nmass indeximgTriq = floor(Int, Nmass)
lastimg = Nmass lastimg = floor(Int, Nmass)
lastimgTriq = Nmass lastimgTriq = floor(Int, Nmass)
end end
# the onbutton handler will set the variable to false after the block is executed # the onbutton handler will set the variable to false after the block is executed
#/home/julian/Documentos/Cinvestav_2024/Web/Archivos IMZML/royaimg.imzML
@onbutton Main_Process begin @onbutton Main_Process begin
Disab_btn = true #We disable the button to avoid multiple requests Disab_btn = true #We disable the button to avoid multiple requests
indeximg = Nmass indeximg = floor(Int, Nmass)
full_route = joinpath(file_route, file_name) full_route = joinpath(file_route, file_name)
if isfile(full_route) && Nmass > 0 && Tol > 0 && Tol <= 1 if isfile(full_route) && Nmass > 0 && Tol > 0 && Tol <= 1
msg = "File exists, Nmass=$(Nmass) Tol=$(Tol). Please do not press the start button until confirmation" msg = "File exists, Nmass=$(Nmass) Tol=$(Tol). Please do not press the start button until confirmation"
@ -118,17 +124,17 @@ using Statistics
if triqProb < 0 || triqProb > 1 if triqProb < 0 || triqProb > 1
triqProb = 0.1 triqProb = 0.1
end end
SaveBitmap(joinpath("public", "TrIQ_$(Int(Nmass)).bmp"), SaveBitmap(joinpath("public", "TrIQ_$(floor(Int, Nmass)).bmp"),
TrIQ(slice, Int(triqColor), triqProb), TrIQ(slice, Int(triqColor), triqProb),
ViridisPalette) ViridisPalette)
testT = "/TrIQ_$(Int(Nmass)).bmp" # we define the starting value of the images testT = "/TrIQ_$(floor(Int, Nmass)).bmp" # we define the starting value of the images
msgtriq = "TrIQ image with the Nmass of $(Int(Nmass))" msgtriq = "TrIQ image with the Nmass of $(floor(Int, Nmass))"
else # if we don't else # if we don't
SaveBitmap(joinpath("public", "$(Int(Nmass)).bmp"), SaveBitmap(joinpath("public", "$(floor(Int, Nmass)).bmp"),
IntQuant(slice), IntQuant(slice),
ViridisPalette) ViridisPalette)
test = "/$(Int(Nmass)).bmp" # we define the starting value of the images test = "/$(floor(Int, Nmass)).bmp" # we define the starting value of the images
msgimg = "image with the Nmass of $(Int(Nmass))" msgimg = "image with the Nmass of $(floor(Int, Nmass))"
end end
msg = "The file has been created inside the 'public' folder of the app" msg = "The file has been created inside the 'public' folder of the app"
else else
@ -137,6 +143,7 @@ using Statistics
spectra = nothing # Important for memory cleaning spectra = nothing # Important for memory cleaning
slice = nothing slice = nothing
GC.gc() # Trigger garbage collection GC.gc() # Trigger garbage collection
ccall(:malloc_trim, Int32, (Int32,), 0) # Ensure julia returns the freed memory to OS
Disab_btn = false Disab_btn = false
end end
@onbutton ImgMinus begin @onbutton ImgMinus begin
@ -150,6 +157,8 @@ using Statistics
test = "/$(indeximg).bmp" test = "/$(indeximg).bmp"
msgimg = "image with the Nmass of $(indeximg)" msgimg = "image with the Nmass of $(indeximg)"
lastimg = indeximg lastimg = indeximg
GC.gc() # Trigger garbage collection
ccall(:malloc_trim, Int32, (Int32,), 0) # Ensure julia returns the freed memory to OS
end end
@onbutton ImgPlus begin @onbutton ImgPlus begin
indeximg+=1 indeximg+=1
@ -162,6 +171,8 @@ using Statistics
test = "/$(indeximg).bmp" test = "/$(indeximg).bmp"
msgimg = "image with the Nmass of $(indeximg)" msgimg = "image with the Nmass of $(indeximg)"
lastimg = indeximg lastimg = indeximg
GC.gc() # Trigger garbage collection
ccall(:malloc_trim, Int32, (Int32,), 0) # Ensure julia returns the freed memory to OS
end end
@onbutton ImgMinusT begin @onbutton ImgMinusT begin
@ -175,6 +186,8 @@ using Statistics
testT = "/TrIQ_$(indeximgTriq).bmp" testT = "/TrIQ_$(indeximgTriq).bmp"
msgtriq = "TrIQ image with the Nmass of $(indeximgTriq)" msgtriq = "TrIQ image with the Nmass of $(indeximgTriq)"
lastimgTriq = indeximgTriq lastimgTriq = indeximgTriq
GC.gc() # Trigger garbage collection
ccall(:malloc_trim, Int32, (Int32,), 0) # Ensure julia returns the freed memory to OS
end end
@onbutton ImgPlusT begin @onbutton ImgPlusT begin
indeximgTriq+=1 indeximgTriq+=1
@ -187,8 +200,11 @@ using Statistics
testT = "/TrIQ_$(indeximgTriq).bmp" testT = "/TrIQ_$(indeximgTriq).bmp"
msgtriq = "TrIQ image with the Nmass of $(indeximgTriq)" msgtriq = "TrIQ image with the Nmass of $(indeximgTriq)"
lastimgTriq = indeximgTriq lastimgTriq = indeximgTriq
GC.gc() # Trigger garbage collection
ccall(:malloc_trim, Int32, (Int32,), 0) # Ensure julia returns the freed memory to OS
end end
GC.gc() # Trigger garbage collection GC.gc() # Trigger garbage collection
ccall(:malloc_trim, Int32, (Int32,), 0) # Ensure julia returns the freed memory to OS
end end
# == Pages == # == Pages ==
# register a new route and the page that will be loaded on access # register a new route and the page that will be loaded on access

View File

@ -1,14 +1,15 @@
<header> <header>
<h4>Julia mzML imzML GUI&nbsp;</h4> <h4>Julia mzML imzML GUI&nbsp;</h4>
<h6>Please make sure the ibd, the mzML and the imzML files are located in the same directory and have the same name</h6>
<h6>It may take a while to generate the image and the plot, please be patient</h6>
</header> </header>
<h6>Please make sure the ibd, the mzML and the imzML files are located in the same directory and have the same name</h6>
<h6>It may take a while to generate the image, don't press the Start button more than once until it finishes</h6>
<div class="row"> <div class="row">
<div class="st-col col-12 col-sm st-module"> <div class="st-col col-12 col-sm st-module">
<div class="row"> <div class="row">
<div class="st-col col-12 col-sm st-module"> <div class="st-col col-12 col-sm st-module">
<!--Left DIV--> <!--Left DIV-->
<!--<q-file v-model="file_route" filled="" label="Select your imzML file" accept=".txt"></q-file>--> <!--<q-file v-model="file_route" filled="" label="Select your imzML file" accept=".imzML"></q-file>-->
<q-input id="ijii1" v-model="file_route" :dense="true" label="Insert the route to your imzML file"></q-input> <q-input id="ijii1" v-model="file_route" :dense="true" label="Insert the route to your imzML file"></q-input>
<q-input id="ijii1-2" v-model="file_name" :dense="true" label="Insert the name of your imzML file"></q-input> <q-input id="ijii1-2" v-model="file_name" :dense="true" label="Insert the name of your imzML file"></q-input>
<p id="i7brk">full route: {{full_route}} {{warning_fr}}</p> <p id="i7brk">full route: {{full_route}} {{warning_fr}}</p>
@ -66,5 +67,8 @@
</div> </div>
</div> </div>
</div> </div>
<div class="row">
<div class="st-col col-12 col-sm st-module">
<plotly :data="plotdata" :layout="plotlayout"> </plotly> <plotly :data="plotdata" :layout="plotlayout"> </plotly>
</div>
</div>