def document(self, doc: libsbml.SBMLDocument) -> Dict[str, str]: """Info for SBMLDocument. :param doc: SBMLDocument :return: information dictionary for SBMLDocument """ d = self.sbase_dict(doc) packages: Dict[str, Any] = {} packages["document"] = { "level": doc.getLevel(), "version": doc.getVersion() } plugins: List[Dict[str, Any]] = [] for k in range(doc.getNumPlugins()): plugin: libsbml.SBMLDocumentPlugin = doc.getPlugin(k) prefix: str = plugin.getPrefix() version: int = plugin.getPackageVersion() plugins.append({"prefix": prefix, "version": version}) packages["plugins"] = plugins d["packages"] = packages return d
def info_document(self, doc: libsbml.SBMLDocument) -> Dict[str, str]: """Info dictionary for SBaseRef. :param doc: SBMLDocument :return: information dictionary for SBMLDocument """ info = self.info_sbase(doc) packages = [ f'<span class="package">L{doc.getLevel()}V{doc.getVersion()}</span>' ] for k in range(doc.getNumPlugins()): plugin = doc.getPlugin(k) prefix = plugin.getPrefix() version = plugin.getPackageVersion() packages.append( f'<span class="package">{prefix}-V{version}</span>') info["packages"] = " ".join(packages) return info
def flatten_external_model_definitions( doc: libsbml.SBMLDocument, validate: bool = False) -> libsbml.SBMLDocument: """Converts all ExternalModelDefinitions to ModelDefinitions. I.e. the definition of models in external files are read and directly included in the top model. The resulting comp model consists than only of a single file. The model refs in the submodel do not change in the process, so no need to update the submodels. :param doc: SBMLDocument :param validate: validation flag :return: SBMLDocument with ExternalModelDefinitions replaced """ logger.debug("* flattenExternalModelDefinitions") # FIXME: handle multiple levels of hierarchies. Recursively to handle the ExternalModelDefinitions of submodels logger.warning( "flattenExternalModelDefinitions is experimental and does not work recursively!" ) comp_doc = doc.getPlugin("comp") if comp_doc is None: logger.warning( "Model is not a comp model, no ExternalModelDefinitions") return doc emd_list = comp_doc.getListOfExternalModelDefinitions() if (emd_list is None) or (len(emd_list) == 0): # no ExternalModelDefinitions logger.warning("Model does not contain any ExternalModelDefinitions") return doc else: emd_ids = [] for emd in emd_list: logger.debug(emd) emd_ids.append(emd.getId()) # get the model definition from the model ref_model = emd.getReferencedModel() ref_doc = ref_model.getSBMLDocument() # print(ref_model) for k in range(ref_doc.getNumPlugins()): plugin = ref_doc.getPlugin(k) # print(k, plugin) # enable the package on the main SBMLDocument uri = plugin.getURI() prefix = plugin.getPrefix() doc.enablePackage(uri, prefix, True) # print("\n") # add model definition for model md = libsbml.ModelDefinition(ref_model) comp_doc.addModelDefinition(md) # remove the emds afterwards for emd_id in emd_ids: # remove the emd from the model comp_doc.removeExternalModelDefinition(emd_id) # validate if validate: validate_doc(doc) return doc