Skip to content

Commit 27f1539

Browse files
authored
Merge pull request #26 from nossleinad/message-type-declaration
Be consistent with message type declaration
2 parents 8a8c9b0 + 42e0a35 commit 27f1539

File tree

6 files changed

+42
-20
lines changed

6 files changed

+42
-20
lines changed

src/core/algorithms/ancestors.jl

+11-11
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function depth_first_reconstruction(
2929
run_fel_up = true,
3030
run_fel_down = true,
3131
partition_list = 1:length(tree.message),
32-
node_message_dict = Dict{FelNode,Vector{Partition}}(),
32+
node_message_dict = Dict{FelNode,Vector{<:Partition}}(),
3333
)
3434
if run_fel_up
3535
felsenstein!(tree, model_func, partition_list = partition_list)
@@ -56,7 +56,7 @@ function depth_first_reconstruction(
5656
run_fel_up = true,
5757
run_fel_down = true,
5858
partition_list = 1:length(tree.message),
59-
node_message_dict = Dict{FelNode,Vector{Partition}}(),
59+
node_message_dict = Dict{FelNode,Vector{<:Partition}}(),
6060
)
6161
depth_first_reconstruction(
6262
tree,
@@ -76,7 +76,7 @@ function depth_first_reconstruction(
7676
run_fel_up = true,
7777
run_fel_down = true,
7878
partition_list = 1:length(tree.message),
79-
node_message_dict = Dict{FelNode,Vector{Partition}}(),
79+
node_message_dict = Dict{FelNode,Vector{<:Partition}}(),
8080
)
8181
depth_first_reconstruction(
8282
tree,
@@ -91,7 +91,7 @@ end
9191

9292
#For marginal reconstructions
9393
function reconstruct_marginal_node!(
94-
node_message_dict::Dict{FelNode,Vector{Partition}},
94+
node_message_dict::Dict{FelNode,Vector{<:Partition}},
9595
node::FelNode,
9696
model_array::Vector{<:BranchModel},
9797
partition_list,
@@ -109,7 +109,7 @@ end
109109

110110
export marginal_state_dict
111111
"""
112-
marginal_state_dict(tree::FelNode, model; partition_list = 1:length(tree.message), node_message_dict = Dict{FelNode,Vector{Partition}}())
112+
marginal_state_dict(tree::FelNode, model; partition_list = 1:length(tree.message), node_message_dict = Dict{FelNode,Vector{<:Partition}}())
113113
114114
Takes in a tree and a model (which can be a single model, an array of models, or a function that maps FelNode->Array{<:BranchModel}), and
115115
returns a dictionary mapping nodes to their marginal reconstructions (ie. P(state|all observations,model)). A subset of partitions can be specified by partition_list,
@@ -119,7 +119,7 @@ function marginal_state_dict(
119119
tree::FelNode,
120120
model;
121121
partition_list = 1:length(tree.message),
122-
node_message_dict = Dict{FelNode,Vector{Partition}}(),
122+
node_message_dict = Dict{FelNode,Vector{<:Partition}}(),
123123
)
124124
return depth_first_reconstruction(
125125
tree,
@@ -133,7 +133,7 @@ end
133133
#For joint max reconstructions
134134
export dependent_reconstruction!
135135
function dependent_reconstruction!(
136-
node_message_dict::Dict{FelNode,Vector{Partition}},
136+
node_message_dict::Dict{FelNode,Vector{<:Partition}},
137137
node::FelNode,
138138
model_array::Vector{<:BranchModel},
139139
partition_list;
@@ -173,7 +173,7 @@ reconstruct_cascading_max_node!(node_message_dict, node, model_array, partition_
173173
)
174174
export cascading_max_state_dict
175175
"""
176-
cascading_max_state_dict(tree::FelNode, model; partition_list = 1:length(tree.message), node_message_dict = Dict{FelNode,Vector{Partition}}())
176+
cascading_max_state_dict(tree::FelNode, model; partition_list = 1:length(tree.message), node_message_dict = Dict{FelNode,Vector{<:Partition}}())
177177
178178
Takes in a tree and a model (which can be a single model, an array of models, or a function that maps FelNode->Array{<:BranchModel}), and
179179
returns a dictionary mapping nodes to their inferred ancestors under the following scheme: the state that maximizes the marginal likelihood is selected at the root,
@@ -184,7 +184,7 @@ function cascading_max_state_dict(
184184
tree::FelNode,
185185
model;
186186
partition_list = 1:length(tree.message),
187-
node_message_dict = Dict{FelNode,Vector{Partition}}(),
187+
node_message_dict = Dict{FelNode,Vector{<:Partition}}(),
188188
)
189189
return depth_first_reconstruction(
190190
tree,
@@ -206,7 +206,7 @@ conditioned_sample_node!(node_message_dict, node, model_array, partition_list) =
206206
)
207207
export endpoint_conditioned_sample_state_dict
208208
"""
209-
endpoint_conditioned_sample_state_dict(tree::FelNode, model; partition_list = 1:length(tree.message), node_message_dict = Dict{FelNode,Vector{Partition}}())
209+
endpoint_conditioned_sample_state_dict(tree::FelNode, model; partition_list = 1:length(tree.message), node_message_dict = Dict{FelNode,Vector{<:Partition}}())
210210
211211
Takes in a tree and a model (which can be a single model, an array of models, or a function that maps FelNode->Array{<:BranchModel}), and draws samples under the model
212212
conditions on the leaf observations. These samples are stored in the node_message_dict, which is returned. A subset of partitions can be specified by partition_list, and a
@@ -216,7 +216,7 @@ function endpoint_conditioned_sample_state_dict(
216216
tree::FelNode,
217217
model;
218218
partition_list = 1:length(tree.message),
219-
node_message_dict = Dict{FelNode,Vector{Partition}}(),
219+
node_message_dict = Dict{FelNode,Vector{<:Partition}}(),
220220
)
221221
return depth_first_reconstruction(
222222
tree,

src/core/algorithms/branchlength_optim.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#Model list should be a list of P matrices.
22
function branch_LL_up(
33
bl::Real,
4-
temp_message::Vector{Partition},
4+
temp_message::Vector{<:Partition},
55
node::FelNode,
66
model_list::Vector{<:BranchModel},
77
partition_list,
@@ -22,8 +22,8 @@ end
2222
#I need to add a version of this that takes a generic optimizer function and uses that instead of golden_section_maximize on just the branchlength.
2323
#This is for cases where the user stores node-level parameters and wants to optimize them.
2424
function branchlength_optim!(
25-
temp_message::Vector{Partition},
26-
message_to_set::Vector{Partition},
25+
temp_message::Vector{<:Partition},
26+
message_to_set::Vector{<:Partition},
2727
node::FelNode,
2828
models,
2929
partition_list,

src/core/algorithms/nni_optim.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22

33
function nni_optim!(
4-
temp_message::Vector{Partition},
5-
message_to_set::Vector{Partition},
4+
temp_message::Vector{<:Partition},
5+
message_to_set::Vector{<:Partition},
66
node::FelNode,
77
models,
88
partition_list;
@@ -72,8 +72,8 @@ end
7272

7373
#Unsure if this is the best choice to handle the model,models, and model_func stuff.
7474
function nni_optim!(
75-
temp_message::Vector{Partition},
76-
message_to_set::Vector{Partition},
75+
temp_message::Vector{<:Partition},
76+
message_to_set::Vector{<:Partition},
7777
node::FelNode,
7878
models::Vector{<:BranchModel},
7979
partition_list;
@@ -89,8 +89,8 @@ function nni_optim!(
8989
)
9090
end
9191
function nni_optim!(
92-
temp_message::Vector{Partition},
93-
message_to_set::Vector{Partition},
92+
temp_message::Vector{<:Partition},
93+
message_to_set::Vector{<:Partition},
9494
node::FelNode,
9595
model::BranchModel,
9696
partition_list;

src/models/models.jl

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function partition_from_template(partition_template::T) where {T <: DiscretePart
4848
end
4949
=#
5050

51+
#Note: not enforcing a return type causes some unnecesarry conversions
5152
copy_message(msg::Vector{<:Partition}) = [copy_partition(x) for x in msg]
5253

5354
#This is a function shared for all models - perhaps move this elsewhere

test/message_type_stability.jl

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
begin
2+
# Single partition example
3+
tree = sim_tree(n = 10)
4+
GAA_partition = GappyAminoAcidPartition(5)
5+
AA_freqs = [1 / GAA_partition.states for _ = 1:GAA_partition.states]
6+
GAA_partition.state .= AA_freqs
7+
internal_message_init!(tree, GAA_partition)
8+
Q = gappy_Q_from_symmetric_rate_matrix(WAGmatrix, 1.0, AA_freqs)
9+
model = DiagonalizedCTMC(Q)
10+
sample_down!(tree, model)
11+
felsenstein!(tree, model)
12+
13+
# These would previously break since Vector{GappyAminoAcidPartition} is not <: Vector{Partition}, for example.
14+
branchlength_optim!(tree, model)
15+
marginal_state_dict(tree, model)
16+
nni_optim!(tree, model)
17+
end

test/runtests.jl

+4
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ using Test
2626
include("partition_selection.jl")
2727
end
2828

29+
@testset "message_type_stability" begin
30+
include("message_type_stability.jl")
31+
end
32+
2933
end

0 commit comments

Comments
 (0)