Loading JSON serialised objects#

Note

These docs now use the new_type core objects via the following setting.

import os

# using new types without requiring an explicit argument
os.environ["COGENT3_NEW_TYPE"] = "1"

The load_json app loads JSON serialised cogent3 objects from a file, returning whatever was stored.

In the writing JSON section, we wrote a likelihood function object to disk in JSON serialised format, now let’s load it back! All we need is the path to which it was written. Since write_json writes to a data store, this will be <path_to_dstore>/<identifier>.

Tip

To follow along with this example, first head to the writing JSON section to write out this data, or replace the path with a JSON file on your machine.

from cogent3 import get_app

load_json_app = get_app("load_json")
lf = load_json_app(f"{path_to_dstore}/gn_params.json")
lf

GN

log-likelihood = -6987.9632

number of free parameters = 22

Global params
A>CA>GA>TC>AC>GC>TG>AG>CG>TT>AT>C
0.873.660.911.592.126.028.221.230.631.253.42
Edge params
edgeparentlength
Galagoroot0.17
HowlerMonroot0.04
Rhesusedge.30.02
Orangutanedge.20.01
Gorillaedge.10.00
Humanedge.00.01
Chimpanzeeedge.00.00
edge.0edge.10.00
edge.1edge.20.00
edge.2edge.30.01
edge.3root0.01
Motif params
ACGT
0.380.170.210.24