bbop-graph-noctua
Advanced tools
Comparing version 0.0.16 to 0.0.17
108
lib/edit.js
@@ -1017,2 +1017,53 @@ /** | ||
/** | ||
* Merge another graph into the current graph, with special overwrite | ||
* rules. In essence, this could be used when trying to simulate a | ||
* rebuild even though you got merge data. | ||
* | ||
* Annotations in any top-level item (graph, node, edge), or lack | ||
* thereof, from the incoming graph is preferred. | ||
* | ||
* All extant edges and nodes in the incoming graph are clobbered. | ||
* | ||
* The incoming graph is considered to be "complete", so any edges | ||
* where both the source and sink are in the incoming graph are | ||
* considered to be the only edges between those node. | ||
* | ||
* Graph ID is /not/ copied. | ||
* | ||
* Beware that you're in the right folded mode. | ||
* | ||
* @param {graph} in_graph - the graph to merge in | ||
* @returns {Boolean} if graph was loaded | ||
*/ | ||
noctua_graph.prototype.merge_special = function(in_graph){ | ||
var anchor = this; | ||
// Since we can actually legally have an edge delete in the | ||
// merge, let's go ahead and cycle through the "complete" | ||
// graph and toss edges from individuals involved in the | ||
// merge. | ||
var involved_node = {}; | ||
each(in_graph.all_nodes(), function(node){ | ||
involved_node[node.id()] = true; | ||
}); | ||
// Okay, now get rid of all edges that are defined by the | ||
// involved nodes. | ||
each(anchor.all_edges(), function(edge){ | ||
if(involved_node[edge.subject_id()] && involved_node[edge.object_id()]){ | ||
anchor.remove_edge_by_id(edge.id()); | ||
} | ||
}); | ||
// Blitz our old annotations as all new will be incoming (and | ||
// the merge just takes the superset). Will be fine with fix: | ||
// https://github.com/geneontology/minerva/issues/5 | ||
anchor.annotations([]); | ||
var ret = anchor.merge_in(in_graph); | ||
return ret; | ||
}; | ||
/** | ||
* DEPRECATED | ||
* | ||
* This uses a subgraph to update the contents of the current | ||
@@ -1044,2 +1095,3 @@ * graph. The update graph is considered to be an updated complete | ||
* | ||
* @deprecated | ||
* @param {graph} in_graph - the graph to update with | ||
@@ -1421,7 +1473,7 @@ * @returns {Boolean} if graph was loaded | ||
// Optional layout hints. | ||
this._x_init = null; // initial layout hint | ||
this._y_init = null; | ||
// this.xlast = null; // last known location | ||
// this.ylast = null; | ||
// // Optional layout hints. | ||
// this._x_init = null; // initial layout hint | ||
// this._y_init = null; | ||
// // this.xlast = null; // last known location | ||
// // this.ylast = null; | ||
}; | ||
@@ -1463,5 +1515,5 @@ bbop.extend(noctua_node, bbop_node); | ||
// Coordinates. | ||
new_clone._x_init = anchor._x_init; | ||
new_clone._y_init = anchor._y_init; | ||
// // Coordinates. | ||
// new_clone._x_init = anchor._x_init; | ||
// new_clone._y_init = anchor._y_init; | ||
@@ -1633,23 +1685,23 @@ return new_clone; | ||
/** | ||
* Get/set "x" value of node. | ||
* | ||
* @param {Number} value - number | ||
* @returns {Number|null} type or null | ||
*/ | ||
noctua_node.prototype.x_init = function(value){ | ||
if(value) this._x_init = value; | ||
return this._x_init; | ||
}; | ||
// /** | ||
// * Get/set "x" value of node. | ||
// * | ||
// * @param {Number} value - number | ||
// * @returns {Number|null} type or null | ||
// */ | ||
// noctua_node.prototype.x_init = function(value){ | ||
// if(value) this._x_init = value; | ||
// return this._x_init; | ||
// }; | ||
/** | ||
* Get/set "y" value of node. | ||
* | ||
* @param {Number} value - number | ||
* @returns {Number|null} type or null | ||
*/ | ||
noctua_node.prototype.y_init = function(value){ | ||
if(value) this._y_init = value; | ||
return this._y_init; | ||
}; | ||
// /** | ||
// * Get/set "y" value of node. | ||
// * | ||
// * @param {Number} value - number | ||
// * @returns {Number|null} type or null | ||
// */ | ||
// noctua_node.prototype.y_init = function(value){ | ||
// if(value) this._y_init = value; | ||
// return this._y_init; | ||
// }; | ||
@@ -1656,0 +1708,0 @@ /// |
{ | ||
"name": "bbop-graph-noctua", | ||
"version": "0.0.16", | ||
"version": "0.0.17", | ||
"license": "BSD-3-Clause", | ||
@@ -5,0 +5,0 @@ "description": "A subclass of bbop-graph that layers on a complete annotation and graph editing model for the Noctua set of tools.", |
@@ -401,3 +401,3 @@ //// | ||
assert.equal(g.all_nodes().length, 8, 'updated graph has eight nodes'); | ||
assert.equal(g.all_edges().length, 4, 'updated graph has seven edges'); | ||
assert.equal(g.all_edges().length, 4, 'updated graph has four edges'); | ||
@@ -407,2 +407,48 @@ }); | ||
describe("special/dumb merge updating", function(){ | ||
it('updating with a subgraph to make it like a rebuild', function(){ | ||
// Setup. | ||
var g = new model.graph(); | ||
var raw_resp = require('./minerva-01.json'); | ||
var rellist = ['RO:0002333', 'BFO:0000066']; | ||
g.load_data_basic(raw_resp['data']); | ||
g.fold_go_noctua(rellist); | ||
// Make a new graph to operate on. | ||
var update_g = new model.graph(); | ||
// Graph annotations. | ||
var an1 = new model.annotation({"key": "title", "value": "meow"}); | ||
update_g.add_annotation(an1); | ||
// Graph parts. | ||
var un1 = new model.node('gomodel:taxon_559292-5525a0fc0000001-GO-0005515-5525a0fc0000023'); | ||
var un2 = new model.node('gomodel_taxon_559292-5525a0fc0000001-GO-1990334-553ff9ed0000011'); | ||
var un3 = new model.node('blahblah'); | ||
var ue1 = new model.edge(un1.id(), un2.id(), 'RO:1234567'); | ||
update_g.add_node(un1); | ||
update_g.add_node(un2); | ||
update_g.add_node(un3); | ||
update_g.add_edge(ue1); | ||
// Double check. | ||
assert.equal(update_g.all_nodes().length, 3, 'subgraph has 3 nodes'); | ||
assert.equal(update_g.all_edges().length, 1, 'subgraph has 1 edge'); | ||
assert.equal(update_g.annotations().length, 1, 'subgraph has 1 ann'); | ||
// Update our graph with new graph. | ||
g.merge_special(update_g); | ||
// Graph annotations clobbered. | ||
assert.equal(g.annotations().length, 1, 'rebuild merge graph has 1 ann'); | ||
assert.equal(g.annotations()[0].key(), 'title', 'has title'); | ||
assert.equal(g.annotations()[0].value(), 'meow', 'title "meow"'); | ||
// We have one new node and same edges. | ||
assert.equal(g.all_nodes().length, 8, 'updated graph has eight nodes'); | ||
assert.equal(g.all_edges().length, 7, 'updated graph has seven edges'); | ||
}); | ||
}); | ||
describe("unfolding works", function(){ | ||
@@ -409,0 +455,0 @@ |
6341070
27273