diff --git a/plate-tool-lib/src/csv/alternative_formats.rs b/plate-tool-lib/src/csv/alternative_formats.rs new file mode 100644 index 0000000..7059760 --- /dev/null +++ b/plate-tool-lib/src/csv/alternative_formats.rs @@ -0,0 +1,26 @@ +use serde::Serialize; + +use super::TransferRecord; + +// Format preferred by the Echo Client when using the Pick-List function. +// Note that this does not export plate info! +// Exports of this type should combine all transfers between the two actively selected plates. +#[derive(Serialize, Debug)] +pub struct EchoClientTransferRecord { + #[serde(rename = "SrcWell")] + pub source_well: String, + #[serde(rename = "DestWell")] + pub destination_well: String, + #[serde(rename = "XferVol")] + pub volume: f32, +} + +impl From for EchoClientTransferRecord { + fn from(value: TransferRecord) -> Self { + EchoClientTransferRecord { + source_well: value.source_well, + destination_well: value.destination_well, + volume: value.volume, + } + } +} diff --git a/plate-tool-lib/src/csv/conversion.rs b/plate-tool-lib/src/csv/conversion.rs index 825b77e..903d95b 100644 --- a/plate-tool-lib/src/csv/conversion.rs +++ b/plate-tool-lib/src/csv/conversion.rs @@ -1,10 +1,9 @@ use crate::transfer::Transfer; use crate::util::*; -use super::{TransferRecord, transfer_record::TransferRecordDeserializeIntermediate, mangle_headers::mangle_headers}; +use super::{alternative_formats::EchoClientTransferRecord, mangle_headers::mangle_headers, transfer_record::TransferRecordDeserializeIntermediate, TransferRecord}; use lazy_static::lazy_static; use regex::Regex; -use serde::{Deserialize, Serialize}; use std::error::Error; pub fn transfer_to_records( @@ -44,6 +43,15 @@ pub fn records_to_csv(trs: Vec) -> Result Ok(data) } +pub fn records_to_echo_client_csv(trs: Vec) -> Result> { + let mut wtr = csv::WriterBuilder::new().from_writer(vec![]); + for record in trs { + wtr.serialize(Into::::into(record))? + } + let data = String::from_utf8(wtr.into_inner()?)?; + Ok(data) +} + pub fn string_well_to_pt(input: &str) -> Option<(u8, u8)> { lazy_static! { static ref REGEX: Regex = Regex::new(r"([A-Z,a-z]+)(\d+)").unwrap(); diff --git a/plate-tool-lib/src/csv/mod.rs b/plate-tool-lib/src/csv/mod.rs index 957fe10..9bff0a5 100644 --- a/plate-tool-lib/src/csv/mod.rs +++ b/plate-tool-lib/src/csv/mod.rs @@ -2,6 +2,7 @@ mod transfer_record; mod conversion; mod auto; mod mangle_headers; +mod alternative_formats; pub use transfer_record::volume_default; pub use transfer_record::TransferRecord;