def permuted_copy(self, partition=None):
        """ Return a copy of the collection with all alignment columns permuted
        """
        def take(n, iterable):
            return [next(iterable) for _ in range(n)]

        if partition is None:
            partition = Partition([1] * len(self))

        index_tuples = partition.get_membership()

        alignments = []
        for ix in index_tuples:
            concat = Concatenation(self, ix)
            sites = concat.alignment.get_sites()
            random.shuffle(sites)
            d = dict(zip(concat.alignment.get_names(), [iter(x) for x in zip(*sites)]))
            new_seqs = [[(k, ''.join(take(l, d[k]))) for k in d] for l in concat.lengths]

            for seqs, datatype, name in zip(new_seqs, concat.datatypes, concat.names):
                alignment = Alignment(seqs, datatype)
                alignment.name = name
                alignments.append(alignment)

        return self.__class__(records=sorted(alignments, key=lambda x: SORT_KEY(x.name)))
def permuted_copy ( self , partition = None ) : def take ( n , iterable ) : return [ next ( iterable ) for _ in range ( n ) ] if partition is None : partition = Partition ( [ 1 ] * len ( self ) ) index_tuples = partition . get_membership ( ) alignments = [ ] for ix in index_tuples : concat = Concatenation ( self , ix ) sites = concat . alignment . get_sites ( ) random . shuffle ( sites ) d = dict ( zip ( concat . alignment . get_names ( ) , [ iter ( x ) for x in zip ( * sites ) ] ) ) new_seqs = [ [ ( k , '' . join ( take ( l , d [ k ] ) ) ) for k in d ] for l in concat . lengths ] for seqs , datatype , name in zip ( new_seqs , concat . datatypes , concat . names ) : alignment = Alignment ( seqs , datatype ) alignment . name = name alignments . append ( alignment ) return self . __class__ ( records = sorted ( alignments , key = lambda x : SORT_KEY ( x . name ) ) )
Return a copy of the collection with all alignment columns permuted