use bincode::Decode;
use std::collections::HashMap;
#[derive(Decode, Debug, Clone)]
pub struct PlaceDB {
pub seq_desc: SeqBuilder,
pub seq_index: PlaceIndex,
}
impl PlaceDB {
pub fn new(desc: SeqBuilder, index: PlaceIndex) -> PlaceDB {
PlaceDB {
seq_desc: desc,
seq_index: index,
}
}
}
#[derive(Decode, Debug, Clone)]
pub struct SeqBuilder {
pub exact: Vec<SeqDesc>,
pub iupac: Vec<SeqDesc>,
pub all: Vec<SeqDesc>,
}
#[derive(Decode, Debug, Clone)]
pub struct SeqDesc {
pub id: String,
pub ac: String, pub dt: String, pub de: String, pub kw: Vec<String>, pub os: String, pub ra: String, pub rt: String, pub rl: String, pub rd: String, pub rc: String, pub sq: String, }
impl std::fmt::Display for SeqDesc {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let header = format!("{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n",
"ID", "Accession", "Date", "Description", "Keywords", "Organism Source",
"Reference Authors", "Reference Title", "Reference Location",
"Reference Details", "Reference Comments", "Sequence");
let row = format!("{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n",
self.id, self.ac, self.dt, self.de,
self.kw.join(", "), self.os, self.ra, self.rt, self.rl,
self.rd, self.rc, self.sq);
write!(f, "{}{}", header, row)
}
}
#[derive(Decode, Debug, Clone)]
pub struct PlaceIndex {
pub id_index: HashMap<String, usize>,
pub ac_index: HashMap<String, usize>,
}