Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting nodes without edges

I have a ton of nodes in a graph, and with some filters I am able to remove some edges by some condition, using cy.remove(myCollection).

It happens sometimes that all edges to a node is removed and therefore its sitting alone without edges. Is there any way in Cytoscape to find these nodes without edges?

I was out in something like:

cy.nodes(/*:inside*/).filter(node => node.connectedEdges().size() === 0)

But this returns an empty collection?

like image 583
janhartmann Avatar asked Sep 06 '26 01:09

janhartmann


1 Answers

I've had a similar problem: I had to remove nodes without edges from a graph. I solved it by using node.degree() with a function that cycles through nodes of my graph and finds those with degree=0 (both indegree and outdegree, which means that the nodes have neither sources nor targets).

    `cy.nodes(function(element){
        if( element.isNode() && element.degree()<1){
            cy.remove(element)
        }
    })`

Hope it could be useful to fix your problem

like image 109
Alessandro P Avatar answered Sep 07 '26 13:09

Alessandro P



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!