-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First prototype of structs for BMA parsing with serde.
- Loading branch information
Showing
6 changed files
with
268 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use biodivine_lib_bma_data::json_model::JsonBmaModel; | ||
use std::fs::read_to_string; | ||
|
||
fn main() { | ||
let json_data = | ||
read_to_string("models/json/SimpleBifurcation.json").expect("Unable to read file"); | ||
let resting_neuron: JsonBmaModel = | ||
serde_json::from_str(&json_data).expect("JSON was not well-formatted"); | ||
println!("{:?}", resting_neuron); | ||
|
||
let json_data = read_to_string("models/json/RestingNeuron.json").expect("Unable to read file"); | ||
let resting_neuron: JsonBmaModel = | ||
serde_json::from_str(&json_data).expect("JSON was not well-formatted"); | ||
println!("{:?}", resting_neuron); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use biodivine_lib_bma_data::xml_model::XmlBmaModel; | ||
use std::fs::read_to_string; | ||
|
||
fn main() { | ||
let xml_data = read_to_string("models/xml/VerySmallTestCase.xml").expect("Unable to read file"); | ||
let xml_model: XmlBmaModel = | ||
serde_xml_rs::from_str(&xml_data).expect("XML was not well-formatted"); | ||
println!("{:?}", xml_model); | ||
|
||
let xml_data = read_to_string("models/xml/Skin1D.xml").expect("Unable to read file"); | ||
let xml_model: XmlBmaModel = | ||
serde_xml_rs::from_str(&xml_data).expect("XML was not well-formatted"); | ||
println!("{:?}", xml_model); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Model { | ||
#[serde(rename = "Name")] | ||
name: String, | ||
#[serde(rename = "Variables")] | ||
variables: Vec<Variable>, | ||
#[serde(rename = "Relationships")] | ||
relationships: Vec<Relationship>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Variable { | ||
#[serde(rename = "Id")] | ||
id: u32, | ||
#[serde(rename = "RangeFrom")] | ||
range_from: f64, | ||
#[serde(rename = "RangeTo")] | ||
range_to: f64, | ||
#[serde(rename = "Formula")] | ||
formula: String, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Relationship { | ||
#[serde(rename = "Id")] | ||
id: u32, | ||
#[serde(rename = "FromVariable")] | ||
from_variable: u32, | ||
#[serde(rename = "ToVariable")] | ||
to_variable: u32, | ||
#[serde(rename = "Type")] | ||
r#type: String, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Layout { | ||
#[serde(rename = "Variables")] | ||
variables: Vec<LayoutVariable>, | ||
#[serde(rename = "Containers")] | ||
containers: Vec<Container>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct LayoutVariable { | ||
#[serde(rename = "Id")] | ||
id: u32, | ||
#[serde(rename = "Name")] | ||
name: String, | ||
#[serde(rename = "Type")] | ||
r#type: String, | ||
#[serde(rename = "ContainerId")] | ||
container_id: u32, | ||
#[serde(rename = "PositionX")] | ||
position_x: f64, | ||
#[serde(rename = "PositionY")] | ||
position_y: f64, | ||
#[serde(rename = "CellX")] | ||
cell_x: Option<u32>, | ||
#[serde(rename = "CellY")] | ||
cell_y: Option<u32>, | ||
#[serde(rename = "Angle")] | ||
angle: f64, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Container { | ||
#[serde(rename = "Id")] | ||
id: u32, | ||
#[serde(rename = "Name")] | ||
name: Option<String>, | ||
#[serde(rename = "Size")] | ||
size: u32, | ||
#[serde(rename = "PositionX")] | ||
position_x: f64, | ||
#[serde(rename = "PositionY")] | ||
position_y: f64, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct JsonBmaModel { | ||
#[serde(rename = "Model")] | ||
model: Model, | ||
#[serde(rename = "Layout")] | ||
layout: Option<Layout>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
//! Rust library for working with models in BMA format. | ||
#[derive(Clone, Debug, Eq, Hash, PartialEq)] | ||
pub struct BmaModel {} | ||
|
||
// TODO :) | ||
pub mod json_model; | ||
pub mod xml_model; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
#[serde(rename = "Model")] | ||
struct Model { | ||
#[serde(rename = "Id")] | ||
id: u32, | ||
#[serde(rename = "Name")] | ||
name: String, | ||
#[serde(rename = "BioCheckVersion")] | ||
biocheck_version: String, | ||
#[serde(rename = "Description")] | ||
description: String, | ||
#[serde(rename = "CreatedDate")] | ||
created_date: String, | ||
#[serde(rename = "ModifiedDate")] | ||
modified_date: String, | ||
#[serde(rename = "Layout")] | ||
layout: Layout, | ||
#[serde(rename = "Containers")] | ||
containers: Containers, | ||
#[serde(rename = "Variables")] | ||
variables: Variables, | ||
#[serde(rename = "Relationships")] | ||
relationships: Relationships, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Layout { | ||
#[serde(rename = "Columns")] | ||
columns: u32, | ||
#[serde(rename = "Rows")] | ||
rows: u32, | ||
#[serde(rename = "ZoomLevel")] | ||
zoom_level: u32, | ||
#[serde(rename = "PanX")] | ||
pan_x: i32, | ||
#[serde(rename = "PanY")] | ||
pan_y: i32, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Containers { | ||
#[serde(rename = "Container")] | ||
container: Vec<Container>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Container { | ||
#[serde(rename = "Id")] | ||
id: u32, | ||
#[serde(rename = "Name")] | ||
name: String, | ||
#[serde(rename = "PositionX")] | ||
position_x: f64, | ||
#[serde(rename = "PositionY")] | ||
position_y: f64, | ||
#[serde(rename = "Size")] | ||
size: u32, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Variables { | ||
#[serde(rename = "Variable")] | ||
variable: Vec<Variable>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Variable { | ||
#[serde(rename = "Id")] | ||
id: u32, | ||
#[serde(rename = "Name")] | ||
name: String, | ||
#[serde(rename = "ContainerId")] | ||
container_id: u32, | ||
#[serde(rename = "Type")] | ||
r#type: String, | ||
#[serde(rename = "RangeFrom")] | ||
range_from: f64, | ||
#[serde(rename = "RangeTo")] | ||
range_to: f64, | ||
#[serde(rename = "Formula")] | ||
formula: String, | ||
#[serde(rename = "PositionX")] | ||
position_x: f64, | ||
#[serde(rename = "PositionY")] | ||
position_y: f64, | ||
#[serde(rename = "CellX")] | ||
cell_x: u32, | ||
#[serde(rename = "CellY")] | ||
cell_y: u32, | ||
#[serde(rename = "Angle")] | ||
angle: f64, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Relationships { | ||
#[serde(rename = "Relationship")] | ||
relationship: Vec<Relationship>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Relationship { | ||
#[serde(rename = "Id")] | ||
id: u32, | ||
#[serde(rename = "ContainerId")] | ||
container_id: u32, | ||
#[serde(rename = "FromVariableId")] | ||
from_variable_id: u32, | ||
#[serde(rename = "ToVariableId")] | ||
to_variable_id: u32, | ||
#[serde(rename = "Type")] | ||
r#type: String, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct XmlBmaModel { | ||
#[serde(rename = "Id")] | ||
id: u32, | ||
#[serde(rename = "Name")] | ||
name: String, | ||
#[serde(rename = "BioCheckVersion")] | ||
biocheck_version: String, | ||
#[serde(rename = "Description")] | ||
description: String, | ||
#[serde(rename = "CreatedDate")] | ||
created_date: String, | ||
#[serde(rename = "ModifiedDate")] | ||
modified_date: String, | ||
#[serde(rename = "Layout")] | ||
layout: Layout, | ||
#[serde(rename = "Containers")] | ||
containers: Containers, | ||
#[serde(rename = "Variables")] | ||
variables: Variables, | ||
#[serde(rename = "Relationships")] | ||
relationships: Relationships, | ||
} |