sciforge-hub 0.0.4

Central hub orchestrating Sciforge subsystems (api, engine, tools).
Documentation
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
//! Dispatch handler for aging biology functions.

use super::super::params::*;
use crate::domain::biology as bio;
use crate::domain::common::errors::{HubError, HubResult};
use crate::engine::experience::runner::RunOutput;

pub(super) fn dispatch(func: &str, p: &Params) -> HubResult<RunOutput> {
    match func {
        "telomere_shortening" => Ok(RunOutput::Scalar(bio::aging::damage::telomere_shortening(
            get_f(p, "initial_length")?,
            get_f(p, "loss_per_division")?,
            get_f(p, "divisions")?,
        ))),
        "aging_hayflick_limit" => Ok(RunOutput::Scalar(bio::aging::damage::hayflick_limit(
            get_f(p, "initial_length")?,
            get_f(p, "critical_length")?,
            get_f(p, "loss_per_division")?,
        ))),
        "telomerase_equilibrium" => Ok(RunOutput::Scalar(
            bio::aging::damage::telomerase_equilibrium(
                get_f(p, "shortening_rate")?,
                get_f(p, "elongation_rate")?,
                get_f(p, "initial")?,
                get_f(p, "t")?,
            ),
        )),
        "oxidative_damage_accumulation" => Ok(RunOutput::Scalar(
            bio::aging::damage::oxidative_damage_accumulation(
                get_f(p, "production_rate")?,
                get_f(p, "repair_rate")?,
                get_f(p, "t")?,
                get_f(p, "initial_damage")?,
            ),
        )),
        "mitochondrial_damage" => Ok(RunOutput::Scalar(bio::aging::damage::mitochondrial_damage(
            get_f(p, "intact_fraction")?,
            get_f(p, "damage_rate")?,
            get_f(p, "dt")?,
        ))),
        "senescent_cell_fraction" => Ok(RunOutput::Scalar(
            bio::aging::damage::senescent_cell_fraction(
                get_f(p, "division_rate")?,
                get_f(p, "senescence_prob")?,
                get_f(p, "clearance_rate")?,
                get_f(p, "t")?,
            ),
        )),
        "caloric_restriction_lifespan" => Ok(RunOutput::Scalar(
            bio::aging::damage::caloric_restriction_lifespan(
                get_f(p, "base_lifespan")?,
                get_f(p, "restriction_fraction")?,
                get_f(p, "effect_coefficient")?,
            ),
        )),
        "reliability_theory_survival" => Ok(RunOutput::Scalar(
            bio::aging::damage::reliability_theory_survival(
                get_u(p, "n_elements")?,
                get_f(p, "element_failure_rate")?,
                get_u(p, "redundancy")?,
                get_f(p, "t")?,
            ),
        )),
        "ros_steady_state" => Ok(RunOutput::Scalar(bio::aging::damage::ros_steady_state(
            get_f(p, "production_rate")?,
            get_f(p, "sod_activity")?,
            get_f(p, "catalase_activity")?,
        ))),
        "protein_aggregation" => Ok(RunOutput::Scalar(bio::aging::damage::protein_aggregation(
            get_f(p, "misfolded")?,
            get_f(p, "aggregation_rate")?,
            get_f(p, "chaperone_capacity")?,
            get_f(p, "dt")?,
        ))),
        "dna_repair_capacity" => Ok(RunOutput::Scalar(bio::aging::damage::dna_repair_capacity(
            get_f(p, "age")?,
            get_f(p, "base_capacity")?,
            get_f(p, "decline_rate")?,
        ))),
        "somatic_mutation_accumulation" => Ok(RunOutput::Scalar(
            bio::aging::damage::somatic_mutation_accumulation(
                get_f(p, "mutation_rate")?,
                get_f(p, "divisions")?,
                get_f(p, "repair_efficiency")?,
            ),
        )),
        "epigenetic_clock_horvath" => Ok(RunOutput::Scalar(
            bio::aging::damage::epigenetic_clock_horvath(
                get_v(p, "cpg_values")?,
                get_v(p, "coefficients")?,
                get_f(p, "intercept")?,
            ),
        )),
        "nad_decline" => Ok(RunOutput::Scalar(bio::aging::damage::nad_decline(
            get_f(p, "initial_nad")?,
            get_f(p, "decline_rate")?,
            get_f(p, "age")?,
        ))),
        "aging_autophagy_flux" => Ok(RunOutput::Scalar(bio::aging::damage::autophagy_flux(
            get_f(p, "substrate")?,
            get_f(p, "autophagosome_formation")?,
            get_f(p, "lysosomal_activity")?,
            get_f(p, "age_factor")?,
        ))),
        "stem_cell_exhaustion" => Ok(RunOutput::Scalar(bio::aging::damage::stem_cell_exhaustion(
            get_f(p, "initial_pool")?,
            get_f(p, "division_rate")?,
            get_f(p, "senescence_prob")?,
            get_f(p, "age")?,
        ))),
        "inflammaging_cytokine" => Ok(RunOutput::Scalar(
            bio::aging::damage::inflammaging_cytokine(
                get_f(p, "basal")?,
                get_f(p, "senescent_cells")?,
                get_f(p, "amplification")?,
            ),
        )),
        "crosslink_accumulation" => Ok(RunOutput::Scalar(
            bio::aging::damage::crosslink_accumulation(
                get_f(p, "rate")?,
                get_f(p, "turnover")?,
                get_f(p, "t")?,
            ),
        )),
        "lipofuscin_accumulation" => Ok(RunOutput::Scalar(
            bio::aging::damage::lipofuscin_accumulation(
                get_f(p, "production_rate")?,
                get_f(p, "t")?,
            ),
        )),
        "immune_senescence" => Ok(RunOutput::Scalar(bio::aging::damage::immune_senescence(
            get_f(p, "naive_t_cells")?,
            get_f(p, "thymic_output_rate")?,
            get_f(p, "age")?,
            get_f(p, "proliferation_capacity")?,
        ))),
        "gompertz_mortality_rate" => Ok(RunOutput::Scalar(
            bio::aging::mortality::gompertz_mortality_rate(
                get_f(p, "a")?,
                get_f(p, "b")?,
                get_f(p, "age")?,
            ),
        )),
        "gompertz_makeham" => Ok(RunOutput::Scalar(bio::aging::mortality::gompertz_makeham(
            get_f(p, "a")?,
            get_f(p, "b")?,
            get_f(p, "c")?,
            get_f(p, "age")?,
        ))),
        "weibull_mortality_hazard" => Ok(RunOutput::Scalar(
            bio::aging::mortality::weibull_mortality_hazard(
                get_f(p, "lambda")?,
                get_f(p, "k")?,
                get_f(p, "age")?,
            ),
        )),
        "mortality_doubling_time" => Ok(RunOutput::Scalar(
            bio::aging::mortality::mortality_doubling_time(get_f(p, "b")?),
        )),
        "survival_probability" => Ok(RunOutput::Scalar(
            bio::aging::mortality::survival_probability(get_v(p, "hazard_rates")?, get_f(p, "dt")?),
        )),
        "deceleration_plateau" => Ok(RunOutput::Scalar(
            bio::aging::mortality::deceleration_plateau(
                get_f(p, "age")?,
                get_f(p, "plateau_age")?,
                get_f(p, "plateau_rate")?,
                get_f(p, "a")?,
                get_f(p, "b")?,
            ),
        )),
        "frailty_deficit_index" => Ok(RunOutput::Scalar(
            bio::aging::mortality::frailty_deficit_index(
                get_u(p, "deficits")?,
                get_u(p, "total_items")?,
            ),
        )),
        "phenotypic_age_levine" => Ok(RunOutput::Scalar(
            bio::aging::mortality::phenotypic_age_levine(
                get_f(p, "albumin")?,
                get_f(p, "creatinine")?,
                get_f(p, "glucose")?,
                get_f(p, "crp")?,
                get_f(p, "lymphocyte_pct")?,
                get_f(p, "mcv")?,
                get_f(p, "rdw")?,
                get_f(p, "alp")?,
                get_f(p, "wbc")?,
                get_f(p, "chronological_age")?,
            ),
        )),
        "horvath_clock" => Ok(RunOutput::Scalar(bio::aging::mortality::horvath_clock(
            get_v(p, "cpg_betas")?,
            get_v(p, "coefficients")?,
            get_f(p, "intercept")?,
        ))),
        "cr_lifespan_extension" => Ok(RunOutput::Scalar(
            bio::aging::mortality::cr_lifespan_extension(
                get_f(p, "baseline_lifespan")?,
                get_f(p, "restriction_fraction")?,
                get_f(p, "max_extension")?,
            ),
        )),
        "reliability_theory_failure" => Ok(RunOutput::Scalar(
            bio::aging::mortality::reliability_theory_failure(
                get_u(p, "initial_elements")?,
                get_u(p, "redundancy")?,
                get_f(p, "failure_rate")?,
                get_f(p, "t")?,
            ),
        )),
        "ros_production_rate" => Ok(RunOutput::Scalar(
            bio::aging::oxidative_stress::ros_production_rate(
                get_f(p, "metabolic_rate")?,
                get_f(p, "coupling_efficiency")?,
            ),
        )),
        "antioxidant_capacity" => Ok(RunOutput::Scalar(
            bio::aging::oxidative_stress::antioxidant_capacity(
                get_f(p, "sod")?,
                get_f(p, "catalase")?,
                get_f(p, "glutathione")?,
                get_f(p, "k_sod")?,
                get_f(p, "k_cat")?,
                get_f(p, "k_gsh")?,
            ),
        )),
        "oxidative_damage_rate" => Ok(RunOutput::Scalar(
            bio::aging::oxidative_stress::oxidative_damage_rate(
                get_f(p, "ros_level")?,
                get_f(p, "antioxidant")?,
            ),
        )),
        "lipid_peroxidation" => Ok(RunOutput::Scalar(
            bio::aging::oxidative_stress::lipid_peroxidation(
                get_f(p, "pufa_concentration")?,
                get_f(p, "ros_level")?,
                get_f(p, "k_initiation")?,
                get_f(p, "k_propagation")?,
            ),
        )),
        "protein_carbonylation" => Ok(RunOutput::Scalar(
            bio::aging::oxidative_stress::protein_carbonylation(
                get_f(p, "protein_conc")?,
                get_f(p, "ros_level")?,
                get_f(p, "rate_constant")?,
            ),
        )),
        "dna_8oxog_formation" => Ok(RunOutput::Scalar(
            bio::aging::oxidative_stress::dna_8oxog_formation(
                get_f(p, "ros_level")?,
                get_f(p, "guanine_sites")?,
                get_f(p, "k_oxidation")?,
            ),
        )),
        "mitochondrial_ros_vicious_cycle" => Ok(RunOutput::Scalar(
            bio::aging::oxidative_stress::mitochondrial_ros_vicious_cycle(
                get_f(p, "damage")?,
                get_f(p, "ros_base")?,
                get_f(p, "amplification")?,
                get_f(p, "repair_rate")?,
                get_f(p, "dt")?,
            ),
        )),
        "glutathione_ratio" => Ok(RunOutput::Scalar(
            bio::aging::oxidative_stress::glutathione_ratio(get_f(p, "gsh")?, get_f(p, "gssg")?),
        )),
        "fenton_reaction_rate" => Ok(RunOutput::Scalar(
            bio::aging::oxidative_stress::fenton_reaction_rate(
                get_f(p, "fe2")?,
                get_f(p, "h2o2")?,
                get_f(p, "k_fenton")?,
            ),
        )),
        "nrf2_response" => Ok(RunOutput::Scalar(
            bio::aging::oxidative_stress::nrf2_response(
                get_f(p, "ros_level")?,
                get_f(p, "keap1")?,
                get_f(p, "k_activation")?,
            ),
        )),
        "carbonyl_stress" => Ok(RunOutput::Scalar(
            bio::aging::oxidative_stress::carbonyl_stress(
                get_f(p, "methylglyoxal")?,
                get_f(p, "glyoxalase")?,
                get_f(p, "km")?,
            ),
        )),
        "aging_oxidative_stress_index" => Ok(RunOutput::Scalar(
            bio::aging::oxidative_stress::oxidative_stress_index(
                get_f(p, "total_oxidant")?,
                get_f(p, "total_antioxidant")?,
            ),
        )),
        "gompertz_mortality" => Ok(RunOutput::Scalar(
            bio::aging::senescence::gompertz_mortality(
                get_f(p, "a")?,
                get_f(p, "b")?,
                get_f(p, "age")?,
            ),
        )),
        "aging_gompertz_survival" => Ok(RunOutput::Scalar(
            bio::aging::senescence::gompertz_survival(
                get_f(p, "a")?,
                get_f(p, "b")?,
                get_f(p, "age")?,
            ),
        )),
        "weibull_mortality" => Ok(RunOutput::Scalar(
            bio::aging::senescence::weibull_mortality(
                get_f(p, "lambda")?,
                get_f(p, "k")?,
                get_f(p, "age")?,
            ),
        )),
        "aging_weibull_survival" => {
            Ok(RunOutput::Scalar(bio::aging::senescence::weibull_survival(
                get_f(p, "lambda")?,
                get_f(p, "k")?,
                get_f(p, "age")?,
            )))
        }
        "gompertz_makeham_mortality" => Ok(RunOutput::Scalar(
            bio::aging::senescence::gompertz_makeham_mortality(
                get_f(p, "a")?,
                get_f(p, "b")?,
                get_f(p, "c")?,
                get_f(p, "age")?,
            ),
        )),
        "mortality_rate_doubling_time" => Ok(RunOutput::Scalar(
            bio::aging::senescence::mortality_rate_doubling_time(get_f(p, "b")?),
        )),
        "siler_mortality" => Ok(RunOutput::Scalar(bio::aging::senescence::siler_mortality(
            get_f(p, "a1")?,
            get_f(p, "b1")?,
            get_f(p, "a2")?,
            get_f(p, "a3")?,
            get_f(p, "b3")?,
            get_f(p, "age")?,
        ))),
        "logistic_mortality_plateau" => Ok(RunOutput::Scalar(
            bio::aging::senescence::logistic_mortality_plateau(
                get_f(p, "a")?,
                get_f(p, "b")?,
                get_f(p, "c")?,
                get_f(p, "age")?,
            ),
        )),
        "demographic_entropy" => Ok(RunOutput::Scalar(
            bio::aging::senescence::demographic_entropy(get_v(p, "life_table_lx")?),
        )),
        "net_reproduction_rate" => Ok(RunOutput::Scalar(
            bio::aging::senescence::net_reproduction_rate(
                get_v(p, "survivorship")?,
                get_v(p, "fecundity")?,
            ),
        )),
        "aging_generation_time" => Ok(RunOutput::Scalar(bio::aging::senescence::generation_time(
            get_v(p, "survivorship")?,
            get_v(p, "fecundity")?,
        ))),
        "actuarial_senescence_rate" => Ok(RunOutput::Scalar(
            bio::aging::senescence::actuarial_senescence_rate(
                get_f(p, "mortality_young")?,
                get_f(p, "mortality_old")?,
                get_f(p, "age_interval")?,
            ),
        )),
        "proportional_hazards" => Ok(RunOutput::Scalar(
            bio::aging::senescence::proportional_hazards(
                get_f(p, "baseline_hazard")?,
                get_v(p, "covariates")?,
                get_v(p, "coefficients")?,
            ),
        )),
        "biological_age_levine" => Ok(RunOutput::Scalar(
            bio::aging::senescence::biological_age_levine(
                get_f(p, "chronological_age")?,
                get_f(p, "albumin")?,
                get_f(p, "creatinine")?,
                get_f(p, "glucose")?,
                get_f(p, "crp_ln")?,
                get_f(p, "lymphocyte_pct")?,
                get_f(p, "mcv")?,
                get_f(p, "rdw")?,
                get_f(p, "alkaline_phosphatase")?,
                get_f(p, "wbc")?,
            ),
        )),
        "frailty_index" => {
            let deficits_present = get_i(p, "deficits_present")? as u32;
            let deficits_measured = get_i(p, "deficits_measured")? as u32;
            Ok(RunOutput::Scalar(bio::aging::senescence::frailty_index(
                deficits_present,
                deficits_measured,
            )))
        }
        "disability_free_life_expectancy" => Ok(RunOutput::Scalar(
            bio::aging::senescence::disability_free_life_expectancy(
                get_v(p, "survival")?,
                get_v(p, "disability_free")?,
            ),
        )),
        "telomere_attrition" => Ok(RunOutput::Scalar(
            bio::aging::telomeres::telomere_attrition(
                get_f(p, "initial_length")?,
                get_f(p, "loss_per_division")?,
                get_u(p, "divisions")?,
            ),
        )),
        "telomerase_elongation" => Ok(RunOutput::Scalar(
            bio::aging::telomeres::telomerase_elongation(
                get_f(p, "current_length")?,
                get_f(p, "rate")?,
                get_f(p, "telomerase_activity")?,
            ),
        )),
        "replicative_limit" => Ok(RunOutput::Scalar(bio::aging::telomeres::replicative_limit(
            get_f(p, "initial_length")?,
            get_f(p, "loss_per_division")?,
            get_f(p, "critical_length")?,
        ))),
        "telomere_length_distribution" => Ok(RunOutput::Vector(
            bio::aging::telomeres::telomere_length_distribution(
                get_f(p, "mean")?,
                get_f(p, "std_dev")?,
                get_u(p, "n_chromosomes")?,
            ),
        )),
        "critical_shortening_probability" => Ok(RunOutput::Scalar(
            bio::aging::telomeres::critical_shortening_probability(
                get_f(p, "mean_length")?,
                get_f(p, "std_dev")?,
                get_f(p, "critical")?,
            ),
        )),
        "shelterin_protection" => Ok(RunOutput::Scalar(
            bio::aging::telomeres::shelterin_protection(
                get_f(p, "telomere_length")?,
                get_f(p, "shelterin_kd")?,
            ),
        )),
        "end_replication_problem" => Ok(RunOutput::Scalar(
            bio::aging::telomeres::end_replication_problem(
                get_f(p, "lagging_strand_loss")?,
                get_u(p, "divisions")?,
            ),
        )),
        "alt_pathway_elongation" => Ok(RunOutput::Scalar(
            bio::aging::telomeres::alt_pathway_elongation(
                get_f(p, "recombination_rate")?,
                get_f(p, "donor_length")?,
                get_f(p, "recipient_length")?,
            ),
        )),
        "telomere_age_regression" => Ok(RunOutput::Scalar(
            bio::aging::telomeres::telomere_age_regression(
                get_f(p, "age")?,
                get_f(p, "birth_length")?,
                get_f(p, "annual_loss")?,
            ),
        )),
        "gompertz_survival" => Ok(RunOutput::Scalar(
            bio::aging::senescence::gompertz_survival(
                get_f(p, "a")?,
                get_f(p, "b")?,
                get_f(p, "age")?,
            ),
        )),
        "oxidative_stress_index" => Ok(RunOutput::Scalar(
            bio::aging::oxidative_stress::oxidative_stress_index(
                get_f(p, "total_oxidant")?,
                get_f(p, "total_antioxidant")?,
            ),
        )),
        "weibull_survival" => Ok(RunOutput::Scalar(bio::aging::senescence::weibull_survival(
            get_f(p, "lambda")?,
            get_f(p, "k")?,
            get_f(p, "age")?,
        ))),
        "life_expectancy" => {
            let v = get_v(p, "times")?;
            let s = get_v(p, "survivals")?;
            let curve: Vec<(f64, f64)> = v.iter().zip(s.iter()).map(|(&t, &sv)| (t, sv)).collect();
            Ok(RunOutput::Scalar(bio::aging::mortality::life_expectancy(
                &curve,
            )))
        }
        _ => Err(HubError::InvalidInput(format!("unknown function: {func}"))),
    }
}