libsbml
libsbml copied to clipboard
Add ASTNode converters for geneProductAssociations
So, I'm adding some Antimony support for FBC, and I'm realizing that one thing I need is a converter from ASTNodes to and from the and/or logic of GeneProductAssociations. Would it be helpful to implement this in libsbml directly, so that others could also do the same conversion? Something like:
ASTNode* GeneProductAssociation::getAssociationAsASTNode()
int GeneProductAssociation::createChildAssociationFromASTNode(const ASTNode* astn)
(tagging @fbergmann @bgoli @skeating, for any opinions)
That would be great. Basically every tool is reimplementing the logic which is very error prone because there are often issues with the brackets, whitespaces, newlines in the string representation. Having a single implementation which we could reuse would be nice.
There currently is a string version of that with FbcAssociation::parseFbcInfixAssociation(const std::string& association, FbcModelPlugin* plugin, bool usingId, bool addMissingGP) and a non-public FbcAssociation* toAssociation(const ASTNode* node, FbcModelPlugin* plugin, bool usingId, bool addMissingGP) that works from ASTNode. And of course there is the corresponding toString versions that would create the string for it.
Ideally those same functions would be maintained. Not that we duplicate the code. It is in FbcAssociation, since it worked for the different versions.
I did find those functions eventually, but they use some sort of non-standard infix, presumably that matches a somewhat common way of writing them. They also use plus and times instead of 'and' and 'or', I think so that the order of operations from their infix is what they want. There's also routines that add gene products to the model automatically, mangling the names again in different ways.
All told, there's nothing public that I can use (since the infix it wants and produces is non-standard), and even if we made the private ASTNode* function public, I couldn't use that either, since it uses plus and times. I just need ASTNodes that are actual 'and' and 'or' nodes, with names that are the actual IDs of gene products.
It's fine if I just implement this for myself, but my guess was that other simulators might also find it useful.
(I would only be adding functions that used ASTNodes, to be completely agnostic of the infix. Users could translate them using the standard libsbml ast-to-infix translators, or use their own, or use the 'toInfix' routines from the FbcAssociation class.)
Such functions may be useful as, for example, in Python you can then easily map from ASTnodes to Python AST's. In my stuff I currently map directly from GeneProductAssociations to Python trees and avoid infix altogether.