Error While Saving Model after Bounds Modification

16 views
Skip to first unread message

Rakesh Mandal

unread,
Jul 8, 2022, 3:28:52 AM7/8/22
to cobra pie
Hello everyone,
I have two lists of upper bound and lower bound values. I modified my reaction bounds like this.

for i, rxn in enumerate(model.reactions):
    rxn.bounds = ( lwb[i], upb[i] )


But while saving the model, it shows the following error:

cobra.io.write_sbml_model(model, ''TPM_avg.xml'')
Screenshot 2022-07-08 124714.jpg

When I changed the bounds by manually writing like this, it showed no error while saving.

model.reactions.MAR08762.bounds = (-0.9730982564134064 , 0.9730982564134064)
model.reactions.MAR08764.bounds = (0.0 , 0.001)
model.reactions.MAR08766.bounds = (-0.15081222128094757 , 0.15081222128094757)
model.reactions.MAR08767.bounds = (0.0 , 0.05002992950568093)
model.reactions.MAR00454.bounds = (0.0 , 0.001)
model.reactions.MAR04297.bounds = (0.0 , 0.04643264517106)
model.reactions.MAR04310.bounds = (0.0 , 0.0009999927140217114)
model.reactions.MAR04315.bounds = (-0.02097143439726379 , 0.02097143439726379)
model.reactions.MAR04316.bounds = (-0.15081222128094704 , 0.15081222128094704)
.....

But writing this way is not feasible, because I have thousands of reactions for thousands of models to change bounds for. Any idea about how to rectify this error or any other way of doing this process.

Thanks,
Rakesh

ch.d...@gmail.com

unread,
Jul 13, 2022, 3:36:20 PM7/13/22
to cobra pie
Looks like at least one of your lower bounds is not a number. What does your `lwb` list look like?

Matthias König

unread,
Jul 14, 2022, 3:20:00 AM7/14/22
to cobra pie
Yes, I am pretty sure your bounds are invalid. This could be multiple things such as incorrect trailing commas, NaN values, ...
I would just check this in your loop and print the offending bound values then it is pretty obvious what is wrong
E.g. something along the lines of 

for i, rxn in enumerate(model.reactions):
    lb = lwb[i]
    print("lb", lb, type(lb))
    ub = upb[i]
    print("ub", ub, type(ub))
    rxn.bounds = (lb, ub)

This will show you the problem in your bounds. After fixing your bound types/values this should work.
Best Matthias
Reply all
Reply to author
Forward
0 new messages