First of all, I should confess that I'm very bad at everything graph-related. My trees are implemented as nested dictionaries that represent unweighted Markov chains.
class Tree(object):
    def __init__(self, depth=6, seq=None):
        self.graph = dict()
        self.depth = depth
        if seq is not None:
            self.build(seq)
    def build(self, seq):
        for i in xrange(len(seq)):
            sseq = seq[i:i+self.depth]
            for j in xrange(len(sseq)):
                if j == 0:
                    if sseq[j] not in self.graph:
                        self.graph[sseq[j]] = dict()
                    nest_pointer = self.graph[sseq[j]]
                else:
                    if sseq[j] not in nest_pointer:
                        nest_pointer[sseq[j]] = dict()
                    nest_pointer = nest_pointer[sseq[j]]
What I need is to be able to compare two trees while being aware of the depth at which dissimilarities occur, because I'm gonna use a hierarchical similarity scoring system, so a simple recursive DFS doesn't do the trick.
P.S.
If you can propose a better data structure for my trees, I would appreciate it a lot. I went with dictionaries to get maximum time performance. Thank you in advance.
 
    