#[cfg(feature = "csv")]
pub use self::private::UniProtCsv as Csv;
#[cfg(feature = "fasta")]
pub use self::private::UniProtFasta as Fasta;
#[cfg(feature = "xml")]
pub use self::private::UniProtXml as Xml;
mod private {
use std::convert::AsRef;
use std::path::Path;
use db::uniprot::RecordList;
use traits::*;
use util::ResultType;
#[cfg(feature = "fasta")]
pub struct UniProtFasta;
#[cfg(feature = "fasta")]
impl UniProtFasta {
#[inline(always)]
pub fn to_string(list: &RecordList) -> ResultType<String> {
list.to_fasta_string()
}
#[inline(always)]
pub fn to_file<P: AsRef<Path>>(list: &RecordList, path: P) -> ResultType<()> {
list.to_fasta_file(path)
}
#[inline(always)]
pub fn from_string(text: &str) -> ResultType<RecordList> {
RecordList::from_fasta_string(text)
}
#[inline(always)]
pub fn from_file<P: AsRef<Path>>(path: P) -> ResultType<RecordList> {
RecordList::from_fasta_file(path)
}
}
#[cfg(feature = "csv")]
pub struct UniProtCsv;
#[cfg(feature = "csv")]
impl UniProtCsv {
#[inline(always)]
pub fn to_string(list: &RecordList) -> ResultType<String> {
list.to_csv_string(b'\t')
}
#[inline(always)]
pub fn to_file<P: AsRef<Path>>(list: &RecordList, path: P) -> ResultType<()> {
list.to_csv_file(path, b'\t')
}
#[inline(always)]
pub fn from_string(text: &str) -> ResultType<RecordList> {
RecordList::from_csv_string(text, b'\t')
}
#[inline(always)]
pub fn from_file<P: AsRef<Path>>(path: P) -> ResultType<RecordList> {
RecordList::from_csv_file(path, b'\t')
}
}
#[cfg(feature = "xml")]
pub struct UniProtXml;
#[cfg(feature = "xml")]
impl UniProtXml {
#[inline(always)]
pub fn to_string(list: &RecordList) -> ResultType<String> {
list.to_xml_string()
}
#[inline(always)]
pub fn to_file<P: AsRef<Path>>(list: &RecordList, path: P) -> ResultType<()> {
list.to_xml_file(path)
}
#[inline(always)]
pub fn from_string(text: &str) -> ResultType<RecordList> {
RecordList::from_xml_string(text)
}
#[inline(always)]
pub fn from_file<P: AsRef<Path>>(path: P) -> ResultType<RecordList> {
RecordList::from_xml_file(path)
}
}
}
#[cfg(test)]
mod tests {
use std::fs::read_to_string;
use std::path::PathBuf;
use test::testdata_dir;
use super::*;
#[cfg(feature = "fasta")]
fn fasta_dir() -> PathBuf {
let mut dir = testdata_dir();
dir.push("uniprot/fasta");
dir
}
#[cfg(feature = "fasta")]
#[test]
#[ignore]
fn fasta_test() {
let mut path = fasta_dir();
path.push("list.fasta");
let expected = read_to_string(&path).unwrap();
let actual = Fasta::to_string(&Fasta::from_file(&path).unwrap()).unwrap();
assert_eq!(expected.lines().nth(1), actual.lines().nth(1));
assert_eq!(expected.lines().nth(2), actual.lines().nth(2));
}
#[cfg(feature = "csv")]
fn csv_dir() -> PathBuf {
let mut dir = testdata_dir();
dir.push("uniprot/csv");
dir
}
#[cfg(feature = "csv")]
#[test]
#[ignore]
fn csv_test() {
let mut path = csv_dir();
path.push("list.csv");
let expected = read_to_string(&path).unwrap();
let actual = Csv::to_string(&Csv::from_file(&path).unwrap()).unwrap();
assert_eq!(expected, actual.trim_right());
}
#[cfg(feature = "xml")]
fn xml_dir() -> PathBuf {
let mut dir = testdata_dir();
dir.push("uniprot/xml");
dir
}
#[cfg(feature = "xml")]
#[test]
#[ignore]
fn xml_test() {
let mut path = xml_dir();
path.push("list.xml");
let actual = Xml::to_string(&Xml::from_file(&path).unwrap());
assert!(actual.is_ok());
}
}