Skip to content

Commit c294abe

Browse files
Script to run timecourse in parallel.
1 parent 6d3aeab commit c294abe

5 files changed

Lines changed: 74 additions & 7 deletions

File tree

data/badmodels.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ BIOMD0000000133
4848
BIOMD0000000134
4949
BIOMD0000000135
5050
BIOMD0000000136
51+
BIOMD0000000137
5152
BIOMD0000000138
5253
BIOMD0000000139
5354
BIOMD0000000140
@@ -146,6 +147,7 @@ BIOMD0000000403
146147
BIOMD0000000404
147148
BIOMD0000000408
148149
BIOMD0000000416
150+
BIOMD0000000424
149151
BIOMD0000000429
150152
BIOMD0000000437
151153
BIOMD0000000450

docs/research_agenda.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
# Research Agenda
22

3-
## To what extent is BioModels linear?
3+
## How well can BioModels be modelled by a system of linear differential equaitons?
44
- [x] Fit first order monomial to all models and calculate $R^2$ for species time courses.
55
- Minimum $R^2$ is model $R^2$
66
- Individual $R^2$ are for species.
77
- [x] Evaluate the density of coefficients in the Jacobian.
88
- [ ] For the linear models, assess their dimensionality to see if dimension reduction is possible
99
- [ ] Characterize the linear models based on the what is being model and possibly other characteristics.
10-
11-
## What are the main reasons for nonlinear behavior?
12-
- [ ] Analyze the nonlinear models to determine which species are nonlinear and how/when the Jacobian changes to look at reactions.
1310

1411
## How robust is linearity to perturbations of initial values?
1512
- [ ] repeat the linear studies with perturbations of $\pm 5\%$, $\pm 19\%$, $\pm 20\%$, and $\pm 50\%$.
1613
- [ ] Can robustness be improved by training the regression on perturbation data?
1714

15+
## What are the main reasons for nonlinear behavior?
16+
- [ ] Analyze the nonlinear models to determine which species are nonlinear and how/when the Jacobian changes to look at reactions.
17+
1818
## Are some nonlinear models piecewise linear?
19-
- [ ] Use a standard package for partitioning regressions to see if linearity can be achieved in segements of the time course.
19+
- [ ] Use a standard package for partitioning regressions to see if linearity can be achieved in segements of the time course.
20+
- [ ] Normalize Jacobians
21+
- [ ] k-means cluster with cluster distances with minimum cluster size.
22+
- [ ] SystemDiscovery for each cluster
23+
- [ ] Prediction using: (a) ${\bf x} (t)$ using SystemDiscover of cluster at $t$ similarly for adjacent time points; (b) apply gaussian kernel on points; (c) denormalize

scripts/run_parallel_timecourse.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
# Run make_biomodels_timecourse.py in parallel across N workers.
3+
# Each worker receives an evenly divided slice of the 1078 BioModels.
4+
#
5+
# Usage: bash scripts/run_parallel_timecourse.sh <number_of_processes>
6+
7+
#set -euo pipefail
8+
9+
if [ $# -ne 1 ] || ! [[ $1 =~ ^[1-9][0-9]*$ ]]; then
10+
echo "Usage: $0 <number_of_processes>" >&2
11+
exit 1
12+
fi
13+
14+
NUM_PROCESSES=$1
15+
TOTAL_MODELS=1078
16+
TOTAL_MODELS=20
17+
FIRST_MODEL=1
18+
LAST_MODEL=$(( FIRST_MODEL + TOTAL_MODELS - 1 ))
19+
20+
# Ceiling division: chunk = ceil(TOTAL / N)
21+
CHUNK=$(( (TOTAL_MODELS + NUM_PROCESSES - 1) / NUM_PROCESSES ))
22+
23+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
24+
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
25+
26+
source "$PROJECT_DIR/activate.sh"
27+
mkdir -p "$PROJECT_DIR/logs"
28+
29+
echo "Launching $NUM_PROCESSES workers (~$CHUNK models each)..."
30+
31+
for i in $(seq 0 $(( NUM_PROCESSES - 1 ))); do
32+
FIRST=$(( FIRST_MODEL + i * CHUNK ))
33+
LAST=$(( FIRST + CHUNK - 1 ))
34+
if [ "$LAST" -gt "$LAST_MODEL" ]; then
35+
LAST=$LAST_MODEL
36+
fi
37+
LOG="$PROJECT_DIR/logs/timecourse_${FIRST}_${LAST}.log"
38+
echo " Worker $(( i + 1 )): models $FIRST$LAST$LOG"
39+
python "$SCRIPT_DIR/make_biomodels_timecourse.py" \
40+
--first_model_num "$FIRST" \
41+
--last_model_num "$LAST" \
42+
> "$LOG" 2>&1 &
43+
done
44+
45+
echo "All workers launched. Waiting for completion..."
46+
wait
47+
echo "Done."

src/timecourse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ def __eq__(self, other: object) -> bool:
7676
else bool(np.isclose(self.end_time, other.end_time))) and
7777
self.num_point == other.num_point and
7878
bool(np.allclose(self.timecourse_df.values,
79-
other.timecourse_df.values)) and
79+
other.timecourse_df.values, equal_nan=True)) and
8080
bool(np.allclose(self.jacobian_collection_arr,
81-
other.jacobian_collection_arr)))
81+
other.jacobian_collection_arr, equal_nan=True)))
8282

8383
def _updateEndtime(self, end_time: Optional[float]=None):
8484
"""Determine the end time and its source."""

tests/test_timecourse.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from timecourse import Timecourse # type: ignore
1919

2020
IGNORE_TESTS = False
21+
HAS_REAL_ZIP = os.path.isfile(cn.TIMECOURSE_ZIP_PATH)
22+
BIOMODEL_53 = "BIOMD0000000053"
2123

2224
ANTIMONY_MODEL = """
2325
S1 -> S2; k1*S1
@@ -640,5 +642,17 @@ def test_subplot_ylabel_is_concentration(self) -> None:
640642
self.assertEqual(ax.get_ylabel(), "concentration")
641643

642644

645+
class TestTimecourseEqRealBiomodel(unittest.TestCase):
646+
"""Verifies __eq__ with a real BioModel timecourse loaded from the zip archive."""
647+
648+
@unittest.skipUnless(HAS_REAL_ZIP, "Real timecourse zip not found")
649+
def test_biomodel53_equals_itself(self) -> None:
650+
if IGNORE_TESTS:
651+
return
652+
from timecourse_iterator import TimecourseIterator # type: ignore
653+
tc = TimecourseIterator().getTimecourse(BIOMODEL_53)
654+
self.assertEqual(tc, tc)
655+
656+
643657
if __name__ == "__main__":
644658
unittest.main()

0 commit comments

Comments
 (0)