Find all adjacent nodes of a node until stop selected nodes are reached

Hi

Please see the joined graph (png image).

I need to find all the neighboring nodes to blue nodes until the next blue node is reached.

For example, If I start from the “IQSEC1” node, I would like to have the following result :

IQSEC1 -> GNAQ -> DGKD
IQSEC1 -> NR2C2-> MTA2
IQSEC1 -> PB1-> DNAJB4

How can I do this?

Rplot

I am not sure if there is a simpler way than writing your own graph traversal that stops at blue nodes.

You could maybe try something along these lines:

  • Remove all blue nodes, except your starting point.
  • Find the connected component that contains your starting point. You can use subcomponent. This gives you almost what you want, but without the terminating blue nodes.
  • Take the union of the first-order neighbourhood of all nodes in this component. Select those which are blue. Add these blue ones to the component.
  • Create the induced_subgraph of the nodes you collected. This should give the result you are looking for.