Skip to main content

gapsmith_core/
compartment.rs

1//! Compartment identifiers.
2//!
3//! gapseq models use three compartments: cytosol (`c0`), extracellular (`e0`),
4//! and periplasm (`p0`). See `src/construct_full_model.R:8`.
5
6use serde::{Deserialize, Serialize};
7
8/// Compact compartment index. Stored as `u8` so per-metabolite compartment
9/// membership is a cheap vector of bytes.
10#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
11#[serde(transparent)]
12pub struct CompartmentId(pub u8);
13
14impl CompartmentId {
15    pub const CYTOSOL: CompartmentId = CompartmentId(0);
16    pub const EXTRACELLULAR: CompartmentId = CompartmentId(1);
17    pub const PERIPLASM: CompartmentId = CompartmentId(2);
18}
19
20/// Compartment metadata carried on the model.
21#[derive(Clone, Debug, Serialize, Deserialize)]
22pub struct Compartment {
23    pub id: String,   // e.g. "c0"
24    pub name: String, // e.g. "Cytosol"
25}
26
27impl Compartment {
28    pub fn cytosol() -> Self {
29        Self { id: "c0".into(), name: "Cytosol".into() }
30    }
31    pub fn extracellular() -> Self {
32        Self { id: "e0".into(), name: "Extracellular".into() }
33    }
34    pub fn periplasm() -> Self {
35        Self { id: "p0".into(), name: "Periplasm".into() }
36    }
37    pub fn default_three() -> Vec<Compartment> {
38        vec![Self::cytosol(), Self::extracellular(), Self::periplasm()]
39    }
40}