def findNode (current, toFind, path, dbCursor):

    if current in path:
        return

    path = list(path)
    path.append(current)


    # Base Case
    if current == toFind:
        print "Relationship Pathway FOUND!"
        print "Pathway: {}".format(translateList(path, dbCursor))
        sys.exit()


    # Establish string for queries
    query = "SELECT CUI1, REL, CUI2, SAB from MRREL where CUI2 = '{}'" \
            "AND SAB = 'MTH' AND (REL = 'RN' OR REL = 'CHD')"

    # Establish connection and query MySQL database
    try:

        # Executue a query serach
        dbCursor.execute (query.format(current))

    # Catch errors from MySQL
    except MySQLdb.Error, e:
        try:
            # Prints the error
            print "MySQL Error [{}]: {} --- while querying {}".format(\
                                                e.args[0], e.args[1], current)

        except IndexError:
            # Prints the 1 argument error
            print "MySQL Error: {} --- while querying {}".format(str(e),\
                                                                current)

        sys.exit()
def findNode(current, toFind, path, dbCursor):

    if current in path:
        return

    path = list(path)
    path.append(current)

    # Base Case
    if current == toFind:
        print "Relationship Pathway FOUND!"
        print "Pathway: {}".format(translateList(path, dbCursor))
        sys.exit()

    # Establish string for queries
    query = "SELECT CUI1, REL, CUI2, SAB from MRREL where CUI2 = '{}'" \
            "AND SAB = 'MTH' AND (REL = 'RN' OR REL = 'CHD')"

    # Establish connection and query MySQL database
    try:

        # Executue a query serach
        dbCursor.execute(query.format(current))

    # Catch errors from MySQL
    except MySQLdb.Error, e:
        try:
            # Prints the error
            print "MySQL Error [{}]: {} --- while querying {}".format(\
                                                e.args[0], e.args[1], current)

        except IndexError:
            # Prints the 1 argument error
            print "MySQL Error: {} --- while querying {}".format(str(e),\
                                                                current)

        sys.exit()
        if cui1 not in childrenSet:
            parentList.append(cui1)

# Tracks time taken
if debugOn:
    currentTime = datetime.now()
    print "Took: {}".format(currentTime - lastTime)
    lastTime = currentTime
else:
    print "Done!"

# If debugging is on, translate the dictionaries and lists prematurely
if debugOn:
    sys.stdout.write(
        "Step 2.5 of 6: Translating Relations (DEBUG MODE) . . . ")
    topTier = translateList(topTier, cur)
    relationsDict = translateDictionary(relationsDict, cur)
    leaves = translateList(leaves, cur)
    currentTime = datetime.now()
    print "Took: {}".format(currentTime - lastTime)
    lastTime = currentTime

# Progress Message
sys.stdout.write("Step 3 of 6: Building Initial Hierarchy . . . ")

# Will hold the hierarchy while being built and cleaned up
inProgressHier = defaultdict(list)

# Keeps tracks of loops encountered
loopsDict = defaultdict(list)
        # then add it to the parentList
        if cui1 not in childrenSet:
            parentList.append(cui1)

# Tracks time taken
if debugOn:
    currentTime = datetime.now()
    print "Took: {}".format(currentTime - lastTime)
    lastTime = currentTime
else:
    print "Done!"

# If debugging is on, translate the dictionaries and lists prematurely
if debugOn:
    sys.stdout.write( "Step 2.5 of 6: Translating Relations (DEBUG MODE) . . . ")
    topTier = translateList( topTier, cur )
    relationsDict = translateDictionary( relationsDict, cur )
    leaves = translateList( leaves, cur )
    currentTime = datetime.now()
    print "Took: {}".format(currentTime - lastTime)
    lastTime = currentTime

# Progress Message
sys.stdout.write("Step 3 of 6: Building Initial Hierarchy . . . ")


# Will hold the hierarchy while being built and cleaned up
inProgressHier = defaultdict(list)

# Keeps tracks of loops encountered
loopsDict = defaultdict(list)