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
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//! This library provides a convenient interface to the RING webservice,
//! a software for computing protein interaction networks.

#![doc(html_root_url = "https://docs.rs/ring_api/0.1.0")]
#![deny(missing_debug_implementations, missing_copy_implementations,
        trivial_casts, trivial_numeric_casts,
        unsafe_code,
        unstable_features,
        anonymous_parameters, bare_trait_objects,
        variant_size_differences,
        unused_import_braces, unused_qualifications, missing_docs)]
#![allow(clippy::single_match, clippy::match_same_arms, clippy::match_ref_pats,
         clippy::clone_on_ref_ptr, clippy::needless_pass_by_value)]
#![deny(clippy::wrong_pub_self_convention, clippy::used_underscore_binding,
        clippy::similar_names, clippy::pub_enum_variant_names,
        clippy::missing_docs_in_private_items,
        clippy::non_ascii_literal, clippy::unicode_not_nfc,
        clippy::result_unwrap_used, clippy::option_unwrap_used,
        clippy::option_map_unwrap_or_else, clippy::option_map_unwrap_or,
        clippy::filter_map,
        clippy::shadow_unrelated, clippy::shadow_reuse, clippy::shadow_same,
        clippy::int_plus_one, clippy::string_add_assign, clippy::if_not_else,
        clippy::invalid_upcast_comparisons,
        clippy::cast_precision_loss, clippy::cast_lossless,
        clippy::cast_possible_wrap, clippy::cast_possible_truncation,
        clippy::mutex_integer, clippy::mut_mut, clippy::items_after_statements,
        clippy::print_stdout, clippy::mem_forget, clippy::maybe_infinite_iter)]

#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_json;
extern crate reqwest;

pub use client::*;
pub use error::*;
pub use requests::*;
pub use settings::*;
pub use job::*;

pub mod client;
pub mod error;
pub mod requests;
pub mod settings;
pub mod job;
pub mod multipart;

#[cfg(test)]
#[allow(clippy::print_stdout)]
mod tests {
    use super::*;

    #[test]
    fn submit_id() -> Result<()> {
        use std::{
            thread::sleep,
            time::Duration,
        };

        let client = Client::new();
        let request = SubmitId {
            pdb_id: String::from("3S6A"),
            settings: Settings {
                chain: Chain::Id('A'),
                network_policy: NetworkPolicy::CAlpha,
                interactions: InteractionType::All,
                ..Default::default()
            },
        };
        let response = client.send(&request)?;
        println!("{:#?}", response);

        loop {
            let request = Status {
                job_id: response.job_id.clone(),
            };
            let response = client.send(&request)?;

            println!("{:#?}", response);

            match response.status {
                JobStatus::Complete => break Ok(()),
                JobStatus::Failed => panic!("job failed"),
                JobStatus::InProgress | JobStatus::Partial => {}
            }

            sleep(Duration::from_secs(5));
        }
    }

    #[test]
    pub fn submit_structure() -> Result<()> {
        use std::{
            thread::sleep,
            time::Duration,
        };

        let client = Client::new();
        let request = SubmitStructure::with_pdb_file("testdata/3s6a.pdb")?;
        let response = client.send(&request)?;
        println!("{:#?}", response);

        loop {
            let request = Status {
                job_id: response.job_id.clone(),
            };
            let response = client.send(&request)?;

            println!("{:#?}", response);

            match response.status {
                JobStatus::Complete => break Ok(()),
                JobStatus::Failed => panic!("job failed"),
                JobStatus::InProgress | JobStatus::Partial => {}
            }

            sleep(Duration::from_secs(5));
        }
    }

    #[test]
    fn serde() -> std::result::Result<(), Box<dyn std::error::Error>> {
        let s1 = Settings {
            chain: Chain::Id('X'),
            network_policy: NetworkPolicy::CBeta,
            interactions: InteractionType::NoSpecific,
            sequence_separation: 42,
            thresholds: Thresholds::relaxed(),
            skip_hetero: true,
            skip_water: false,
            perform_msa: true,
            ..Default::default()
        };
        let json = serde_json::to_string_pretty(&s1)?;
        let s2: Settings = serde_json::from_str(&json)?;
        assert_eq!(s1, s2);

        let json_default = serde_json::to_string(&Settings::default())?;
        let s_default: Settings = serde_json::from_str(&json_default)?;
        assert_eq!(s_default, Settings::default());

        Ok(())
    }

    #[test]
    fn retrieve_result() -> Result<()> {
        let client = Client::new();
        let job_id = JobId::from("5cefd030b265bd294b0f6b2c");
        let request = RetrieveResult { job_id };
        let response = client.send(&request)?;

        println!("{:#?}", response.nodes[0]);
        println!("{:#?}", response.edges[2]);
        println!("{}", response.edges[2].node_id_1);
        println!("{}", response.edges[2].interaction);

        Ok(())
    }
}