Преглед на файлове

adding SM tag on BAM header during impory

Thomas преди 3 седмици
родител
ревизия
0ee77e1f7c
променени са 1 файла, в които са добавени 12 реда и са изтрити 11 реда
  1. 12 11
      src/collection/prom_run.rs

+ 12 - 11
src/collection/prom_run.rs

@@ -72,19 +72,13 @@ use crate::{
     collection::{
         bam_stats::WGSBamStats,
         flowcells::IdInput,
-        minknow::{parse_pore_activity_from_reader, MinKnowSampleSheet, PoreStateEntry},
+        minknow::{MinKnowSampleSheet, PoreStateEntry, parse_pore_activity_from_reader},
         pod5::Pod5,
-    },
-    commands::{
+    }, commands::{
         dorado::DoradoAlign,
         modkit::ModkitSummary,
         samtools::{SamtoolsIndex, SamtoolsMergeMany, SamtoolsSort},
-    },
-    config::Config,
-    helpers::{get_genome_sizes, list_files_recursive, remove_bam_with_index, TempFileGuard},
-    locker::SampleLock,
-    pipes::InitializeSolo,
-    run, run_many,
+    }, config::Config, helpers::{TempFileGuard, get_genome_sizes, list_files_recursive, remove_bam_with_index}, io::bam::read_sm_tag_or_inject, locker::SampleLock, pipes::InitializeSolo, run, run_many
 };
 
 /// Represent a complete ONT PromethION sequencing run with all associated files.
@@ -1415,12 +1409,19 @@ fn merge_into_existing_final(
 ///
 /// Source is already sorted (from sort_and_index_chunks), so only
 /// move and index are needed.
-fn create_new_final(source: &Path, destination: &Path, config: &Config) -> anyhow::Result<()> {
+fn create_new_final(source: &Path, destination: &Path, case: &IdInput, config: &Config) -> anyhow::Result<()> {
     info!("  Creating new final BAM: {}", destination.display());
 
     // Source already sorted — just move and index
     atomic_replace(source, destination)?;
 
+    // Adding SM tag in BAM without (if not demultiplexed if so it should be the barcode name)
+    let _ = read_sm_tag_or_inject(
+        &destination.to_string_lossy(),
+        &format!("{}_{}", case.case_id, case.sample_type),
+        config,
+    )?;
+
     index_bam(destination, config)
         .with_context(|| format!("Failed to index final BAM: {}", destination.display()))?;
 
@@ -1587,7 +1588,7 @@ fn finalize_case_bams(
         if final_bam_path.exists() {
             merge_into_existing_final(&merged_case_bam, &final_bam_path, tmp_dir, config)?;
         } else {
-            create_new_final(&merged_case_bam, &final_bam_path, config)?;
+            create_new_final(&merged_case_bam, &final_bam_path, case, config)?;
         }
 
         for chunk in chunk_bams {