|
|
@@ -15,10 +15,10 @@ use serde::{Deserialize, Serialize};
|
|
|
|
|
|
use crate::{
|
|
|
collection::minknow::{parse_pore_activity_from_reader, parse_throughput_from_reader},
|
|
|
- helpers::{find_files, list_directories},
|
|
|
+ helpers::{find_files, list_directories}, io::writers::get_gz_writer,
|
|
|
};
|
|
|
|
|
|
-use super::minknow::{MinKnowSampleSheet, PoreStateEntry, ThroughputEntry};
|
|
|
+use super::minknow::{MinKnowSampleSheet, PoreStateEntry, PoreStateEntryExt, ThroughputEntry};
|
|
|
|
|
|
/// A collection of `IdInput` records, with utility methods
|
|
|
/// for loading, saving, deduplication, and construction from TSV.
|
|
|
@@ -169,11 +169,13 @@ impl FlowCells {
|
|
|
}
|
|
|
|
|
|
pub fn save_to_archive(&mut self, archive_path: &str) -> anyhow::Result<()> {
|
|
|
- let file = OpenOptions::new()
|
|
|
- .write(true)
|
|
|
- .create(true)
|
|
|
- .truncate(true)
|
|
|
- .open(archive_path)
|
|
|
+ // let file = OpenOptions::new()
|
|
|
+ // .write(true)
|
|
|
+ // .create(true)
|
|
|
+ // .truncate(true)
|
|
|
+ // .open(archive_path)
|
|
|
+ // .with_context(|| format!("Failed to open archive file for writing: {archive_path}"))?;
|
|
|
+ let file = get_gz_writer(archive_path, true)
|
|
|
.with_context(|| format!("Failed to open archive file for writing: {archive_path}"))?;
|
|
|
|
|
|
serde_json::to_writer_pretty(file, &self.flow_cells)
|
|
|
@@ -193,7 +195,9 @@ impl FlowCells {
|
|
|
/// # Errors
|
|
|
/// Returns an error if scanning fails or if directory layout is invalid.
|
|
|
pub fn load_from_local(&mut self, local_dir: &str) -> anyhow::Result<()> {
|
|
|
+ info!("Scanning {local_dir} for sample sheets.");
|
|
|
let sample_sheets = find_files(&format!("{local_dir}/**/sample_sheet*"))?;
|
|
|
+ info!("{} sample sheets found.", sample_sheets.len());
|
|
|
|
|
|
for path in sample_sheets {
|
|
|
let dir = path
|
|
|
@@ -667,22 +671,31 @@ pub fn scan_local(dir: &str) -> anyhow::Result<ExperimentData> {
|
|
|
if path.contains("pore_activity") {
|
|
|
let mut reader =
|
|
|
File::open(&file).with_context(|| format!("Failed to open: {}", file.display()))?;
|
|
|
- pore_activity = Some(parse_pore_activity_from_reader(&mut reader).with_context(
|
|
|
- || {
|
|
|
- format!(
|
|
|
- "Failed to parse pore activity date from: {}",
|
|
|
- file.display()
|
|
|
- )
|
|
|
- },
|
|
|
- )?);
|
|
|
+ pore_activity = Some(
|
|
|
+ parse_pore_activity_from_reader(&mut reader)
|
|
|
+ .map(|d| d.group_by_state_and_time(60.0))
|
|
|
+ .with_context(|| {
|
|
|
+ format!(
|
|
|
+ "Failed to parse pore activity date from: {}",
|
|
|
+ file.display()
|
|
|
+ )
|
|
|
+ })?,
|
|
|
+ );
|
|
|
} else if path.contains("sample_sheet") {
|
|
|
sample_sheet = Some(path.clone());
|
|
|
} else if path.contains("throughput") {
|
|
|
let mut reader =
|
|
|
File::open(&file).with_context(|| format!("Failed to open: {}", file.display()))?;
|
|
|
- throughput = Some(parse_throughput_from_reader(&mut reader).with_context(|| {
|
|
|
- format!("Failed to parse throughput date from: {}", file.display())
|
|
|
- })?);
|
|
|
+ throughput = Some(
|
|
|
+ parse_throughput_from_reader(&mut reader)
|
|
|
+ .with_context(|| {
|
|
|
+ format!("Failed to parse throughput data from: {}", file.display())
|
|
|
+ })?
|
|
|
+ .into_iter()
|
|
|
+ .enumerate()
|
|
|
+ .filter_map(|(i, item)| if i % 60 == 0 { Some(item) } else { None })
|
|
|
+ .collect(),
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
result.push((path, size, modified_utc));
|
|
|
@@ -692,6 +705,7 @@ pub fn scan_local(dir: &str) -> anyhow::Result<ExperimentData> {
|
|
|
let sample_sheet = MinKnowSampleSheet::from_path(&sample_sheet)
|
|
|
.context(anyhow::anyhow!("Can't parse sample sheet data"))?;
|
|
|
|
|
|
+ // info!("{} files found in {}", result.len(), dir);
|
|
|
Ok((sample_sheet, pore_activity, throughput, result))
|
|
|
}
|
|
|
|