1use std::io;
2
3pub enum UriType {
4 Fasta(String),
5 Pdb(String),
6 PdbGz(String),
7 Cif(String),
8 CifGz(String),
9 XmlGz(String),
10}
11
12impl UriType {
13 pub fn get_type(t: &str) -> Result<UriType, io::Error> {
14 let t = String::from(t);
15 match t.to_uppercase().as_ref() {
16 "FASTA" => Ok(UriType::Fasta(t)),
17 "PDB" => Ok(UriType::Pdb(t)),
18 "PDBGZ" => Ok(UriType::PdbGz(t)),
19 "CIF" => Ok(UriType::Cif(t)),
20 "CIFGZ" => Ok(UriType::CifGz(t)),
21 "XML" => Ok(UriType::XmlGz(t)),
22 _ => Err(io::Error::new(
23 io::ErrorKind::InvalidInput,
24 format!(
25 "[Error] '{}' is not an accepted format. Use -h to see available types",
26 t
27 ),
28 )),
29 }
30 }
31
32 pub fn generate_uri(&self, id: &str) -> String {
33 match self {
34 UriType::Fasta(_) => format!("https://www.rcsb.org/pdb/download/downloadFastaFiles.do?structureIdList={}&compressionType=uncompressed", id),
35 UriType::Pdb(_) => format!("https://files.rcsb.org/download/{}.pdb", id),
36 UriType::PdbGz(_) => format!("https://files.rcsb.org/download/{}.pdb.gz", id),
37 UriType::Cif(_) => format!("https://files.rcsb.org/download/{}.cif", id),
38 UriType::CifGz(_) => format!("https://files.rcsb.org/download/{}.cif.gz", id),
39 UriType::XmlGz(_) => format!("https://files.rcsb.org/download/{}.xml.gz", id),
40 }
41 }
42
43 pub fn get_extension(&self) -> &str {
44 match self {
45 UriType::Fasta(_) => ".fasta",
46 UriType::Pdb(_) => ".pdb",
47 UriType::Cif(_) => ".cif",
48 UriType::PdbGz(_) => ".pdb.gz",
49 UriType::CifGz(_) => ".cif.gz",
50 UriType::XmlGz(_) => ".xml.gz",
51 }
52 }
53}