Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first attempts at writing the serializers for the new types PhylogeneticModel and GroupBasedPhylogeneticModel #4010

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions experimental/AlgebraicStatistics/src/AlgebraicStatistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ include("PhylogeneticModels.jl")
include("PhylogeneticAuxiliary.jl")
include("PhylogeneticParametrization.jl")

include("serialization.jl")

#export models
export cavender_farris_neyman_model
export jukes_cantor_model
Expand Down
58 changes: 58 additions & 0 deletions experimental/AlgebraicStatistics/src/serialization.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
@register_serialization_type PhylogeneticModel uses_params
@register_serialization_type GroupBasedPhylogeneticModel uses_params
antonydellavecchia marked this conversation as resolved.
Show resolved Hide resolved

function save_object(s::SerializerState, pm::PhylogeneticModel)
save_data_dict(s) do
save_object(s, pm.graph, :tree) # already implemented
antonydellavecchia marked this conversation as resolved.
Show resolved Hide resolved
save_object(s, pm.n_states, :states) # already implemented
save_object(s, pm.prob_ring, :probability_ring) # already implemented
save_object(s, pm.root_distr, :root_distribution) # needs to be implemented, or we change the entry type to QQFieldElem
save_object(s, pm.trans_matrices, :transition_matrices) # needs to be implemented

Check warning on line 10 in experimental/AlgebraicStatistics/src/serialization.jl

View check run for this annotation

Codecov / codecov/patch

experimental/AlgebraicStatistics/src/serialization.jl#L4-L10

Added lines #L4 - L10 were not covered by tests
end
end

function save_object(s::SerializerState, pm::GroupBasedPhylogeneticModel)
save_data_dict(s) do
save_object(s,pm.phylo_model,:phylomodel) # details see above
save_object(s, pm.fourier_ring, :fourier_ring) # already implemented
save_object(s,pm.fourier_params,:fourier_params) # needs to be implemented
save_object(s,pm.group,:group) # already implemented

Check warning on line 19 in experimental/AlgebraicStatistics/src/serialization.jl

View check run for this annotation

Codecov / codecov/patch

experimental/AlgebraicStatistics/src/serialization.jl#L14-L19

Added lines #L14 - L19 were not covered by tests
end
end


function load_object(s::DeserializerState, ::Type{<: PhylogeneticModel})
graph = load_object(s, Graph{Directed}, :tree)
n_states = load_object(s, Int64, :states)
prob_ring = load_object(s, QQMPolyRing, :probability_ring)
root_distr = load_object(s, Vector{Any}, :root_distribution)
trans_matrices = load_object(s, Dict{Edge, MatElem{QQMPolyRingElem}}, :trans_matrices)

Check warning on line 29 in experimental/AlgebraicStatistics/src/serialization.jl

View check run for this annotation

Codecov / codecov/patch

experimental/AlgebraicStatistics/src/serialization.jl#L24-L29

Added lines #L24 - L29 were not covered by tests

return PhylogeneticModel(graph, n_states, prob_ring, root_distr, trans_matrices)

Check warning on line 31 in experimental/AlgebraicStatistics/src/serialization.jl

View check run for this annotation

Codecov / codecov/patch

experimental/AlgebraicStatistics/src/serialization.jl#L31

Added line #L31 was not covered by tests
end

function load_object(s::DeserializerState, ::Type{<: GroupBasedPhylogeneticModel})
phylomodel = load_object(s, PhylogeneticModel, :phylomodel)
fourier_ring = load_object(s, QQMPolyRing, :fourier_ring)
fourier_params = load_object(s, Dict{Edge, Vector{QQMPolyRingElem}} , :fourier_params)
group = load_object(s, Vector{FinGenAbGroupElem}, :group)

Check warning on line 38 in experimental/AlgebraicStatistics/src/serialization.jl

View check run for this annotation

Codecov / codecov/patch

experimental/AlgebraicStatistics/src/serialization.jl#L34-L38

Added lines #L34 - L38 were not covered by tests

return GroupBasedPhylogeneticModel(phylomodel, fourier_ring, fourier_params, group)

Check warning on line 40 in experimental/AlgebraicStatistics/src/serialization.jl

View check run for this annotation

Codecov / codecov/patch

experimental/AlgebraicStatistics/src/serialization.jl#L40

Added line #L40 was not covered by tests
end

### Structure of both Types: ###

#= struct PhylogeneticModel
graph::Graph{Directed}
n_states::Int
prob_ring::MPolyRing{QQFieldElem}
root_distr::Vector{Any}
trans_matrices::Dict{Edge, MatElem{QQMPolyRingElem}}
end

struct GroupBasedPhylogeneticModel
phylo_model::PhylogeneticModel
fourier_ring::MPolyRing{QQFieldElem}
fourier_params::Dict{Edge, Vector{QQMPolyRingElem}}
group::Vector{FinGenAbGroupElem}
end =#
Loading