Skip to content

Commit

Permalink
Merge pull request #604 from opencobra/fix-unique
Browse files Browse the repository at this point in the history
Fix unique metabolites finding
  • Loading branch information
Midnighter committed Jan 30, 2019
2 parents 915541c + 3cfe782 commit ce730b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ History

Next Release
------------
* Enhance the function for finding unique metabolites and make it more robust.
* Improve logging output when there is a problem with serializing a result to
JSON.
* Fix some test cases that got broken by cobrapy's new boundary identification.
Expand Down
12 changes: 11 additions & 1 deletion memote/support/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,17 @@ def find_oxygen_reactions(model):

def find_unique_metabolites(model):
"""Return set of metabolite IDs without duplicates from compartments."""
return set(met.id.split("_", 1)[0] for met in model.metabolites)
unique = set()
for met in model.metabolites:
is_missing = True
for comp in model.compartments:
if met.id.endswith("_{}".format(comp)):
unique.add(met.id[:-(len(comp) + 1)])
is_missing = False
break
if is_missing:
unique.add(met.id)
return unique


@lrudecorator(size=2)
Expand Down

0 comments on commit ce730b9

Please sign in to comment.