Skip to content

Commit

Permalink
add Meff field in Alignment - initialize it when compute_weights -
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreBarrat committed Oct 2, 2024
1 parent 2bafe81 commit 22768ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/alignment.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ of `data`. They do not have to be unique, and can be ignored
data::Matrix{T}
alphabet::Union{Nothing, Alphabet{A,T}}
weights::Vector{Float64} = ones(size(data, 2))/size(data, 2) # phylogenetic weights of sequences
Meff::Float64 = size(data, 2)
names::Vector{String} = fill("", size(data, 2))
function Alignment{A,T}(data, alphabet, weights, ::Nothing) where {A, T}
return Alignment{A,T}(data, alphabet, weights, fill("", size(data, 2)))
function Alignment{A,T}(data, alphabet, weights, Meff, ::Nothing) where {A, T}
return Alignment{A,T}(data, alphabet, weights, Meff, fill("", size(data, 2)))
end
function Alignment{A,T}(data, alphabet, weights, names) where {A,T}
function Alignment{A,T}(data, alphabet, weights, Meff, names) where {A,T}
@assert length(names) == length(weights) == size(data, 2) """\
Inconsistent sizes between `data`, `weight` and `names` \
- got $(size(data,2)), $(length(weights)), $(length(names))
Expand All @@ -62,9 +63,10 @@ of `data`. They do not have to be unique, and can be ignored
@assert isapprox(sum(weights), 1; rtol = 1e-8) """
Weights must sum to 1 - got $(sum(weights))
"""
@assert Meff <= size(data, 2) "Effective M larger than number of sequences $(Meff) > $(size(data,2))"

alphabet_copy = isnothing(alphabet) ? nothing : copy(alphabet)
return new{A,T}(Matrix(data), alphabet_copy, copy(weights), string.(names))
return new{A,T}(Matrix(data), alphabet_copy, copy(weights), Meff, string.(names))
end
end

Expand Down
1 change: 1 addition & 0 deletions src/weights.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Compute and set weights for `X`. See `compute_weights`.
function compute_weights!(X, θ = 0.2; kwargs...)
w, Meff = compute_weights(X, θ; kwargs...)
X.weights = w
X.Meff = Meff
return w, Meff
end

Expand Down

0 comments on commit 22768ca

Please sign in to comment.