Skip to content

Commit

Permalink
ran black
Browse files Browse the repository at this point in the history
  • Loading branch information
uri.akavia committed Aug 7, 2022
1 parent f5729b9 commit b7d746b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/cobra/core/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def metabolites(self) -> Dict[Metabolite, float]:

@metabolites.setter
@resettable
def metabolites(self, value: Dict[Metabolite, float]) -> None:
def metabolites(self, value: Dict[Metabolite, float]) -> None:
"""Set metabolites to a dictionary of metabolites and coefficients.
Parameters
Expand Down Expand Up @@ -1228,8 +1228,10 @@ def add_metabolites(
# Make sure metabolites being added belong to the same model, or
# else copy them.
if isinstance(metabolite, Metabolite):
if (metabolite.model is not None) and self.model and (
metabolite.model is not self._model
if (
(metabolite.model is not None)
and self.model
and (metabolite.model is not self._model)
):
metabolite = metabolite.copy()

Expand Down
13 changes: 9 additions & 4 deletions src/cobra/core/species.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ..core.object import Object
from ..util import HistoryManager


if TYPE_CHECKING:
from .. import Model, Reaction

Expand Down Expand Up @@ -57,12 +58,14 @@ def reactions(self) -> FrozenSet:
A frozenset that includes the reactions of the species.
"""
if self.model and self.__class__.__name__ == "Gene":
return self.model.reactions.query(lambda x: self in x, 'genes')
return self.model.reactions.query(lambda x: self in x, "genes")
elif self.model and self.__class__.__name__ == "Metabolite":
return self.model.reactions.query(lambda x: self in x, 'metabolites')
return self.model.reactions.query(lambda x: self in x, "metabolites")
return frozenset(self._reaction)

def reaction_add(self, reaction: Reaction, context: Optional[HistoryManager] = None) -> None:
def reaction_add(
self, reaction: Reaction, context: Optional[HistoryManager] = None
) -> None:
"""Add reaction to .reaction field, with context.
If this is called with a context, will be reversed when exiting the context.
Expand All @@ -77,7 +80,9 @@ def reaction_add(self, reaction: Reaction, context: Optional[HistoryManager] = N
if context:
context(partial(self._reaction.remove, reaction))

def reaction_remove(self, reaction: Reaction, context: Optional[HistoryManager] = None) -> None:
def reaction_remove(
self, reaction: Reaction, context: Optional[HistoryManager] = None
) -> None:
"""Remove reaction from .reaction field, with context.
If this is called with a context, will be reversed when exiting the context.
Expand Down
7 changes: 3 additions & 4 deletions tests/test_core/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,10 +1020,9 @@ def test_add_reactions_from_another_model(model: Model, data_directory: Path) ->
data_directory: Path
Directory where mini_cobra.xml is found.
"""
mini = read_sbml_model(data_directory / 'mini_cobra.xml')
mini.add_reactions([model.reactions.get_by_id('ACALD')])
assert len(mini.metabolites.get_by_id('acald_c').reactions) == 1

mini = read_sbml_model(data_directory / "mini_cobra.xml")
mini.add_reactions([model.reactions.get_by_id("ACALD")])
assert len(mini.metabolites.get_by_id("acald_c").reactions) == 1


def test_add_reactions_single_existing(model: Model) -> None:
Expand Down

0 comments on commit b7d746b

Please sign in to comment.