<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Input & Output
MEANS package provides a set of routines for serialisation (saving) and deserialisation (loading) of the MEANS-specific objects into human-readable YAML format.
These routines all reside inside means.io package, which is imported by default from the package root.
This tutorial will quickly how to include them in your workflow.
First, let's import the means package together with the example models
Step1:  Let's use a $p53$ model as an example object for serialisation.
Step2:  Human-Readable Serialisation
The serialisation to string is done via means.io.dump(object) function that takes any serialisable object as it's argument
Step3:  Note how this format is equally easy for both humans and machines to read. 
This is double readability is the main reason why YAML format has been chosen to serialise MEANS objects.
Deserialisation can be done by via means.io.load(serialised_string) function, as shown below
Step4:  Since most of the serialisation will be done to and from files, MEANS provides a set of convenience functions for performing these, 
namely to_file and from_file functions
Step5:  The serialisation functions dump, and to_file can handle lists of items equally well, for instance, we could try to serialise both $p53$ model and $Hes1$ model at the same time
Step6:  The form of items being serialisied is completely free (you can serialise anything using these routines). 
However, some objects may not be as human-readable when serialised as MEANS ones are, so some care needs to be taken of what is being serialised when human readability is important.
All MEANS objects also have shorthand methods to_file and from_file to write them to and read them from files
Step7:  Binary Serialisation
If human readability is not important, binary serialisation using python's pickle module is suggested instead of MEANS IO routines as it is much faster. The following example shows how to serialise a model object to a string using pickle.
Step8:  Similarly, pickle.dump and pickle.load functions can be used to write the pickled binary to file and read it back from it.
To reiterate the difference between binary and human-readable serialisation, 
the following tests show the overall difference in runtime speeds between these two forms
Step9:  The binary serialisation is about 28 times faster than the human-readable one, however human-readable form is easier to integrate to other process, as well as platform compatible (pickle can only deserialise python objects).
Whenever designing a pipeline, it is important to take these matters into account and choose appropriate solution for your particular case.
<ASSISTANT_TASK:>
Python Code:
import means
import means.examples
Explanation: Input & Output
MEANS package provides a set of routines for serialisation (saving) and deserialisation (loading) of the MEANS-specific objects into human-readable YAML format.
These routines all reside inside means.io package, which is imported by default from the package root.
This tutorial will quickly how to include them in your workflow.
First, let's import the means package together with the example models
End of explanation
p53 = means.examples.MODEL_P53
p53
Explanation: Let's use a $p53$ model as an example object for serialisation.
End of explanation
serialised_p53 = means.io.dump(p53)
print serialised_p53
Explanation: Human-Readable Serialisation
The serialisation to string is done via means.io.dump(object) function that takes any serialisable object as it's argument:
End of explanation
deserialised_p53 = means.io.load(serialised_p53)
deserialised_p53
Explanation: Note how this format is equally easy for both humans and machines to read. 
This is double readability is the main reason why YAML format has been chosen to serialise MEANS objects.
Deserialisation can be done by via means.io.load(serialised_string) function, as shown below:
End of explanation
# Store P53 to file
means.io.to_file(p53, 'p53-tutorial.txt') 
 # Read P53 back from the file
p53_from_file = means.io.from_file('p53-tutorial.txt')
p53_from_file
Explanation: Since most of the serialisation will be done to and from files, MEANS provides a set of convenience functions for performing these, 
namely to_file and from_file functions:
End of explanation
p53_hes1 = [means.examples.MODEL_P53, means.examples.MODEL_HES1]
print means.io.dump(p53_hes1)
Explanation: The serialisation functions dump, and to_file can handle lists of items equally well, for instance, we could try to serialise both $p53$ model and $Hes1$ model at the same time:
End of explanation
# Write p53 to file
p53.to_file('p53-shorthand.txt') 
# Read it back again from the file, 
# will throw an error if the file serialised is not a Model
means.Model.from_file('p53-shorthand.txt') 
                                           
Explanation: The form of items being serialisied is completely free (you can serialise anything using these routines). 
However, some objects may not be as human-readable when serialised as MEANS ones are, so some care needs to be taken of what is being serialised when human readability is important.
All MEANS objects also have shorthand methods to_file and from_file to write them to and read them from files:
End of explanation
# C-based pickle implementation (cPickle) is faster than the pythonic one so use that
import cPickle as pickle 
# Highest protocol should provide best compression and speed
pickled_p53 = pickle.dumps(p53, pickle.HIGHEST_PROTOCOL) 
depickled_p53 = pickle.loads(pickled_p53)
# Return the depickled_p53
depickled_p53
Explanation: Binary Serialisation
If human readability is not important, binary serialisation using python's pickle module is suggested instead of MEANS IO routines as it is much faster. The following example shows how to serialise a model object to a string using pickle.
End of explanation
%timeit means.io.load(means.io.dump(p53))
%timeit pickle.loads(pickle.dumps(p53, pickle.HIGHEST_PROTOCOL))
Explanation: Similarly, pickle.dump and pickle.load functions can be used to write the pickled binary to file and read it back from it.
To reiterate the difference between binary and human-readable serialisation, 
the following tests show the overall difference in runtime speeds between these two forms:
End of explanation
import os
# Cleanup:
os.unlink('p53-tutorial.txt')
os.unlink('p53-shorthand.txt')
Explanation: The binary serialisation is about 28 times faster than the human-readable one, however human-readable form is easier to integrate to other process, as well as platform compatible (pickle can only deserialise python objects).
Whenever designing a pipeline, it is important to take these matters into account and choose appropriate solution for your particular case.
End of explanation
<END_TASK>