Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bbop-graph-noctua

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bbop-graph-noctua - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

187

lib/edit.js

@@ -35,3 +35,3 @@ /**

* @constructor
* @param {Object} kv_set - (optional) a set of keys and values; a simple object
* @param {Object} [kv_set] - optional a set of keys and values; a simple object
* @returns {this} new instance

@@ -64,3 +64,2 @@ */

*
* @memberOf annotation
* @returns {String} string

@@ -76,4 +75,4 @@ */

* @param {String} key - string
* @param {String} value - (optional) string
* @param {String} value_type - (optional) string
* @param {String} [value] - string
* @param {String} [value_type] - string
* @returns {String|null} returns property is key

@@ -108,3 +107,3 @@ */

*
* @param {String} key - (optional) string
* @param {String} [key] - string
* @returns {String|null} returns string of annotation

@@ -121,3 +120,3 @@ */

*
* @param {String} value - (optional) string
* @param {String} [value] - string
* @returns {String|null} returns string of annotation

@@ -134,3 +133,3 @@ */

*
* @param {String} value_type - (optional) string
* @param {String} [value_type] - string
* @returns {String|null} returns string of annotation

@@ -195,3 +194,3 @@ */

* @function
* @param {Array} in_anns - (optional) list of annotations to clobber current list
* @param {Array} [in_anns] - list of annotations to clobber current list
* @returns {Array} list of all annotations

@@ -297,3 +296,3 @@ */

* @function
* @param {Array} indivs - (optional) list of {node} to clobber current list
* @param {Array} [indivs] - list of {node} to clobber current list
* @returns {Array} list of all referenced individuals

@@ -506,3 +505,3 @@ */

* @alias graph
* @param {String} new_id - (optional) new id; otherwise new unique generated
* @param {String} [new_id] - new id; otherwise new unique generated
* @returns {this}

@@ -539,3 +538,3 @@ */

* @param {string} object - node id string or node
* @param {string} predicate - (optional) a user-friendly description of the node
* @param {string} [predicate] - a user-friendly description of the node
* @returns {edge} bbop model edge

@@ -551,4 +550,4 @@ */

* @param {string} id - a unique id for the node
* @param {string} label - (optional) a user-friendly description of the node
* @param {Array} types - (optional) list of types to pre-load
* @param {string} [label] - a user-friendly description of the node
* @param {Array} [types] - list of types to pre-load
* @returns {node} new bbop model node

@@ -561,2 +560,32 @@ */

/**
* Create a clone of the graph.
*
* @returns {graph} bbop model graph
*/
noctua_graph.prototype.clone = function(){
var anchor = this;
var new_graph = anchor.create_graph();
// Collect the nodes and edges.
each(anchor.all_nodes(), function(node){
new_graph.add_node(node.clone());
});
each(anchor.all_edges(), function(edge){
new_graph.add_edge(edge.clone());
});
// Collect other information.
new_graph.default_predicate = anchor.default_predicate;
new_graph._id = anchor._id;
// Copy new things: annotations.
each(anchor._annotations, function(annotation){
new_graph._annotations.push(annotation.clone());
});
return new_graph;
};
/**
* Create a graph for use in internal operations.

@@ -686,3 +715,3 @@ *

/**
* Return a node by its element id.
* Return a copy of a {node} by its element id.
*

@@ -701,3 +730,4 @@ * @returns {node|null} node

/**
* Return a node by its corresponding Minerva JSON rep individual.
* Return a copy of a {node} by its corresponding Minerva JSON rep
* individual.
*

@@ -735,3 +765,3 @@ * @returns {node|null} node

* @param {String} node_id - the id for a node
* @param {Boolean} clean_p - (optional) remove all edges connects to node (default false)
* @param {Boolean} [clean_p] - remove all edges connects to node (default false)
* @returns {Boolean} true if node found and destroyed

@@ -867,3 +897,3 @@ */

* @param {String} object_id - object by ID
* @param {String} predicate_id - (Optional) predicate ID or default
* @param {String} [predicate_id] - predicate ID or default
* @returns {Boolean} true if such an edge was found and deleted, false otherwise

@@ -1146,2 +1176,77 @@ */

/**
* 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 targets
* (that are themselves leaves) fold them in to the contained subgraph
* item, and remove them from the top-level graph.
*
* TODO: inferred individuals
*
* @param {Object} the "data" portion of a Minerva graph-related response.
* @returns {Boolean} if data was loaded
*/
noctua_graph.prototype.load_data_go_noctua = function(data){
var anchor = this;
// Start out with the evidence folded graph.
var ret = anchor.load_data_fold_evidence(data);
if( ! ret ){ return false; } // Early bail on bad upstream.
// It is foldable if it is a root node (re: opposite of leaf--only
// target) and if it only has the one child (no way out--re: collapsible ).
function _foldable_p(node){
var ret = false;
if( anchor.is_root_node(node.id()) &&
anchor.get_child_nodes(node.id()).length == 1 ){
//console.log("foldable: " + node.id());
ret = true;
}
return ret;
}
// Okay, first scan all nodes for our pattern.
each(anchor.all_nodes(), function(ind){
// The possible base subgraph (seeding with current node--note
// the clone so we don't have infinite recursion) we might
// capture.
var subgraph = anchor.create_graph();
subgraph.add_node(ind.clone());
// Check a set of relations for completeness: enabled_by and
// occurs_in (location).
var collapsable_relations = ['RO:0002333', 'BFO:0000066'];
each(collapsable_relations, function(relation){
var kids = anchor.get_parent_nodes(ind.id(), relation);
each(kids, function(kid){
if( _foldable_p(kid) ){
// Preserve it and its edge in the new subgraph.
subgraph.add_node(kid.clone());
subgraph.add_edge(
anchor.get_parent_edges(ind.id(), relation)[0].clone());
// Remove same from the original graph, edge will be
// destroyed in the halo.
anchor.remove_node(kid.id(), true);
}
});
});
// A usable folding subgraph only occurred when the are more
// than 1 node in it; i.e. we actually actually added things
// to our local subgraph and removed them from the master
// graph.
if( subgraph.all_nodes().length > 1 ){
//console.log('slurpable subgraph for: ' + ind.id());
ind.subgraph(subgraph);
}
});
return ret;
};
///

@@ -1158,5 +1263,5 @@ /// Node subclass and overrides.

* @alias node
* @param {String} in_id - (optional) new id; otherwise new unique generated
* @param {String} in_label - (optional) node "label"
* @param {Array} in_types - (optional) list of Objects or strings--anything that can be parsed by class_expression
* @param {String} [in_id] - new id; otherwise new unique generated
* @param {String} [in_label] - node "label"
* @param {Array} [in_types] - list of Objects or strings--anything that can be parsed by class_expression
* @returns {this}

@@ -1173,2 +1278,3 @@ */

this._referenced_individuals = [];
this._embedded_subgraph = null;

@@ -1216,3 +1322,4 @@ // Incoming ID or generate ourselves.

// Transfer over the new goodies.
// Transfer over the new goodies, starting with annotations and
// referenced individuals.
each(anchor._annotations, function(annotation){

@@ -1224,2 +1331,11 @@ new_clone._annotations.push(annotation.clone());

});
// Embedded subgraph.
if( anchor._embedded_subgraph ){
new_clone._embedded_subgraph = anchor._embedded_subgraph.clone();
}else{
new_clone._embedded_subgraph = null;
}
// Coordinates.
new_clone._x_init = anchor._x_init;

@@ -1235,3 +1351,3 @@ new_clone._y_init = anchor._y_init;

* Parameters:
* @param {Array} in_types - (optional) raw JSON type objects
* @param {Array} [in_types] - raw JSON type objects
* @returns {Array} array of types

@@ -1299,2 +1415,21 @@ */

/**
* Get/set the "contained" subgraph. This subgraph is still considered
* to be part of the graph, but is "hidden" under this node for most
* use cases except serialization.
*
* To put it another way, unless you specifically load this with a
* specialized loader, it will remain unpopulated. During
* serialization, it should be recursively walked and dumped.
*
* @param {graph} [subgraph] - the subgraph to "hide" inside this individual in the graph
* @returns {graph|null} contained subgraph
*/
noctua_node.prototype.subgraph = function(subgraph){
if( subgraph && bbop.what_is(subgraph) == 'bbop-graph-noctua.graph'){
this._embedded_subgraph = subgraph;
}
return this._embedded_subgraph;
};
/**
* Get/set "x" value of node.

@@ -1334,3 +1469,3 @@ *

* @param {String} object - required object id
* @param {String} predicate - (optional) preidcate id; if not provided, will use defined default (you probably want to provide one--explicit is better)
* @param {String} [predicate] - preidcate id; if not provided, will use defined default (you probably want to provide one--explicit is better)
* @returns {this}

@@ -1395,3 +1530,3 @@ */

* @deprecated
* @param {String} value - (optional) string
* @param {String} [value] - string
* @returns {String} string

@@ -1408,3 +1543,3 @@ */

* @deprecated
* @param {String} value - (optional) string
* @param {String} [value] - string
* @returns {String} string

@@ -1421,3 +1556,3 @@ */

* @deprecated
* @param {String} value - (optional) string
* @param {String} [value] - string
* @returns {String} string

@@ -1424,0 +1559,0 @@ */

4

package.json
{
"name": "bbop-graph-noctua",
"version": "0.0.5",
"version": "0.0.6",
"license": "BSD-3-Clause",

@@ -33,3 +33,3 @@ "description": "A subclass of bbop-graph that layers on a complete annotation and graph editing model for the Noctua set of tools.",

"bbop-core": "0.0.4",
"bbop-graph": "0.0.12",
"bbop-graph": "0.0.13",
"class-expression": "0.0.4",

@@ -36,0 +36,0 @@ "underscore": "1.8.3"

@@ -251,2 +251,47 @@ ////

describe('abbreviate graph as expected in go noctua loader', function(){
it('pull in many subgraphs', function(){
// Setup.
var g = new model.graph();
var raw_resp = require('./minerva-01.json');
g.load_data_go_noctua(raw_resp['data']);
// Basic structure count.
assert.equal(g.all_nodes().length, 7, 'only seven nodes left');
assert.equal(g.all_edges().length, 7, 'only seven edges left');
// Five subragphs, all containing the embedding individual as
// part of this loader's process.
var num_sub = 0;
var self_contained_sub = 0;
each(g.all_nodes(), function(n){
if( n.subgraph() ){
num_sub++;
var s = n.subgraph();
//console.log('sub in: ' + n.id());
//console.log('sub is: ' + typeof(s.get_node));
if( s.get_node(n.id()) ){
self_contained_sub++;
}
}
});
assert.equal(num_sub, 5, 'five embedded subgraphs');
assert.equal(self_contained_sub, 5, 'five self-containing subgraphs');
// Close examination of a single subgraph.
var nid = 'gomodel:taxon_559292-5525a0fc0000001-GO-0005515-5525a0fc0000023';
var n = g.get_node(nid);
assert.equal(n._is_a, 'bbop-graph-noctua.node', 'node is a node');
var s = n.subgraph();
//console.log(s);
assert.equal(s._is_a, 'bbop-graph-noctua.graph', 'graph is a graph');
assert.equal(s.all_nodes().length, 2, 'subgraph has two nodes');
assert.equal(s.all_edges().length, 1, 'subgraph has one edges');
assert.equal(s.all_edges()[0].predicate_id(), 'RO:0002333', 'correct subraph edge');
//console.log();
});
});
// var assert = require('chai').assert;

@@ -253,0 +298,0 @@ // var model = new require('..');

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc