Cloning an SBML file with changes

3 views
Skip to first unread message

Alex Enersen

unread,
Nov 2, 2018, 7:55:48 PM11/2/18
to libsbml-development
I need to read an SBML file, make changes to it, and then export it as a new SBML file. Currently, this is my method:

SBMLReader reader = new SBMLReader();
SBMLDocument document = reader.readSBML(filename);
Model model = document.getModel();

*changes to the SBML file here*

SBMLDocument newDocument = new SBMLDocument();
newDocument.setModel(model);
SBMLWriter writer = new SBMLWriter();
String clonedSBML = writer.writeSBMLToString(newDocument);
return clonedSBML;

It reads the model just fine, but when I try assigning the model to the new document, nothing gets copied over. When clonedSBML is returned, it's only the header. None of the species or reactions are in clonedSBML.

Is there an easy way of reading an SBML file, altering its properties, and then returning it as a new SBML file?

Frank Bergmann

unread,
Nov 3, 2018, 7:37:32 PM11/3/18
to libsbml-d...@googlegroups.com, Alex Enersen
from the snippet you were posting, there seems actually, to be no
reason to create a new document at all. if you just

- read the model ,
- make changes to the model and
- write it to a different file

you should have no issues with the call. So i would just skip the
newDocument / setModel bits altogether.

If i would have to hazard a guess as to why it failed, i would assume
that the setModel call would have failed. if you say new
SBMLDocument() a new SBML document will be created with teh default
level / version. Presumably that would be Level 3, Version 2. Then
when you call setModel() ... and that model is likely incompatible
(i.e just not the same level / version). Then setModel would tell you
that in a return value.

cheers
Frank
> --
> You received this message because you are subscribed to the Google Groups "libsbml-development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to libsbml-develop...@googlegroups.com.
> To post to this group, send email to libsbml-d...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/libsbml-development/617bc4e2-c6c6-4fbf-9779-255e3af4830b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages