deepbiop_fa/encode/
option.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use derive_builder::Builder;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display, Formatter};

use pyo3::prelude::*;
use pyo3_stub_gen::derive::*;

pub const BASES: &[u8] = b"ATCGN";

#[gen_stub_pyclass]
#[pyclass(module = "deepbiop.fa")]
#[derive(Debug, Builder, Default, Clone, Serialize, Deserialize)]
pub struct FaEncoderOption {
    #[pyo3(get, set)]
    #[builder(default = "BASES.to_vec()")]
    pub bases: Vec<u8>,
}

#[gen_stub_pymethods]
#[pymethods]
impl FaEncoderOption {
    #[new]
    #[pyo3(signature = (bases))]
    fn py_new(bases: String) -> Self {
        FaEncoderOptionBuilder::default()
            .bases(bases.as_bytes().to_vec())
            .build()
            .expect("Failed to build FqEncoderOption from Python arguments.")
    }
}

impl Display for FaEncoderOption {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        write!(f, "FaEncoderOption {{ bases: {:?} }}", self.bases)
    }
}