cadnano_format/
cadnano.rs

1use serde_json;
2use std::path::Path;
3use Error;
4use std::fs::{File};
5
6#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
7pub struct Cadnano {
8    pub name: String,
9    pub vstrands: Vec<VStrand>,
10}
11
12#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
13pub struct VStrand {
14    pub col: isize,
15
16    // Position of insertions
17    #[serde(rename = "loop")]
18    pub loop_: Vec<isize>,
19    pub num: isize,
20    pub row: isize,
21    pub scaf: Vec<(isize, isize, isize, isize)>,
22    #[serde(rename = "scafLoop")]
23    pub scaf_loop: Vec<isize>,
24    pub skip: Vec<isize>,
25    // Each element is a corner (helix number, position, helix number,
26    // position).
27    pub stap: Vec<(isize, isize, isize, isize)>,
28    #[serde(rename = "stapLoop")]
29    pub stap_loop: Vec<isize>,
30    pub stap_colors: Vec<(isize, isize)>
31}
32
33impl Cadnano {
34    pub fn from_file<P:AsRef<Path>>(file: P) -> Result<Self, Error> {
35        let f = File::open(file)?;
36        Ok(serde_json::from_reader(&f)?)
37    }
38
39    pub fn to_file<P:AsRef<Path>>(&self, file: P) -> Result<(), Error> {
40        let f = File::create(file)?;
41        serde_json::to_writer(&f, self)?;
42        Ok(())
43    }
44
45}