'Recursive method for parsing newick string, works by stripping down the string into substring
of newick contained with brackers, which is used to call itself.
Eg ... ( A, B, (D, E)C, F, G ) ...
We will make the preceeding nodes first A, B, then the internal node C, its children D, E,
and finally the succeeding nodes F, G'

def parseNode(self, string, depth):

    if (string == ''):
        return
    if (string.find('(') == (-1)):
        return self._makeNodesFromString(string, depth)
    nodes = []
    start = 0
    lenOfPreceedingInternalNodeString = 0
    bracketStack = []
    for j in range(len(string)):
        if (string[j] == '('):
            bracketStack.append(j)
            continue
        if (string[j] == ')'):
            i = bracketStack.pop()
            if (len(bracketStack) == 0):
                InternalNode = None
                startSubstring = string[(start + lenOfPreceedingInternalNodeString):i]
                preceedingNodes = self._makeNodesFromString(startSubstring, depth)
                nodes += preceedingNodes
                if ((j + 1) < len(string)):
                    stringRightOfBracket = string[(j + 1):]
                    match = re.search('[\\)\\,\\(]', stringRightOfBracket)
                    if match:
                        indexOfNextSymbol = match.start()
                        stringRepOfInternalNode = stringRightOfBracket[:indexOfNextSymbol]
                        internalNodes = self._makeNodesFromString(stringRepOfInternalNode, depth)
                        if (len(internalNodes) > 0):
                            InternalNode = internalNodes[0]
                        lenOfPreceedingInternalNodeString = len(stringRepOfInternalNode)
                    else:
                        InternalNode = self._makeNodesFromString(string[(j + 1):], depth)[0]
                        lenOfPreceedingInternalNodeString = (len(string) - j)
                if (InternalNode is None):
                    InternalNode = self.phyloTree.makeNode('', depth=depth, isInternal=True)
                    lenOfPreceedingInternalNodeString = 0
                childSubString = string[(i + 1):j]
                InternalNode.addChildNode(self.parseNode(childSubString, (depth + 1)))
                nodes.append(InternalNode)
                start = (j + 1)
            continue
    if (depth == 0):
        return nodes[0]
    endString = string[start:]
    if (string[(start - 1)] == ')'):
        match = re.search('[\\)\\,\\(]', endString)
        if match:
            endOfNodeName = ((start + match.start()) + 1)
            endString = string[endOfNodeName:]
            nodes += self._makeNodesFromString(endString, depth)
    return nodes
