"Failed to interpret file %s as a pickle" % repr(file)

4,139 views
Skip to first unread message

Andrea Edwards

unread,
Mar 25, 2014, 1:43:06 PM3/25/14
to cobr...@googlegroups.com
Hi,
I am a new user and am playing around with the example scripts. I downloaded a coupld of .xml files from BioModels database (attached), and I tried the following script and got the corresponding error:

from cobra import Model, Reaction, Metabolite
from cobra.io.sbml import create_cobra_model_from_sbml_file
from cobra.io.sbml import write_cobra_model_to_sbml_file
mod = load('BIOMD0000000172.xml')
sbml_out_file = 'BIOMD0000000172.out.xml'
sbml_level = 2
sbml_version = 1

---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)
<ipython-input-37-bcb83ef302b7> in <module>()
      2 from cobra.io.sbml import create_cobra_model_from_sbml_file
      3 from cobra.io.sbml import write_cobra_model_to_sbml_file
----> 4 mod = load('BIOMD0000000172.xml')
      5 sbml_out_file = 'BIOMD0000000172.out.xml'
      6 sbml_level = 2

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/lib/npyio.pyc in load(file, mmap_mode)
    357             except:
    358                 raise IOError, \
--> 359                     "Failed to interpret file %s as a pickle" % repr(file)
    360     finally:
    361         if own_fid:

IOError: Failed to interpret file 'BIOMD0000000172.xml' as a pickle

I also tried the following:

from cobra import Model, Reaction, Metabolite
from cobra.io.sbml import create_cobra_model_from_sbml_file
from cobra.io.sbml import write_cobra_model_to_sbml_file
mod = Model('BIOMD0000000172.xml')
sbml_out_file = 'BIOMD0000000172.out.xml'
sbml_level = 2
sbml_version = 1

cobra_model = create_cobra_model_from_sbml_file(BIOMD0000000172.xml
                                                , print_time=True)

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-33-059b0aadb530> in <module>()
----> 1 cobra_model = create_cobra_model_from_sbml_file(BIOMD0000000172.xml, print_time=True)

NameError: name 'BIOMD0000000172' is not defined

Can you help me figure out how to solve these issues? Thanks so much

Andrea Edwards

unread,
Mar 25, 2014, 1:45:19 PM3/25/14
to cobr...@googlegroups.com
Here are the files I tried
BIOMD0000000051.xml
BIOMD0000000172.xml

Dr. Scientist

unread,
Mar 25, 2014, 1:46:25 PM3/25/14
to cobr...@googlegroups.com
Basically, the load command is for loading a pickled file so you get the first error.

For the second error you need to have quotes around your file name otherwise python thinks that it's a variable which hasn't been defined.

try the following snippet

from cobra.io.sbml import create_cobra_model_from_sbml_file
cobra_model = create_cobra_model_from_sbml_file('BIOMD0000000172.xml')


On Tuesday, March 25, 2014 11:43:06 AM UTC-6, Andrea Edwards wrote:

Andrea Edwards

unread,
Mar 25, 2014, 2:06:55 PM3/25/14
to cobr...@googlegroups.com
How do I create a pickled file from a .xml file?

Dr. Scientist

unread,
Mar 25, 2014, 2:10:54 PM3/25/14
to cobr...@googlegroups.com
If you want a pickled version of your model then you read the sbml file into a cobra Model object and then dump it.  But if you want to start manipulating your model then there's no need to make a pickle just read in the sbml file.

#Read in the model file
from cobra.io.sbml import create_cobra_model_from_sbml_file
cobra_model = create_cobra_model_from_sbml_file('BIOMD0000000172.xml')

#then dump the python object into a pickle
from cPickle import dump
with open('my_pickle_file', 'w') as out_file:
    dump(cobra_model, out_file)

Andrea Edwards

unread,
Mar 25, 2014, 3:00:50 PM3/25/14
to cobr...@googlegroups.com
Thanks for your help! I opened the model with cobra_model = create_cobra_model_from_sbml_file('BIOMD0000000172.xml') and it worked. Now I am wondering why I get -0.000 for the simulated growth rate. I compared the the file with the salmonella and ecoli files in the test directory, and it seems I need to manipulate the BIOMD0000000172.xml file somehow to get a simulated growth rate.

Andrea Edwards

unread,
Mar 25, 2014, 3:05:38 PM3/25/14
to cobr...@googlegroups.com
In general, all the SBML files (or at least the ones I have viewed at random) from BioModels are very different from the two that come in the test directory. How/where can I find files like the ones associated with this cobrapy package. Or, is it the job of cobrapy to make these files? Sorry for my confusion. 

Dr. Scientist

unread,
Mar 25, 2014, 4:06:10 PM3/25/14
to cobr...@googlegroups.com
you'll probably need to figure out which reaction in your model corresponds to biomass and set its objective coefficient and then set the appropriate values for your system's boundaries, i.e. exchange reactions.  you'll either want to start learning more about your model by reading any associated papers or by contacting the creators.

Nikolaus Sonnenschein

unread,
Mar 25, 2014, 4:12:40 PM3/25/14
to cobr...@googlegroups.com
The model you're trying to simulate is a kinetic model of yeast glycolysis and does not contain an objective function. Just for testing purposes you can set an objective coefficient like this:

cobra_model.reactions.ATPase.objective_coefficient = 1.

And then check if you get some flux through the system.

I would also recommend that you read something like http://www.nature.com/nbt/journal/v28/n3/abs/nbt.1614.html to get up to speed with constraint-based modeling.

Check out http://sbrg.github.io/MASS-Toolbox/ if you actually want to simulate the model dynamically.

biomodels.net contains mostly ode and stochastic models of small size. Checkout bigg.ucsd.edu or http://metanetx.org/ for more suitable models.

Best,

Niko

Andrea Edwards

unread,
Mar 25, 2014, 5:59:04 PM3/25/14
to cobr...@googlegroups.com
Thank you very very much for pointing me in the right direction!
Reply all
Reply to author
Forward
0 new messages