Skip to content

Commit

Permalink
Merge pull request #20 from nossleinad/fix_obs2partition!
Browse files Browse the repository at this point in the history
Fix issue #19
  • Loading branch information
murrellb authored May 16, 2024
2 parents af0b4ed + 9788e60 commit 6d25159
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
11 changes: 6 additions & 5 deletions src/models/discrete_models/codon_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 12 additions & 10 deletions src/models/discrete_models/utils/seq_to_vec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6d25159

Please sign in to comment.