bbop-graph-noctua
Advanced tools
Comparing version 0.0.13 to 0.0.14
169
lib/edit.js
@@ -1113,3 +1113,3 @@ /** | ||
*/ | ||
noctua_graph.prototype.load_data_base = function(data){ | ||
noctua_graph.prototype.load_data_basic = function(data){ | ||
var anchor = this; | ||
@@ -1151,5 +1151,4 @@ | ||
/** | ||
* Load minerva data response. However, this time, we're going to fold | ||
* the evidence individuals into the edges and nodes that reference | ||
* them under the referenced_individual functions. | ||
* Fold the evidence individuals into the edges and nodes that | ||
* reference them under the referenced_individual functions. | ||
* | ||
@@ -1164,3 +1163,3 @@ * Currently, a single pass is run to fold evidence individuals into | ||
*/ | ||
noctua_graph.prototype.load_data_fold_evidence = function(data){ | ||
noctua_graph.prototype.fold_evidence = function(){ | ||
var anchor = this; | ||
@@ -1170,96 +1169,67 @@ | ||
if( data ){ | ||
// Load the graph parts as usual. | ||
var graph_id = data['id'] || null; | ||
var graph_anns = data['annotations'] || []; | ||
if( graph_id ){ anchor.id(graph_id); } | ||
if( ! us.isEmpty(graph_anns) ){ | ||
each(graph_anns, function(ann_kv_set){ | ||
var na = new annotation(ann_kv_set); | ||
anchor.add_annotation(na); | ||
}); | ||
} | ||
// Find the evidence singletons for future lookup. | ||
var singletons = {}; | ||
each(anchor.get_singleton_nodes(), function(singleton){ | ||
var sid = singleton.id(); | ||
singletons[sid] = singleton; | ||
}); | ||
// Currently, evidence does not have edges, and if they did, | ||
// we wouldn't want to handle them here. All edges in. | ||
var facts = data['facts']; | ||
each(facts, function(fact){ | ||
anchor.add_edge_from_fact(fact); | ||
}); | ||
//console.log('singletons'); | ||
//console.log(us.keys(singletons).length); | ||
// Start by adding all of the individuals to the graph. | ||
var inds = data['individuals']; | ||
each(inds, function(ind){ | ||
anchor.add_node_from_individual(ind); | ||
}); | ||
// Find the evidence singletons for future lookup. | ||
var singletons = {}; | ||
each(anchor.get_singleton_nodes(), function(singleton){ | ||
var sid = singleton.id(); | ||
singletons[sid] = singleton; | ||
}); | ||
//console.log('singletons'); | ||
//console.log(us.keys(singletons).length); | ||
// Take and, and see if it is an evidence reference. | ||
function is_iri_ev_p(ann){ | ||
var ret = false; | ||
if( ann.key() == 'evidence' && ann.value_type() == 'IRI' ){ | ||
ret = true; | ||
} | ||
return ret; | ||
// Take and, and see if it is an evidence reference. | ||
function is_iri_ev_p(ann){ | ||
var ret = false; | ||
if( ann.key() == 'evidence' && ann.value_type() == 'IRI' ){ | ||
ret = true; | ||
} | ||
return ret; | ||
} | ||
// For any node, look at all of the annotations, and fold in | ||
// ones that 1) pass the test and 2) reference a singleton | ||
// node. | ||
function fold_in_reference(node, test_p){ | ||
each(node.annotations(), function(ann){ | ||
//console.log(ann.key(), ann.value_type(), ann.value()); | ||
// Is it an evidence annotation. | ||
//if( ann.key() == 'evidence' && ann.value_type() == 'IRI' ){ | ||
if( test_p(ann) ){ | ||
// If so, and the individual in question is a | ||
// singleton (if not, we don't fold it). | ||
var ref_node_id = ann.value(); | ||
if( singletons[ref_node_id] ){ | ||
// Remove node from the graph. | ||
anchor.remove_node(ref_node_id); | ||
// Add as referenced individual. | ||
var ev_indiv = singletons[ref_node_id]; | ||
var c1 = node.add_referenced_individual(ev_indiv); | ||
//console.log('<<' + node.id() + '>1>', c1.length); | ||
//var c2 = node.referenced_individuals(); | ||
//console.log('<<' + node.id() + '>2>', c2.length); | ||
// console.log(node) | ||
} | ||
// For any node, look at all of the annotations, and fold in | ||
// ones that 1) pass the test and 2) reference a singleton | ||
// node. | ||
function fold_in_reference(node, test_p){ | ||
each(node.annotations(), function(ann){ | ||
//console.log(ann.key(), ann.value_type(), ann.value()); | ||
// Is it an evidence annotation. | ||
//if( ann.key() == 'evidence' && ann.value_type() == 'IRI' ){ | ||
if( test_p(ann) ){ | ||
// If so, and the individual in question is a | ||
// singleton (if not, we don't fold it). | ||
var ref_node_id = ann.value(); | ||
if( singletons[ref_node_id] ){ | ||
// Remove node from the graph. | ||
anchor.remove_node(ref_node_id); | ||
// Add as referenced individual. | ||
var ev_indiv = singletons[ref_node_id]; | ||
var c1 = node.add_referenced_individual(ev_indiv); | ||
//console.log('<<' + node.id() + '>1>', c1.length); | ||
//var c2 = node.referenced_individuals(); | ||
//console.log('<<' + node.id() + '>2>', c2.length); | ||
// console.log(node) | ||
} | ||
}); | ||
} | ||
// Add the evidence singletons into the structure by | ||
// scanning through the nodes and adding them as referenced | ||
// individuals. | ||
each(anchor.all_nodes(), function(node){ | ||
fold_in_reference(node, is_iri_ev_p); | ||
} | ||
}); | ||
} | ||
// Add the evidence singletons into the structure by | ||
// scanning through the nodes and adding them as referenced | ||
// individuals. | ||
each(anchor.all_nodes(), function(node){ | ||
fold_in_reference(node, is_iri_ev_p); | ||
}); | ||
// We also need to do the same thing with the edges, adding | ||
// back in the evidence as referenced individuals. | ||
each(anchor.all_edges(), function(edge){ | ||
fold_in_reference(edge, is_iri_ev_p); | ||
}); | ||
ret = true; | ||
// We also need to do the same thing with the edges, adding | ||
// back in the evidence as referenced individuals. | ||
each(anchor.all_edges(), function(edge){ | ||
fold_in_reference(edge, is_iri_ev_p); | ||
}); | ||
ret = true; | ||
} | ||
// console.log(anchor); | ||
return ret; | ||
@@ -1269,8 +1239,7 @@ }; | ||
/** | ||
* Load minerva data response. However, this time, in addition to | ||
* everything we did for {load_data_evidence_fold}, we're going to | ||
* search for nodes that have enabled_by and/or occurs_in (or any | ||
* other specified relation) targets (that are themselves leaves) fold | ||
* them in to the contained subgraph item, and remove them from the | ||
* top-level graph. | ||
* In addition to everything we did for {load_data_evidence_fold}, | ||
* we're going to search for nodes that have enabled_by and/or | ||
* occurs_in (or any other specified relation) targets (that are | ||
* themselves leaves) fold them in to the contained subgraph item, and | ||
* remove them from the top-level graph. | ||
* | ||
@@ -1283,7 +1252,7 @@ * TODO: inferred individuals | ||
*/ | ||
noctua_graph.prototype.load_data_go_noctua = function(data, relation_list){ | ||
noctua_graph.prototype.fold_go_noctua = function(relation_list){ | ||
var anchor = this; | ||
// Start out with the evidence folded graph. | ||
var ret = anchor.load_data_fold_evidence(data); | ||
var ret = anchor.fold_evidence(); | ||
if( ! ret ){ return false; } // Early bail on bad upstream. | ||
@@ -1290,0 +1259,0 @@ |
{ | ||
"name": "bbop-graph-noctua", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"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.", |
@@ -115,3 +115,3 @@ //// | ||
var g = new model.graph(); | ||
g.load_data_base(raw_resp['data']); | ||
g.load_data_basic(raw_resp['data']); | ||
@@ -128,3 +128,3 @@ // Right? | ||
var g = new model.graph(); | ||
g.load_data_base(raw_resp['data']); | ||
g.load_data_basic(raw_resp['data']); | ||
@@ -153,3 +153,3 @@ assert.equal(g.id(),'gomodel:taxon_559292-5525a0fc0000001_all_indivdual', | ||
var g = new model.graph(); | ||
g.load_data_base(raw_resp['data']); | ||
g.load_data_basic(raw_resp['data']); | ||
@@ -189,3 +189,4 @@ // Head up from our one leaf | ||
var g = new model.graph(); | ||
g.load_data_fold_evidence(raw_resp['data']); | ||
g.load_data_basic(raw_resp['data']); | ||
g.fold_evidence(); | ||
@@ -238,3 +239,4 @@ // Okay, we should have a lot less nodes now. | ||
var g_new = new model.graph(); | ||
g_new.load_data_fold_evidence(raw_resp['data']); | ||
g_new.load_data_basic(raw_resp['data']); | ||
g_new.fold_evidence(); | ||
@@ -264,3 +266,4 @@ // Empty g_base should now essentially be g_new. | ||
var rellist = ['RO:0002333', 'BFO:0000066']; | ||
g.load_data_go_noctua(raw_resp['data'], rellist); | ||
g.load_data_basic(raw_resp['data']); | ||
g.fold_go_noctua(rellist); | ||
@@ -311,3 +314,4 @@ // Basic structure count. | ||
var rellist = ['RO:0002333', 'BFO:0000066']; | ||
g.load_data_go_noctua(raw_resp['data'], rellist); | ||
g.load_data_basic(raw_resp['data']); | ||
g.fold_go_noctua(rellist); | ||
@@ -340,3 +344,4 @@ var nid = 'gomodel:taxon_559292-5525a0fc0000001-GO-0005515-5525a0fc0000023'; | ||
var rellist = ['RO:0002333', 'BFO:0000066']; | ||
g.load_data_go_noctua(raw_resp['data'], rellist); | ||
g.load_data_basic(raw_resp['data']); | ||
g.fold_go_noctua(rellist); | ||
@@ -343,0 +348,0 @@ // Make a new graph to operate on. |
6333147
27066