Skip to content

Commit

Permalink
Ignore 'duplicate' links between linked features
Browse files Browse the repository at this point in the history
  • Loading branch information
joshkh committed May 22, 2017
1 parent 957292e commit 0fb3d81
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion 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.10",
"version": "0.4.11",
"description": "Model for representing Molecular Interaction data",
"main": "src/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
var model;


$.get( "json/EBI-1202920.json", function( data ) {
$.get( "json/EBI-9082861.json", function( data ) {
model = new MIModel(data).load().then(function(m) {
window.m = m;
});
Expand Down
18 changes: 14 additions & 4 deletions src/models/Interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var Interaction = Backbone.Model.extend({
initialize: function(participants) {



// Give each participant a reference back to this interaction
this.set("participants", new Participants(this.get("participants").map(function(participant){
participant.interaction = this;
Expand Down Expand Up @@ -51,18 +50,29 @@ var Interaction = Backbone.Model.extend({
}, this)));
}, this);

function sortNumber(a,b) {
return a - b;
}

// Populate the features collection
// TODO: Avoid Duplicates
this.get("features").each(function(feature) {

var links = new Links();
feature.get("linkedFeatures").each(function(f) {
links.add(f);
});


links.add(feature);
this.get("links").add({features: links});
}, this);

// Collect the ids of the linked features for later removing duplicates
var ids = links.map(function(l) {
return l.get("id");
});

// Remove the duplicates
this.get("links").add({features: links, id: ids.sort(sortNumber).join("-")});
}, this);
}

});
Expand Down

0 comments on commit 0fb3d81

Please sign in to comment.