def _pathway_feature_permutation(pathway_feature_tuples,
                                 permutation_max_iters):
    pathways, features = [list(elements_at_position)
                          for elements_at_position in
                          zip(*pathway_feature_tuples)]
    original_pathways = pathways[:]
    random.shuffle(pathways)
    feature_block_locations = {}
    i = 0
    while i < len(pathways):
        starting_index = i
        current_feature = features[i]
        pathway_set = set()
        while i < len(pathways) and features[i] == current_feature:
            if pathways[i] not in pathway_set:
                pathway_set.add(pathways[i])
            else:
                k = 0
                random_pathway = None
                while True:
                    j = random.choice(range(0, len(pathways)))
                    random_pathway = pathways[j]
                    random_feature = features[j]
                    if (random_pathway != pathways[i] and
                            random_pathway not in pathway_set):
                        if random_feature not in feature_block_locations:
                            break
                        feature_block_start, feature_block_end = \
                            feature_block_locations[random_feature]
                        pathway_block = pathways[feature_block_start:
                                                 feature_block_end]
                        if pathways[i] not in pathway_block:
                            break
                    k += 1
                    if k > permutation_max_iters:
                        print("Permutation step: reached the maximum "
                              "number of iterations {0}.".format(
                                permutation_max_iters))
                        return None
                pathway_set.add(random_pathway)
                pathways[j] = pathways[i]
                pathways[i] = random_pathway
            i += 1
        ending_index = i
        feature_block_locations[current_feature] = (
            starting_index, ending_index)
    if original_pathways == pathways:
        return None
    return list(zip(pathways, features))