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

allpy

changeset 308:4d610c277281

Moved PDB-related stuff from base Block to allpy.pdb.Block
author Daniil Alexeyevsky <me.dendik@gmail.com>
date Thu, 16 Dec 2010 20:45:57 +0300
parents 237deca17963
children 0c3c1856113a
files allpy/base.py allpy/pdb.py
diffstat 2 files changed, 51 insertions(+), 47 deletions(-) [+]
line diff
     1.1 --- a/allpy/base.py	Thu Dec 16 20:42:42 2010 +0300
     1.2 +++ b/allpy/base.py	Thu Dec 16 20:45:57 2010 +0300
     1.3 @@ -1,13 +1,8 @@
     1.4  import sys
     1.5 -import os
     1.6 -import os.path
     1.7 -from tempfile import NamedTemporaryFile
     1.8 -import urllib2
     1.9  
    1.10  import config
    1.11  import fasta
    1.12  from graph import Graph
    1.13 -from Bio.PDB.DSSP import make_dssp_dict
    1.14  import data.codes
    1.15  
    1.16  default_gaps = set((".", "-", "~"))
    1.17 @@ -459,45 +454,4 @@
    1.18          alignment_sequence = self.alignment.body[sequence]
    1.19          return (alignment_sequence[i] for i in self.positions)
    1.20  
    1.21 -    def ca_atoms(self, sequence, pdb_chain):
    1.22 -        """ Iterates Ca-atom of monomers of this sequence from this block  """
    1.23 -        return (sequence.pdb_residues[pdb_chain][monomer] for monomer in self.monomers())
    1.24 -
    1.25 -    def sequences_chains(self):
    1.26 -        """ Iterates pairs (sequence, chain) """
    1.27 -        for sequence in self.alignment.sequences:
    1.28 -            if sequence in self.sequences:
    1.29 -                for chain in sequence.pdb_chains:
    1.30 -                    yield (sequence, chain)
    1.31 -
    1.32 -    def superimpose(self):
    1.33 -        """ Superimpose all pdb_chains in this block """
    1.34 -        sequences_chains = list(self.sequences_chains())
    1.35 -        if len(sequences_chains) >= 1:
    1.36 -            sup = Superimposer()
    1.37 -            fixed_sequence, fixed_chain = sequences_chains.pop()
    1.38 -            fixed_atoms = self.ca_atoms(fixed_sequence, fixed_chain)
    1.39 -            for sequence, chain in sequences_chains:
    1.40 -                moving_atoms =  self.ca_atoms(sequence, chain)
    1.41 -                sup.set_atoms(fixed_atoms, moving_atoms)
    1.42 -                # Apply rotation/translation to the moving atoms
    1.43 -                sup.apply(moving_atoms)
    1.44 -
    1.45 -    def pdb_save(self, out_file):
    1.46 -        """ Save all sequences
    1.47 -
    1.48 -        Returns {(sequence, chain): CHAIN}
    1.49 -        CHAIN is chain letter in new file
    1.50 -        """
    1.51 -        tmp_file = NamedTemporaryFile(delete=False)
    1.52 -        tmp_file.close()
    1.53 -
    1.54 -        for sequence, chain in self.sequences_chains():
    1.55 -            sequence.pdb_save(tmp_file.name, chain)
    1.56 -            # TODO: read from tmp_file.name
    1.57 -            # change CHAIN
    1.58 -            # add to out_file
    1.59 -
    1.60 -        os.unlink(NamedTemporaryFile)
    1.61 -
    1.62  # vim: set ts=4 sts=4 sw=4 et:
     2.1 --- a/allpy/pdb.py	Thu Dec 16 20:42:42 2010 +0300
     2.2 +++ b/allpy/pdb.py	Thu Dec 16 20:45:57 2010 +0300
     2.3 @@ -7,9 +7,16 @@
     2.4  """
     2.5  
     2.6  import re
     2.7 -import base
     2.8 +import os
     2.9 +import os.path
    2.10 +from tempfile import NamedTemporaryFile
    2.11 +import urllib2
    2.12 +
    2.13  from Bio.PDB import PDBParser
    2.14  from Bio.PDB import Superimposer, CaPPBuilder, PDBIO
    2.15 +from Bio.PDB.DSSP import make_dssp_dict
    2.16 +
    2.17 +import base
    2.18  
    2.19  
    2.20  # for pdb-codes
    2.21 @@ -221,4 +228,47 @@
    2.22          (sequence.pdb_secstr[pdb_chain][m] if sequence.secstr_has(pdb_chain, m) else gap)
    2.23          for m in self.body[sequence]])
    2.24  
    2.25 +class Block(base.Block):
    2.26 +
    2.27 +    def ca_atoms(self, sequence, pdb_chain):
    2.28 +        """ Iterates Ca-atom of monomers of this sequence from this block  """
    2.29 +        return (sequence.pdb_residues[pdb_chain][monomer] for monomer in self.monomers())
    2.30 +
    2.31 +    def sequences_chains(self):
    2.32 +        """ Iterates pairs (sequence, chain) """
    2.33 +        for sequence in self.alignment.sequences:
    2.34 +            if sequence in self.sequences:
    2.35 +                for chain in sequence.pdb_chains:
    2.36 +                    yield (sequence, chain)
    2.37 +
    2.38 +    def superimpose(self):
    2.39 +        """ Superimpose all pdb_chains in this block """
    2.40 +        sequences_chains = list(self.sequences_chains())
    2.41 +        if len(sequences_chains) >= 1:
    2.42 +            sup = Superimposer()
    2.43 +            fixed_sequence, fixed_chain = sequences_chains.pop()
    2.44 +            fixed_atoms = self.ca_atoms(fixed_sequence, fixed_chain)
    2.45 +            for sequence, chain in sequences_chains:
    2.46 +                moving_atoms =  self.ca_atoms(sequence, chain)
    2.47 +                sup.set_atoms(fixed_atoms, moving_atoms)
    2.48 +                # Apply rotation/translation to the moving atoms
    2.49 +                sup.apply(moving_atoms)
    2.50 +
    2.51 +    def pdb_save(self, out_file):
    2.52 +        """ Save all sequences
    2.53 +
    2.54 +        Returns {(sequence, chain): CHAIN}
    2.55 +        CHAIN is chain letter in new file
    2.56 +        """
    2.57 +        tmp_file = NamedTemporaryFile(delete=False)
    2.58 +        tmp_file.close()
    2.59 +
    2.60 +        for sequence, chain in self.sequences_chains():
    2.61 +            sequence.pdb_save(tmp_file.name, chain)
    2.62 +            # TODO: read from tmp_file.name
    2.63 +            # change CHAIN
    2.64 +            # add to out_file
    2.65 +
    2.66 +        os.unlink(NamedTemporaryFile)
    2.67 +
    2.68  # vim: set ts=4 sts=4 sw=4 et: