|
19 | 19 |
|
20 | 20 | Author: Brett G. Olivier |
21 | 21 | |
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 $) |
23 | 23 |
|
24 | 24 | """ |
25 | 25 | ## gets rid of "invalid variable name" info |
@@ -1745,6 +1745,52 @@ def deleteAllFluxBoundsWithValue(self, value): |
1745 | 1745 | cntr += 1 |
1746 | 1746 | print('\nDeleted {} \"{}\" bounds'.format(cntr, value)) |
1747 | 1747 |
|
| 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 | + |
1748 | 1794 | def deleteSpecies(self, sid, also_delete=None): |
1749 | 1795 | """ |
1750 | 1796 | Deletes a species object with id |
|
0 commit comments