Skip to content

Commit

Permalink
Merge changes from WIP branch
Browse files Browse the repository at this point in the history
  • Loading branch information
joshkh committed May 9, 2017
2 parents ee6a5b3 + ea1d41f commit 957292e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 9 deletions.
10 changes: 5 additions & 5 deletions dist/mi-model.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mi-model",
"version": "0.4.9",
"version": "0.4.10",
"description": "Model for representing Molecular Interaction data",
"main": "src/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
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;
});

});
Expand Down
5 changes: 5 additions & 0 deletions src/models/Interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var Backbone = require('backbone');
var Participants = require('./Participant').Participants;
var Features = require('./Feature').Features;
var Links = require('./Link').Links;
var Expand = require('../utils/expand');

var Interaction = Backbone.Model.extend({

Expand All @@ -13,6 +14,10 @@ var Interaction = Backbone.Model.extend({
links: new Links()
},

expand: function() {
Expand(this);
},

initialize: function(participants) {


Expand Down
10 changes: 9 additions & 1 deletion src/models/Participant.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ var Participant = Backbone.Model.extend({

var Participants = Backbone.Collection.extend({

model: Participant
model: Participant,

withStoichiometry: function(){
filtered = this.filter(function(participant) {
return participant.get("stoichiometry") > 1
});

return new Participants(filtered);
}

});

Expand Down
40 changes: 40 additions & 0 deletions src/utils/expand.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 957292e

Please sign in to comment.