JSBML functions: renameSIdRefs, renameMetaIdRefs, renameUnitSIdRefs

4 views
Skip to first unread message

Matthias König

unread,
Jul 21, 2020, 4:06:03 PM7/21/20
to jsbml-development
Hi all,
I am  working on the comp flattening in JSBML.

As part of the flattening algorithm I have to rename SIdRefs and MetaIdRefs when flattening the submodels. I basically have to add prefixes to many SIds and MetaIds. These have then to be replaced wherever they occur in a model, i.e. all references to the Sid or MetaId have to be replaced/renamed.

In libsbml simple helpers exist which allow to replace the occurence of SIdRefs and MetaIdRefs. These are `renameSIdRefs`, `renameMetaIdRefs` and `renameUnitIdRefs` (see description below).

The usage is basically something like

// found element --> renaming
element->setId(newSId);

// update all references to this element
List *allElements = document->getAllElements();
for (unsigned int i = 0; i < allElements->getSize(); ++i)
     static_cast<SBase*>(allElements->get(i))->renameSIdRefs(oldSId, newSId);

I.e. it is quite costly to rename a lot of ids. In addition there is a helper function renameAllIds

def renameAllIds(self, idTransformer, filter=None):
"""
renameAllIds(Model self, IdentifierTransformer idTransformer, ElementFilter filter=None) -> int
renameAllIds(Model self, IdentifierTransformer idTransformer) -> int


Internal implementation method.

"""
return _libsbml.Model_renameAllIds(self, idTransformer, filter)


I am looking for this functionality in JSBML. I.e. how can I rename (efficiently) many SIds and MetaIds so that the respective SIds and MetaIds are updated? Which function could help me here in JSBML?

Best Matthias



def renameSIdRefs(self, oldid, newid):
"""
renameSIdRefs(SBase self, string oldid, string newid)


Replaces all uses of a given 'SIdRef' type attribute value with
another value.

In SBML, object identifiers are of a data type called SId. In SBML
Level 3, an explicit data type called SIdRef was introduced for
attribute values that refer to SId values in previous Levels of SBML,
this data type did not exist and attributes were simply described to
as 'referring to an identifier', but the effective data type was the
same as SIdRef in Level 3. These and other methods of libSBML refer
to the type SIdRef for all Levels of SBML, even if the corresponding
SBML specification did not explicitly name the data type.

This method works by looking at all attributes and (if appropriate)
mathematical formulas in MathML content, comparing the referenced
identifiers to the value of 'oldid'. If any matches are found, the
matching values are replaced with 'newid'. The method does not
descend into child elements.

Parameter 'oldid' is the old identifier. Parameter 'newid' is the new
identifier.

"""
return _libsbml.SBase_renameSIdRefs(self, oldid, newid)


def renameMetaIdRefs(self, oldid, newid):
"""
renameMetaIdRefs(SBase self, string oldid, string newid)


Replaces all uses of a given meta identifier attribute value with
another value.

In SBML, object 'meta' identifiers are of the XML data type ID the
SBML object attribute itself is typically named metaid. All
attributes that hold values referring to values of type ID are of the
XML data type IDREF. They are also sometimes informally referred to
as 'metaid refs', in analogy to the SBML-defined type SIdRef.

This method works by looking at all meta-identifier attribute values,
comparing the identifiers to the value of 'oldid'. If any matches are
found, the matching identifiers are replaced with 'newid'. The method
does not descend into child elements.

Parameter 'oldid' is the old identifier. Parameter 'newid' is the new
identifier.

"""
return _libsbml.SBase_renameMetaIdRefs(self, oldid, newid)


def renameUnitSIdRefs(self, oldid, newid):
"""
renameUnitSIdRefs(SBase self, string oldid, string newid)


Replaces all uses of a given 'UnitSIdRef' type attribute value with
another value.

In SBML, unit definitions have identifiers of type UnitSId. In SBML
Level 3, an explicit data type called UnitSIdRef was introduced for
attribute values that refer to UnitSId values in previous Levels of
SBML, this data type did not exist and attributes were simply
described to as 'referring to a unit identifier', but the effective
data type was the same as UnitSIdRef in Level 3. These and other
methods of libSBML refer to the type UnitSIdRef for all Levels of
SBML, even if the corresponding SBML specification did not explicitly
name the data type.

This method works by looking at all unit identifier attribute values
(including, if appropriate, inside mathematical formulas), comparing
the referenced unit identifiers to the value of 'oldid'. If any
matches are found, the matching values are replaced with 'newid'. The
method does not descend into child elements.

Parameter 'oldid' is the old identifier. Parameter 'newid' is the new
identifier.

"""
return _libsbml.SBase_renameUnitSIdRefs(self, oldid, newid)


Reply all
Reply to author
Forward
0 new messages