blul_core/domain/dtos/
blast_builder.rs

1use super::taxon::Taxon;
2
3use md5;
4use serde::{Deserialize, Serialize};
5use std::fmt;
6use uuid::Uuid;
7
8// ? --------------------------------------------------------------------------
9// ? Wrapper for Query Sequences
10// ? --------------------------------------------------------------------------
11
12#[derive(Debug)]
13pub struct QuerySequence {
14    pub hash_header: md5::Digest,
15    pub full_identifier: &'static str,
16    pub sequence: &'static str,
17}
18
19impl QuerySequence {
20    /// This is the constructor like method for the `QuerySequenceDTO` object.
21    #[allow(dead_code)]
22    pub fn create(
23        header: &'static str,
24        sequence: &'static str,
25    ) -> QuerySequence {
26        let sequence_hash = md5::compute(sequence);
27
28        QuerySequence {
29            hash_header: sequence_hash,
30            full_identifier: header,
31            sequence,
32        }
33    }
34}
35
36// ? --------------------------------------------------------------------------
37// ? Wrapper for Blast Builder
38// ? --------------------------------------------------------------------------
39
40#[derive(Clone, Debug, Serialize, clap::ValueEnum, Deserialize)]
41#[serde(rename_all = "camelCase")]
42pub enum Strand {
43    Both,
44    Plus,
45    Minus,
46}
47
48impl fmt::Display for Strand {
49    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
50        match self {
51            Strand::Both => write!(f, "both"),
52            Strand::Plus => write!(f, "plus"),
53            Strand::Minus => write!(f, "minus"),
54        }
55    }
56}
57
58#[derive(Clone, Debug, Serialize, Deserialize)]
59#[serde(rename_all = "camelCase")]
60pub struct BlastBuilder {
61    pub(crate) is_config: bool,
62    pub(crate) run_id: Uuid,
63    pub(crate) blutils_version: String,
64
65    // ? IO related parameters
66    pub subject_reads: String,
67    pub taxon: Taxon,
68
69    // ? BlastN configuration related parameters
70    pub out_format: String,
71    pub max_target_seqs: i32,
72    pub perc_identity: i32,
73    pub query_cov: i32,
74    pub strand: Strand,
75    pub e_value: f32,
76    pub word_size: i32,
77}
78
79impl BlastBuilder {
80    pub fn default(subject_reads: &str, taxon: Taxon) -> Self {
81        BlastBuilder {
82            is_config: true,
83            run_id: Uuid::new_v4(),
84            blutils_version: env!("CARGO_PKG_VERSION").to_string(),
85            subject_reads: subject_reads.to_string(),
86            taxon,
87            out_format: "6 qseqid saccver staxid pident length mismatch gapopen qstart qend sstart send evalue bitscore".to_string(),
88            max_target_seqs: 10,
89            perc_identity: 80,
90            query_cov: 80,
91            strand: Strand::Both,
92            e_value: 0.001,
93            word_size: 15,
94        }
95    }
96
97    pub fn with_max_target_seqs(mut self, max_target_seqs: i32) -> Self {
98        self.max_target_seqs = max_target_seqs;
99        self
100    }
101
102    pub fn with_perc_identity(mut self, perc_identity: i32) -> Self {
103        self.perc_identity = perc_identity;
104        self
105    }
106
107    pub fn with_query_cov(mut self, query_cov: i32) -> Self {
108        self.query_cov = query_cov;
109        self
110    }
111
112    pub fn with_strand(mut self, strand: Strand) -> Self {
113        self.strand = strand;
114        self
115    }
116
117    pub fn with_e_value(mut self, e_value: f32) -> Self {
118        self.e_value = e_value;
119        self
120    }
121
122    pub fn with_word_size(mut self, word_size: i32) -> Self {
123        self.word_size = word_size;
124        self
125    }
126}