allpy
changeset 173:45573ee48844
Project.alignment --> Project.body
author | boris <bnagaev@gmail.com> |
---|---|
date | Wed, 03 Nov 2010 19:01:50 +0300 |
parents | 854e33626cbe |
children | afe1db2a19a2 |
files | lib/block.py lib/project.py |
diffstat | 2 files changed, 23 insertions(+), 23 deletions(-) [+] |
line diff
1.1 --- a/lib/block.py Tue Nov 02 20:44:18 2010 +0300 1.2 +++ b/lib/block.py Wed Nov 03 19:01:50 2010 +0300 1.3 @@ -19,7 +19,7 @@ 1.4 * self.project -- project object, which the block belongs to 1.5 * self.sequences - set of sequence objects that contain monomers 1.6 and/or gaps, that constitute the block 1.7 - * self.positions -- list of positions of the project.alignment that 1.8 + * self.positions -- list of positions of the project.body that 1.9 are included in the block; position[i+1] is always to the right from position[i] 1.10 1.11 Don't change self.sequences -- it may be a link to other block.sequences 1.12 @@ -52,7 +52,7 @@ 1.13 are made. 1.14 """ 1.15 for sequence in self.sequences: 1.16 - alignment_monomers = self.project.alignment[sequence] 1.17 + alignment_monomers = self.project.body[sequence] 1.18 block_monomers = [alignment_monomers[i] for i in self.positions] 1.19 string = ''.join([m.type.code1 if m else '-' for m in block_monomers]) 1.20 save_fasta(out_file, string, sequence.name, sequence.description, long_line) 1.21 @@ -84,8 +84,8 @@ 1.22 distances = [] 1.23 for sequence in self.sequences: 1.24 for chain in sequence.pdb_chains: 1.25 - m1 = self.project.alignment[sequence][i] 1.26 - m2 = self.project.alignment[sequence][j] 1.27 + m1 = self.project.body[sequence][i] 1.28 + m2 = self.project.body[sequence][j] 1.29 if m1 and m2: 1.30 r1 = sequence.pdb_residues[chain][m1] 1.31 r2 = sequence.pdb_residues[chain][m2] 1.32 @@ -126,7 +126,7 @@ 1.33 1.34 def monomers(self, sequence): 1.35 """ Iterates monomers of this sequence from this block """ 1.36 - alignment_sequence = self.project.alignment[sequence] 1.37 + alignment_sequence = self.project.body[sequence] 1.38 return (alignment_sequence[i] for i in self.positions) 1.39 1.40 def ca_atoms(self, sequence, pdb_chain):
2.1 --- a/lib/project.py Tue Nov 02 20:44:18 2010 +0300 2.2 +++ b/lib/project.py Wed Nov 03 19:01:50 2010 +0300 2.3 @@ -16,7 +16,7 @@ 2.4 from fasta import save_fasta 2.5 2.6 class Project(object): 2.7 - """ Alignment representing class 2.8 + """ Alignment 2.9 2.10 Mandatory data: 2.11 * sequences -- list of Sequence objects. Sequences don't contain gaps 2.12 @@ -41,27 +41,27 @@ 2.13 """ 2.14 if len(args)>1:#overloaded constructor 2.15 self.sequences=args[0] 2.16 - self.alignment=args[1] 2.17 + self.body=args[1] 2.18 elif len(args)==0: 2.19 self.sequences=[] 2.20 - self.alignment={} 2.21 + self.body={} 2.22 else: 2.23 - self.sequences,self.alignment=Project.from_fasta(args[0]) 2.24 + self.sequences, self.body = Project.from_fasta(args[0]) 2.25 2.26 def __len__(self): 2.27 """ Returns width, ie length of each sequence with gaps """ 2.28 - return max([len(line) for line in self.alignment.values()]) 2.29 + return max([len(line) for line in self.body.values()]) 2.30 2.31 def thickness(self): 2.32 """ The number of sequences in alignment (it's thickness). """ 2.33 - return len(self.alignment) 2.34 + return len(self.body) 2.35 2.36 def calc_identity(self): 2.37 """ Calculate the identity of alignment positions for colouring. 2.38 2.39 For every (row, column) in alignment the percentage of the exactly 2.40 same residue in the same column in the alignment is calculated. 2.41 - The data structure is just like the Project.alignment, but istead of 2.42 + The data structure is just like the Project.body, but istead of 2.43 monomers it contains float percentages. 2.44 """ 2.45 # Oh, God, that's awful! Absolutely not understandable. 2.46 @@ -70,9 +70,9 @@ 2.47 all_columns = [] 2.48 for position in range(len(self)): 2.49 column_percentage = {} 2.50 - for seq in self.alignment: 2.51 - if self.alignment[seq][position] is not None: 2.52 - aa = self.alignment[seq][position].code 2.53 + for seq in self.body: 2.54 + if self.body[seq][position] is not None: 2.55 + aa = self.body[seq][position].code 2.56 else: 2.57 aa = None 2.58 if aa in allpy_data.amino_acids: 2.59 @@ -88,8 +88,8 @@ 2.60 for seq in self.identity_percentages: 2.61 line = self.identity_percentages[seq] 2.62 for position in range(len(self)): 2.63 - if self.alignment[seq][position] is not None: 2.64 - aa = self.alignment[seq][position].code 2.65 + if self.body[seq][position] is not None: 2.66 + aa = self.body[seq][position].code 2.67 else: 2.68 aa = None 2.69 line.append(all_columns[position].get(aa)) 2.70 @@ -161,7 +161,7 @@ 2.71 max_length = max(len(sequence) for sequence in sequences) 2.72 for sequence in sequences: 2.73 gaps_count = max_length - len(sequence) 2.74 - project.alignment[sequence] = sequence.monomers + [None] * gaps_count 2.75 + project.body[sequence] = sequence.monomers + [None] * gaps_count 2.76 return project 2.77 2.78 def save_fasta(self, out_file, long_line=70, gap='-'): 2.79 @@ -189,15 +189,15 @@ 2.80 raise Exception("Align: Cann't find sequence %s in muscle output" % \ 2.81 sequence.name) 2.82 old_monomers = iter(sequence.monomers) 2.83 - self.alignment[sequence] = [] 2.84 + self.body[sequence] = [] 2.85 for monomer in alignment[new_sequence]: 2.86 if not monomer: 2.87 - self.alignment[sequence].append(monomer) 2.88 + self.body[sequence].append(monomer) 2.89 else: 2.90 old_monomer = old_monomers.next() 2.91 if monomer != old_monomer: 2.92 raise Exception("Align: alignment errors") 2.93 - self.alignment[sequence].append(old_monomer) 2.94 + self.body[sequence].append(old_monomer) 2.95 os.unlink(tmp_file.name) 2.96 2.97 2.98 @@ -214,7 +214,7 @@ 2.99 if sequence and sequences: 2.100 raise Exception("Wrong usage. read help") 2.101 indexes = dict([(v, k) for( k, v) in enumerate(self.sequences)]) 2.102 - alignment = self.alignment.items() 2.103 + alignment = self.body.items() 2.104 alignment.sort(key=lambda i: indexes[i[0]]) 2.105 alignment = [monomers for seq, monomers in alignment] 2.106 for column in zip(*alignment): 2.107 @@ -230,7 +230,7 @@ 2.108 """ Returns string representing secondary structure """ 2.109 return ''.join([ 2.110 (sequence.pdb_secstr[pdb_chain][m] if sequence.secstr_has(pdb_chain, m) else gap) 2.111 - for m in self.alignment[sequence]]) 2.112 + for m in self.body[sequence]]) 2.113 2.114 def save_secstr(self, out_file, sequence, pdb_chain, 2.115 name, description='', gap='-', long_line=70):