Skip to content

Commit c5d680b

Browse files
committed
synch to svn
1 parent dfe0e59 commit c5d680b

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

src/CBModel.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
Author: Brett G. Olivier
2121
Contact email: [email protected]
22-
Last edit: $Author: bgoli $ ($Id: CBModel.py 688 2019-06-28 14:14:48Z bgoli $)
22+
Last edit: $Author: bgoli $ ($Id: CBModel.py 690 2019-07-09 20:00:41Z bgoli $)
2323
2424
"""
2525
## gets rid of "invalid variable name" info
@@ -1745,6 +1745,52 @@ def deleteAllFluxBoundsWithValue(self, value):
17451745
cntr += 1
17461746
print('\nDeleted {} \"{}\" bounds'.format(cntr, value))
17471747

1748+
def deleteCompartment(self, sid, check_components=True):
1749+
"""
1750+
Deletes a compartment object with id. Returns True if the compartment is deleted, False if not. In addition if components were checked
1751+
a list of id's that reference the compartment are also returned.
1752+
1753+
- *sid* the compartment id
1754+
- *check_components* [default=True] if enabled check that no species or reactions makes
1755+
use of the compartment, fail if it does.
1756+
1757+
"""
1758+
1759+
if sid not in self.getCompartmentIds():
1760+
print('\n\"{}\" is not a valid compartment id.\n'.format(sid))
1761+
return False
1762+
out = True
1763+
if check_components:
1764+
rc = [r.getId() for r in self.reactions if r.compartment == sid]
1765+
sc = [s.getId() for s in self.species if s.compartment == sid]
1766+
pc = [p.getId() for p in self.parameters if p.compartment == sid]
1767+
mc = []
1768+
1769+
if len(rc) > 0:
1770+
err = ','.join(rc)
1771+
print('Reactions: {} are located in compartment \"{}\"'.format(err, sid))
1772+
out = False
1773+
if len(sc) > 0:
1774+
err = ','.join(sc)
1775+
print('Species: {} are located in compartment \"{}\"'.format(err, sid))
1776+
out = False
1777+
if len(pc) > 0:
1778+
err = ','.join(pc)
1779+
print('Parameters: {} are located in compartment \"{}\"'.format(err, sid))
1780+
out = False
1781+
if sid == self.compartment:
1782+
print('The model is located in compartment: {}'.format(err, sid))
1783+
mc = [self.getId()]
1784+
out = False
1785+
1786+
if out:
1787+
self.compartments.remove(self.getCompartment(sid))
1788+
return True
1789+
else:
1790+
print('\nDeleteCompartment failed to delete compartment: {}\n'.format(sid))
1791+
return out, sc+mc+pc+rc
1792+
1793+
17481794
def deleteSpecies(self, sid, also_delete=None):
17491795
"""
17501796
Deletes a species object with id

0 commit comments

Comments
 (0)