blul_proc/
execute_blast.rs1use blul_core::domain::{
2 dtos::blast_builder::BlastBuilder,
3 entities::execute_blastn::{ExecuteBlastn, ExecutionResponse},
4};
5use mycelium_base::utils::errors::{execution_err, MappedErrors};
6use subprocess::{Exec, Redirection};
7
8#[derive(Debug)]
9pub struct ExecuteBlastnProcRepository {}
10
11impl ExecuteBlastn for ExecuteBlastnProcRepository {
12 fn run(
13 &self,
14 query_sequences: String,
15 blast_config: BlastBuilder,
16 threads: usize,
17 ) -> Result<ExecutionResponse, MappedErrors> {
18 let blast_response = match Exec::cmd("blastn")
19 .stdin(&*query_sequences)
20 .arg("-db")
21 .arg(&blast_config.subject_reads)
22 .arg("-outfmt")
23 .arg(&blast_config.out_format.to_string())
24 .arg("-max_target_seqs")
25 .arg(&blast_config.max_target_seqs.to_string())
26 .arg("-perc_identity")
27 .arg(&blast_config.perc_identity.to_string())
28 .arg("-qcov_hsp_perc")
29 .arg(&blast_config.query_cov.to_string())
30 .arg("-strand")
31 .arg(&blast_config.strand.to_string())
32 .arg("-evalue")
33 .arg(&blast_config.e_value.to_string())
34 .arg("-word_size")
35 .arg(&blast_config.word_size.to_string())
36 .arg("-num_threads")
37 .arg(threads.to_string())
38 .stdout(Redirection::Pipe)
39 .stderr(Redirection::Pipe)
40 .capture()
41 {
42 Err(err) => {
43 return execution_err(format!(
44 "Unexpected error detected on execute blast: {err}"
45 ))
46 .as_error()
47 }
48 Ok(res) => res,
49 };
50
51 if !blast_response.success() {
52 return Ok(ExecutionResponse::Fail(blast_response.stderr_str()));
53 }
54
55 Ok(ExecutionResponse::Success(blast_response.stdout_str()))
56 }
57}