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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use crate::common::parser::{parse_date, FieldParser};
use crate::types::*;
use nom::{bytes::complete::take, character::complete::multispace1, combinator::map, IResult};
pub struct HeaderParser;
impl FieldParser for HeaderParser {
type Output = Header;
fn parse(inp: &str) -> IResult<&str, Self::Output> {
let (inp, _) = take(4usize)(inp)?;
let (inp, classification) = map(map(take(40usize), str::trim), str::to_owned)(inp)?;
let (inp, deposition_date) = parse_date(inp)?;
let (inp, _) = take(3usize)(inp)?;
let (inp, id_code) = map(take(4usize), str::to_owned)(inp)?;
let (inp, _) = multispace1(inp)?;
Ok((
inp,
Header {
classification,
deposition_date,
id_code,
},
))
}
}
pub struct HeaderParserStreaming;
pub struct HeaderParserParallel;
#[cfg(test)]
mod tests {
use super::*;
use chrono::NaiveDate;
#[test]
fn test_parse_header() {
let i = " VIRAL PROTEIN 27-MAR-98 1A8O \nTITLE HIV CAPSID C-TERMINAL DOMAIN ";
let (i, r) = HeaderParser::parse(i).unwrap();
assert_eq!(
i.to_owned(),
"TITLE HIV CAPSID C-TERMINAL DOMAIN "
.to_owned()
);
assert_eq!(
r,
Header {
classification: "VIRAL PROTEIN".to_owned(),
deposition_date: NaiveDate::from_ymd(1998i32, 3u32, 27u32),
id_code: "1A8O".to_owned()
}
)
}
}