Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/rev/27e866560087
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 01:02:39 2012
Кодировка:
allpy: 27e866560087

allpy

changeset 491:27e866560087

allpy/structure: add blocks3d method to BlockMixin * reimplement blocks finding algorithm in method BlockMinix.blocks3d * add methods BlockMixin.monomers() and BlockMixin.continuous_blocks() monomers() returns all monomers inside block continuous_blocks() returns list of continuous blocks (using alignment) * add defaults of blocks3d to allpy/config.py
author boris (netbook) <bnagaev@gmail.com>
date Mon, 21 Feb 2011 17:53:04 +0300
parents 126f99bf234d
children 672a9a5ff125
files allpy/config.py allpy/structure.py
diffstat 2 files changed, 79 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/allpy/config.py	Mon Feb 21 14:30:22 2011 +0300
     1.2 +++ b/allpy/config.py	Mon Feb 21 17:53:04 2011 +0300
     1.3 @@ -15,4 +15,7 @@
     1.4  # max number of cores (including main core)
     1.5  ac_count = 5
     1.6  
     1.7 +# blocks3d
     1.8 +min_width = 3
     1.9 +timeout_2 = 10 # bron-kerbosh for blocks
    1.10  
     2.1 --- a/allpy/structure.py	Mon Feb 21 14:30:22 2011 +0300
     2.2 +++ b/allpy/structure.py	Mon Feb 21 17:53:04 2011 +0300
     2.3 @@ -238,6 +238,82 @@
     2.4                      break
     2.5          return GCs
     2.6  
     2.7 +    def blocks3d(self, max_delta=config.delta,
     2.8 +    timeout=config.timeout, timeout_2=config.timeout_2,
     2.9 +    min_width=config.min_width):
    2.10 +        """ Returns length-sorted list of reliable blocks
    2.11 +
    2.12 +        * max_delta -- threshold of distance spreading
    2.13 +        * timeout -- Bron-Kerbosh timeout (couple cores)
    2.14 +        * timeout_2 -- Bron-Kerbosh timeout (blocks)
    2.15 +        * min_width -- min width of each core
    2.16 +        """
    2.17 +        Block = self.__class__
    2.18 +        # for sorting
    2.19 +        key_column = lambda c: return self.columns.index(c)
    2.20 +        key_sequence = lambda s: return self.sequences.index(c)
    2.21 +        vertices = sum([seq for seq in self.sequences], [])
    2.22 +        edges = {}
    2.23 +        for i, seq1 in enumerate(self.sequences):
    2.24 +            for j, seq2 in enumerate(self.sequences):
    2.25 +                if i < j:
    2.26 +                    block = copy(self)
    2.27 +                    block.sequences = [seq1, seq2]
    2.28 +                    cores = block.geometrical_cores(max_delta=max_delta,
    2.29 +                        timeout=timeout, minsize=min_width)
    2.30 +                    for core in cores:
    2.31 +                        core_block = copy(block)
    2.32 +                        core_block.columns = sorted(core, key=key_column)
    2.33 +                        for part_block in core_block.continuous_blocks():
    2.34 +                            if len(part.columns) >= min_width:
    2.35 +                                monomers = part.monomers()
    2.36 +                                for m1 in monomers:
    2.37 +                                    for m2 in monomers:
    2.38 +                                        edges
    2.39 +                                        edge = Graph.edge(m1, m2)
    2.40 +                                        edges[edge] = 1.0
    2.41 +        graph = Graph(vertices, edges)
    2.42 +        cliques = graph.cliques(minsize=min_width*2, timeout=timeout_2)
    2.43 +        used_monomers = set()
    2.44 +        for clique in cliques:
    2.45 +            clique -= used_monomers
    2.46 +            used_monomers += clique
    2.47 +            while clique:
    2.48 +                sequences = set(m.sequence for m in clique)
    2.49 +                sequences.sort(key=key_sequence)
    2.50 +                columns = set(m.column for m in clique)
    2.51 +                columns.sort(key=key_column)
    2.52 +                height = len(sequences)
    2.53 +                if height <= 1:
    2.54 +                    break
    2.55 +                filled_columns = [c for c in columns
    2.56 +                    if len(clique & set(c.values())) == height]
    2.57 +                block = copy(self)
    2.58 +                block.columns = filled_columns
    2.59 +                block.sequences = sequences
    2.60 +                clique -= block.monomers()
    2.61 +                yield block
    2.62 +
    2.63 +    def continuous_blocks(self):
    2.64 +        """ Return list of continued blocks """
    2.65 +        self_columns = set(self.columns)
    2.66 +        columns_batch = []
    2.67 +        for column in self.alignment.columns:
    2.68 +            if column in self_columns:
    2.69 +                columns_batch.append(column)
    2.70 +            elif columns_batch:
    2.71 +                block = copy(self)
    2.72 +                block.columns = columns_batch
    2.73 +                columns_batch = []
    2.74 +                yield block
    2.75 +
    2.76 +    def monomers(self):
    2.77 +        """ Return list of all monomers in this block """
    2.78 +        for column in self.columns:
    2.79 +            for sequence in self.sequences:
    2.80 +                if sequence in column:
    2.81 +                    yield column[sequence]
    2.82 +
    2.83      def superimpose(self, gc):
    2.84          """ Superimpose monomers from this block at gc positions """
    2.85          gc = list(gc)