chore: format
This commit is contained in:
parent
6a9a7ff0ff
commit
43331ff8f2
|
@ -55,7 +55,7 @@ fn SourcePlateCell(cx: Scope<PlateCellProps>, i: u8, j: u8, color: Option<String
|
||||||
};
|
};
|
||||||
let color_string = match color {
|
let color_string = match color {
|
||||||
Some(c) => c.clone(),
|
Some(c) => c.clone(),
|
||||||
None => "None".to_string()
|
None => "None".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
|
|
|
@ -18,7 +18,7 @@ impl Plate {
|
||||||
|
|
||||||
pub enum PlateType {
|
pub enum PlateType {
|
||||||
Source,
|
Source,
|
||||||
Destination
|
Destination,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum PlateFormat {
|
pub enum PlateFormat {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use super::plate::Plate;
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum Region {
|
pub enum Region {
|
||||||
Rect((u8, u8), (u8, u8)),
|
Rect((u8, u8), (u8, u8)),
|
||||||
Point((u8,u8))
|
Point((u8, u8)),
|
||||||
}
|
}
|
||||||
impl TryFrom<Region> for ((u8, u8), (u8, u8)) {
|
impl TryFrom<Region> for ((u8, u8), (u8, u8)) {
|
||||||
type Error = &'static str;
|
type Error = &'static str;
|
||||||
|
@ -47,7 +47,9 @@ impl TransferRegion<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return wells;
|
return wells;
|
||||||
} else { panic!("Source region is just a point!") }
|
} else {
|
||||||
|
panic!("Source region is just a point!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub fn get_destination_wells(&self) -> Vec<(u8, u8)> {
|
pub fn get_destination_wells(&self) -> Vec<(u8, u8)> {
|
||||||
let map = self.calculate_map();
|
let map = self.calculate_map();
|
||||||
|
@ -70,15 +72,16 @@ impl TransferRegion<'_> {
|
||||||
if let Err(msg) = self.validate() {
|
if let Err(msg) = self.validate() {
|
||||||
eprintln!("{}", msg);
|
eprintln!("{}", msg);
|
||||||
eprintln!("This transfer will be empty.");
|
eprintln!("This transfer will be empty.");
|
||||||
return Box::new(|(_,_)| None)
|
return Box::new(|(_, _)| None);
|
||||||
}
|
}
|
||||||
|
|
||||||
let source_wells = self.get_source_wells();
|
let source_wells = self.get_source_wells();
|
||||||
let il_dest = self.interleave_dest.unwrap_or((1, 1));
|
let il_dest = self.interleave_dest.unwrap_or((1, 1));
|
||||||
let il_source = self.interleave_source.unwrap_or((1, 1));
|
let il_source = self.interleave_source.unwrap_or((1, 1));
|
||||||
|
|
||||||
|
let source_corners: ((u8, u8), (u8, u8)) = self
|
||||||
let source_corners: ((u8,u8),(u8,u8)) = self.source_region.try_into()
|
.source_region
|
||||||
|
.try_into()
|
||||||
.expect("Source region should not be a point");
|
.expect("Source region should not be a point");
|
||||||
let (source_ul, _) = standardize_rectangle(&source_corners.0, &source_corners.1);
|
let (source_ul, _) = standardize_rectangle(&source_corners.0, &source_corners.1);
|
||||||
// This map is not necessarily injective or surjective,
|
// This map is not necessarily injective or surjective,
|
||||||
|
@ -88,20 +91,31 @@ impl TransferRegion<'_> {
|
||||||
|
|
||||||
// Non-replicate transfers:
|
// Non-replicate transfers:
|
||||||
match self.dest_region {
|
match self.dest_region {
|
||||||
Region::Point((x,y)) => return Box::new(move |(i,j)| {
|
Region::Point((x, y)) => {
|
||||||
|
return Box::new(move |(i, j)| {
|
||||||
if source_wells.contains(&(i, j)) {
|
if source_wells.contains(&(i, j)) {
|
||||||
// Validity here already checked by self.validate()
|
// Validity here already checked by self.validate()
|
||||||
Some(vec!((
|
Some(vec![(
|
||||||
x + i.checked_sub(source_ul.0).expect("Point cannot have been less than UL")
|
x + i
|
||||||
.checked_div(il_source.0.abs() as u8).expect("Source interleave cannot be 0")
|
.checked_sub(source_ul.0)
|
||||||
|
.expect("Point cannot have been less than UL")
|
||||||
|
.checked_div(il_source.0.abs() as u8)
|
||||||
|
.expect("Source interleave cannot be 0")
|
||||||
.mul(il_dest.0.abs() as u8),
|
.mul(il_dest.0.abs() as u8),
|
||||||
y + j.checked_sub(source_ul.1).expect("Point cannot have been less than UL")
|
y + j
|
||||||
.checked_div(il_source.1.abs() as u8).expect("Source interleave cannot be 0")
|
.checked_sub(source_ul.1)
|
||||||
|
.expect("Point cannot have been less than UL")
|
||||||
|
.checked_div(il_source.1.abs() as u8)
|
||||||
|
.expect("Source interleave cannot be 0")
|
||||||
.mul(il_dest.1.abs() as u8),
|
.mul(il_dest.1.abs() as u8),
|
||||||
)))
|
)])
|
||||||
} else { None }
|
} else {
|
||||||
}),
|
None
|
||||||
Region::Rect(c1, c2) => return Box::new(move |(i,j)| {
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Region::Rect(c1, c2) => {
|
||||||
|
return Box::new(move |(i, j)| {
|
||||||
// Because of our call to validate,
|
// Because of our call to validate,
|
||||||
// we can assume that our destination region contains
|
// we can assume that our destination region contains
|
||||||
// an integer number of our source regions.
|
// an integer number of our source regions.
|
||||||
|
@ -110,9 +124,16 @@ impl TransferRegion<'_> {
|
||||||
let possible_destination_wells = create_dense_rectangle(&c1, &c2);
|
let possible_destination_wells = create_dense_rectangle(&c1, &c2);
|
||||||
let (ds1, ds2) = standardize_rectangle(&c1, &c2);
|
let (ds1, ds2) = standardize_rectangle(&c1, &c2);
|
||||||
let (s1, s2) = standardize_rectangle(&source_corners.0, &source_corners.1);
|
let (s1, s2) = standardize_rectangle(&source_corners.0, &source_corners.1);
|
||||||
let dims = (s2.0.checked_sub(s1.0).unwrap()+1, s2.1.checked_sub(s1.1).unwrap()+1);
|
let dims = (
|
||||||
let relative_ij = (i.checked_sub(source_ul.0).expect("Point cannot have been less than UL"),
|
s2.0.checked_sub(s1.0).unwrap() + 1,
|
||||||
j.checked_sub(source_ul.1).expect("Point cannot have been less than UL"));
|
s2.1.checked_sub(s1.1).unwrap() + 1,
|
||||||
|
);
|
||||||
|
let relative_ij = (
|
||||||
|
i.checked_sub(source_ul.0)
|
||||||
|
.expect("Point cannot have been less than UL"),
|
||||||
|
j.checked_sub(source_ul.1)
|
||||||
|
.expect("Point cannot have been less than UL"),
|
||||||
|
);
|
||||||
/*
|
/*
|
||||||
println!("{} % {} == {}", i, dims.0, i*il_dest.0.abs() as u8 % dims.0);
|
println!("{} % {} == {}", i, dims.0, i*il_dest.0.abs() as u8 % dims.0);
|
||||||
for a in ds1.0..=ds2.0 {
|
for a in ds1.0..=ds2.0 {
|
||||||
|
@ -131,16 +152,27 @@ impl TransferRegion<'_> {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Some(possible_destination_wells.into_iter()
|
Some(
|
||||||
.filter(|(x,y)| i*il_dest.0.abs() as u8 % dims.0
|
possible_destination_wells
|
||||||
== (x.checked_sub(ds1.0).unwrap() + 1) % dims.0 &&
|
.into_iter()
|
||||||
j*il_dest.1.abs() as u8 % dims.1
|
.filter(|(x, y)| {
|
||||||
== (y.checked_sub(ds1.1).unwrap() + 1) % dims.1)
|
i * il_dest.0.abs() as u8 % dims.0
|
||||||
.filter(|(x,y)| (x.checked_sub(ds1.0).unwrap()) % il_dest.0.abs() as u8 == 0 &&
|
== (x.checked_sub(ds1.0).unwrap() + 1) % dims.0
|
||||||
(y.checked_sub(ds1.1).unwrap()) % il_dest.1.abs() as u8 == 0)
|
&& j * il_dest.1.abs() as u8 % dims.1
|
||||||
.collect())
|
== (y.checked_sub(ds1.1).unwrap() + 1) % dims.1
|
||||||
} else { None }
|
|
||||||
})
|
})
|
||||||
|
.filter(|(x, y)| {
|
||||||
|
(x.checked_sub(ds1.0).unwrap()) % il_dest.0.abs() as u8 == 0
|
||||||
|
&& (y.checked_sub(ds1.1).unwrap()) % il_dest.1.abs() as u8
|
||||||
|
== 0
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,19 +192,16 @@ impl TransferRegion<'_> {
|
||||||
Region::Point(_) => return Err("Source region should not be a point!"),
|
Region::Point(_) => return Err("Source region should not be a point!"),
|
||||||
Region::Rect(s1, s2) => {
|
Region::Rect(s1, s2) => {
|
||||||
// Check if all source wells exist:
|
// Check if all source wells exist:
|
||||||
if s1.0 == 0 || s1.1 == 0
|
if s1.0 == 0 || s1.1 == 0 || s2.0 == 0 || s2.1 == 0 {
|
||||||
|| s2.0 == 0 || s2.1 == 0 {
|
return Err("Source region is out-of-bounds! (Too small)");
|
||||||
return Err("Source region is out-of-bounds! (Too small)")
|
|
||||||
}
|
}
|
||||||
// Sufficient to check if the corners are in-bounds
|
// Sufficient to check if the corners are in-bounds
|
||||||
let source_max = self.source_plate.size();
|
let source_max = self.source_plate.size();
|
||||||
if s1.0 > source_max.0 ||
|
if s1.0 > source_max.0 || s2.0 > source_max.0 {
|
||||||
s2.0 > source_max.0 {
|
return Err("Source region is out-of-bounds! (Too tall)");
|
||||||
return Err("Source region is out-of-bounds! (Too tall)")
|
|
||||||
}
|
}
|
||||||
if s1.1 > source_max.1 ||
|
if s1.1 > source_max.1 || s2.1 > source_max.1 {
|
||||||
s2.1 > source_max.1 {
|
return Err("Source region is out-of-bounds! (Too wide)");
|
||||||
return Err("Source region is out-of-bounds! (Too wide)")
|
|
||||||
}
|
}
|
||||||
// Check that source lengths divide destination lengths
|
// Check that source lengths divide destination lengths
|
||||||
match &self.dest_region {
|
match &self.dest_region {
|
||||||
|
@ -184,25 +213,28 @@ impl TransferRegion<'_> {
|
||||||
// (dim)*(il) - (il - 1)
|
// (dim)*(il) - (il - 1)
|
||||||
let dest_diff_i = ((il_dest.0.abs() as u8) * u8::abs_diff(d1.0, d2.0))
|
let dest_diff_i = ((il_dest.0.abs() as u8) * u8::abs_diff(d1.0, d2.0))
|
||||||
.checked_sub(il_dest.0.abs() as u8 - 1)
|
.checked_sub(il_dest.0.abs() as u8 - 1)
|
||||||
.expect("Dimension is somehow negative?")+1;
|
.expect("Dimension is somehow negative?")
|
||||||
|
+ 1;
|
||||||
let dest_diff_j = ((il_dest.1.abs() as u8) * u8::abs_diff(d1.1, d2.1))
|
let dest_diff_j = ((il_dest.1.abs() as u8) * u8::abs_diff(d1.1, d2.1))
|
||||||
.checked_sub(il_dest.1.abs() as u8 - 1)
|
.checked_sub(il_dest.1.abs() as u8 - 1)
|
||||||
.expect("Dimension is somehow negative?")+1;
|
.expect("Dimension is somehow negative?")
|
||||||
|
+ 1;
|
||||||
let source_diff_i = ((il_source.0.abs() as u8) * u8::abs_diff(s1.0, s2.0))
|
let source_diff_i = ((il_source.0.abs() as u8) * u8::abs_diff(s1.0, s2.0))
|
||||||
.checked_sub(il_source.0.abs() as u8 - 1)
|
.checked_sub(il_source.0.abs() as u8 - 1)
|
||||||
.expect("Dimension is somehow negative?")+1;
|
.expect("Dimension is somehow negative?")
|
||||||
|
+ 1;
|
||||||
let source_diff_j = ((il_source.1.abs() as u8) * u8::abs_diff(s1.1, s2.1))
|
let source_diff_j = ((il_source.1.abs() as u8) * u8::abs_diff(s1.1, s2.1))
|
||||||
.checked_sub(il_source.1.abs() as u8 - 1)
|
.checked_sub(il_source.1.abs() as u8 - 1)
|
||||||
.expect("Dimension is somehow negative?")+1;
|
.expect("Dimension is somehow negative?")
|
||||||
|
+ 1;
|
||||||
|
|
||||||
if dest_diff_i % source_diff_i != 0 {
|
if dest_diff_i % source_diff_i != 0 {
|
||||||
eprintln!("{} {}", source_diff_i, dest_diff_i);
|
eprintln!("{} {}", source_diff_i, dest_diff_i);
|
||||||
return Err("Replicate region has indivisible height!")
|
return Err("Replicate region has indivisible height!");
|
||||||
}
|
}
|
||||||
if dest_diff_j % source_diff_j != 0 {
|
if dest_diff_j % source_diff_j != 0 {
|
||||||
eprintln!("{} {}", source_diff_j, source_diff_j);
|
eprintln!("{} {}", source_diff_j, source_diff_j);
|
||||||
return Err("Replicate region has indivisible width!")
|
return Err("Replicate region has indivisible width!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,18 +243,16 @@ impl TransferRegion<'_> {
|
||||||
|
|
||||||
if let Some(source_il) = self.interleave_source {
|
if let Some(source_il) = self.interleave_source {
|
||||||
if source_il.0 == 0 || source_il.1 == 0 {
|
if source_il.0 == 0 || source_il.1 == 0 {
|
||||||
return Err("Source interleave cannot be zero!")
|
return Err("Source interleave cannot be zero!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Check if all destination wells exist:
|
// Check if all destination wells exist:
|
||||||
// NOT IMPLEMENTED
|
// NOT IMPLEMENTED
|
||||||
// Should *not* happen in this function---otherwise
|
// Should *not* happen in this function---otherwise
|
||||||
// we'd get a nasty recursive loop.
|
// we'd get a nasty recursive loop.
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
return Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,10 +263,8 @@ fn in_region(pt: (u8,u8), r: &Region) -> bool {
|
||||||
&& pt.0 >= u8::min(c1.0, c2.0)
|
&& pt.0 >= u8::min(c1.0, c2.0)
|
||||||
&& pt.1 <= u8::max(c1.1, c2.1)
|
&& pt.1 <= u8::max(c1.1, c2.1)
|
||||||
&& pt.1 >= u8::min(c1.1, c2.1)
|
&& pt.1 >= u8::min(c1.1, c2.1)
|
||||||
},
|
|
||||||
Region::Point((i, j)) => {
|
|
||||||
pt.0 == *i && pt.1 == *j
|
|
||||||
}
|
}
|
||||||
|
Region::Point((i, j)) => pt.0 == *i && pt.1 == *j,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +287,10 @@ fn standardize_rectangle(c1: &(u8,u8), c2: &(u8,u8)) -> ((u8,u8),(u8,u8)) {
|
||||||
let upper_left_j = u8::min(c1.1, c2.1);
|
let upper_left_j = u8::min(c1.1, c2.1);
|
||||||
let bottom_right_i = u8::max(c1.0, c2.0);
|
let bottom_right_i = u8::max(c1.0, c2.0);
|
||||||
let bottom_right_j = u8::max(c1.1, c2.1);
|
let bottom_right_j = u8::max(c1.1, c2.1);
|
||||||
return ((upper_left_i,upper_left_j),(bottom_right_i,bottom_right_j));
|
return (
|
||||||
|
(upper_left_i, upper_left_j),
|
||||||
|
(bottom_right_i, bottom_right_j),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
|
11
src/lib.rs
11
src/lib.rs
|
@ -22,17 +22,16 @@ pub fn App(cx: Scope) -> Element {
|
||||||
|
|
||||||
pub fn plate_test() {
|
pub fn plate_test() {
|
||||||
let source = plate::Plate::new(plate::PlateType::Source, plate::PlateFormat::W96);
|
let source = plate::Plate::new(plate::PlateType::Source, plate::PlateFormat::W96);
|
||||||
let destination = plate::Plate::new(plate::PlateType::Destination, plate::PlateFormat::W96);
|
let destination = plate::Plate::new(plate::PlateType::Destination, plate::PlateFormat::W384);
|
||||||
|
|
||||||
let transfer = transfer_region::TransferRegion {
|
let transfer = transfer_region::TransferRegion {
|
||||||
source_plate: &source,
|
source_plate: &source,
|
||||||
source_region: transfer_region::Region::Rect((1,1), (6,6)),
|
source_region: transfer_region::Region::Rect((1, 1), (5, 1)),
|
||||||
dest_plate: &destination,
|
dest_plate: &destination,
|
||||||
dest_region: transfer_region::Region::Point((2,2)),
|
dest_region: transfer_region::Region::Rect((1, 1), (10, 4)),
|
||||||
|
//dest_region: transfer_region::Region::Point((3,3)),
|
||||||
interleave_source: None,
|
interleave_source: None,
|
||||||
interleave_dest: None
|
interleave_dest: Some((1, 2)),
|
||||||
};
|
};
|
||||||
println!("{}", transfer);
|
println!("{}", transfer);
|
||||||
println!("{:?}", transfer.get_source_wells());
|
|
||||||
println!("{:?}", transfer.get_destination_wells());
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use plate_tool::App;
|
|
||||||
use plate_tool::plate_test;
|
use plate_tool::plate_test;
|
||||||
|
use plate_tool::App;
|
||||||
use wasm_logger;
|
use wasm_logger;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
Loading…
Reference in New Issue