diff --git a/public/index.html b/public/index.html
index 3daf701..c333a01 100644
--- a/public/index.html
+++ b/public/index.html
@@ -13,9 +13,10 @@
var model;
- $.get( "json/EBI-9691559.json", function( data ) {
+ $.get( "json/EBI-1202920.json", function( data ) {
model = new MIModel(data).load().then(function(m) {
- console.log("model", m);
+ window.m = m;
+
});
});
diff --git a/src/models/Interaction.js b/src/models/Interaction.js
index f40f6e9..b62d85f 100644
--- a/src/models/Interaction.js
+++ b/src/models/Interaction.js
@@ -4,6 +4,7 @@ Backbone = require('backbone')
Participants = require('./Participant').Participants
Features = require('./Feature').Features;
Links = require('./Link').Links;
+Expand = require('../utils/expand');
_ = require('underscore');
@@ -15,6 +16,10 @@ Interaction = Backbone.Model.extend({
links: new Links()
},
+ expand: function() {
+ Expand(this);
+ },
+
initialize: function(participants) {
diff --git a/src/models/Participant.js b/src/models/Participant.js
index 1d4fa5d..1a6fdaa 100644
--- a/src/models/Participant.js
+++ b/src/models/Participant.js
@@ -57,7 +57,15 @@ Participant = Backbone.Model.extend({
Participants = Backbone.Collection.extend({
- model: Participant
+ model: Participant,
+
+ withStoichiometry: function(){
+ filtered = this.filter(function(participant) {
+ return participant.get("stoichiometry") > 1
+ });
+
+ return new Participants(filtered);
+ }
});
diff --git a/src/utils/expand.js b/src/utils/expand.js
new file mode 100644
index 0000000..571e09c
--- /dev/null
+++ b/src/utils/expand.js
@@ -0,0 +1,40 @@
+var expand;
+
+
+
+nextAvailableId = function(participants) {
+
+ var ids = participants.map(function(p) {
+ return p.get("id");
+ });
+
+ return Math.max.apply(null, ids) + 1
+};
+
+expand = function(interaction) {
+ participants = interaction.get("participants").withStoichiometry();
+
+ var clones = [];
+
+ participants.each(function(p) {
+
+ for (var i = 0; i < p.get("stoichiometry"); i++) {
+ var clone = p.clone();
+ clone.set("id", nextAvailableId(participants) + i);
+ clone.set("clone?", true);
+ clone.set("fromParticipant", p);
+ interaction.get("participants").add(clone);
+ }
+
+ });
+
+
+ interaction.set("expanded?", true);
+
+ // console.log("returning", interaction);
+
+ return interaction;
+
+}
+
+module.exports = expand;