Thomas 4 dní pred
rodič
commit
9681be650f
3 zmenil súbory, kde vykonal 34 pridanie a 47 odobranie
  1. 0 20
      Cargo.lock
  2. 0 1
      Cargo.toml
  3. 34 26
      src/scan/scan.rs

+ 0 - 20
Cargo.lock

@@ -1000,12 +1000,6 @@ version = "0.1.9"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
 
-[[package]]
-name = "fastrand"
-version = "2.4.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6"
-
 [[package]]
 name = "filetime"
 version = "0.2.27"
@@ -1993,7 +1987,6 @@ dependencies = [
  "serde",
  "serde_json",
  "tar",
- "tempfile",
  "thiserror 2.0.17",
  "toml 0.9.10+spec-1.1.0",
  "tracing",
@@ -2786,19 +2779,6 @@ dependencies = [
  "xattr",
 ]
 
-[[package]]
-name = "tempfile"
-version = "3.27.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
-dependencies = [
- "fastrand",
- "getrandom 0.3.4",
- "once_cell",
- "rustix",
- "windows-sys 0.61.2",
-]
-
 [[package]]
 name = "thiserror"
 version = "1.0.69"

+ 0 - 1
Cargo.toml

@@ -55,7 +55,6 @@ triple_accel = "0.4.0"
 chainfile = "0.3.0"
 omics = "0.2.0"
 filetime = "0.2.27"
-tempfile = "3.27.0"
 
 [profile.dev]
 opt-level = 0

+ 34 - 26
src/scan/scan.rs

@@ -722,7 +722,8 @@ pub fn par_whole_scan(id: &str, time_point: &str, config: &Config) -> anyhow::Re
                 bin_size,
                 chunk_n_bin,
                 config.bam_min_mapq,
-            )?;
+            )
+            .with_context(|| format!("failed scanning contig {contig}"))?;
 
             debug!("Scan {contig}, sorting bins");
             bins.par_sort_unstable_by(|a, b| a.start.cmp(&b.start));
@@ -732,40 +733,47 @@ pub fn par_whole_scan(id: &str, time_point: &str, config: &Config) -> anyhow::Re
 
             debug!("Scan {contig}, writing file");
 
-            {
-                let temp_file = tempfile::NamedTempFile::new_in(&config.tmp_dir)
-                    .with_context(|| format!("failed to create temp file in {out_dir:?}"))?;
-
-                let temp_path = temp_file.into_temp_path();
+            let out_path = std::path::Path::new(&out_file);
+            let out_parent = out_path
+                .parent()
+                .with_context(|| format!("output file has no parent: {out_file}"))?;
 
-                {
-                    let temp_path_str = temp_path
-                        .to_str()
-                        .with_context(|| format!("temp path not valid UTF-8: {temp_path:?}"))?;
+            std::fs::create_dir_all(out_parent)
+                .with_context(|| format!("failed to create output dir: {out_parent:?}"))?;
 
-                    let mut writer = get_gz_writer(temp_path_str, true)
-                        .with_context(|| format!("failed to open BGZF file: {temp_path_str}"))?;
+            let tmp_path = out_parent.join(format!(
+                ".{}.{}.{}.tmp",
+                contig,
+                std::process::id(),
+                std::thread::current().name().unwrap_or("rayon")
+            ));
 
-                    for bin in &bins {
-                        writeln!(writer, "{}", bin.to_tsv_row()).with_context(|| {
-                            format!("failed writing {contig} row to {temp_path_str}")
-                        })?;
-                    }
+            let tmp_path_str = tmp_path
+                .to_str()
+                .with_context(|| format!("temp path is not valid UTF-8: {tmp_path:?}"))?;
 
-                    writer
-                        .flush()
-                        .with_context(|| format!("failed flushing BGZF writer: {temp_path_str}"))?;
+            {
+                let mut writer = get_gz_writer(tmp_path_str, true)
+                    .with_context(|| format!("failed to open BGZF temp file: {tmp_path_str}"))?;
 
-                    writer
-                        .close()
-                        .with_context(|| format!("failed closing BGZF writer: {temp_path_str}"))?;
+                for bin in &bins {
+                    writeln!(writer, "{}", bin.to_tsv_row()).with_context(|| {
+                        format!("failed writing {contig} row to {tmp_path_str}")
+                    })?;
                 }
 
-                temp_path
-                    .persist(&out_file)
-                    .with_context(|| format!("failed atomic rename to {out_file}"))?;
+                writer
+                    .flush()
+                    .with_context(|| format!("failed flushing BGZF writer: {tmp_path_str}"))?;
+
+                writer.close().with_context(|| {
+                    format!("failed closing/finalizing BGZF writer: {tmp_path_str}")
+                })?;
             }
 
+            std::fs::rename(&tmp_path, &out_file)
+                .with_context(|| format!("failed atomic rename {tmp_path_str} -> {out_file}"))?;
+
             Ok(())
         })?;