Writing JSON Serialised Objects¶
Using JSON, we can serialise cogent3
objects to a file for easy storage and retrieval.
Create an example object to serialise¶
Let’s create a LikelihoodFunction
object to use in this example. It is generated from fitting the General Nucleotide (GN) model to an alignment of BRCA1 in primates.
write_json
- writing JSON-serialised object to file¶
Using the write_json
app, we can write out the likelihood function as a JSON-serialised object, making it easy to retrieve the model parameters for future reference if required.
We need to provide the write_json
app with a data store to which it will write. Optionally when we apply the app we can specify an identifier for the data, which will name the file.
Note
Learn how to load a JSON serialised object in the loading JSON serialised objects section!
Tip
When running this code on your machine, remember to replace path_to_dir
with an actual directory path.