Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine tests and some refactors #22

Merged
merged 5 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ julia = "1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"

[targets]
test = ["Test"]
test = ["Test", "Aqua"]
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/camilogarciabotero/BioMarkovChains.jl/blob/main/LICENSE)
[![Work in Progress](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
[![Downloads](https://shields.io/endpoint?url=https://pkgs.genieframework.com/api/v1/badge/BioMarkovChains&label=downloads)](https://pkgs.genieframework.com?packages=BioMarkovChains)
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)

</div>

Expand Down Expand Up @@ -50,7 +51,7 @@ Let find one ORF in a random `LongDNA` :
using BioSequences, GeneFinder, BioMarkovChains

sequence = randdnaseq(10^3)
orfdna = getorfdna(sequence, min_len=75)[1]
orfdna = get_orfs_dna(sequence, min_len=75)[1]
```

If we translate it, we get a 69aa sequence:
Expand All @@ -71,7 +72,7 @@ BioMarkovChain(orfdna, 2)
```

```
BioMarkovChain with DNAAlphabet{4}() Alphabet:
BioMarkovChain of DNAAlphabet{4}():
- Transition Probability Matrix -> Matrix{Float64}(4 × 4):
0.2123 0.2731 0.278 0.2366
0.2017 0.3072 0.2687 0.2224
Expand All @@ -94,7 +95,7 @@ ECOLICDS
```

```
BioMarkovChain with DNAAlphabet{4}() Alphabet:
BioMarkovChain of DNAAlphabet{4}():
- Transition Probability Matrix -> Matrix{Float64}(4 × 4):
0.31 0.224 0.199 0.268
0.251 0.215 0.313 0.221
Expand Down
4 changes: 2 additions & 2 deletions docs/src/biomarkovchains.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ build a transition model (`BioMarkovChain`):
BioMarkovChain(sequence)
```

BioMarkovChain with DNA Alphabet:
BioMarkovChain of DNAAlphabet{4}():
- Transition Probability Matrix --> Matrix{Float64}(4 × 4):
0.0 1.0 0.0 0.0
0.0 0.5 0.2 0.3
Expand All @@ -149,7 +149,7 @@ the *n-step transition probability matrix* ``\mathscr{M}^{n} = (\mathscr{m}_{ij}
BioMarkovChain(sequence, 2)
```

BioMarkovChain with DNA Alphabet:
BioMarkovChain of DNAAlphabet{4}():
- Transition Probability Matrix --> Matrix{Float64}(4 × 4):
0.0 0.5 0.2 0.3
0.05 0.475 0.325 0.15
Expand Down
3 changes: 3 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<a href="https://github.com/camilogarciabotero/BioMarkovChains.jl/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License"></a>
<a href="https://www.repostatus.org/#wip"><img src="https://www.repostatus.org/badges/latest/wip.svg" alt="Work in Progress"></a>
<a href="https://pkgs.genieframework.com?packages=BioMarkovChains"><img src="https://shields.io/endpoint?url=https://pkgs.genieframework.com/api/v1/badge/BioMarkovChains&label=downloads" alt="Downloads"></a>
<a href="https://github.com/JuliaTesting/Aqua.jl">
<img src="https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg" alt="Aqua QA">
</a>

</div>

Expand Down
17 changes: 9 additions & 8 deletions src/extended.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import Base: show, length, eltype
import Base: show, length, eltype, size
# import StatsAPI: fit!

function Base.show(io::IO, model::BioMarkovChain)
function Base.show(
io::IO,
model::BioMarkovChain
)
# # Print the type name
# println(io, "BioMarkovChain:")

Expand All @@ -10,7 +13,7 @@ function Base.show(io::IO, model::BioMarkovChain)
alphabet_type = eltype(model)

# Print the type name with inferred alphabet type
println(io, "BioMarkovChain with $alphabet_type Alphabet:")
println(io, "BioMarkovChain of $alphabet_type:")

# Print the transition probability matrix
println(io, " - Transition Probability Matrix -> Matrix{Float64}($(size(model.tpm, 1)) × $(size(model.tpm, 2))):")
Expand Down Expand Up @@ -45,11 +48,9 @@ function Base.show(io::IO, model::BioMarkovChain)
println(io, " ", "$(model.n)")
end

Base.length(bmc::BioMarkovChain) = length(bmc.inits)

function Base.eltype(bmc::BioMarkovChain)
return bmc.alphabet
end
@inline Base.length(bmc::BioMarkovChain) = length(bmc.inits)
@inline Base.size(bmc::BioMarkovChain) = size(bmc.tpm)
@inline Base.eltype(bmc::BioMarkovChain) = bmc.alphabet

"""
fit!(bmc::BMC, inits:Vector{Float64}, tpm::Matrix{Float64})
Expand Down
1 change: 0 additions & 1 deletion src/models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const CPGPOS = begin
BMC(DNAAlphabet{4}(), tpm, inits)
end


const CPGNEG = begin
tpm = [
0.300 0.205 0.285 0.210
Expand Down
13 changes: 10 additions & 3 deletions src/perronfrobenius.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,23 @@ n = 2
pf = perronfrobenius(sequence, n)
```
"""
function perronfrobenius(sequence::SeqOrView{A}; n::Int64=1) where A
function perronfrobenius(
sequence::SeqOrView{A};
n::Int64=1
) where {A}
tpm = transition_probability_matrix(sequence, n)
return copy(tpm')
end

function perronfrobenius(bmc::BioMarkovChain)
function perronfrobenius(
bmc::BioMarkovChain
)
return copy(bmc.tpm')
end

function perronfrobenius(tpm::Matrix{Float64})
function perronfrobenius(
tpm::Matrix{Float64}
)
return copy(tpm')
end

Expand Down
10 changes: 10 additions & 0 deletions test/aquatests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@testset "Aqua" begin

Aqua.test_ambiguities(BioMarkovChains)
Aqua.test_persistent_tasks(BioMarkovChains)
Aqua.test_piracies(BioMarkovChains)
Aqua.test_stale_deps(BioMarkovChains)
Aqua.test_unbound_args(BioMarkovChains)
Aqua.test_undefined_exports(BioMarkovChains)

end
6 changes: 6 additions & 0 deletions test/oddstests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@testset "lorm" begin

lorm01 = log_odds_ratio_matrix(CPGPOS, CPGNEG, b=2) # Extracted from the Biological Sequence Analysis: probabilistic models of proteins and nucleic acids, Durbin et al. 1998
@test lorm01 == [-0.7369655941662062 0.4185519834550808 0.5798915111737342 -0.8073549220576043; -0.913064363228719 0.3043934355948513 1.8126298640982785 -0.6838158876474414; -0.6232794322722583 0.4626269577971041 0.3315782649210818 -0.7346554334790053; -1.1638248019058943 0.5708084064112958 0.3951379418411391 -0.6820299186813209]

end
19 changes: 4 additions & 15 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
module BioMarkovChainsTests

using Test
using Aqua
using BioMarkovChains
using BioSequences

@testset "lorm" begin

lorm01 = log_odds_ratio_matrix(CPGPOS, CPGNEG, b=2) # Extracted from the Biological Sequence Analysis: probabilistic models of proteins and nucleic acids, Durbin et al. 1998
lorm01 == [-0.7369655941662062 0.4185519834550808 0.5798915111737342 -0.8073549220576043; -0.913064363228719 0.3043934355948513 1.8126298640982785 -0.6838158876474414; -0.6232794322722583 0.4626269577971041 0.3315782649210818 -0.7346554334790053; -1.1638248019058943 0.5708084064112958 0.3951379418411391 -0.6820299186813209]
end

@testset "tpm" begin
seq01 = dna"CCTCCCGGACCCTGGGCTCGGGAC"
tpm01 = transition_probability_matrix(seq01)
@test round.(tpm01, digits = 3) == [0.0 1.0 0.0 0.0; 0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0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0]
end
include("tpmtests.jl")
include("oddstests.jl")
include("aquatests.jl")

end
11 changes: 11 additions & 0 deletions test/tpmtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@testset "tpm" begin

seq01 = dna"CCTCCCGGACCCTGGGCTCGGGAC"
tpm01 = transition_probability_matrix(seq01)
@test round.(tpm01, digits = 3) == [0.0 1.0 0.0 0.0; 0.0 0.5 0.2 0.3; 0.25 0.125 0.625 0.0; 0.0 0.667 0.333 0.0]

seq02 = aa"ACDEFGHIKLMNPQRSTVWY"
tpm02 = transition_probability_matrix(seq02)
@test round.(tpm02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