Skip to content

Commit

Permalink
clean up and package setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ayush9pandey committed Mar 31, 2020
1 parent 9d9d879 commit 2872a33
Show file tree
Hide file tree
Showing 45 changed files with 2,581 additions and 6,412 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: python
python:
- "3.6"
- "3.7"
# command to run tests
script:
- "python setup.py test"
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2018, Build-A-Cell
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include tests/*.py
include README.md
include LICENSE
exclude auto_reduce.egg-info/*
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Automated Model Reduction Tool for SBML models
## Refer to the [bioRxiv paper](https://www.biorxiv.org/content/10.1101/640276v1) for more details

### To run - Use `michaelis-menten.ipynb` or other jupyter notebooks as demonstrative examples.

### Contact : Ayush Pandey (apandet at caltech dot edu) for any feedback or suggestions.
Refer to the [bioRxiv paper](https://www.biorxiv.org/content/10.1101/2020.02.15.950840v2.full.pdf) for more details
To run - Go through tutorial files inside tutorials folder then check out some common examples in the examples folder. To check if different tools are working properly, run tests.
Contact : Ayush Pandey (apandet at caltech dot edu) for any feedback or suggestions.
74 changes: 37 additions & 37 deletions auto_reduce/model_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def get_error_metric_with_input(self, reduced_sys):


def get_error_metric(self, reduced_sys):
# Give option for get_error_metric(sys1, sys2)
"""
Returns the error defined as the 2-norm of y - y_hat.
y = Cx and y_hat = C_hat x_hat OR
Expand All @@ -160,6 +161,7 @@ def get_robustness_metric_with_input(self, reduced_sys):
return

def get_robustness_metric(self, reduced_sys):
# Create an option so the default way this is done is given two systems compute robustness metric.
# Implementing Theorem 2
timepoints_ssm = self.timepoints_ssm
_, x_sols, full_ssm = self.get_solutions()
Expand Down Expand Up @@ -231,7 +233,7 @@ def solve_timescale_separation(self, attempt_states):
attempt = []
for state in attempt_states:
attempt.append(self.x.index(state))
print('attempting to retain :', attempt)
print('attempting reduced states index:', attempt)
x_c = []
fast_states = []
f_c = []
Expand All @@ -250,12 +252,11 @@ def solve_timescale_separation(self, attempt_states):
x_hat.append(x[i])
x_hat_init.append(x_init[i])
# print('Reduced set of variables is', x_hat)
# print('f_hat = ',f_hat)
# print('f_hat = ',hat)
# print('Collapsed set of variables is', x_c)

# Try 1
lookup_collapsed = {}
for i in range(len(x_c)):
# print('Solving for ', x_c[i])
x_c_sub = solve(Eq(f_c[i]), x_c[i])
lookup_collapsed[x_c[i]] = x_c_sub
if len(x_c_sub) == 0:
Expand All @@ -267,33 +268,37 @@ def solve_timescale_separation(self, attempt_states):
for sub in x_c_sub:
if sub == 0:
x_c_sub.remove(0)
else:
# for sym in x_c_sub[0].free_symbols:
count = 0
while count >= 0:
sym = x_c_sub[0].free_symbols[count]
if sym in lookup_collapsed.keys():
print('The state {0} has been solved for but appears in the solution for the next variable, making the sub with {1} into the corresponding f_c and solving again should fix this.'.format(sym, lookup_collapsed[sym][0]))
if lookup_collapsed[sym][0] is None:
raise ValueError('Something went wrong...Check reduced/full/collapsed state descriptions.')
f_c[i] = f_c[i].subs(sym, lookup_collapsed[sym][0])
# print('Updating old x_c_sub then')
x_c_sub = solve(Eq(f_c[i]), x_c[i])
if len(x_c_sub) > 1:
# print('Multiple solutions obtained. Chooosing non-zero solution, check consistency. The solutions are ', x_c_sub)
for sub in x_c_sub:
if sub == 0:
x_c_sub.remove(0)
# print('with ',x_c_sub)
lookup_collapsed[x_c[i]] = x_c_sub
count = 0
elif count != len(x_c_sub[0].free_symbols) - 1:
count = count + 1
else:
count = -1
print('Solved for {0} to get {1}'.format(x_c[i], x_c_sub[0]))
# This x_c_sub should not contain previously eliminated variables otherwise circles continue
fast_states.append(x_c_sub[0])
count = 0
print(x_c_sub[0])
while count >= 0:
# print(count)
if count == len(list(x_c_sub[0].free_symbols)):
count = -1
continue
sym = list(x_c_sub[0].free_symbols)[count]
if sym not in x:
count = count + 1
continue
if sym in lookup_collapsed.keys():
# print('The state {0} has been solved for but appears in the solution for the next variable, making the sub with {1} into the corresponding f_c and solving again should fix this.'.format(sym, lookup_collapsed[sym][0]))
if lookup_collapsed[sym][0] is None:
raise ValueError('Something went wrong...Check reduced/full/collapsed state descriptions.')
f_c[i] = f_c[i].subs(sym, lookup_collapsed[sym][0])
# print('Updating old x_c_sub then')
x_c_sub = solve(Eq(f_c[i]), x_c[i])
if len(x_c_sub) > 1:
# print('Multiple solutions obtained. Chooosing non-zero solution, check consistency. The solutions are ', x_c_sub)
for sub in x_c_sub:
if sub == 0:
x_c_sub.remove(0)
# print('with ',x_c_sub)
lookup_collapsed[x_c[i]] = x_c_sub
count = 0
elif count != len(list(x_c_sub[0].free_symbols)) - 1:
count = count + 1
# print('Solved for {0} to get {1}'.format(x_c[i], x_c_sub[0]))
# This x_c_sub should not contain previously eliminated variables otherwise circles continue
fast_states.append(x_c_sub[0])

for i in range(len(fast_states)):
if fast_states[i] == []:
Expand All @@ -302,11 +307,6 @@ def solve_timescale_separation(self, attempt_states):
# print('Substituting {0} for variable {1} into f_hat{2}'.format(fast_states[i], x_c[i], j))
f_hat[j] = f_hat[j].subs(x_c[i], fast_states[i])
# print('f_hat = ',f_hat[j])
for j in range(len(f_c)):
# print('Substituting {0} for variable {1} into f_c{2}'.format(fast_states[i], x_c[i], j))
f_c[j] = f_c[j].subs(x_c[i], fast_states[i])
# print('f_c = ',f_c[j])

# Continue
for i in range(len(x_hat)):
for j in range(len(f_c)):
Expand Down Expand Up @@ -338,9 +338,9 @@ def solve_timescale_separation(self, attempt_states):
if flag:
warnings.warn('Check model consistency')
print('The time-scale separation that retains states {0} does not work because the state-variables {1} appear in the reduced model'.format(attempt, bugged_states))
return None, None
else:
print('Successful time-scale separation solution obtained.')
# return None, None

reduced_sys = create_system(x_hat, f_hat, params = self.params, C = C_hat,
params_values = self.params_values, x_init = x_hat_init)
Expand Down
6 changes: 6 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Automated Model Reduction Tool for SBML models
## Refer to the [bioRxiv paper](https://www.biorxiv.org/content/10.1101/640276v1) for more details

### To run - Use `michaelis-menten.ipynb` or other jupyter notebooks as demonstrative examples.

### Contact : Ayush Pandey (apandet at caltech dot edu) for any feedback or suggestions.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes

0 comments on commit 2872a33

Please sign in to comment.