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

allpy

changeset 111:62e38970ffa2

broken: lib::project::column -- new returning value sequence::pdb_chain_chain_add completed
author boris <bnagaev@gmail.com>
date Sat, 23 Oct 2010 12:57:07 +0400
parents b43daeb9d767
children b7b963287d31
files lib/monomer.py lib/project.py lib/sequence.py
diffstat 3 files changed, 40 insertions(+), 17 deletions(-) [+]
line diff
     1.1 --- a/lib/monomer.py	Sat Oct 23 12:07:21 2010 +0400
     1.2 +++ b/lib/monomer.py	Sat Oct 23 12:57:07 2010 +0400
     1.3 @@ -31,6 +31,10 @@
     1.4      @staticmethod
     1.5      def from_name(name):
     1.6          return index_name[name.capitalize()]
     1.7 +      
     1.8 +    @staticmethod
     1.9 +    def from_pdb_residue(pdb_residue):
    1.10 +        return MonomerType.from_code3(pdb_residue.get_resname())
    1.11          
    1.12      # TO DISCUSS
    1.13      def __eq__(self, other):
    1.14 @@ -47,10 +51,10 @@
    1.15      """
    1.16      def __init__(self, monomer_type):
    1.17          self.type = monomer_type
    1.18 -        self.pdb_residue = []
    1.19 +        self.pdb_residues = {}
    1.20          
    1.21 -    def pdb_residue_add(self, pdb_chain, pdb_residue):
    1.22 -        self.pdb_residue[pdb_chain] = pdb_residue
    1.23 +    def pdb_residue_add(self, chain, residue):
    1.24 +        self.pdb_residues[chain] = residue
    1.25      
    1.26      def __eq__(self, other):
    1.27          return self.type == other.type
     2.1 --- a/lib/project.py	Sat Oct 23 12:07:21 2010 +0400
     2.2 +++ b/lib/project.py	Sat Oct 23 12:57:07 2010 +0400
     2.3 @@ -12,7 +12,6 @@
     2.4  import allpy_data
     2.5  import os
     2.6  from tempfile import mkstemp
     2.7 -import sys
     2.8  
     2.9  class Project(object):
    2.10      """
    2.11 @@ -198,8 +197,8 @@
    2.12          """
    2.13          returns list of columns of alignment
    2.14          sequence or sequences:
    2.15 -            if sequence is given, then column is monomer
    2.16 -            if sequences is given, then column is dict {sequence: monomer}
    2.17 +            if sequence is given, then column is (original_monomer, monomer)
    2.18 +            if sequences is given, then column is dict (original_monomer, {sequence: monomer}) 
    2.19              if both of them are given, it is an error
    2.20          original (Sequence type):
    2.21              if given, this filters only columns represented by original sequence
    2.22 @@ -210,11 +209,11 @@
    2.23          alignment = self.alignment.items()
    2.24          alignment.sort(key=lambda i: indexes[i[0]])
    2.25          alignment = [monomers for seq, monomers in alignment]
    2.26 -        for column in zip(alignment):
    2.27 -            if not original or column[index[original]]:
    2.28 +        for column in zip(*alignment):
    2.29 +            if not original or column[indexes[original]]:
    2.30                  if sequence:
    2.31 -                    yield column[index[sequence]]
    2.32 +                    yield (column[indexes[original]], column[indexes[sequence]])
    2.33                  else:
    2.34 -                    yield dict([(s, column[index[s]]) for s in sequences])
    2.35 +                    yield (column[indexes[original]], dict([(s, column[indexes[s]]) for s in sequences]))
    2.36          
    2.37          
     3.1 --- a/lib/sequence.py	Sat Oct 23 12:07:21 2010 +0400
     3.2 +++ b/lib/sequence.py	Sat Oct 23 12:57:07 2010 +0400
     3.3 @@ -3,6 +3,8 @@
     3.4  from Bio.PDB import PDBParser, CaPPBuilder
     3.5  from allpy_pdb import Pdb
     3.6  import project
     3.7 +import sys
     3.8 +
     3.9  
    3.10  cappbuilder = CaPPBuilder()
    3.11  
    3.12 @@ -17,10 +19,13 @@
    3.13      TODO: class Protein: container of multiple Sequences,
    3.14            class ProteinMononer: container of multiple Monomers
    3.15      """
    3.16 -    def __init__(self, monomers, name='', description=""):
    3.17 +    def __init__(self, monomers=None, name='', description=""):
    3.18 +        if not monomers:
    3.19 +            monomers = []
    3.20          self.name = name
    3.21          self.description = description
    3.22          self.monomers = monomers 
    3.23 +        self.pdb_chains = []
    3.24      
    3.25      def __len__(self):
    3.26          return len(self.monomers)
    3.27 @@ -41,13 +46,14 @@
    3.28          and align each Monomer with PDB.Residue (TODO)
    3.29          """
    3.30          name = Pdb.std_id(pdb_id, pdb_chain, pdb_model)
    3.31 -        self.pdb_chain = PDBParser().get_structure(name, pdb_file)[pdb_model][pdb_chain]
    3.32 -        peptide = cappbuilder.build_peptides(self.pdb_chain)
    3.33 -        pdb_sequence = Sequence.from_str(str(peptide[0].get_sequence())) # TRU?
    3.34 +        chain = PDBParser().get_structure(name, pdb_file)[pdb_model][pdb_chain]
    3.35 +        self.pdb_chains.append(chain)
    3.36 +        pdb_sequence = Sequence.from_pdb_chain(chain)
    3.37          alignment = project.Project.from_sequences(self, pdb_sequence)
    3.38          alignment.muscle_align()
    3.39 -        for pdb_monomer in alignment.column(sequence=pdb_sequence, original=self):
    3.40 -            pdb_monomer.pdb_residue_add(self.pdb_chain, 
    3.41 +        for monomer, pdb_monomer in alignment.column(sequence=pdb_sequence, original=self):
    3.42 +            monomer.pdb_residue_add(chain, pdb_monomer.pdb_residues[chain])
    3.43 +            #~ pdb_monomer.pdb_residue_add(self.pdb_chain, 
    3.44          # FIXME: align and map
    3.45          
    3.46      @staticmethod
    3.47 @@ -55,6 +61,21 @@
    3.48          monomers = [monomer_kind.from_code1(aa).instance() for aa in fasta_str]
    3.49          return Sequence(monomers, name, description)
    3.50  
    3.51 +    @staticmethod
    3.52 +    def from_pdb_chain(chain):
    3.53 +        """
    3.54 +        chain is Bio.PDB.Chain
    3.55 +        returns Sequence with Monomers with link to Bio.PDB.Residue
    3.56 +        """
    3.57 +        peptide = cappbuilder.build_peptides(chain)[0]        
    3.58 +        sequence = Sequence()
    3.59 +        sequence.pdb_chains = [chain]
    3.60 +        for ca_atom in peptide.get_ca_list():
    3.61 +            residue = ca_atom.get_parent()
    3.62 +            monomer = AminoAcidType.from_pdb_residue(residue).instance()
    3.63 +            monomer.pdb_residue_add(chain, residue)
    3.64 +            sequence.monomers.append(monomer)
    3.65 +        return sequence
    3.66          
    3.67          
    3.68          
    3.69 @@ -63,4 +84,3 @@
    3.70          
    3.71          
    3.72          
    3.73 -