Compare commits

..

No commits in common. "3d8445ec82ff82c7320eb5a1e8f83fa3c8fa5ba1" and "03d7f08e633ceae1f8e2e578f6f291867a9f513b" have entirely different histories.

1 changed files with 84 additions and 116 deletions

View File

@ -131,8 +131,10 @@ impl TransferRegion {
pub fn calculate_map(&self) -> Box<dyn Fn(Well) -> Option<Vec<Well>> + '_> {
// By validating first, we have a stronger guarantee that
// this function will not panic. :)
// log::debug!("Validating: {:?}", self.validate());
if let Err(msg) = self.validate() {
log::error!("{}\nThis transfer will be empty.", msg);
eprintln!("{}", msg);
eprintln!("This transfer will be empty.");
return Box::new(|_| None);
}
@ -202,30 +204,22 @@ impl TransferRegion {
);
let count = (
// How many times can we replicate?
if il_dest.0.unsigned_abs() == 0 {
1
} else {
(1..)
.position(|n| {
(n * number_used_src_wells.0 * il_dest.0.unsigned_abs())
.saturating_sub(il_dest.0.unsigned_abs())
n * number_used_src_wells.0 * il_dest.0.unsigned_abs()
- il_dest.0.unsigned_abs()
+ 1
> d_dims.0
})
.unwrap() as u8
},
if il_dest.1.unsigned_abs() == 0 {
1
} else {
.unwrap() as u8,
(1..)
.position(|n| {
(n * number_used_src_wells.1 * il_dest.1.unsigned_abs())
.saturating_sub(il_dest.1.unsigned_abs())
n * number_used_src_wells.1 * il_dest.1.unsigned_abs()
- il_dest.1.unsigned_abs()
+ 1
> d_dims.1
})
.unwrap() as u8
},
.unwrap() as u8,
);
let i = i
.saturating_sub(s_ul.row)
@ -233,34 +227,30 @@ impl TransferRegion {
let j = j
.saturating_sub(s_ul.col)
.saturating_div(il_source.1.unsigned_abs());
let checked_il_dest = (u8::max(il_dest.0.unsigned_abs(), 1u8),
u8::max(il_dest.1.unsigned_abs(), 1u8));
let row_modulus = number_used_src_wells.0 * checked_il_dest.0;
let column_modulus = number_used_src_wells.1 * checked_il_dest.1;
Some(
possible_destination_wells
.into_iter()
.filter(|Well { row: x , ..}| {
x.checked_sub(d_ul.row).unwrap()
% row_modulus // Counter along x
% (number_used_src_wells.0 * il_dest.0.unsigned_abs()) // Counter along x
== (il_dest.0.unsigned_abs() *i)
% row_modulus
% (number_used_src_wells.0 * il_dest.0.unsigned_abs())
})
.filter(|Well { col: y, .. }| {
y.checked_sub(d_ul.col).unwrap()
% column_modulus // Counter along u
% (number_used_src_wells.1 * il_dest.1.unsigned_abs()) // Counter along u
== (il_dest.1.unsigned_abs() *j)
% column_modulus
% (number_used_src_wells.1 * il_dest.1.unsigned_abs())
})
.filter(|Well { row: x, col: y }| {
// How many times have we replicated? < How many are we allowed
// to replicate?
x.checked_sub(d_ul.row).unwrap().div_euclid(
row_modulus
number_used_src_wells.0 * il_dest.0.unsigned_abs(),
) < count.0
&& y.checked_sub(d_ul.col).unwrap().div_euclid(
column_modulus
number_used_src_wells.1 * il_dest.1.unsigned_abs(),
) < count.1
})
.collect(),
@ -318,15 +308,11 @@ impl TransferRegion {
// log::debug!("s1.1: {}, max.1: {}", s1.1, source_max.1);
return Err("Source region is out-of-bounds! (Too wide)");
}
if il_dest == (0,0) {
return Err("Refusing to pool both dimensions in a rectangular transfer!\nPlease select a point in the destination plate.")
}
}
Region::Custom(_) => return Ok(()),
}
if il_source.0 == 0 || il_source.1 == 0 {
if il_source.0 == 0 || il_dest.1 == 0 {
return Err("Source interleave cannot be zero!");
}
@ -523,16 +509,12 @@ mod tests {
let transfer1_map = transfer1.calculate_map();
assert_eq!(
transfer1_map(Well{ row: 1, col: 1}),
Some(
vec! {Well{ row: 2, col: 2}, Well{ row: 2, col: 8}, Well{ row: 8, col: 2}, Well{ row: 8, col: 8}}
),
Some(vec! {Well{ row: 2, col: 2}, Well{ row: 2, col: 8}, Well{ row: 8, col: 2}, Well{ row: 8, col: 8}}),
"Failed type replicate 1"
);
assert_eq!(
transfer1_map(Well{ row: 2, col: 1}),
Some(
vec! {Well{ row: 5, col: 2}, Well{ row: 5, col: 8}, Well{ row: 11, col: 2}, Well{ row: 11, col: 8}}
),
Some(vec! {Well{ row: 5, col: 2}, Well{ row: 5, col: 8}, Well{ row: 11, col: 2}, Well{ row: 11, col: 8}}),
"Failed type replicate 1"
);
@ -548,14 +530,7 @@ mod tests {
let transfer2_dest = transfer2.get_destination_wells();
assert_eq!(
transfer2_source,
vec![
Well { row: 1, col: 1 },
Well { row: 1, col: 2 },
Well { row: 1, col: 3 },
Well { row: 2, col: 1 },
Well { row: 2, col: 2 },
Well { row: 2, col: 3 }
],
vec![Well{ row: 1, col: 1}, Well{ row: 1, col: 2}, Well{ row: 1, col: 3}, Well{ row: 2, col: 1}, Well{ row: 2, col: 2}, Well{ row: 2, col: 3}],
"Failed type replicate 2 source"
);
assert_eq!(
@ -607,14 +582,7 @@ mod tests {
// Skipping source check---it's just 12 wells.
assert_eq!(
transfer1_dest,
vec![
Well { row: 1, col: 9 },
Well { row: 1, col: 11 },
Well { row: 1, col: 13 },
Well { row: 1, col: 15 }
]
.into_iter()
.collect(),
vec![Well{ row: 1, col: 9}, Well{ row: 1, col: 11}, Well{ row: 1, col: 13}, Well{ row: 1, col: 15}].into_iter().collect(),
"Failed type pool 1 dest"
);
assert_eq!(