Help with creating a query that will return only the relavant nodes and the relavent relationships

Hello everyone!

I hope you could help me with an issue i'm trying to figure out.

i'm trying to show my graphs in the most comfortable way I can in neodash and in neo4j as well.

for example I have these 2 graphs.

What I want from them is to see in each only the dark green color(SubGraphInstance), the label FROM GRAPH to my orange nodes(CellInstances), from (CellInstance-orange nodes) I want to see the red nodes(Functions of these cellIntsances) with the relationship CELL_TYPE(from orange to red node), in addition I want to see from the orange node the relationship FROM_CELL, to another orange node with relationship TO_CELL.

my purpose is to to get rid of all the additional nodes like the connection(beige) nodes, and the variables of the red functions and their relationships

without damaging my entities. and to be able to see all as a graph

When I tried to do merge with the following cypher , I couldn't add to the changed graph anything, couldn't make calculations or connect it to another graph.

MATCH (a1:CellType{transformType:'ANALOG_TO_ANALOG'}), (a2:Function {expression:"x+y"}), (a3:Variable {variableName:'x'}),(a4:Variable {variableName:'y'})

WITH head(collect([a1,a2,a3,a4])) as nodes

CALL apoc.refactor.mergeNodes(nodes,{properties:"combine", mergeRels:true}) yield node

Return node;

then, I tried these too options that were better becuse my data wasn't merged.

MATCH (a:SubGraphInstance) where a.name = "alpha1"
CALL apoc.path.spanningTree(a,{maxLevel:5}) YIELD path
RETURN path

AND this as well

MATCH p = (g:SubGraphInstance)-[:FROM_GRAPH]->(o:CellInstance)-[*10]-(r:Function)

RETURN p

verachkaverachk_0-1658730139115.png

verachkaverachk_0-1658731928473.png

If there is a way to merge the data without damaging it then it will be good as well,

my ideal graph in general looked like this drawing:

verachkaverachk_1-1658730740679.png

Vera.