ref_solver/parsing/
dict.rs1use std::path::Path;
2
3use crate::core::header::QueryHeader;
4use crate::parsing::sam::ParseError;
5
6pub fn parse_dict_file(path: &Path) -> Result<QueryHeader, ParseError> {
13 let content = std::fs::read_to_string(path)?;
14 parse_dict_text(&content)
15}
16
17pub fn parse_dict_text(text: &str) -> Result<QueryHeader, ParseError> {
24 crate::parsing::sam::parse_header_text(text)
26}
27
28#[cfg(test)]
29mod tests {
30 use super::*;
31
32 #[test]
33 fn test_parse_dict_text() {
34 let dict = r"@HD VN:1.6
35@SQ SN:chr1 LN:248956422 M5:6aef897c3d6ff0c78aff06ac189178dd UR:file:///reference/hg38.fa
36@SQ SN:chr2 LN:242193529 M5:f98db672eb0993dcfdabafe2a882905c UR:file:///reference/hg38.fa
37";
38
39 let query = parse_dict_text(dict).unwrap();
40 assert_eq!(query.contigs.len(), 2);
41 assert_eq!(query.contigs[0].name, "chr1");
42 assert_eq!(
43 query.contigs[0].uri,
44 Some("file:///reference/hg38.fa".to_string())
45 );
46 }
47}