Thomas 9 months ago
parent
commit
6dbf83feb8
3 changed files with 133 additions and 144 deletions
  1. 1 12
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 131 131
      src/assembler/spoa.rs

+ 1 - 12
Cargo.lock

@@ -1,6 +1,6 @@
 # This file is automatically @generated by Cargo.
 # It is not intended for manual editing.
-version = 3
+version = 4
 
 [[package]]
 name = "adler2"
@@ -719,7 +719,6 @@ dependencies = [
  "rayon",
  "regex",
  "rust-htslib",
- "rust-spoa",
  "seq_io",
  "serde",
  "thiserror",
@@ -882,16 +881,6 @@ dependencies = [
  "url",
 ]
 
-[[package]]
-name = "rust-spoa"
-version = "0.2.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d3e2b549b9af17763a1e6f040e8aa2e5c1cbe4a762390b5a1798fdc24971cf35"
-dependencies = [
- "cc",
- "cmake",
-]
-
 [[package]]
 name = "rustc-hash"
 version = "1.1.0"

+ 1 - 1
Cargo.toml

@@ -23,5 +23,5 @@ csv = "1.3.0"
 serde = { version = "1.0.209", features = ["derive"] }
 thiserror = "1.0.63"
 seq_io = "0.3.2"
-rust-spoa = "0.2.4"
+# rust-spoa = "0.2.4"
 

+ 131 - 131
src/assembler/spoa.rs

@@ -1,131 +1,131 @@
-// https://github.com/pjedge/rust-spoa
-
-// use poa_consensus;
-
-use std::{fs, path::{Path, PathBuf}};
-
-use log::info;
-
-use crate::io::{bam::read_bam, fastq::records_to_fastq};
-
-use super::{default_save, Assemble, AssembleConfig};
-
-#[derive(Debug, Clone)]
-pub struct SpoaConfig {
-    pub output_dir: PathBuf,
-    pub consensus_max_length: usize,
-    pub alignment_type: i32,
-    pub match_score: i32,
-    pub mismatch_score: i32,
-    pub gap_open: i32,
-    pub gap_extend: i32,
-}
-impl Default for SpoaConfig {
-    fn default() -> Self {
-        Self {
-            consensus_max_length: 100_000,
-            alignment_type: 1,
-            match_score: 5,
-            mismatch_score: -4,
-            gap_open: -3,
-            gap_extend: -1,
-            output_dir: PathBuf::default(),
-        }
-    }
-}
-
-impl SpoaConfig {
-    pub fn new(output_dir: &str) -> Self {
-        SpoaConfig {
-            output_dir: PathBuf::from(output_dir),
-            ..Default::default()
-        }
-    }
-}
-
-#[derive(Debug)]
-pub struct Spoa {
-    pub config: SpoaConfig,
-    pub input_id: String,
-    pub tmp_dir: String,
-    pub input_fq: String,
-
-    pub input_records: Vec<bam::Record>,
-    pub contigs: Option<Vec<String>>,
-}
-
-impl Assemble for Spoa {
-    fn init(input_bam: &std::path::Path, config: &AssembleConfig) -> anyhow::Result<Self> {
-        match config {
-            AssembleConfig::Spoa(config) => {
-                let input_id = input_bam.file_stem().unwrap().to_str().unwrap().to_string();
-                let input_records = read_bam(input_bam)?;
-
-                let tmp_dir = format!("/tmp/ass_{}", uuid::Uuid::new_v4());
-                info!("Creating tmp directory {tmp_dir}");
-                fs::create_dir(&tmp_dir)?;
-
-                let input_fq = format!("{}/{}.fastq", tmp_dir, input_id);
-                if !Path::new(&input_fq).exists() {
-                    records_to_fastq(&input_records, &input_fq)?;
-                }
-
-                Ok(Self {
-                    config: config.clone(),
-                    input_id,
-                    input_records,
-                    contigs: None,
-                    tmp_dir,
-                    input_fq,
-                })
-            }
-            _ => Err(anyhow::anyhow!("Wrong config format for Spoa.")),
-        }
-    }
-
-    fn assemble(mut self) -> anyhow::Result<Self> {
-        let sequences: Vec<Vec<u8>> = self
-            .input_records
-            .iter()
-            .map(|r| {
-                let mut seq = r.sequence().to_vec();
-                seq.push(0);
-                seq
-            })
-            .collect();
-
-        self.contigs = Some(vec![String::from_utf8(poa_consensus(
-            &sequences,
-            &self.config,
-        ))?]);
-
-        Ok(self)
-    }
-
-    fn save(self) -> anyhow::Result<()> {
-        default_save(
-            "spoa",
-            self.contigs,
-            self.input_id,
-            self.config.output_dir,
-            self.input_fq,
-            self.input_records,
-            self.tmp_dir,
-        )
-        // info!("{:#?}", self.contigs);
-        // info!("{:#?}", self.contigs.unwrap().len());
-        // Ok(())
-    }
-}
-
-pub fn poa_consensus(seq: &Vec<Vec<u8>>, config: &SpoaConfig) -> Vec<u8> {
-    rust_spoa::poa_consensus(
-        seq,
-        config.consensus_max_length,
-        config.alignment_type,
-        config.match_score,
-        config.mismatch_score,
-        config.gap_open,
-        config.gap_extend,
-    )
-}
+// // https://github.com/pjedge/rust-spoa
+//
+// // use poa_consensus;
+//
+// use std::{fs, path::{Path, PathBuf}};
+//
+// use log::info;
+//
+// use crate::io::{bam::read_bam, fastq::records_to_fastq};
+//
+// use super::{default_save, Assemble, AssembleConfig};
+//
+// #[derive(Debug, Clone)]
+// pub struct SpoaConfig {
+//     pub output_dir: PathBuf,
+//     pub consensus_max_length: usize,
+//     pub alignment_type: i32,
+//     pub match_score: i32,
+//     pub mismatch_score: i32,
+//     pub gap_open: i32,
+//     pub gap_extend: i32,
+// }
+// impl Default for SpoaConfig {
+//     fn default() -> Self {
+//         Self {
+//             consensus_max_length: 100_000,
+//             alignment_type: 1,
+//             match_score: 5,
+//             mismatch_score: -4,
+//             gap_open: -3,
+//             gap_extend: -1,
+//             output_dir: PathBuf::default(),
+//         }
+//     }
+// }
+//
+// impl SpoaConfig {
+//     pub fn new(output_dir: &str) -> Self {
+//         SpoaConfig {
+//             output_dir: PathBuf::from(output_dir),
+//             ..Default::default()
+//         }
+//     }
+// }
+//
+// #[derive(Debug)]
+// pub struct Spoa {
+//     pub config: SpoaConfig,
+//     pub input_id: String,
+//     pub tmp_dir: String,
+//     pub input_fq: String,
+//
+//     pub input_records: Vec<bam::Record>,
+//     pub contigs: Option<Vec<String>>,
+// }
+//
+// impl Assemble for Spoa {
+//     fn init(input_bam: &std::path::Path, config: &AssembleConfig) -> anyhow::Result<Self> {
+//         match config {
+//             AssembleConfig::Spoa(config) => {
+//                 let input_id = input_bam.file_stem().unwrap().to_str().unwrap().to_string();
+//                 let input_records = read_bam(input_bam)?;
+//
+//                 let tmp_dir = format!("/tmp/ass_{}", uuid::Uuid::new_v4());
+//                 info!("Creating tmp directory {tmp_dir}");
+//                 fs::create_dir(&tmp_dir)?;
+//
+//                 let input_fq = format!("{}/{}.fastq", tmp_dir, input_id);
+//                 if !Path::new(&input_fq).exists() {
+//                     records_to_fastq(&input_records, &input_fq)?;
+//                 }
+//
+//                 Ok(Self {
+//                     config: config.clone(),
+//                     input_id,
+//                     input_records,
+//                     contigs: None,
+//                     tmp_dir,
+//                     input_fq,
+//                 })
+//             }
+//             _ => Err(anyhow::anyhow!("Wrong config format for Spoa.")),
+//         }
+//     }
+//
+//     fn assemble(mut self) -> anyhow::Result<Self> {
+//         let sequences: Vec<Vec<u8>> = self
+//             .input_records
+//             .iter()
+//             .map(|r| {
+//                 let mut seq = r.sequence().to_vec();
+//                 seq.push(0);
+//                 seq
+//             })
+//             .collect();
+//
+//         self.contigs = Some(vec![String::from_utf8(poa_consensus(
+//             &sequences,
+//             &self.config,
+//         ))?]);
+//
+//         Ok(self)
+//     }
+//
+//     fn save(self) -> anyhow::Result<()> {
+//         default_save(
+//             "spoa",
+//             self.contigs,
+//             self.input_id,
+//             self.config.output_dir,
+//             self.input_fq,
+//             self.input_records,
+//             self.tmp_dir,
+//         )
+//         // info!("{:#?}", self.contigs);
+//         // info!("{:#?}", self.contigs.unwrap().len());
+//         // Ok(())
+//     }
+// }
+//
+// pub fn poa_consensus(seq: &Vec<Vec<u8>>, config: &SpoaConfig) -> Vec<u8> {
+//     rust_spoa::poa_consensus(
+//         seq,
+//         config.consensus_max_length,
+//         config.alignment_type,
+//         config.match_score,
+//         config.mismatch_score,
+//         config.gap_open,
+//         config.gap_extend,
+//     )
+// }