deepbiop_core/seq.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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
use needletail::Sequence;
use pyo3::prelude::*;
use pyo3_stub_gen::derive::*;
/// Normalize a DNA sequence by converting any non-standard nucleotides to standard ones.
///
/// This function takes a DNA sequence as a `String` and a boolean flag `iupac` indicating whether to normalize using IUPAC ambiguity codes.
/// It returns a normalized DNA sequence as a `String`.
///
/// # Arguments
///
/// * `seq` - A DNA sequence as a `String`.
/// * `iupac` - A boolean flag indicating whether to normalize using IUPAC ambiguity codes.
///
/// # Returns
///
/// A normalized DNA sequence as a `String`.
#[gen_stub_pyfunction(module = "deepbiop.core")]
#[pyfunction]
pub fn normalize_seq(seq: String, iupac: bool) -> String {
String::from_utf8_lossy(&seq.as_bytes().normalize(iupac)).to_string()
}
/// Generate the reverse complement of a DNA sequence.
///
/// This function takes a DNA sequence as a `String` and returns its reverse complement.
/// The reverse complement is generated by reversing the sequence and replacing each nucleotide
/// with its complement (A<->T, C<->G).
///
/// # Arguments
///
/// * `seq` - A DNA sequence as a `String`
///
/// # Returns
///
/// The reverse complement sequence as a `String`
///
/// # Example
///
/// ```
/// use deepbiop_core::seq::reverse_complement;
///
/// let seq = String::from("ATCG");
/// let rev_comp = reverse_complement(seq);
/// assert_eq!(rev_comp, "CGAT");
/// ```
#[gen_stub_pyfunction(module = "deepbiop.core")]
#[pyfunction]
pub fn reverse_complement(seq: String) -> String {
String::from_utf8(seq.as_bytes().reverse_complement()).unwrap()
}