-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_element.m
More file actions
99 lines (87 loc) · 4.66 KB
/
run_element.m
File metadata and controls
99 lines (87 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
% =========================================================================
% run_element.m — ELEMENT v2.0 Universal Launcher
% =========================================================================
% USAGE (command line):
% matlab -batch "run('run_element.m')"
%
% USAGE (interactive):
% >> run_element
%
% The only file you need to edit before running is:
% inputs/element_config.json
%
% Full documentation: README.md
% =========================================================================
%% ── 0. Resolve repo root ────────────────────────────────────────────────
this_file = mfilename('fullpath');
if isempty(this_file)
REPO_ROOT = pwd;
else
REPO_ROOT = fileparts(this_file);
end
fprintf('\n[ELEMENT] REPO_ROOT: %s\n', REPO_ROOT);
%% ── 1. Load configuration ───────────────────────────────────────────────
cfg_path = fullfile(REPO_ROOT, 'inputs', 'element_config.json');
if ~exist(cfg_path, 'file')
error('[ELEMENT] Config not found: %s\nCopy inputs/element_config.json and edit it.', cfg_path);
end
raw = fileread(cfg_path);
cfg = jsondecode(raw);
fprintf('[ELEMENT] Config loaded: project="%s" organism="%s"\n', ...
cfg.project.id, cfg.project.organism);
%% ── 2. COBRA Toolbox ────────────────────────────────────────────────────
cobra_path = fullfile(REPO_ROOT, cfg.cobratoolbox_path.path);
if ~exist(cobra_path, 'dir')
% Try system install
if exist('initCobraToolbox', 'file')
fprintf('[ELEMENT] Using system COBRA Toolbox.\n');
else
error('[ELEMENT] COBRA Toolbox not found at %s\nRun: git clone https://github.com/opencobra/cobratoolbox.git', cobra_path);
end
else
addpath(genpath(cobra_path));
fprintf('[ELEMENT] COBRA Toolbox added: %s\n', cobra_path);
end
try
initCobraToolbox(false);
catch ME
fprintf('[ELEMENT] WARN initCobraToolbox: %s\n', ME.message);
end
%% ── 3. CPLEX solver (optional, falls back to GLPK) ─────────────────────
addpath(genpath(fullfile(REPO_ROOT, 'matlab'))); % ELEMENT library (all phases)
solver_setup(); % getting/solver_setup — auto-detects CPLEX, falls back to GLPK
%% ── 4. Validate GEM ─────────────────────────────────────────────────────
gem_path = fullfile(REPO_ROOT, cfg.gem.path);
if ~exist(gem_path, 'file')
error('[ELEMENT] GEM not found: %s', gem_path);
end
fprintf('[ELEMENT] GEM: %s\n', gem_path);
%% ── 5. Build paths struct for downstream scripts ────────────────────────
paths.repo_root = REPO_ROOT;
paths.gem = gem_path;
paths.config = cfg_path;
paths.outputs = fullfile(REPO_ROOT, 'outputs');
paths.matlab_dir = fullfile(REPO_ROOT, 'matlab');
paths.inputs_db = fullfile(REPO_ROOT, 'inputs', 'db');
if ~exist(paths.outputs, 'dir'), mkdir(paths.outputs); end
%% ── 6. Map config to WF37-compatible format expected by pipeline ────────
WF_ROOT = REPO_ROOT; % WF_ROOT alias for all sub-scripts
% Build eflux2 weights in outputs/eflux2/
eflux_dir = fullfile(paths.outputs, 'eflux2');
if ~exist(eflux_dir, 'dir'), mkdir(eflux_dir); end
% Pass config values into environment expected by sub-scripts
MAX_ITER = cfg.milp_parameters.max_iterations;
K_ROUTES = cfg.milp_parameters.k_routes_per_iter;
PATIENCE = cfg.milp_parameters.patience;
TARGET_C3 = cfg.milp_parameters.target_C3;
fprintf('\n[ELEMENT] ============================================================\n');
fprintf('[ELEMENT] ELEMENT v1.0 — %s\n', datestr(now));
fprintf('[ELEMENT] Organism : %s\n', cfg.project.organism);
fprintf('[ELEMENT] Substrate: %s → %s\n', cfg.project.substrate_id, cfg.project.product_name);
fprintf('[ELEMENT] MAX_ITER=%d | K_ROUTES=%d | PATIENCE=%d | TARGET_C3=%.2f\n', ...
MAX_ITER, K_ROUTES, PATIENCE, TARGET_C3);
fprintf('[ELEMENT] ============================================================\n');
%% ── 7. Run iterative discovery loop ─────────────────────────────────────
pipeline_iterative_loop(WF_ROOT, MAX_ITER, K_ROUTES, PATIENCE, TARGET_C3);
fprintf('\n[ELEMENT] Pipeline completed: %s\n', datestr(now));
fprintf('[ELEMENT] Results in: %s\n', paths.outputs);fprintf('[ELEMENT] Version: 2.0.0 | Phases: getting→discovery→mecate→core→expression→scoring→reporting\n');