def matches(G, queue):
    """
    If the sequence in 'queue' correspond to a
    node in 'G', return the sequence id, 
    otherwise return False
    """
    if not queue:
        return False
    seq = 0
    for a in queue:
        try:
            seq = G[seq][a]
        except KeyError:
            return False
    return seq