knuckles_parse/records/
seqadv.rs1#[cfg(feature = "serde")]
2use serde::{Deserialize, Serialize};
3
4use super::dbref::DBType;
5
6#[cfg(feature = "python")]
7use knuckles_macro::pydefault;
8
9#[cfg(feature = "python")]
10use pyo3::prelude::*;
11
12#[derive(Debug, Clone)]
13#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
14#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
15#[cfg_attr(feature = "python", pydefault)]
16pub struct SeqAdvRecord {
17 pub id_code: String,
18 pub res_name: String,
19 pub chain_id: char,
20 pub seq_num: i32,
21 pub i_code: Option<char>,
22 pub database: DBType,
23 pub db_accession: String,
24 pub db_res: Option<String>,
25 pub db_seq: Option<i32>,
26 pub conflict: String,
27}
28
29impl SeqAdvRecord {
30 pub fn new(line: &str) -> Self {
31 let database = DBType::new(&line[24..28]);
33 SeqAdvRecord {
34 id_code: line[7..11].trim().to_string(),
35 res_name: line[12..15].trim().to_string(),
36 chain_id: line.chars().nth(16).unwrap(),
37 seq_num: line[18..22].trim().parse().unwrap(),
38 i_code: line[22..23].trim().parse().ok(),
39 database,
40 db_accession: line[29..38].trim().to_string(),
41 db_res: line
42 .get(39..42)
43 .map(|str| str.trim().to_string())
44 .filter(|item| !item.is_empty()),
45 db_seq: line[43..48].trim().parse().ok(),
46 conflict: line[49..].trim().to_string(),
47 }
48 }
49}
50
51impl From<&str> for SeqAdvRecord {
52 fn from(value: &str) -> Self {
53 SeqAdvRecord::new(value)
54 }
55}
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_new_seqdv_record() {
63 let line = "SEQADV 3ABC MET A -1 UNP P10725 EXPRESSION TAG";
64 let record = SeqAdvRecord::new(line);
65 assert_eq!("3ABC", record.id_code);
66 assert_eq!("MET", record.res_name);
67 assert_eq!('A', record.chain_id);
68 assert_eq!(-1, record.seq_num);
69 assert_eq!(None, record.i_code);
70 assert_eq!(DBType::UNP, record.database);
71 assert_eq!("P10725", record.db_accession);
72 assert_eq!(None, record.db_res);
73 assert_eq!(None, record.db_seq);
74 assert_eq!("EXPRESSION TAG", record.conflict);
75
76 let line = "SEQADV 3ABC GLY A 50 UNP P10725 VAL 50 ENGINEERED";
77 let record = SeqAdvRecord::new(line);
78 assert_eq!("3ABC", record.id_code);
79 assert_eq!("GLY", record.res_name);
80 assert_eq!('A', record.chain_id);
81 assert_eq!(50, record.seq_num);
82 assert_eq!(None, record.i_code);
83 assert_eq!(DBType::UNP, record.database);
84 assert_eq!("P10725", record.db_accession);
85 assert_eq!(Some("VAL".to_string()), record.db_res);
86 assert_eq!(Some(50), record.db_seq);
87 assert_eq!("ENGINEERED", record.conflict);
88
89 let line = "SEQADV 2OKW LEU A 64 NOR NOR00669 PHE 14 SEE REMARK 999";
90 let record = SeqAdvRecord::new(line);
91 assert_eq!("2OKW", record.id_code);
92 assert_eq!("LEU", record.res_name);
93 assert_eq!('A', record.chain_id);
94 assert_eq!(64, record.seq_num);
95 assert_eq!(None, record.i_code);
96 assert_eq!(DBType::NORINE, record.database);
97 assert_eq!("NOR00669", record.db_accession);
98 assert_eq!(Some("PHE".to_string()), record.db_res);
99 assert_eq!(Some(14), record.db_seq);
100 assert_eq!("SEE REMARK 999", record.conflict);
101 }
102}