In [ ]:
# PG_USER= PG_HOST= PG_DATABASE= PG_PASSWORD=   jupyter notebook

import psqlgraph
import os

from graphviz import Digraph
from IPython.display import display
from gdcdatamodel.models import *
from gdcdatamodel.viz import create_graphviz
from psqlgraph import PsqlGraphDriver, Node, Edge

HOST = os.environ.get('PG_HOST')
USER = os.environ.get('PG_USER')
DATABASE = os.environ.get('PG_DATABASE')
PASSWORD = os.environ.get('PG_PASSWORD')

g = psqlgraph.PsqlGraphDriver(HOST, USER, PASSWORD, DATABASE)
print('Ready!')

In [ ]:
with g.session_scope():
    cases = g.nodes(Case).subq_path('samples').limit(1).all()
    case_neighbors = [edge.src for case in cases for edge in case.edges_in]
    samples = [sample for case in cases for sample in case.samples]
    portions = [portion for sample in samples for portion in sample.portions]
    analytes = [analyte for portion in portions for analyte in portion.analytes]
    aliquots = [aliquot for analyte in analytes for aliquot in analyte.aliquots]
    nodes = cases + case_neighbors + samples + portions + analytes + aliquots
    display(create_graphviz(nodes))

In [ ]:
## You may need to do something like the following if the above display() command does not render a graph for you

# from IPython.display import Image 

# d = create_graphviz(nodes)
# d.format = 'png'
# d.render()

# Image(filename='Digraph.gv.png')