Skip to content

Commit 6d25159

Browse files
authored
Merge pull request #20 from nossleinad/fix_obs2partition!
Fix issue #19
2 parents af0b4ed + 9788e60 commit 6d25159

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/models/discrete_models/codon_models.jl

+6-5
Original file line numberDiff line numberDiff line change
@@ -341,17 +341,18 @@ function obs2partition!(dest::CodonPartition, seq::String; code = universal_code
341341
error("Sequence length does not match partition")
342342
end
343343

344-
for i = 1:Int(length(seq) / 3)
345-
c = seq[3*(i-1)+1:3*(i-1)+3]
344+
@views for j in axes(dest.state, 2)
345+
c = seq[3*(j-1)+1:3*(j-1)+3]
346346
cod_ind = get(code.string2sense, c, -1)
347347
if cod_ind == -1
348-
dest.state[:, i] = ones(eltype(dest.state), dest.states)
348+
fill!(dest.state[:, j], 1.0)
349349
push!(problem_codons, c)
350350
else
351-
dest.state[:, i] = zeros(eltype(dest.state), dest.states)
352-
dest.state[cod_ind, i] = 1.0
351+
fill!(dest.state[:, j], 0.0)
352+
dest.state[cod_ind, j] = 1.0
353353
end
354354
end
355+
fill!(dest.scaling, 0.0)
355356
return countmap(problem_codons)
356357
end
357358

src/models/discrete_models/utils/seq_to_vec.jl

+12-10
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,20 @@ end
9494

9595

9696

97-
#Creates new memory. This is currently required for the populate_tree function to do things automatically.
9897
function obs2partition!(dest::DiscretePartition, seq::String, dic::Dict)
99-
#if length(seq) != dest.sites
100-
# @warn "obs2partition!() is changing the number of sites in a partition."
101-
#end
102-
dest.state = zeros(eltype(dest.state), dest.states, length(seq))
103-
dest.sites = length(seq)
104-
dest.scaling = zeros(length(seq))
105-
unmatched = ones(eltype(dest.state), dest.states)
106-
for (i, c) in enumerate(uppercase(seq))
107-
dest.state[:, i] = get(dic, c, unmatched)
98+
if length(seq) != dest.sites
99+
error("Sequence length does not match partition")
108100
end
101+
102+
@views for j in axes(dest.state, 2)
103+
value = get(dic, uppercase(seq[j]), -1)
104+
if value == -1
105+
fill!(dest.state[:, j], 1.0)
106+
else
107+
dest.state[:, j] .= value
108+
end
109+
end
110+
fill!(dest.scaling, 0.0)
109111
end
110112
function obs2partition!(dest::NucleotidePartition, seq::String)
111113
obs2partition!(dest, seq, nuc_dict)

0 commit comments

Comments
 (0)