Path counting

You used to be able to figure that out very simply with size( (m)-->() ), but the use of patterns for anything but testing for the existence of a pattern has been deprecated. I have used a 'call' subquery to accomplish the same. I did not have your modified code, so I used the last version. You will need to make your modifications again...sorry.

match (m)
with m, rand() as R
order by R
limit 500
with collect(m) as terminatorNodes
match (n)
where id(n)=100
with n, terminatorNodes
CALL apoc.path.expandConfig(n, {
relationshipFilter:">",
minLevel: 1,
maxLevel: 4,
terminatorNodes: terminatorNodes,
uniqueness: "NODE_PATH"
}) yield path
with n, path, length(path) as hops
with n, nodes(path)[hops] as target, hops
with n, target, hops, count(*) as paths
with n, target, collect({h: hops, p: paths}) as stats
call{
    with target
    optional match (target)-[]->()
    return count(*) as targetOutgoingRelationships
}
return n.name as `start node (n)`, n.cui, target.rScore as `r score`,
target.name as target_node, target.cui,
coalesce([i in stats where i.h = 1][0].p, 0) as `hop-1`,
coalesce([i in stats where i.h = 2][0].p, 0) as `hop-2`,
coalesce([i in stats where i.h = 3][0].p, 0) as `hop-3`,
coalesce([i in stats where i.h = 4][0].p, 0) as `hop-4`,
targetOutgoingRelationships