Exemple #1
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
Exemple #2
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
Exemple #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
Exemple #4
0
    def info_species(self) -> List[Dict[str, Any]]:
        """Information dictionaries for Species.

        :return: list of info dictionaries for Species
        """
        data = []
        for s in self.model.getListOfSpecies():  # type: libsbml.Species
            info = self.info_sbase(s)
            info["compartment"] = s.compartment
            info["has_only_substance_units"] = boolean(
                s.has_only_substance_units)
            info["boundary_condition"] = boolean(s.boundary_condition)
            info["constant"] = boolean(s.constant)
            if s.isSetInitialAmount():
                initial_amount = s.initial_amount
            else:
                initial_amount = empty_html()
            info["initial_amount"] = initial_amount
            if s.isSetInitialConcentration():
                initial_concentration = s.initial_concentration
            else:
                initial_concentration = empty_html()
            info["initial_concentration"] = initial_concentration
            info["units"] = s.getUnits()
            info["substance_units"] = s.substance_units
            info["derived_units"] = derived_units(s)

            if s.isSetConversionFactor():
                cf_sid = s.getConversionFactor()
                cf_p = self.model.getParameter(
                    cf_sid)  # type: libsbml.Parameter
                cf_value = cf_p.getValue()
                cf_units = cf_p.getUnits()

                info["conversion_factor"] = f"{cf_sid}={cf_value} [{cf_units}]"
            else:
                info["conversion_factor"] = empty_html()

            # fbc
            sfbc = s.getPlugin("fbc")
            if sfbc:
                if sfbc.isSetChemicalFormula():
                    info["fbc_formula"] = sfbc.getChemicalFormula()
                if sfbc.isSetCharge():
                    c = sfbc.getCharge()
                    if c != 0:
                        info["fbc_charge"] = f"({sfbc.getCharge()})"
                if ("fbc_formula" in info) or ("fbc_charge" in info):
                    info["fbc"] = f"""
                        <br />
                        <code>
                            {info.get('fbc_formula', '')}{info.get('fbc_charge', '')}
                        </code>
                        """
            data.append(info)
        return data
Exemple #5
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
Exemple #6
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