Skip to content

Commit

Permalink
add outer testset to all tests, so we see all errors
Browse files Browse the repository at this point in the history
  • Loading branch information
marcom committed Nov 30, 2022
1 parent 213f34c commit aef333f
Showing 1 changed file with 138 additions and 135 deletions.
273 changes: 138 additions & 135 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,163 +46,129 @@ function gen_kwargs(; use_beamsize=true)
end


@testset "energy" begin
redirect_stdio(stdout=devnull) do
for kwargs in gen_kwargs(use_beamsize=false)
@test energy("GGGAAACCC", "(((...)))"; kwargs...) isa Unitful.Quantity
end
end
end
@testset verbose=true "LinearFold tests" begin

@testset "mfe" begin
seq = "GGGAAACCC"
con = ".?(.??)??"
redirect_stdio(stdout=devnull) do
for kwargs in gen_kwargs()
dG, structure = mfe(seq; kwargs...)
@test dG isa Unitful.Quantity
@test length(structure) == length(seq)

dG, structure = mfe(seq; constraints=con, kwargs...)
@test dG isa Unitful.Quantity
@test length(structure) == length(seq)
@testset "energy" begin
redirect_stdio(stdout=devnull) do
for kwargs in gen_kwargs(use_beamsize=false)
@test energy("GGGAAACCC", "(((...)))"; kwargs...) isa Unitful.Quantity
end
end
end
end

@testset "zuker_subopt" begin
seq = "GGGGGGAAAACCCCCAAAGGGGAAAAACCCCCAAAGGGGG"

redirect_stdio(stdout=devnull) do
for kwargs in gen_kwargs()
n = length(seq)
subopts = zuker_subopt(seq; kwargs...)
@test length(subopts) > 0
@test subopts isa Vector{Tuple{typeof(1.0u"kcal/mol"),String}}
@test all(x -> length(x[2]) == n, subopts)

subopts = zuker_subopt(seq; delta=10u"kcal/mol", kwargs...)
@test length(subopts) > 0
@test subopts isa Vector{Tuple{typeof(1.0u"kcal/mol"),String}}
@test all(x -> length(x[2]) == n, subopts)
@testset "mfe" begin
seq = "GGGAAACCC"
con = ".?(.??)??"
redirect_stdio(stdout=devnull) do
for kwargs in gen_kwargs()
dG, structure = mfe(seq; kwargs...)
@test dG isa Unitful.Quantity
@test length(structure) == length(seq)

dG, structure = mfe(seq; constraints=con, kwargs...)
@test dG isa Unitful.Quantity
@test length(structure) == length(seq)
end
end
end
end

@testset "partfn" begin
seq = "GGGAAACCC"
redirect_stdio(stdout=devnull) do
for kwargs in gen_kwargs()
dG = partfn(seq; kwargs...)
@test dG isa Unitful.Quantity
@testset "zuker_subopt" begin
seq = "GGGGGGAAAACCCCCAAAGGGGAAAAACCCCCAAAGGGGG"

redirect_stdio(stdout=devnull) do
for kwargs in gen_kwargs()
n = length(seq)
subopts = zuker_subopt(seq; kwargs...)
@test length(subopts) > 0
@test subopts isa Vector{Tuple{typeof(1.0u"kcal/mol"),String}}
@test all(x -> length(x[2]) == n, subopts)

subopts = zuker_subopt(seq; delta=10u"kcal/mol", kwargs...)
@test length(subopts) > 0
@test subopts isa Vector{Tuple{typeof(1.0u"kcal/mol"),String}}
@test all(x -> length(x[2]) == n, subopts)
end
end
end
end

@testset "bpp" begin
seq = "GGGAAACCC"
n = length(seq)

redirect_stdio(stdout=devnull) do
for kwargs in gen_kwargs()
dG, p = bpp(seq; kwargs...)
@test dG isa Unitful.Quantity
@test eltype(p) <: AbstractFloat
@test axes(p) == (1:n, 1:n)
@test all(x -> 0.0 <= x <= 1.0, p)

dG, p = bpp(seq; bpp_cutoff=0.2, kwargs...)
@test dG isa Unitful.Quantity
@test eltype(p) <: AbstractFloat
@test axes(p) == (1:n, 1:n)
@test all(x -> 0.0 <= x <= 1.0, p)
@testset "partfn" begin
seq = "GGGAAACCC"
redirect_stdio(stdout=devnull) do
for kwargs in gen_kwargs()
dG = partfn(seq; kwargs...)
@test dG isa Unitful.Quantity
end
end
end
end

@testset "mea" begin
seq = "GGGAAAACCCC"

redirect_stdio(stdout=devnull) do
for kwargs in gen_kwargs()
dG, structure = mea(seq; kwargs...)
@test dG isa Unitful.Quantity
@test length(structure) == length(seq)
@testset "bpp" begin
seq = "GGGAAACCC"
n = length(seq)

dG, structure = mea(seq; gamma=2.0, kwargs...)
@test dG isa Unitful.Quantity
@test length(structure) == length(seq)
redirect_stdio(stdout=devnull) do
for kwargs in gen_kwargs()
dG, p = bpp(seq; kwargs...)
@test dG isa Unitful.Quantity
@test eltype(p) <: AbstractFloat
@test axes(p) == (1:n, 1:n)
@test all(x -> 0.0 <= x <= 1.0, p)

dG, p = bpp(seq; bpp_cutoff=0.2, kwargs...)
@test dG isa Unitful.Quantity
@test eltype(p) <: AbstractFloat
@test axes(p) == (1:n, 1:n)
@test all(x -> 0.0 <= x <= 1.0, p)
end
end
end
end

@testset "threshknot" begin
seq = "GGGGAAAACCCC"
n = length(seq)

redirect_stdio(stdout=devnull) do
for kwargs in gen_kwargs()
dG, pt = threshknot(seq; kwargs...)
@test dG isa Unitful.Quantity
@test length(pt) == length(seq)
@test eltype(pt) == Int
@test all(i -> 0 <= i <= n, pt)

dG, pt = threshknot(seq; threshold=0.2, kwargs...)
@test dG isa Unitful.Quantity
@test length(pt) == length(seq)
@test eltype(pt) == Int
@test all(i -> 0 <= i <= n, pt)
end
end
end
@testset "mea" begin
seq = "GGGAAAACCCC"

@testset "sample_structures" begin
seq = "GGGAAACC"
nsamples = 20

for opts in Iterators.product(
[nothing, 50],
[nothing, true, false],
[nothing, true, false],
[nothing, true, false])
optnames = [:beamsize, :is_nonsaving, :is_sharpturn, :verbose]
kwargs = NamedTuple()
for (i, name) in enumerate(optnames)
val = opts[i]
if !isnothing(val)
kwargs = NamedTuple((pairs(kwargs)..., name => val))
redirect_stdio(stdout=devnull) do
for kwargs in gen_kwargs()
dG, structure = mea(seq; kwargs...)
@test dG isa Unitful.Quantity
@test length(structure) == length(seq)

dG, structure = mea(seq; gamma=2.0, kwargs...)
@test dG isa Unitful.Quantity
@test length(structure) == length(seq)
end
end
end

@testset "threshknot" begin
seq = "GGGGAAAACCCC"
n = length(seq)

redirect_stdio(stdout=devnull) do
n = length(seq)
samples = sample_structures(seq; kwargs...)
@test length(samples) == 10
@test all(s -> length(s) == n, samples)

samples = sample_structures(seq; num_samples=nsamples, kwargs...)
@test length(samples) == nsamples
@test all(s -> length(s) == n, samples)
for kwargs in gen_kwargs()
dG, pt = threshknot(seq; kwargs...)
@test dG isa Unitful.Quantity
@test length(pt) == length(seq)
@test eltype(pt) == Int
@test all(i -> 0 <= i <= n, pt)

dG, pt = threshknot(seq; threshold=0.2, kwargs...)
@test dG isa Unitful.Quantity
@test length(pt) == length(seq)
@test eltype(pt) == Int
@test all(i -> 0 <= i <= n, pt)
end
end
end
end

@testset "sample_structures" begin
seq = "GGGAAACC"
nsamples = 20

@testset "turbofold" begin
for seqs in [
["GGGAAACC", "GCGAAAAAACGCA"],
["GGGAAACC", "GCGAAAAAACGCA", "CCCCUUUUUGGGGG"]]
for opts in Iterators.product(
[nothing, 50],
[nothing, 50],
[nothing, 2],
[nothing, 4],
[nothing, 2],
[nothing, 0.2],
[nothing, true, false],
[nothing, true, false],
[nothing, true, false])
optnames = [:beamsize_hmm, :beamsize_cky, :iterations,
:threshknot_min_helix_len, :threshknot_iterations, :threshknot_threshold,
:verbose]
optnames = [:beamsize, :is_nonsaving, :is_sharpturn, :verbose]
kwargs = NamedTuple()
for (i, name) in enumerate(optnames)
val = opts[i]
Expand All @@ -211,13 +177,50 @@ end
end
end
redirect_stdio(stdout=devnull) do
msa, pts = turbofold(seqs; kwargs...)
@test msa isa Vector{FASTA.Record}
@test pts isa Vector{Vector{Int}}
@test length(msa) == length(seqs)
@test length(pts) == length(seqs)
@test length.(pts) == length.(seqs)
n = length(seq)
samples = sample_structures(seq; kwargs...)
@test length(samples) == 10
@test all(s -> length(s) == n, samples)

samples = sample_structures(seq; num_samples=nsamples, kwargs...)
@test length(samples) == nsamples
@test all(s -> length(s) == n, samples)
end
end
end

@testset "turbofold" begin
for seqs in [
["GGGAAACC", "GCGAAAAAACGCA"],
["GGGAAACC", "GCGAAAAAACGCA", "CCCCUUUUUGGGGG"]]
for opts in Iterators.product(
[nothing, 50],
[nothing, 50],
[nothing, 2],
[nothing, 4],
[nothing, 2],
[nothing, 0.2],
[nothing, true, false])
optnames = [:beamsize_hmm, :beamsize_cky, :iterations,
:threshknot_min_helix_len, :threshknot_iterations, :threshknot_threshold,
:verbose]
kwargs = NamedTuple()
for (i, name) in enumerate(optnames)
val = opts[i]
if !isnothing(val)
kwargs = NamedTuple((pairs(kwargs)..., name => val))
end
end
redirect_stdio(stdout=devnull) do
msa, pts = turbofold(seqs; kwargs...)
@test msa isa Vector{FASTA.Record}
@test pts isa Vector{Vector{Int}}
@test length(msa) == length(seqs)
@test length(pts) == length(seqs)
@test length.(pts) == length.(seqs)
end
end
end
end

end

0 comments on commit aef333f

Please sign in to comment.