# Pulling a reachable subgraph of a DAG

Hi all,
Excited to try TigerGraph, but I can’t figure out how to do what I need in GSQL, or if it even supports what I’m looking for. Specifically, for an arbitrary DAG, I need to get the subgraph defined by all vertices reachable from a specified vertex (both nodes and edges). This neo4j APOC function appears to do the job - is there any equivalent in TigerGraph? Thanks so much for your help!

``-Matt``

Hi Matt,

please check the list of our algorithm libraries here:
https://docs.tigergraph.com/graph-algorithm-library

The difference between Neo4J and TigerGraph is that in Neo4J Cypher cannot do advanced graph analytics - so you need a procedure like the one you posted. In TigerGraph, you can write your own advanced graph query using GSQL only and not needing path expanders on top.

A simple query to show all connections of a single vertex would be like this:

``````CREATE QUERY allConnection(VERTEX<Patient> p) FOR GRAPH MyGraph {
ListAccum<EDGE> @@edgeList;
seed = {p};

S1 = SELECT s
FROM seed:s -(:e)-:t
ACCUM @@edgeList += e;

PRINT S1,@@edgeList;
}
``````

You can check our tgcloud.io Covid-19 solution, this GSQL is included into it.

Best,
Bruno

ah, I see - thank you!

What if you then wanted to subsequently run an algorithm on that sub-graph ? Like a centrality ?

you would find a collection of algorythms in our Github directory:

Hi Bruno,

Unfortunately that does not answer the question? The algorithm is not the issue here. The issue is how do you pass the result of a query to another query, if that result is a subgraph.

It is all about decomposing your case. My suspicion at this point is there is no way you can do that, because you can’t pass an edgset as a parameter.

1 - Solution 1: Would be to tag the vertex set or edset, and call a sub query with the taggedvertexset only, but somehow the subquery need to be aware of the tag used. by tag i just mean the accum variable and the meaning of its value used.

2 - Merge all the algorithm that you have in one global algorithm and run the all thing.

My use case for a particular demo i want to do is:

a) Select a set of node submitted as input
b) Expand the set of nodes 1 hop away and the union of the original set and the new nodes 1 hop away of each nodes, becomes the new seed set.
c)Optional add also every node in the shortest path of each pair of the original seed set, that is not in the seedset yet
c)Run a Centrality or Pangerank algorithm on that set.

Hence
I) How to structure such a program elegantly with GSQL queries capability ?
II) How to run that in stage to showcase a step by step to the user ?

Hope it make sense ?

OK, now I understood it better. You can achieve this by using subqueries
https://docs.tigergraph.com/dev/gsql-ref/querying/operators-functions-and-expressions#queries-as-functions

or using a single query and storing the results in accumulators:
https://docs.tigergraph.com/start/accumulators-tutorial

Of course, you can use accumulators in subqueries too.

Bruno

I Will try Thank you