Example #1
0
def boundsStringFromReaction(reaction: libsbml.Reaction,
                             model: libsbml.Model) -> str:
    """Render string of bounds from the reaction.

    :param reaction: SBML reaction instance
    :param model: SBML model instance
    :return: String of bounds extracted from the reaction
    """
    bounds = ""
    rfbc = reaction.getPlugin("fbc")
    if rfbc is not None:
        # get values for bounds
        lb_id, ub_id = None, None
        lb_value, ub_value = None, None
        if rfbc.isSetLowerFluxBound():
            lb_id = rfbc.getLowerFluxBound()
            lb_p = model.getParameter(lb_id)
            if lb_p.isSetValue():
                lb_value = lb_p.getValue()
        if rfbc.isSetUpperFluxBound():
            ub_id = rfbc.getUpperFluxBound()
            ub_p = model.getParameter(ub_id)
            if ub_p.isSetValue():
                ub_value = ub_p.getValue()
        if (lb_value is not None) or (ub_value is not None):
            bounds = f"""
                    <code>[{lb_value}
                    <i class="fa fa-sort fa-rotate-90" aria-hidden="true"></i>
                    {ub_value}]
                    </code>
                    """
    return bounds
Example #2
0
    def _gene_product_association_from_reaction(
        reaction: libsbml.Reaction, ) -> Optional[str]:
        """Render string representation of the GeneProductAssociation for given reaction.

        :param reaction: SBML reaction instance
        :return: string representation of GeneProductAssociation
        """

        rfbc = reaction.getPlugin("fbc")
        gpa = (str(rfbc.getGeneProductAssociation().getAssociation().toInfix())
               if (rfbc and rfbc.isSetGeneProductAssociation()) else None)

        return gpa
Example #3
0
def geneProductAssociationStringFromReaction(
        reaction: libsbml.Reaction) -> str:
    """Render string representation of the GeneProductAssociation for given reaction.

    :param reaction: SBML reaction instance
    :return: string representation of GeneProductAssociation
    """
    info = ""
    rfbc = reaction.getPlugin("fbc")

    if rfbc and rfbc.isSetGeneProductAssociation():
        gpa = rfbc.getGeneProductAssociation()
        association = gpa.getAssociation()
        info = association.toInfix()
    return info
Example #4
0
    def _bounds_dict_from_reaction(reaction: libsbml.Reaction,
                                   model: libsbml.Model) -> Optional[Dict]:
        """Render string of bounds from the reaction.

        :param reaction: SBML reaction instance
        :param model: SBML model instance
        :return: String of bounds extracted from the reaction
        """
        bounds: Optional[Dict]
        rfbc = reaction.getPlugin("fbc")
        if rfbc is not None:
            # get values for bounds
            lb_id: Optional[str] = None
            ub_id: Optional[str] = None
            lb_value: Optional[float] = None
            ub_value: Optional[float] = None
            if rfbc.isSetLowerFluxBound():
                lb_id = rfbc.getLowerFluxBound()
                lb_p: libsbml.Parameter = model.getParameter(lb_id)
                if lb_p.isSetValue():
                    lb_value = lb_p.getValue()
            if rfbc.isSetUpperFluxBound():
                ub_id = rfbc.getUpperFluxBound()
                ub_p: libsbml.Parameter = model.getParameter(ub_id)
                if ub_p.isSetValue():
                    ub_value = ub_p.getValue()

            bounds = {
                "lowerFluxBound": {
                    "id": lb_id,
                    "value": lb_value,
                },
                "upperFluxBound": {
                    "id": ub_id,
                    "value": ub_value,
                },
            }

        else:
            bounds = None

        return bounds
Example #5
0
def set_flux_bounds(reaction: libsbml.Reaction, lb: float, ub: float) -> None:
    """Set flux bounds on given reaction."""
    rplugin = reaction.getPlugin("fbc")
    rplugin.setLowerFluxBound(lb)
    rplugin.setUpperFluxBound(ub)