Example #1
0
    def info_parameters(
            self, assignment_map: Dict[str, str]) -> List[Dict[str, Any]]:
        """Information dictionaries for Parameters.

        :param assignment_map: map of assignments for symbols
        :return: list of info dictionaries for Reactions
        """
        items = []
        for item in self.model.getListOfParameters(
        ):  # type: libsbml.Parameter
            info = self.info_sbase(item)
            info["units"] = item.units
            if item.isSetValue():
                value = item.value
            else:
                value_formula = assignment_map.get(item.id, None)
                if value_formula is None:
                    warnings.warn(
                        f"No value for parameter via Value, InitialAssignment or "
                        f"AssignmentRule: {item.id}")
                value = math(value_formula, self.math_render)
            info["value"] = value
            info["derived_units"] = derived_units(item)
            info["constant"] = boolean(item.constant)
            items.append(info)
        return items
Example #2
0
    def info_reactions(self) -> List[Dict[str, Any]]:
        """Information dictionaries for ListOfReactions.

        :return: list of info dictionaries for Reactions
        """
        data = []
        for r in self.model.getListOfReactions():  # type: libsbml.Reaction
            info = self.info_sbase(r)
            if r.reversible:
                reversible = '<td class ="success">&#8646;</td>'
            else:
                reversible = '<td class ="danger">&#10142;</td>'
            info["reversible"] = reversible
            info["equation"] = formating.equationStringFromReaction(r)

            modifiers = [mod.getSpecies() for mod in r.getListOfModifiers()]
            if modifiers:
                modifiers_html = "<br />".join(modifiers)
            else:
                modifiers_html = empty_html()
            info["modifiers"] = modifiers_html

            klaw = r.getKineticLaw()
            info["formula"] = math(klaw, self.math_render)
            info["derived_units"] = derived_units(klaw)

            # fbc
            info["fbc_bounds"] = formating.boundsStringFromReaction(
                r, self.model)
            info[
                "fbc_gpa"] = formating.geneProductAssociationStringFromReaction(
                    r)
            data.append(info)

        return data
Example #3
0
    def info_compartments(
            self, assignment_map: Dict[str, str]) -> List[Dict[str, Any]]:
        """Information dictionaries for Compartments.

        :param assignment_map: map of assignments for symbols
        :return: list of info dictionaries for Compartments
        """
        data = []
        for c in self.model.getListOfCompartments(
        ):  # type: libsbml.Compartment
            info = self.info_sbase(c)
            info["units"] = c.units
            if c.isSetSpatialDimensions():
                spatial_dimensions = c.spatial_dimensions
            else:
                spatial_dimensions = empty_html()
            info["spatial_dimensions"] = spatial_dimensions
            info["constant"] = boolean(c.constant)
            info["derived_units"] = derived_units(c)
            if c.isSetSize():
                size = c.size
            else:
                size = math(assignment_map.get(c.id, ""), self.math_render)
            info["size"] = size
            data.append(info)
        return data
Example #4
0
    def info_function_definitions(self) -> List[Dict[str, Any]]:
        """Information dictionaries for FunctionDefinitions.

        :return: list of info dictionaries for FunctionDefinitions
        """
        data = []
        for (fd) in (self.model.getListOfFunctionDefinitions()
                     ):  # type: libsbml.FunctionDefinition
            info = self.info_sbase(fd)
            info["math"] = math(fd, self.math_render)
            data.append(info)
        return data
Example #5
0
    def info_constraints(self) -> List[Dict[str, Any]]:
        """Information dictionaries for Constraints.

        :return: list of info dictionaries for Constraints
        """
        data = []
        for constraint in self.model.getListOfConstraints(
        ):  # type: libsbml.Constraint
            info = self.info_sbase(constraint)
            info["constraint"] = math(constraint, self.math_render)
            data.append(info)

        return data
Example #6
0
    def info_rules(self) -> List[Dict[str, Any]]:
        """Information dictionaries for Rules.

        :return: list of info dictionaries for Rules
        """
        data = []
        for rule in self.model.getListOfRules():
            info = self.info_sbase(rule)
            info["variable"] = formating.ruleVariableToString(rule)
            info["assignment"] = math(rule, self.math_render)
            info["derived_units"] = derived_units(rule)

            data.append(info)
        return data
Example #7
0
    def info_initial_assignments(self) -> List[Dict[str, Any]]:
        """Information dictionaries for InitialAssignments.

        :return: list of info dictionaries for InitialAssignments
        """
        data = []
        for (assignment) in (self.model.getListOfInitialAssignments()
                             ):  # type: libsbml.InitialAssignment
            info = self.info_sbase(assignment)
            info["symbol"] = assignment.symbol
            info["assignment"] = math(assignment, self.math_render)
            info["derived_units"] = derived_units(assignment)
            data.append(info)
        return data
Example #8
0
    def info_sbase(sbase: libsbml.SBase) -> Dict[str, Any]:
        """Info dictionary for SBase.

        :param sbase: SBase instance for which info dictionary is to be created
        :return info dictionary for item
        """
        info = {
            "object": sbase,
            "id": sbase.getId(),
            "metaId": metaid_html(sbase),
            "sbo": sbo(sbase),
            "cvterm": cvterm(sbase),
            "notes": notes(sbase),
            "annotation": annotation_html(sbase),
        }

        if sbase.isSetName():
            name = sbase.name
        else:
            name = empty_html()
        info["name"] = name
        info["id_html"] = id_html(sbase)

        # comp
        item_comp = sbase.getPlugin("comp")
        if item_comp and type(item_comp) == libsbml.CompSBasePlugin:
            # ReplacedBy
            if item_comp.isSetReplacedBy():
                replaced_by = item_comp.getReplacedBy()
                submodel_ref = replaced_by.getSubmodelRef()
                info["replaced_by"] = f"""
                    <br /><i class="fa fa-arrow-circle-right" aria-hidden="true"></i>
                    <code>ReplacedBy {submodel_ref}:{sbaseref(replaced_by)}</code>
                    """

            # ListOfReplacedElements
            if item_comp.getNumReplacedElements() > 0:
                replaced_elements = []
                for rep_el in item_comp.getListOfReplacedElements():
                    submodel_ref = rep_el.getSubmodelRef()
                    replaced_elements.append(f"""
                        <br /><i class="fa fa-arrow-circle-left" aria-hidden="true"></i>
                        <code>ReplacedElement {submodel_ref}:{sbaseref(rep_el)}</code>
                        """)
                if len(replaced_elements) == 0:
                    replaced_elements_combined = ""
                else:
                    replaced_elements_combined = "".join(replaced_elements)
                info["replaced_elements"] = replaced_elements_combined

        # distrib
        sbml_distrib: libsbml.DistribSBasePlugin = sbase.getPlugin("distrib")
        if sbml_distrib and isinstance(sbml_distrib,
                                       libsbml.DistribSBasePlugin):
            info["uncertainties"] = []
            info["uncert_strings"] = []

            for uncertainty in sbml_distrib.getListOfUncertainties():
                u_dict = SBMLModelInfo.info_sbase(uncertainty)

                u_dict["uncert_parameters"] = []
                u_dict["uncert_params_strings"] = []

                upar: libsbml.UncertParameter
                for upar in uncertainty.getListOfUncertParameters():
                    param_dict = {}
                    param_str = ""
                    if upar.isSetVar():
                        param_dict["var"] = upar.getVar()
                        param_str += f"{param_dict['var']}, "
                    if upar.isSetValue():
                        param_dict["value"] = upar.getValue()
                        param_str += f"{param_dict['value']}, "
                    if upar.isSetUnits():
                        param_dict["units"] = upar.getUnits()
                        param_str += f"{param_dict['units']}, "
                    if upar.isSetType():
                        param_dict["type"] = upar.getTypeAsString()
                        param_str += f"{param_dict['type']}, "
                    if upar.isSetDefinitionURL():
                        param_dict["definition_url"] = f"""
                                        <a href='{upar.getDefinitionURL()}'>
                                        {upar.getDefinitionURL()}</a>
                                        """
                        param_str += param_dict["definition_url"]
                    if upar.isSetMath():
                        param_dict["math"] = formating.math(upar.getMath())
                        param_str += f"{param_dict['math']}, "

                    # create param info string
                    param_str = "<li>"
                    for key in param_dict.keys():
                        param_str += f"{key}:{param_dict.get(key, '')}, "
                    param_str += "</li>"

                    u_dict["uncert_parameters"].append(param_dict)
                    u_dict["uncert_params_strings"].append(param_str)

                info["uncertainties"].append(u_dict)

        return info