|
|
@@ -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,
|
|
|
+// )
|
|
|
+// }
|