knuckles_parse/records/
seqres.rs

1#[cfg(feature = "serde")]
2use serde::{Deserialize, Serialize};
3
4#[cfg(feature = "python")]
5use pyo3::prelude::*;
6
7#[cfg(feature = "python")]
8use knuckles_macro::pydefault;
9
10/// Represents a SEQRES record containing sequence information.
11///
12/// SEQRES records contain the amino acid or nucleic acid sequence of residues
13/// in each chain of the macromolecule. Multiple SEQRES records may be used
14/// for a single chain if the sequence is long.
15///
16/// # Fields
17///
18/// - `ser_num`: Serial number of the SEQRES record for the current chain
19/// - `chain_id`: Chain identifier
20/// - `num_res`: Total number of residues in the chain
21/// - `res_names`: List of residue names in this record
22///
23/// # Example
24///
25/// ```rust
26/// use knuckles_parse::records::seqres::SeqresRecord;
27///
28/// let line = "SEQRES   1 A  147  THR SER ASN PHE ALA ASP GLY LYS ASP ALA ILE LEU GLU";
29/// let seqres = SeqresRecord::from(line);
30/// assert_eq!(seqres.chain_id, 'A');
31/// assert_eq!(seqres.num_res, 147);
32/// ```
33#[derive(Debug, Clone)]
34#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
35#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
36#[cfg_attr(feature = "python", pydefault)]
37pub struct SeqresRecord {
38    /// Serial number of this SEQRES record for the current chain
39    pub ser_num: u32,
40    /// Chain identifier
41    pub chain_id: char,
42    /// Total number of residues in the chain
43    pub num_res: i16,
44    /// List of residue names in this SEQRES record
45    pub res_names: Vec<String>,
46}
47
48impl SeqresRecord {
49    /// Create a new SeqresRecord by parsing a SEQRES line.
50    pub fn new(str: &str) -> Self {
51        Self {
52            ser_num: str[7..10].trim().parse().unwrap(),
53            chain_id: str.chars().nth(11).unwrap(),
54            num_res: str[13..17].trim().parse().unwrap(),
55            res_names: str[19..]
56                .split_whitespace()
57                .map(|s| s.to_string())
58                .collect(),
59        }
60    }
61}
62
63impl From<&str> for SeqresRecord {
64    fn from(line: &str) -> Self {
65        Self::new(line)
66    }
67}