Cytoscape- Selecting directed edges - cytoscape

In Cytoscape, I have bi-directional edges from a reference node. How do I select only those edges that have a particular directionality. For example selecting all the outward directed edges from the reference node.

Have you tried using this:
cy.$id('yourID').outgoers();
This selects all edges going out of the specified node, which you can get by a click-event e.g.
If you want to get the outgoing nodes behind these edges, you can use this:
cy.$id('yourID').outgoers().targets();
http://js.cytoscape.org/#nodes.outgoers
http://js.cytoscape.org/#edges.targets

Related

How to get all nodes within an area surrounded by a node type by using Cypher (Neo4j)

I am trying to do the following:
Let's say this is the initial graph: Initial Graph
I want to get all the blue nodes between red nodes and connect them to a new yellow node. I want to do this for every blue node area seperated by red nodes.
What I am trying to tell: The Result I Want
I want to do this without creating redundant yellow nodes and unnecessary traversals. Also, I want to do this in a single query, if it is possible.
Initially I achieved creating yellow nodes and connecting them by getting paths which start with a red node and end with another red node. However, this solution led to creating redundant yellow nodes since there are some areas seperated by 3 or more red nodes. For instance if a blue node area is seperated by 3 red nodes, this solution finds 3 different paths in that area, therefore creates 3 different yellow nodes. So I had to delete redundant yellow nodes in another query which was terrible in terms of efficiency.
After that, I tried using apoc expand functions, however they require minLevel and maxLevel parameters which again leads to finding more than one path in a blue node area.
In short, the real question is how can I achieve getting each blue node area as a single path without compromising efficiency?
Edit: I also tried creating a yellow node for each blue node directly connected to the red node near it and then connected the other blue nodes to the yellow node if they are reachable through blue nodes, however this query also takes too much time.
As far as I am concerned matching paths like the following query affects time efficiency too negatively:
MATCH path = (:YELLOW)-[link*]-(:BLUE)-[:CONNECTION]-(:RED)
WHERE single(x IN nodes(path) WHERE x:RED)
//Then connect nodes in path to the yellow node if there is no connection
Any suggestions?

Cytoscape define edge length

I am creating a manual layout for a network in Cytoscape version 3.8.2. I would like to be able to define the edge lengths, so the network looks more uniform. Is there a way to define the property edge length?
Specifically, I want something like the below subsection of a network to be a perfect circle.
No, the edge length is not a property in Cytoscape. You would need to calculate it based on the source and target node positions. One way to achieve what you want would be select all of the outer nodes, then do a degree-sorted circular layout, and then drag your central node back into the center.
-- scooter

JUNG layout for left-to-right placement of nodes

Is there an optimal layout in JUNG for left-to-right placement of nodes in the graph? I'm looking for something that would model a data lineage and need to represent this somewhat linearly (left to right).
If your graph is a tree, then you can use the TreeLayout and do some post-processing to rotate it to have the root on the left instead of the top (see the L2RTreeLayoutDemo for an example of how to do this).
If your graph is only sort of tree-shaped, then you may want to extract a tree from your graph first (see MinimumSpanningTreeDemo for one way to do this automatically) and then follow the procedure above.
If neither of those works for you (for example, this won't work if your graph has multiple "roots"), then you will probably need to create your own layout, perhaps based on TreeLayout.

How bind some nodes in spritekit and move them in a bunch along one trajectory?

I create game with spriteKit in Xcode. I need to create carousel and move 4 nodes around one pillar.
carousel
How can I move some bind nodes? It`s necessary to change zPosition when node approaches the pillar and when node comes out from behind the pillar. How it can be implemented?
To group your nodes together, just create a new SKNode, add it to the scene, and anything that needs to be grouped to this, just call move(toParent:) on the nodes that need to be moved.
let groupedNode = SKNode()
self.addChild(groupedNode)
node1.move(toParent:groupedNode)
As for zPosition, it is relative to the parent, so if your pillar is at 2, and your group is at 1, to make your individual nodes above the pillar, you need to make the node 2. This will make the node zPosition really 3 (node + group) placing it above the pillar.

Graphviz: Control node align in a subgraph

Consider the following subgraph, with 5 Mrecod nodes:
Is there a way to force a vertical orientation, with the nodes above each other? I've tried rankdir=TB in the subgraph, with no effect.
I am running graphviz under Ubuntu with no special parameters:
dot -Tpng graph.dot -o img/graph.png
Adam, just to clear up a couple of potentially confusing points:
I'm pretty sure that the rankdir attribute applies to the entire graph, you cannot isolate that particular subgraph.
rankdir=TB is the default value to begin with, so adding it isn't really going to do anything.
That said, if I am reading your subgraph correctly, it looks like:
You have a collection of 5 record-type nodes in a cluster.
Each of those nodes have inbound edges from one or more nodes outside the cluster.
None of the nodes within the cluster have edges between them.
If that's correct, then the nodes in your subgraph have the same rank (or probably do, depending upon the rank of the nodes that connect to them). Setting rankdir=LR (or rankdir=RL) will change the orientation of that subgraph so the nodes are aligned vertically, but it will also change the alignment of the overall graph.
One way to get just those nodes to be aligned vertically is to add an invisible edge between them. For example, if you have nodes A, B, C, D and E, your cluster definition might look something like this:
digraph G {
// ...skipping stuff outside the cluster...
subgraph clusterFoo {
node [shape=record]
A [label="..."]
B [label="..."]
C [label="..."]
D [label="..."]
E [label="..."]
edge [style=invis]
A -> B -> C -> D -> E
}
}
Adding the edges will force the nodes in the subgraph to have a different rank, so the default rankdir=TB will lay out the nodes from top to bottom rather than from left to right. The style=invis attribute on these "false" edges will make them invisible.
If you want to tweak the spacing or alignment of the nodes within the cluster you might also want to play with edge attributes such as weight or minlen/attrs.html#d:minlen), or consider constraint=false on the inbound edges.
If I've misinterpreted your graph or if this doesn't help you at all, can you update your question to add a minimal example of the DOT file you are working with?
PS: On Ubuntu, you can use:
dot -Txlib graph.dot
to quickly open up a window with a rendering of the graph in graph.dot without first writing it to a file. The rendered image will even automatically update when you modify the source file.

Resources