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
use std::io;

pub enum UriType {
    Fasta(String),
    Pdb(String),
    PdbGz(String),
    Cif(String),
    CifGz(String),
    XmlGz(String),
}

impl UriType {
    pub fn get_type(t: &str) -> Result<UriType, io::Error> {
        let t = String::from(t);
        match t.to_uppercase().as_ref() {
            "FASTA" => Ok(UriType::Fasta(t)),
            "PDB" => Ok(UriType::Pdb(t)),
            "PDBGZ" => Ok(UriType::PdbGz(t)),
            "CIF" => Ok(UriType::Cif(t)),
            "CIFGZ" => Ok(UriType::CifGz(t)),
            "XML" => Ok(UriType::XmlGz(t)),
            _ => Err(io::Error::new(
                io::ErrorKind::InvalidInput,
                format!(
                    "[Error] '{}' is not an accepted format. Use -h to see available types",
                    t
                ),
            )),
        }
    }

    pub fn generate_uri(&self, id: &str) -> String {
        match self {
            UriType::Fasta(_) => format!("https://www.rcsb.org/pdb/download/downloadFastaFiles.do?structureIdList={}&compressionType=uncompressed", id),
            UriType::Pdb(_) => format!("https://files.rcsb.org/download/{}.pdb", id),
            UriType::PdbGz(_) => format!("https://files.rcsb.org/download/{}.pdb.gz", id),
            UriType::Cif(_) => format!("https://files.rcsb.org/download/{}.cif", id),
            UriType::CifGz(_) => format!("https://files.rcsb.org/download/{}.cif.gz", id),
            UriType::XmlGz(_) => format!("https://files.rcsb.org/download/{}.xml.gz", id),
        }
    }

    pub fn get_extension(&self) -> &str {
        match self {
            UriType::Fasta(_) => ".fasta",
            UriType::Pdb(_) => ".pdb",
            UriType::Cif(_) => ".cif",
            UriType::PdbGz(_) => ".pdb.gz",
            UriType::CifGz(_) => ".cif.gz",
            UriType::XmlGz(_) => ".xml.gz",
        }
    }
}