Skip to content

Commit 0397c3e

Browse files
author
Hiroaki Imoto
authored
Release v0.7.1 (#48)
* Enable calling run_simulation() * Bump version to 0.7.1
1 parent 7c0ba30 commit 0397c3e

File tree

2 files changed

+83
-86
lines changed

2 files changed

+83
-86
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BioMASS"
22
uuid = "324734c7-f323-4536-9335-775d9be9d101"
33
authors = ["Hiroaki Imoto <himoto@protein.osaka-u.ac.jp>"]
4-
version = "0.7.0"
4+
version = "0.7.1"
55

66
[deps]
77
CMAEvolutionStrategy = "8d3b24bd-414e-49e0-94fb-163cc3a3e411"

src/visulalize.jl

Lines changed: 82 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -351,106 +351,103 @@ function plot_timecourse(
351351
end
352352
end
353353

354-
if isinstalled("matplotlib")
355-
function run_simulation(
356-
model::Model;
357-
viz_type::String="original",
358-
show_all::Bool=false,
359-
stdev::Bool=false,
360-
save_format::String="pdf")
361-
if !isdir(
354+
355+
function run_simulation(
356+
model::Model;
357+
viz_type::String="original",
358+
show_all::Bool=false,
359+
stdev::Bool=false,
360+
save_format::String="pdf")
361+
if !isdir(
362+
joinpath(
363+
model.path,
364+
"figure"
365+
)
366+
)
367+
mkdir(
362368
joinpath(
363369
model.path,
364370
"figure"
365371
)
366372
)
367-
mkdir(
368-
joinpath(
369-
model.path,
370-
"figure"
371-
)
372-
)
373-
end
373+
end
374374

375-
if !(viz_type in ["best", "average", "original", "experiment"])
376-
try
377-
parse(Int64, viz_type)
378-
catch
379-
error(
380-
"Avairable viz_type are: 'best','average','original','experiment','n(=1,2,...)'"
381-
)
382-
end
375+
if !(viz_type in ["best", "average", "original", "experiment"])
376+
try
377+
parse(Int64, viz_type)
378+
catch
379+
error(
380+
"Avairable viz_type are: 'best','average','original','experiment','n(=1,2,...)'"
381+
)
383382
end
383+
end
384384

385-
n_file::Vector{Int} = viz_type in ["original", "experiment"] ? [] : get_executable(model)
385+
n_file::Vector{Int} = viz_type in ["original", "experiment"] ? [] : get_executable(model)
386386

387-
simulaitons_all::Array{Float64,4} = fill(
388-
NaN,
389-
(
390-
length(model.observables),
391-
length(n_file),
392-
length(model.sim.conditions),
393-
length(model.sim.t),
394-
)
387+
simulaitons_all::Array{Float64,4} = fill(
388+
NaN,
389+
(
390+
length(model.observables),
391+
length(n_file),
392+
length(model.sim.conditions),
393+
length(model.sim.t),
395394
)
396-
if viz_type != "experiment"
397-
if length(n_file) > 0
398-
if length(n_file) == 1 && viz_type == "average"
399-
error("viz_type should be best, not $viz_type")
400-
end
401-
for (j, nth_param_set) in enumerate(n_file)
402-
(model, is_successful) = validate!(model, nth_param_set)
403-
if is_successful
404-
for i in eachindex(model.observables)
405-
@inbounds simulaitons_all[i, j, :, :] = model.sim.simulations[i, :, :]
406-
end
407-
end
408-
end
409-
best_fitness_all::Vector{Float64} = fill(Inf, length(n_file))
410-
for (i, nth_param_set) in enumerate(n_file)
411-
local filepath = joinpath(
412-
model.path,
413-
"fitparam",
414-
"$nth_param_set",
415-
"best_fitness",
416-
)
417-
if isfile(filepath * ".dat")
418-
best_fitness_all[i] = readdlm(
419-
filepath * ".dat"
420-
)[1, 1]
421-
elseif isfile(filepath * ".npy")
422-
best_fitness_all[i] = numpy_load(
423-
filepath * ".npy"
424-
)[1, 1]
395+
)
396+
if viz_type != "experiment"
397+
if length(n_file) > 0
398+
if length(n_file) == 1 && viz_type == "average"
399+
error("viz_type should be best, not $viz_type")
400+
end
401+
for (j, nth_param_set) in enumerate(n_file)
402+
(model, is_successful) = validate!(model, nth_param_set)
403+
if is_successful
404+
for i in eachindex(model.observables)
405+
@inbounds simulaitons_all[i, j, :, :] = model.sim.simulations[i, :, :]
425406
end
426407
end
427-
best_param_set::Int = n_file[argmin(best_fitness_all)]
428-
if viz_type == "best"
429-
model, _ = validate!(model, best_param_set)
430-
elseif viz_type != "average" && parse(Int64, viz_type) <= length(n_file)
431-
model, _ = validate!(model, parse(Int64, viz_type))
432-
elseif viz_type != "average" && parse(Int64, viz_type) > length(n_file)
433-
error(
434-
@sprintf(
435-
"n (%d) must be smaller than n_fitparam (%d)",
436-
parse(Int64, viz_type), length(n_file)
437-
)
438-
)
408+
end
409+
best_fitness_all::Vector{Float64} = fill(Inf, length(n_file))
410+
for (i, nth_param_set) in enumerate(n_file)
411+
local filepath = joinpath(
412+
model.path,
413+
"fitparam",
414+
"$nth_param_set",
415+
"best_fitness",
416+
)
417+
if isfile(filepath * ".dat")
418+
best_fitness_all[i] = readdlm(
419+
filepath * ".dat"
420+
)[1, 1]
421+
elseif isfile(filepath * ".npy")
422+
best_fitness_all[i] = numpy_load(
423+
filepath * ".npy"
424+
)[1, 1]
439425
end
440-
else
441-
p::Vector{Float64} = param_values()
442-
u0::Vector{Float64} = initial_values()
443-
if model.sim.simulate!(p, u0) !== nothing
444-
error(
445-
"Simulation failed."
426+
end
427+
best_param_set::Int = n_file[argmin(best_fitness_all)]
428+
if viz_type == "best"
429+
model, _ = validate!(model, best_param_set)
430+
elseif viz_type != "average" && parse(Int64, viz_type) <= length(n_file)
431+
model, _ = validate!(model, parse(Int64, viz_type))
432+
elseif viz_type != "average" && parse(Int64, viz_type) > length(n_file)
433+
error(
434+
@sprintf(
435+
"n (%d) must be smaller than n_fitparam (%d)",
436+
parse(Int64, viz_type), length(n_file)
446437
)
447-
end
438+
)
439+
end
440+
else
441+
p::Vector{Float64} = param_values()
442+
u0::Vector{Float64} = initial_values()
443+
if model.sim.simulate!(p, u0) !== nothing
444+
error(
445+
"Simulation failed."
446+
)
448447
end
449448
end
450-
plot_timecourse(
451-
model, n_file, viz_type, show_all, stdev, simulaitons_all, save_format
452-
)
453449
end
454-
else
455-
println("run_simulation requires matplotlib.")
450+
plot_timecourse(
451+
model, n_file, viz_type, show_all, stdev, simulaitons_all, save_format
452+
)
456453
end

0 commit comments

Comments
 (0)