From 9788e60dbc2b5518a33e46f35fd928150111aed7 Mon Sep 17 00:00:00 2001 From: Maximilian Danielsson Date: Fri, 26 Apr 2024 17:55:36 +0200 Subject: [PATCH] Fix issue --- src/models/discrete_models/codon_models.jl | 11 +++++----- .../discrete_models/utils/seq_to_vec.jl | 22 ++++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/models/discrete_models/codon_models.jl b/src/models/discrete_models/codon_models.jl index 4e058fa..7cc3d82 100644 --- a/src/models/discrete_models/codon_models.jl +++ b/src/models/discrete_models/codon_models.jl @@ -341,17 +341,18 @@ function obs2partition!(dest::CodonPartition, seq::String; code = universal_code error("Sequence length does not match partition") end - for i = 1:Int(length(seq) / 3) - c = seq[3*(i-1)+1:3*(i-1)+3] + @views for j in axes(dest.state, 2) + c = seq[3*(j-1)+1:3*(j-1)+3] cod_ind = get(code.string2sense, c, -1) if cod_ind == -1 - dest.state[:, i] = ones(eltype(dest.state), dest.states) + fill!(dest.state[:, j], 1.0) push!(problem_codons, c) else - dest.state[:, i] = zeros(eltype(dest.state), dest.states) - dest.state[cod_ind, i] = 1.0 + fill!(dest.state[:, j], 0.0) + dest.state[cod_ind, j] = 1.0 end end + fill!(dest.scaling, 0.0) return countmap(problem_codons) end diff --git a/src/models/discrete_models/utils/seq_to_vec.jl b/src/models/discrete_models/utils/seq_to_vec.jl index 99ef2ec..91195da 100644 --- a/src/models/discrete_models/utils/seq_to_vec.jl +++ b/src/models/discrete_models/utils/seq_to_vec.jl @@ -94,18 +94,20 @@ end -#Creates new memory. This is currently required for the populate_tree function to do things automatically. function obs2partition!(dest::DiscretePartition, seq::String, dic::Dict) - #if length(seq) != dest.sites - # @warn "obs2partition!() is changing the number of sites in a partition." - #end - dest.state = zeros(eltype(dest.state), dest.states, length(seq)) - dest.sites = length(seq) - dest.scaling = zeros(length(seq)) - unmatched = ones(eltype(dest.state), dest.states) - for (i, c) in enumerate(uppercase(seq)) - dest.state[:, i] = get(dic, c, unmatched) + if length(seq) != dest.sites + error("Sequence length does not match partition") end + + @views for j in axes(dest.state, 2) + value = get(dic, uppercase(seq[j]), -1) + if value == -1 + fill!(dest.state[:, j], 1.0) + else + dest.state[:, j] .= value + end + end + fill!(dest.scaling, 0.0) end function obs2partition!(dest::NucleotidePartition, seq::String) obs2partition!(dest, seq, nuc_dict)