Plate struct

This commit is contained in:
Emilia Allison 2023-05-11 20:47:31 -04:00
parent 94bb6b249d
commit 3a91b99b6b
Signed by: emilia
GPG Key ID: 7A3F8997BFE894E0
3 changed files with 75 additions and 0 deletions

1
src/data/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod plate;

73
src/data/plate.rs Normal file
View File

@ -0,0 +1,73 @@
pub struct Plate {
pub plate_type: PlateType,
pub plate_format: PlateFormat,
well_groups: Vec<u8>
}
impl Plate {
pub fn new(plate_type: PlateType, plate_format: PlateFormat) -> Self {
let (l,w) = plate_format.size();
Plate {
plate_type,
plate_format,
well_groups: Vec::with_capacity((l*w) as usize)
}
}
pub fn size(&self) -> (u8,u8) {
self.plate_format.size()
}
pub fn get_well_group(&self, i: u8, j: u8) -> u8 {
self.well_groups[ ((i-1)*self.size().1 + (j-1)) as usize ]
}
}
pub enum PlateType {
Source,
Destination
}
pub enum PlateFormat {
W6,
W12,
W24,
W48,
W96,
W384,
W1536,
W3456,
}
impl PlateFormat {
pub fn size(&self) -> (u8,u8) {
match self {
PlateFormat::W6 => (2,3),
PlateFormat::W12 => (3,4),
PlateFormat::W24 => (4,6),
PlateFormat::W48 => (6,8),
PlateFormat::W96 => (8,12),
PlateFormat::W384 => (16,24),
PlateFormat::W1536 => (32,48),
PlateFormat::W3456 => (48,72),
}
}
}
#[cfg(test)]
mod tests {
use super::{Plate, PlateFormat, PlateType};
#[test]
fn test_get_well_group() {
let plate = Plate { // Plate where we know every plate group number
plate_type: PlateType::Source,
plate_format: PlateFormat::W12,
well_groups: vec![1,2,3,4,5,6,7,8,9,10,11,12]
};
assert_eq!(plate.get_well_group(1, 3), 3);
assert_eq!(plate.get_well_group(2, 3), 7);
assert_eq!(plate.get_well_group(3, 1), 9);
}
}

View File

@ -1,5 +1,6 @@
#![allow(non_snake_case)]
mod components;
mod data;
use components::source_plate::SourcePlate;
use dioxus::prelude::*;