use super::types::*;
use crate::error::OxirsResult;
use std::collections::HashMap;
use std::time::{Duration, Instant};
#[derive(Debug, Clone)]
pub struct RegulatoryProtein {
pub name: String,
pub function: RegulatoryFunction,
pub activity_level: f64,
pub binding_sites: Vec<BindingSite>,
pub modifications: Vec<PostTranslationalModification>,
pub half_life: Duration,
pub last_activity: Option<Instant>,
}
#[derive(Debug, Clone)]
pub struct BindingSite {
pub id: String,
pub affinity: f64,
pub specificity: BindingSpecificity,
pub occupied: bool,
pub bound_ligand: Option<String>,
}
#[derive(Debug, Clone)]
#[allow(clippy::upper_case_acronyms)]
pub enum BindingSpecificity {
DNA,
RNA,
Protein,
SmallMolecule,
Metabolite,
}
#[derive(Debug, Clone)]
pub struct PostTranslationalModification {
pub modification_type: ModificationType,
pub position: usize,
pub intensity: f64,
pub timestamp: Instant,
pub enzyme: Option<String>,
}
#[derive(Debug, Clone)]
pub struct CheckpointSystem {
pub spindle_checkpoint: SpindleCheckpoint,
pub dna_damage_checkpoint: DnaDamageCheckpoint,
pub replication_checkpoint: ReplicationCheckpoint,
pub metabolic_checkpoint: MetabolicCheckpoint,
pub quality_control_checkpoint: QualityControlCheckpoint,
}
#[derive(Debug, Clone)]
pub struct SpindleCheckpoint {
pub mad_proteins: Vec<MadProtein>,
pub bub_proteins: Vec<BubProtein>,
pub apc_c_regulation: ApcCRegulation,
pub kinetochore_signals: Vec<KinetochoreSignal>,
}
#[derive(Debug, Clone)]
pub struct MadProtein {
pub protein_type: MadProteinType,
pub activity_level: f64,
pub localization: ProteinLocalization,
pub binding_partners: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct BubProtein {
pub protein_type: BubProteinType,
pub activity_level: f64,
pub kinetochore_binding: bool,
pub phosphorylation_state: PhosphorylationState,
}
#[derive(Debug, Clone)]
pub struct ApcCRegulation {
pub cdc20_level: f64,
pub cdh1_level: f64,
pub activity_state: ApcCActivityState,
pub substrate_recognition: SubstrateRecognition,
}
#[derive(Debug, Clone)]
pub struct KinetochoreSignal {
pub signal_type: KinetochoreSignalType,
pub strength: f64,
pub duration: Duration,
pub source: String,
}
#[derive(Debug, Clone)]
pub struct DnaDamageCheckpoint {
pub atm_activity: f64,
pub atr_activity: f64,
pub p53_level: f64,
pub repair_mechanisms: Vec<DnaRepairMechanism>,
pub damage_sensors: Vec<DamageSensor>,
}
#[derive(Debug, Clone)]
pub struct DnaRepairMechanism {
pub repair_type: DnaRepairType,
pub efficiency: f64,
pub active_proteins: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct DamageSensor {
pub sensor_type: DamageSensorType,
pub sensitivity: f64,
pub response_time: Duration,
}
#[derive(Debug, Clone)]
pub struct ReplicationCheckpoint {
pub replication_forks: Vec<ReplicationFork>,
pub checkpoint_active: bool,
pub fork_protection_complex: ForkProtectionComplex,
}
#[derive(Debug, Clone)]
pub struct ReplicationFork {
pub position: usize,
pub stalled: bool,
pub proteins: Vec<String>,
pub speed: f64,
pub integrity: f64,
}
#[derive(Debug, Clone)]
pub struct ForkProtectionComplex {
pub components: Vec<String>,
pub activity: f64,
pub protection_efficiency: f64,
}
#[derive(Debug, Clone)]
pub struct MetabolicCheckpoint {
pub energy_levels: EnergyLevels,
pub nutrient_availability: NutrientAvailability,
pub metabolic_sensors: Vec<MetabolicSensor>,
}
#[derive(Debug, Clone)]
pub struct EnergyLevels {
pub atp: f64,
pub adp: f64,
pub amp: f64,
pub energy_charge: f64,
}
#[derive(Debug, Clone)]
pub struct NutrientAvailability {
pub glucose: f64,
pub amino_acids: HashMap<String, f64>,
pub lipids: f64,
pub vitamins: HashMap<String, f64>,
}
#[derive(Debug, Clone)]
pub struct MetabolicSensor {
pub sensor_type: MetabolicSensorType,
pub sensitivity: f64,
pub target_metabolite: String,
}
#[derive(Debug, Clone)]
pub struct QualityControlCheckpoint {
pub protein_qc: ProteinQualityControl,
pub rna_qc: RnaQualityControl,
pub organelle_qc: OrganelleQualityControl,
}
#[derive(Debug, Clone)]
pub struct ProteinQualityControl {
pub chaperones: Vec<ChaperoneSystem>,
pub proteasome_activity: f64,
pub autophagy_activity: f64,
}
#[derive(Debug, Clone)]
pub struct ChaperoneSystem {
pub chaperone_type: ChaperoneType,
pub activity: f64,
pub client_proteins: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct RnaQualityControl {
pub nmd_activity: f64,
pub surveillance_activity: f64,
pub exosome_activity: f64,
}
#[derive(Debug, Clone)]
pub struct OrganelleQualityControl {
pub mitochondrial_qc: MitochondrialQC,
pub er_qc: ErQualityControl,
}
#[derive(Debug, Clone)]
pub struct MitochondrialQC {
pub mitophagy_activity: f64,
pub membrane_potential: f64,
pub ros_levels: f64,
}
#[derive(Debug, Clone)]
pub struct ErQualityControl {
pub upr_activity: f64,
pub erad_activity: f64,
pub stress_level: f64,
}
#[derive(Debug, Clone)]
pub enum MadProteinType {
Mad1,
Mad2,
Mad3,
BubR1,
}
#[derive(Debug, Clone)]
pub enum BubProteinType {
Bub1,
Bub3,
BubR1,
}
#[derive(Debug, Clone)]
pub enum ProteinLocalization {
Kinetochore,
SpindlePole,
Cytoplasm,
Nucleus,
Centrosome,
Membrane,
}
#[derive(Debug, Clone)]
pub enum ApcCActivityState {
Active,
Inactive,
PartiallyActive(f64),
}
#[derive(Debug, Clone)]
pub struct SubstrateRecognition {
pub destruction_box: bool,
pub ken_box: bool,
pub abba_motif: bool,
}
#[derive(Debug, Clone)]
pub enum KinetochoreSignalType {
Tension,
Attachment,
Detachment,
Error,
}
#[derive(Debug, Clone)]
pub enum PhosphorylationState {
Phosphorylated,
Dephosphorylated,
PartiallyPhosphorylated(f64),
}
#[derive(Debug, Clone)]
pub enum DnaRepairType {
HomologousRecombination,
NonHomologousEndJoining,
BaseExcisionRepair,
NucleotideExcisionRepair,
MismatchRepair,
}
#[derive(Debug, Clone)]
#[allow(clippy::upper_case_acronyms)]
pub enum DamageSensorType {
ATM,
ATR,
DNAPKcs,
PARP1,
}
#[derive(Debug, Clone)]
#[allow(clippy::upper_case_acronyms)]
pub enum MetabolicSensorType {
AMPK,
MTor,
SIRT1,
HIF1a,
}
#[derive(Debug, Clone)]
pub enum ChaperoneType {
Hsp70,
Hsp90,
Hsp60,
SmallHSPs,
}
impl RegulatoryProtein {
pub fn new(name: String, function: RegulatoryFunction) -> Self {
Self {
name,
function,
activity_level: 1.0,
binding_sites: Vec::new(),
modifications: Vec::new(),
half_life: Duration::from_secs(3600), last_activity: None,
}
}
pub fn activate(&mut self) -> OxirsResult<()> {
self.activity_level = 1.0;
self.last_activity = Some(Instant::now());
Ok(())
}
pub fn deactivate(&mut self) -> OxirsResult<()> {
self.activity_level = 0.0;
Ok(())
}
pub fn add_modification(&mut self, mod_type: ModificationType, position: usize) {
let modification = PostTranslationalModification {
modification_type: mod_type,
position,
intensity: 1.0,
timestamp: Instant::now(),
enzyme: None,
};
self.modifications.push(modification);
}
pub fn remove_modification(&mut self, position: usize) {
self.modifications.retain(|m| m.position != position);
}
pub fn is_active(&self) -> bool {
self.activity_level > 0.1
}
pub fn calculate_current_activity(&self) -> f64 {
let base_activity = self.activity_level;
let modification_factor: f64 = self
.modifications
.iter()
.map(|m| match m.modification_type {
ModificationType::Phosphorylation => 1.2, ModificationType::Methylation => 0.8, ModificationType::Acetylation => 1.1, _ => 1.0,
})
.product();
let time_factor = if let Some(last_active) = self.last_activity {
let elapsed = last_active.elapsed();
if elapsed < self.half_life {
1.0
} else {
0.5_f64.powf(elapsed.as_secs_f64() / self.half_life.as_secs_f64())
}
} else {
1.0
};
base_activity * modification_factor * time_factor
}
}
impl CheckpointSystem {
pub fn new() -> Self {
Self {
spindle_checkpoint: SpindleCheckpoint::new(),
dna_damage_checkpoint: DnaDamageCheckpoint::new(),
replication_checkpoint: ReplicationCheckpoint::new(),
metabolic_checkpoint: MetabolicCheckpoint::new(),
quality_control_checkpoint: QualityControlCheckpoint::new(),
}
}
pub fn evaluate_checkpoints(&self) -> OxirsResult<CheckpointResult> {
let spindle_ok = self.spindle_checkpoint.check_alignment()?;
let dna_ok = self.dna_damage_checkpoint.check_integrity()?;
let replication_ok = self.replication_checkpoint.check_completion()?;
let metabolic_ok = self.metabolic_checkpoint.check_resources()?;
let quality_ok = self.quality_control_checkpoint.check_quality()?;
Ok(CheckpointResult {
spindle_checkpoint: spindle_ok,
dna_damage_checkpoint: dna_ok,
replication_checkpoint: replication_ok,
metabolic_checkpoint: metabolic_ok,
quality_control_checkpoint: quality_ok,
overall_pass: spindle_ok && dna_ok && replication_ok && metabolic_ok && quality_ok,
})
}
pub fn get_status_summary(&self) -> CheckpointStatusSummary {
CheckpointStatusSummary {
active_checkpoints: vec![
"Spindle".to_string(),
"DNA Damage".to_string(),
"Replication".to_string(),
"Metabolic".to_string(),
"Quality Control".to_string(),
],
critical_issues: Vec::new(),
warnings: Vec::new(),
}
}
}
impl Default for SpindleCheckpoint {
fn default() -> Self {
Self::new()
}
}
impl SpindleCheckpoint {
pub fn new() -> Self {
Self {
mad_proteins: vec![
MadProtein {
protein_type: MadProteinType::Mad1,
activity_level: 0.1, localization: ProteinLocalization::Kinetochore,
binding_partners: vec!["Mad2".to_string()],
},
MadProtein {
protein_type: MadProteinType::Mad2,
activity_level: 0.1, localization: ProteinLocalization::Kinetochore,
binding_partners: vec!["Mad1".to_string(), "Cdc20".to_string()],
},
],
bub_proteins: vec![
BubProtein {
protein_type: BubProteinType::Bub1,
activity_level: 1.0,
kinetochore_binding: true,
phosphorylation_state: PhosphorylationState::Phosphorylated,
},
BubProtein {
protein_type: BubProteinType::Bub3,
activity_level: 1.0,
kinetochore_binding: true,
phosphorylation_state: PhosphorylationState::Phosphorylated,
},
],
apc_c_regulation: ApcCRegulation {
cdc20_level: 0.5,
cdh1_level: 0.1,
activity_state: ApcCActivityState::Active, substrate_recognition: SubstrateRecognition {
destruction_box: true,
ken_box: true,
abba_motif: false,
},
},
kinetochore_signals: Vec::new(),
}
}
pub fn check_alignment(&self) -> OxirsResult<bool> {
let mad_activity: f64 = self.mad_proteins.iter().map(|p| p.activity_level).sum();
let apc_active = matches!(
self.apc_c_regulation.activity_state,
ApcCActivityState::Active
);
Ok(mad_activity < 0.5 && apc_active)
}
}
impl Default for DnaDamageCheckpoint {
fn default() -> Self {
Self::new()
}
}
impl DnaDamageCheckpoint {
pub fn new() -> Self {
Self {
atm_activity: 0.0,
atr_activity: 0.0,
p53_level: 0.1,
repair_mechanisms: vec![
DnaRepairMechanism {
repair_type: DnaRepairType::HomologousRecombination,
efficiency: 0.95,
active_proteins: vec![
"BRCA1".to_string(),
"BRCA2".to_string(),
"RAD51".to_string(),
],
},
DnaRepairMechanism {
repair_type: DnaRepairType::NonHomologousEndJoining,
efficiency: 0.85,
active_proteins: vec![
"DNA-PKcs".to_string(),
"Ku70".to_string(),
"Ku80".to_string(),
],
},
],
damage_sensors: vec![
DamageSensor {
sensor_type: DamageSensorType::ATM,
sensitivity: 0.99,
response_time: Duration::from_millis(100),
},
DamageSensor {
sensor_type: DamageSensorType::ATR,
sensitivity: 0.95,
response_time: Duration::from_millis(50),
},
],
}
}
pub fn check_integrity(&self) -> OxirsResult<bool> {
let damage_level = self.atm_activity + self.atr_activity;
Ok(damage_level < 0.1) }
}
impl Default for ReplicationCheckpoint {
fn default() -> Self {
Self::new()
}
}
impl ReplicationCheckpoint {
pub fn new() -> Self {
Self {
replication_forks: Vec::new(),
checkpoint_active: false,
fork_protection_complex: ForkProtectionComplex {
components: vec!["RPA".to_string(), "Rad9".to_string(), "Rad1".to_string()],
activity: 1.0,
protection_efficiency: 0.95,
},
}
}
pub fn check_completion(&self) -> OxirsResult<bool> {
let stalled_forks = self.replication_forks.iter().filter(|f| f.stalled).count();
Ok(stalled_forks == 0)
}
}
impl Default for MetabolicCheckpoint {
fn default() -> Self {
Self::new()
}
}
impl MetabolicCheckpoint {
pub fn new() -> Self {
Self {
energy_levels: EnergyLevels {
atp: 5.0,
adp: 1.0,
amp: 0.1,
energy_charge: 0.9,
},
nutrient_availability: NutrientAvailability {
glucose: 5.0,
amino_acids: HashMap::new(),
lipids: 2.0,
vitamins: HashMap::new(),
},
metabolic_sensors: vec![
MetabolicSensor {
sensor_type: MetabolicSensorType::AMPK,
sensitivity: 0.95,
target_metabolite: "AMP".to_string(),
},
MetabolicSensor {
sensor_type: MetabolicSensorType::MTor,
sensitivity: 0.90,
target_metabolite: "Amino acids".to_string(),
},
],
}
}
pub fn check_resources(&self) -> OxirsResult<bool> {
Ok(self.energy_levels.energy_charge > 0.7 && self.nutrient_availability.glucose > 1.0)
}
}
impl Default for QualityControlCheckpoint {
fn default() -> Self {
Self::new()
}
}
impl QualityControlCheckpoint {
pub fn new() -> Self {
Self {
protein_qc: ProteinQualityControl {
chaperones: vec![
ChaperoneSystem {
chaperone_type: ChaperoneType::Hsp70,
activity: 1.0,
client_proteins: Vec::new(),
},
ChaperoneSystem {
chaperone_type: ChaperoneType::Hsp90,
activity: 1.0,
client_proteins: Vec::new(),
},
],
proteasome_activity: 1.0,
autophagy_activity: 0.8,
},
rna_qc: RnaQualityControl {
nmd_activity: 1.0,
surveillance_activity: 1.0,
exosome_activity: 1.0,
},
organelle_qc: OrganelleQualityControl {
mitochondrial_qc: MitochondrialQC {
mitophagy_activity: 0.8,
membrane_potential: 180.0,
ros_levels: 0.2,
},
er_qc: ErQualityControl {
upr_activity: 0.1,
erad_activity: 1.0,
stress_level: 0.1,
},
},
}
}
pub fn check_quality(&self) -> OxirsResult<bool> {
let protein_ok = self.protein_qc.proteasome_activity > 0.5;
let rna_ok = self.rna_qc.nmd_activity > 0.5;
let organelle_ok = self.organelle_qc.mitochondrial_qc.membrane_potential > 150.0;
Ok(protein_ok && rna_ok && organelle_ok)
}
}
#[derive(Debug, Clone)]
pub struct CheckpointResult {
pub spindle_checkpoint: bool,
pub dna_damage_checkpoint: bool,
pub replication_checkpoint: bool,
pub metabolic_checkpoint: bool,
pub quality_control_checkpoint: bool,
pub overall_pass: bool,
}
#[derive(Debug, Clone)]
pub struct CheckpointStatusSummary {
pub active_checkpoints: Vec<String>,
pub critical_issues: Vec<String>,
pub warnings: Vec<String>,
}
impl Default for RegulatoryProtein {
fn default() -> Self {
Self::new("Unknown".to_string(), RegulatoryFunction::Loading)
}
}
impl Default for CheckpointSystem {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_regulatory_protein_creation() {
let protein =
RegulatoryProtein::new("TestProtein".to_string(), RegulatoryFunction::Loading);
assert_eq!(protein.name, "TestProtein");
assert!(protein.is_active());
}
#[test]
fn test_checkpoint_system() {
let checkpoint = CheckpointSystem::new();
let result = checkpoint
.evaluate_checkpoints()
.expect("operation should succeed");
assert!(result.overall_pass);
}
#[test]
fn test_protein_modification() {
let mut protein =
RegulatoryProtein::new("TestProtein".to_string(), RegulatoryFunction::Loading);
protein.add_modification(ModificationType::Phosphorylation, 100);
assert_eq!(protein.modifications.len(), 1);
protein.remove_modification(100);
assert_eq!(protein.modifications.len(), 0);
}
#[test]
fn test_protein_activity_calculation() {
let mut protein =
RegulatoryProtein::new("TestProtein".to_string(), RegulatoryFunction::Loading);
protein.activate().expect("operation should succeed");
let activity = protein.calculate_current_activity();
assert!(activity > 0.0);
}
}