first patch to fix colorbar coherence with R

This commit is contained in:
Pixelguy14 2025-01-27 18:10:44 -06:00
parent 7667bc26e9
commit e5e6284d53
2 changed files with 117 additions and 112 deletions

25
app.jl
View File

@ -18,7 +18,6 @@ using StipplePlotly
# == Code import == # == Code import ==
# add your data analysis code here or in the lib folder. Code in lib/ will be # add your data analysis code here or in the lib folder. Code in lib/ will be
# automatically loaded # automatically loaded
rgb_ViridisPalette=reinterpret(ColorTypes.RGB24, ViridisPalette)
# == Search functions == # == Search functions ==
function increment_image(current_image, image_list) function increment_image(current_image, image_list)
@ -86,7 +85,7 @@ function loadImgPlot(interfaceImg::String)
name="", name="",
showlegend=false, showlegend=false,
colorscale="Viridis", colorscale="Viridis",
showscale = true, showscale=false,
colorbar=attr( colorbar=attr(
title=attr( title=attr(
text="Intensity", text="Intensity",
@ -272,9 +271,9 @@ end
@in file_route="" @in file_route=""
@in file_name="" @in file_name=""
@in Nmass=0.0 @in Nmass=0.0
@in Tol=0.0 @in Tol=0.1
@in triqProb=0.98 @in triqProb=0.98
@in triqColor=256 @in colorLevel=20
## Interface Buttons ## Interface Buttons
@in btnSearch=false # To search for files in your device @in btnSearch=false # To search for files in your device
@ -475,12 +474,12 @@ end
# Append a query string to force the image to refresh # Append a query string to force the image to refresh
timestamp=string(time_ns()) timestamp=string(time_ns())
if triqEnabled # If we have TrIQ if triqEnabled # If we have TrIQ
if triqColor < 1 || triqColor > 256 ||triqProb < 0 || triqProb > 1 if colorLevel < 2 || colorLevel > 256 ||triqProb < 0.8 || triqProb > 1
msg="Incorrect TrIQ values, please adjust accordingly and try again." msg="Incorrect TrIQ values, please adjust accordingly and try again."
warning_msg=true warning_msg=true
else else
image_path=joinpath("./public", "TrIQ_$(text_nmass).bmp") image_path=joinpath("./public", "TrIQ_$(text_nmass).bmp")
SaveBitmap(joinpath("public", "TrIQ_$(text_nmass).bmp"),TrIQ(slice, Int(triqColor), triqProb),ViridisPalette) SaveBitmap(joinpath("public", "TrIQ_$(text_nmass).bmp"),TrIQ(slice, Int(colorLevel), triqProb),ViridisPalette)
# Flip te image vertically then save it again # Flip te image vertically then save it again
img=load(image_path) img=load(image_path)
if size(img, 1) > size(img, 2) # fix to taller images if size(img, 1) > size(img, 2) # fix to taller images
@ -497,8 +496,12 @@ end
current_triq="TrIQ_$(text_nmass).bmp" current_triq="TrIQ_$(text_nmass).bmp"
msgtriq="TrIQ image with the Nmass of $(replace(text_nmass, "_" => "."))" msgtriq="TrIQ image with the Nmass of $(replace(text_nmass, "_" => "."))"
# Create colorbar # Create colorbar
ticks=round.(range(0, stop=maximum(TrIQ(slice, Int(triqColor), triqProb)), length=10), sigdigits=3) #ticks=round.(range(0, stop=maximum(TrIQ(slice, Int(colorLevel), triqProb)), length=10), sigdigits=3)
Colorbar(fig[1, 1], colormap=rgb_ViridisPalette, limits=(0, maximum(TrIQ(slice, Int(triqColor), triqProb))),ticks=ticks, label="Intensity") #println("ticks: $(round.(range(0, stop=maximum(TrIQ(slice, Int(colorLevel), triqProb)), length=10), sigdigits=3))")
ticks=round.(range(0, (stop=maximum(slice)*triqProb), length=15), sigdigits=3)
#println("ticks 2: $(round.(range(0, (stop=maximum(slice)*triqProb), length=15), sigdigits=3))")
#Colorbar(fig[1, 1], colormap=rgb_ViridisPalette, limits=(0, maximum(TrIQ(slice, Int(colorLevel), triqProb))),ticks=ticks, label="Intensity")
Colorbar(fig[1, 1], colormap=cgrad(:viridis, colorLevel, categorical=true), limits=(0, maximum(slice)*triqProb),ticks=ticks, label="Intensity")
save("public/colorbar_TrIQ_$(text_nmass).png", fig) save("public/colorbar_TrIQ_$(text_nmass).png", fig)
colorbarT="/colorbar_TrIQ_$(text_nmass).png?t=$(timestamp)" colorbarT="/colorbar_TrIQ_$(text_nmass).png?t=$(timestamp)"
# Get current colorbar # Get current colorbar
@ -532,8 +535,10 @@ end
current_msi="MSI_$(text_nmass).bmp" current_msi="MSI_$(text_nmass).bmp"
msgimg="Image with the Nmass of $(replace(text_nmass, "_" => "."))" msgimg="Image with the Nmass of $(replace(text_nmass, "_" => "."))"
# Create colorbar # Create colorbar
ticks=round.(range(0, stop=maximum(slice), length=10), sigdigits=3) #ticks=round.(range(0, stop=maximum(slice), length=10), sigdigits=3)
Colorbar(fig[1, 1], colormap=rgb_ViridisPalette, limits=(0, maximum(slice)),ticks=ticks, label="Intensity") ticks=round.(range(0, stop=maximum(slice), length=15), sigdigits=3)
#Colorbar(fig[1, 1], colormap=rgb_ViridisPalette, limits=(0, maximum(slice)),ticks=ticks, label="Intensity")
Colorbar(fig[1, 1], colormap=cgrad(:viridis, 256, categorical=true), limits=(0, maximum(slice)),ticks=ticks, label="Intensity")
save("public/colorbar_MSI_$(text_nmass).png", fig) save("public/colorbar_MSI_$(text_nmass).png", fig)
colorbar="/colorbar_MSI_$(text_nmass).png?t=$(timestamp)" colorbar="/colorbar_MSI_$(text_nmass).png?t=$(timestamp)"
# Get current colorbar # Get current colorbar

View File

@ -60,10 +60,10 @@
<div class="st-col col-12 col-sm q-ma-sm"> <div class="st-col col-12 col-sm q-ma-sm">
<q-input standout="custom-standout" id="textNmass" step="0.01" v-model="Nmass" <q-input standout="custom-standout" id="textNmass" step="0.01" v-model="Nmass"
label="Mass-to-charge ratio of interest" type="number" label="Mass-to-charge ratio of interest" type="number"
:rules="[ val => !!val || '* Required', val => val >= 0.0 &amp;&amp; val <= 2000.0 || 'Need positive mass values',]"></q-input> :rules="[ val => !!val || '* Required', val => val >= 0.0 || 'Need positive mass values',]"></q-input>
</div> </div>
<div class="st-col col-12 col-sm q-ma-sm"> <div class="st-col col-12 col-sm q-ma-sm">
<q-input standout="custom-standout" id="textTol" step="0.01" v-model="Tol" <q-input standout="custom-standout" id="textTol" step="0.05" v-model="Tol"
label="Mass-to-charge ratio tolerance" type="number" label="Mass-to-charge ratio tolerance" type="number"
:rules="[val => !!val || '* Required', val => val >= 0.0 &amp;&amp; val <= 1.0 || 'Needs to be in range between 0 and 1',]"></q-input> :rules="[val => !!val || '* Required', val => val >= 0.0 &amp;&amp; val <= 1.0 || 'Needs to be in range between 0 and 1',]"></q-input>
</div> </div>
@ -73,19 +73,19 @@
<div class="col-6"> <div class="col-6">
<div class="st-col col-6 col-sm q-ma-sm"> <div class="st-col col-6 col-sm q-ma-sm">
<q-toggle id="btnEnableTriq" v-on:click="triqEnabled" v-model="triqEnabled" color="blue" <q-toggle id="btnEnableTriq" v-on:click="triqEnabled" v-model="triqEnabled" color="blue"
label="Add Threshold Intensity Quantization (TrIQ)!"></q-toggle> label="Add Threshold Intensity Quantization (TrIQ)"></q-toggle>
</div> </div>
<div class="row"> <div class="row">
<div class="st-col col-4 col-sm-4 q-ma-sm"> <div class="st-col col-4 col-sm-4 q-ma-sm">
<q-input standout="custom-standout" id="textTriqProb" step="0.01" v-model="triqProb" <q-input standout="custom-standout" id="textTriqProb" step="0.01" v-model="triqProb"
label="TrIQ probability" type="number" :rules="[ label="TrIQ probability" type="number" :rules="[
val => triqEnabled ? ( '* Required', val >= 0 &amp;&amp; val <= 1 || 'Needs to be in range between 0 and 1') : true val => triqEnabled ? ( '* Required', val >= 0.8 &amp;&amp; val <= 1 || 'Needs to be in range between 0.8 and 1') : true
]" :readonly="!triqEnabled" :disable="!triqEnabled"></q-input> ]" :readonly="!triqEnabled" :disable="!triqEnabled"></q-input>
</div> </div>
<div class="st-col col-4 col-sm-4 q-ma-sm"> <div class="st-col col-4 col-sm-4 q-ma-sm">
<q-input standout="custom-standout" id="textTriqColor" step="1" v-model="triqColor" <q-input standout="custom-standout" id="textcolorLevel" step="1" v-model="colorLevel"
label="TrIQ color levels" type="number" :rules="[ label="TrIQ color levels" type="number" :rules="[
val => triqEnabled ? ( '* Required', val >= 0 &amp;&amp; val <= 256 || 'Needs to be in range between 1 and 256') : true val => triqEnabled ? ( '* Required', val >= 2 &amp;&amp; val <= 256 || 'Needs to be in range between 2 and 256') : true
]" :readonly="!triqEnabled" :disable="!triqEnabled"></q-input> ]" :readonly="!triqEnabled" :disable="!triqEnabled"></q-input>
</div> </div>
</div> </div>