jean_io/formats/gff3/data/
feature.rs1use std::collections::HashMap;
2
3use super::Strand;
4
5#[derive(Debug, Clone, PartialEq)]
6pub struct Entry {
7 pub id: String,
8 pub source: Option<String>,
9 pub feature_type: String,
10 pub start: usize,
11 pub end: usize,
12 pub score: Option<f64>,
13 pub strand: Option<Strand>,
14 pub phase: Option<u8>,
15 pub attributes: Option<HashMap<String, String>>,
16}
17
18fn maybe<T>(t: &Option<T>) -> String
19where
20 T: std::fmt::Display,
21{
22 match t {
23 Some(t) => t.to_string(),
24 None => ".".to_owned(),
25 }
26}
27
28impl std::fmt::Display for Entry {
29 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30 let empty = ".".to_string();
31
32 let _1 = &self.id;
34
35 let _2 = maybe(&self.source);
37
38 let _3 = &self.feature_type;
40
41 let _4 = &self.start.to_string();
43 let _5 = &self.end.to_string();
44
45 let _6 = maybe(&self.score);
47
48 let _7 = maybe(&self.strand);
50
51 let _8 = maybe(&self.phase);
53
54 let _9 = match &self.attributes {
56 Some(attributes) => attributes
57 .iter()
58 .map(|(k, v)| format!("{k}={v}"))
59 .collect::<Vec<String>>()
60 .join(";"),
61 None => empty.clone(),
62 };
63
64 write!(f, "{_1}\t{_2}\t{_3}\t{_4}\t{_5}\t{_6}\t{_7}\t{_8}\t{_9}")
65 }
66}