1use super::types::*;
4use crate::error::OxirsResult;
5use std::collections::HashMap;
6use std::time::{Duration, Instant};
7
8#[derive(Debug, Clone)]
10pub struct RegulatoryProtein {
11 pub name: String,
13 pub function: RegulatoryFunction,
15 pub activity_level: f64,
17 pub binding_sites: Vec<BindingSite>,
19 pub modifications: Vec<PostTranslationalModification>,
21 pub half_life: Duration,
23 pub last_activity: Option<Instant>,
25}
26
27#[derive(Debug, Clone)]
29pub struct BindingSite {
30 pub id: String,
32 pub affinity: f64,
34 pub specificity: BindingSpecificity,
36 pub occupied: bool,
38 pub bound_ligand: Option<String>,
40}
41
42#[derive(Debug, Clone)]
44#[allow(clippy::upper_case_acronyms)]
45pub enum BindingSpecificity {
46 DNA,
47 RNA,
48 Protein,
49 SmallMolecule,
50 Metabolite,
51}
52
53#[derive(Debug, Clone)]
55pub struct PostTranslationalModification {
56 pub modification_type: ModificationType,
58 pub position: usize,
60 pub intensity: f64,
62 pub timestamp: Instant,
64 pub enzyme: Option<String>,
66}
67
68#[derive(Debug, Clone)]
70pub struct CheckpointSystem {
71 pub spindle_checkpoint: SpindleCheckpoint,
73 pub dna_damage_checkpoint: DnaDamageCheckpoint,
75 pub replication_checkpoint: ReplicationCheckpoint,
77 pub metabolic_checkpoint: MetabolicCheckpoint,
79 pub quality_control_checkpoint: QualityControlCheckpoint,
81}
82
83#[derive(Debug, Clone)]
85pub struct SpindleCheckpoint {
86 pub mad_proteins: Vec<MadProtein>,
88 pub bub_proteins: Vec<BubProtein>,
90 pub apc_c_regulation: ApcCRegulation,
92 pub kinetochore_signals: Vec<KinetochoreSignal>,
94}
95
96#[derive(Debug, Clone)]
98pub struct MadProtein {
99 pub protein_type: MadProteinType,
101 pub activity_level: f64,
103 pub localization: ProteinLocalization,
105 pub binding_partners: Vec<String>,
107}
108
109#[derive(Debug, Clone)]
111pub struct BubProtein {
112 pub protein_type: BubProteinType,
114 pub activity_level: f64,
116 pub kinetochore_binding: bool,
118 pub phosphorylation_state: PhosphorylationState,
120}
121
122#[derive(Debug, Clone)]
124pub struct ApcCRegulation {
125 pub cdc20_level: f64,
127 pub cdh1_level: f64,
129 pub activity_state: ApcCActivityState,
131 pub substrate_recognition: SubstrateRecognition,
133}
134
135#[derive(Debug, Clone)]
137pub struct KinetochoreSignal {
138 pub signal_type: KinetochoreSignalType,
140 pub strength: f64,
142 pub duration: Duration,
144 pub source: String,
146}
147
148#[derive(Debug, Clone)]
150pub struct DnaDamageCheckpoint {
151 pub atm_activity: f64,
153 pub atr_activity: f64,
155 pub p53_level: f64,
157 pub repair_mechanisms: Vec<DnaRepairMechanism>,
159 pub damage_sensors: Vec<DamageSensor>,
161}
162
163#[derive(Debug, Clone)]
165pub struct DnaRepairMechanism {
166 pub repair_type: DnaRepairType,
168 pub efficiency: f64,
170 pub active_proteins: Vec<String>,
172}
173
174#[derive(Debug, Clone)]
176pub struct DamageSensor {
177 pub sensor_type: DamageSensorType,
179 pub sensitivity: f64,
181 pub response_time: Duration,
183}
184
185#[derive(Debug, Clone)]
187pub struct ReplicationCheckpoint {
188 pub replication_forks: Vec<ReplicationFork>,
190 pub checkpoint_active: bool,
192 pub fork_protection_complex: ForkProtectionComplex,
194}
195
196#[derive(Debug, Clone)]
198pub struct ReplicationFork {
199 pub position: usize,
201 pub stalled: bool,
203 pub proteins: Vec<String>,
205 pub speed: f64,
207 pub integrity: f64,
209}
210
211#[derive(Debug, Clone)]
213pub struct ForkProtectionComplex {
214 pub components: Vec<String>,
216 pub activity: f64,
218 pub protection_efficiency: f64,
220}
221
222#[derive(Debug, Clone)]
224pub struct MetabolicCheckpoint {
225 pub energy_levels: EnergyLevels,
227 pub nutrient_availability: NutrientAvailability,
229 pub metabolic_sensors: Vec<MetabolicSensor>,
231}
232
233#[derive(Debug, Clone)]
235pub struct EnergyLevels {
236 pub atp: f64,
238 pub adp: f64,
240 pub amp: f64,
242 pub energy_charge: f64,
244}
245
246#[derive(Debug, Clone)]
248pub struct NutrientAvailability {
249 pub glucose: f64,
251 pub amino_acids: HashMap<String, f64>,
253 pub lipids: f64,
255 pub vitamins: HashMap<String, f64>,
257}
258
259#[derive(Debug, Clone)]
261pub struct MetabolicSensor {
262 pub sensor_type: MetabolicSensorType,
264 pub sensitivity: f64,
266 pub target_metabolite: String,
268}
269
270#[derive(Debug, Clone)]
272pub struct QualityControlCheckpoint {
273 pub protein_qc: ProteinQualityControl,
275 pub rna_qc: RnaQualityControl,
277 pub organelle_qc: OrganelleQualityControl,
279}
280
281#[derive(Debug, Clone)]
283pub struct ProteinQualityControl {
284 pub chaperones: Vec<ChaperoneSystem>,
286 pub proteasome_activity: f64,
288 pub autophagy_activity: f64,
290}
291
292#[derive(Debug, Clone)]
294pub struct ChaperoneSystem {
295 pub chaperone_type: ChaperoneType,
297 pub activity: f64,
299 pub client_proteins: Vec<String>,
301}
302
303#[derive(Debug, Clone)]
305pub struct RnaQualityControl {
306 pub nmd_activity: f64,
308 pub surveillance_activity: f64,
310 pub exosome_activity: f64,
312}
313
314#[derive(Debug, Clone)]
316pub struct OrganelleQualityControl {
317 pub mitochondrial_qc: MitochondrialQC,
319 pub er_qc: ErQualityControl,
321}
322
323#[derive(Debug, Clone)]
325pub struct MitochondrialQC {
326 pub mitophagy_activity: f64,
328 pub membrane_potential: f64,
330 pub ros_levels: f64,
332}
333
334#[derive(Debug, Clone)]
336pub struct ErQualityControl {
337 pub upr_activity: f64,
339 pub erad_activity: f64,
341 pub stress_level: f64,
343}
344
345#[derive(Debug, Clone)]
348pub enum MadProteinType {
349 Mad1,
350 Mad2,
351 Mad3,
352 BubR1,
353}
354
355#[derive(Debug, Clone)]
356pub enum BubProteinType {
357 Bub1,
358 Bub3,
359 BubR1,
360}
361
362#[derive(Debug, Clone)]
363pub enum ProteinLocalization {
364 Kinetochore,
365 SpindlePole,
366 Cytoplasm,
367 Nucleus,
368 Centrosome,
369 Membrane,
370}
371
372#[derive(Debug, Clone)]
373pub enum ApcCActivityState {
374 Active,
375 Inactive,
376 PartiallyActive(f64),
377}
378
379#[derive(Debug, Clone)]
380pub struct SubstrateRecognition {
381 pub destruction_box: bool,
382 pub ken_box: bool,
383 pub abba_motif: bool,
384}
385
386#[derive(Debug, Clone)]
387pub enum KinetochoreSignalType {
388 Tension,
389 Attachment,
390 Detachment,
391 Error,
392}
393
394#[derive(Debug, Clone)]
395pub enum PhosphorylationState {
396 Phosphorylated,
397 Dephosphorylated,
398 PartiallyPhosphorylated(f64),
399}
400
401#[derive(Debug, Clone)]
402pub enum DnaRepairType {
403 HomologousRecombination,
404 NonHomologousEndJoining,
405 BaseExcisionRepair,
406 NucleotideExcisionRepair,
407 MismatchRepair,
408}
409
410#[derive(Debug, Clone)]
411#[allow(clippy::upper_case_acronyms)]
412pub enum DamageSensorType {
413 ATM,
414 ATR,
415 DNAPKcs,
416 PARP1,
417}
418
419#[derive(Debug, Clone)]
420#[allow(clippy::upper_case_acronyms)]
421pub enum MetabolicSensorType {
422 AMPK,
423 MTor,
424 SIRT1,
425 HIF1a,
426}
427
428#[derive(Debug, Clone)]
429pub enum ChaperoneType {
430 Hsp70,
431 Hsp90,
432 Hsp60,
433 SmallHSPs,
434}
435
436impl RegulatoryProtein {
437 pub fn new(name: String, function: RegulatoryFunction) -> Self {
439 Self {
440 name,
441 function,
442 activity_level: 1.0,
443 binding_sites: Vec::new(),
444 modifications: Vec::new(),
445 half_life: Duration::from_secs(3600), last_activity: None,
447 }
448 }
449
450 pub fn activate(&mut self) -> OxirsResult<()> {
452 self.activity_level = 1.0;
453 self.last_activity = Some(Instant::now());
454 Ok(())
455 }
456
457 pub fn deactivate(&mut self) -> OxirsResult<()> {
459 self.activity_level = 0.0;
460 Ok(())
461 }
462
463 pub fn add_modification(&mut self, mod_type: ModificationType, position: usize) {
465 let modification = PostTranslationalModification {
466 modification_type: mod_type,
467 position,
468 intensity: 1.0,
469 timestamp: Instant::now(),
470 enzyme: None,
471 };
472 self.modifications.push(modification);
473 }
474
475 pub fn remove_modification(&mut self, position: usize) {
477 self.modifications.retain(|m| m.position != position);
478 }
479
480 pub fn is_active(&self) -> bool {
482 self.activity_level > 0.1
483 }
484
485 pub fn calculate_current_activity(&self) -> f64 {
487 let base_activity = self.activity_level;
488
489 let modification_factor: f64 = self
491 .modifications
492 .iter()
493 .map(|m| match m.modification_type {
494 ModificationType::Phosphorylation => 1.2, ModificationType::Methylation => 0.8, ModificationType::Acetylation => 1.1, _ => 1.0,
498 })
499 .product();
500
501 let time_factor = if let Some(last_active) = self.last_activity {
503 let elapsed = last_active.elapsed();
504 if elapsed < self.half_life {
505 1.0
506 } else {
507 0.5_f64.powf(elapsed.as_secs_f64() / self.half_life.as_secs_f64())
508 }
509 } else {
510 1.0
511 };
512
513 base_activity * modification_factor * time_factor
514 }
515}
516
517impl CheckpointSystem {
518 pub fn new() -> Self {
520 Self {
521 spindle_checkpoint: SpindleCheckpoint::new(),
522 dna_damage_checkpoint: DnaDamageCheckpoint::new(),
523 replication_checkpoint: ReplicationCheckpoint::new(),
524 metabolic_checkpoint: MetabolicCheckpoint::new(),
525 quality_control_checkpoint: QualityControlCheckpoint::new(),
526 }
527 }
528
529 pub fn evaluate_checkpoints(&self) -> OxirsResult<CheckpointResult> {
531 let spindle_ok = self.spindle_checkpoint.check_alignment()?;
532 let dna_ok = self.dna_damage_checkpoint.check_integrity()?;
533 let replication_ok = self.replication_checkpoint.check_completion()?;
534 let metabolic_ok = self.metabolic_checkpoint.check_resources()?;
535 let quality_ok = self.quality_control_checkpoint.check_quality()?;
536
537 Ok(CheckpointResult {
538 spindle_checkpoint: spindle_ok,
539 dna_damage_checkpoint: dna_ok,
540 replication_checkpoint: replication_ok,
541 metabolic_checkpoint: metabolic_ok,
542 quality_control_checkpoint: quality_ok,
543 overall_pass: spindle_ok && dna_ok && replication_ok && metabolic_ok && quality_ok,
544 })
545 }
546
547 pub fn get_status_summary(&self) -> CheckpointStatusSummary {
549 CheckpointStatusSummary {
550 active_checkpoints: vec![
551 "Spindle".to_string(),
552 "DNA Damage".to_string(),
553 "Replication".to_string(),
554 "Metabolic".to_string(),
555 "Quality Control".to_string(),
556 ],
557 critical_issues: Vec::new(),
558 warnings: Vec::new(),
559 }
560 }
561}
562
563impl Default for SpindleCheckpoint {
564 fn default() -> Self {
565 Self::new()
566 }
567}
568
569impl SpindleCheckpoint {
570 pub fn new() -> Self {
572 Self {
573 mad_proteins: vec![
574 MadProtein {
575 protein_type: MadProteinType::Mad1,
576 activity_level: 0.1, localization: ProteinLocalization::Kinetochore,
578 binding_partners: vec!["Mad2".to_string()],
579 },
580 MadProtein {
581 protein_type: MadProteinType::Mad2,
582 activity_level: 0.1, localization: ProteinLocalization::Kinetochore,
584 binding_partners: vec!["Mad1".to_string(), "Cdc20".to_string()],
585 },
586 ],
587 bub_proteins: vec![
588 BubProtein {
589 protein_type: BubProteinType::Bub1,
590 activity_level: 1.0,
591 kinetochore_binding: true,
592 phosphorylation_state: PhosphorylationState::Phosphorylated,
593 },
594 BubProtein {
595 protein_type: BubProteinType::Bub3,
596 activity_level: 1.0,
597 kinetochore_binding: true,
598 phosphorylation_state: PhosphorylationState::Phosphorylated,
599 },
600 ],
601 apc_c_regulation: ApcCRegulation {
602 cdc20_level: 0.5,
603 cdh1_level: 0.1,
604 activity_state: ApcCActivityState::Active, substrate_recognition: SubstrateRecognition {
606 destruction_box: true,
607 ken_box: true,
608 abba_motif: false,
609 },
610 },
611 kinetochore_signals: Vec::new(),
612 }
613 }
614
615 pub fn check_alignment(&self) -> OxirsResult<bool> {
617 let mad_activity: f64 = self.mad_proteins.iter().map(|p| p.activity_level).sum();
619
620 let apc_active = matches!(
622 self.apc_c_regulation.activity_state,
623 ApcCActivityState::Active
624 );
625
626 Ok(mad_activity < 0.5 && apc_active)
627 }
628}
629
630impl Default for DnaDamageCheckpoint {
631 fn default() -> Self {
632 Self::new()
633 }
634}
635
636impl DnaDamageCheckpoint {
637 pub fn new() -> Self {
639 Self {
640 atm_activity: 0.0,
641 atr_activity: 0.0,
642 p53_level: 0.1,
643 repair_mechanisms: vec![
644 DnaRepairMechanism {
645 repair_type: DnaRepairType::HomologousRecombination,
646 efficiency: 0.95,
647 active_proteins: vec![
648 "BRCA1".to_string(),
649 "BRCA2".to_string(),
650 "RAD51".to_string(),
651 ],
652 },
653 DnaRepairMechanism {
654 repair_type: DnaRepairType::NonHomologousEndJoining,
655 efficiency: 0.85,
656 active_proteins: vec![
657 "DNA-PKcs".to_string(),
658 "Ku70".to_string(),
659 "Ku80".to_string(),
660 ],
661 },
662 ],
663 damage_sensors: vec![
664 DamageSensor {
665 sensor_type: DamageSensorType::ATM,
666 sensitivity: 0.99,
667 response_time: Duration::from_millis(100),
668 },
669 DamageSensor {
670 sensor_type: DamageSensorType::ATR,
671 sensitivity: 0.95,
672 response_time: Duration::from_millis(50),
673 },
674 ],
675 }
676 }
677
678 pub fn check_integrity(&self) -> OxirsResult<bool> {
680 let damage_level = self.atm_activity + self.atr_activity;
681 Ok(damage_level < 0.1) }
683}
684
685impl Default for ReplicationCheckpoint {
686 fn default() -> Self {
687 Self::new()
688 }
689}
690
691impl ReplicationCheckpoint {
692 pub fn new() -> Self {
694 Self {
695 replication_forks: Vec::new(),
696 checkpoint_active: false,
697 fork_protection_complex: ForkProtectionComplex {
698 components: vec!["RPA".to_string(), "Rad9".to_string(), "Rad1".to_string()],
699 activity: 1.0,
700 protection_efficiency: 0.95,
701 },
702 }
703 }
704
705 pub fn check_completion(&self) -> OxirsResult<bool> {
707 let stalled_forks = self.replication_forks.iter().filter(|f| f.stalled).count();
708 Ok(stalled_forks == 0)
709 }
710}
711
712impl Default for MetabolicCheckpoint {
713 fn default() -> Self {
714 Self::new()
715 }
716}
717
718impl MetabolicCheckpoint {
719 pub fn new() -> Self {
721 Self {
722 energy_levels: EnergyLevels {
723 atp: 5.0,
724 adp: 1.0,
725 amp: 0.1,
726 energy_charge: 0.9,
727 },
728 nutrient_availability: NutrientAvailability {
729 glucose: 5.0,
730 amino_acids: HashMap::new(),
731 lipids: 2.0,
732 vitamins: HashMap::new(),
733 },
734 metabolic_sensors: vec![
735 MetabolicSensor {
736 sensor_type: MetabolicSensorType::AMPK,
737 sensitivity: 0.95,
738 target_metabolite: "AMP".to_string(),
739 },
740 MetabolicSensor {
741 sensor_type: MetabolicSensorType::MTor,
742 sensitivity: 0.90,
743 target_metabolite: "Amino acids".to_string(),
744 },
745 ],
746 }
747 }
748
749 pub fn check_resources(&self) -> OxirsResult<bool> {
751 Ok(self.energy_levels.energy_charge > 0.7 && self.nutrient_availability.glucose > 1.0)
752 }
753}
754
755impl Default for QualityControlCheckpoint {
756 fn default() -> Self {
757 Self::new()
758 }
759}
760
761impl QualityControlCheckpoint {
762 pub fn new() -> Self {
764 Self {
765 protein_qc: ProteinQualityControl {
766 chaperones: vec![
767 ChaperoneSystem {
768 chaperone_type: ChaperoneType::Hsp70,
769 activity: 1.0,
770 client_proteins: Vec::new(),
771 },
772 ChaperoneSystem {
773 chaperone_type: ChaperoneType::Hsp90,
774 activity: 1.0,
775 client_proteins: Vec::new(),
776 },
777 ],
778 proteasome_activity: 1.0,
779 autophagy_activity: 0.8,
780 },
781 rna_qc: RnaQualityControl {
782 nmd_activity: 1.0,
783 surveillance_activity: 1.0,
784 exosome_activity: 1.0,
785 },
786 organelle_qc: OrganelleQualityControl {
787 mitochondrial_qc: MitochondrialQC {
788 mitophagy_activity: 0.8,
789 membrane_potential: 180.0,
790 ros_levels: 0.2,
791 },
792 er_qc: ErQualityControl {
793 upr_activity: 0.1,
794 erad_activity: 1.0,
795 stress_level: 0.1,
796 },
797 },
798 }
799 }
800
801 pub fn check_quality(&self) -> OxirsResult<bool> {
803 let protein_ok = self.protein_qc.proteasome_activity > 0.5;
804 let rna_ok = self.rna_qc.nmd_activity > 0.5;
805 let organelle_ok = self.organelle_qc.mitochondrial_qc.membrane_potential > 150.0;
806
807 Ok(protein_ok && rna_ok && organelle_ok)
808 }
809}
810
811#[derive(Debug, Clone)]
813pub struct CheckpointResult {
814 pub spindle_checkpoint: bool,
815 pub dna_damage_checkpoint: bool,
816 pub replication_checkpoint: bool,
817 pub metabolic_checkpoint: bool,
818 pub quality_control_checkpoint: bool,
819 pub overall_pass: bool,
820}
821
822#[derive(Debug, Clone)]
824pub struct CheckpointStatusSummary {
825 pub active_checkpoints: Vec<String>,
826 pub critical_issues: Vec<String>,
827 pub warnings: Vec<String>,
828}
829
830impl Default for RegulatoryProtein {
831 fn default() -> Self {
832 Self::new("Unknown".to_string(), RegulatoryFunction::Loading)
833 }
834}
835
836impl Default for CheckpointSystem {
837 fn default() -> Self {
838 Self::new()
839 }
840}
841
842#[cfg(test)]
843mod tests {
844 use super::*;
845
846 #[test]
847 fn test_regulatory_protein_creation() {
848 let protein =
849 RegulatoryProtein::new("TestProtein".to_string(), RegulatoryFunction::Loading);
850 assert_eq!(protein.name, "TestProtein");
851 assert!(protein.is_active());
852 }
853
854 #[test]
855 fn test_checkpoint_system() {
856 let checkpoint = CheckpointSystem::new();
857 let result = checkpoint
858 .evaluate_checkpoints()
859 .expect("operation should succeed");
860 assert!(result.overall_pass);
861 }
862
863 #[test]
864 fn test_protein_modification() {
865 let mut protein =
866 RegulatoryProtein::new("TestProtein".to_string(), RegulatoryFunction::Loading);
867 protein.add_modification(ModificationType::Phosphorylation, 100);
868 assert_eq!(protein.modifications.len(), 1);
869
870 protein.remove_modification(100);
871 assert_eq!(protein.modifications.len(), 0);
872 }
873
874 #[test]
875 fn test_protein_activity_calculation() {
876 let mut protein =
877 RegulatoryProtein::new("TestProtein".to_string(), RegulatoryFunction::Loading);
878 protein.activate().expect("operation should succeed");
879
880 let activity = protein.calculate_current_activity();
881 assert!(activity > 0.0);
882 }
883}