Package mmLib :: Module Sequence
[hide private]
[frames] | no frames]

Source Code for Module mmLib.Sequence

 1  ## Copyright 2002-2010 by PyMMLib Development Group (see AUTHORS file) 
 2  ## This code is part of the PyMMLib distribution and governed by 
 3  ## its license.  Please see the LICENSE file that should have been 
 4  ## included as part of this package. 
 5   
 6  import Library 
 7   
8 -class Sequence(object):
9 """Sequence information for a biopolymer chain. 10 """
11 - def __init__(self):
12 self.sequence_list = list()
13
14 - def __len__(self):
15 return len(self.sequence_list)
16
17 - def __getitem__(self, index):
18 return self.sequence_list[index]
19
20 - def set_from_three_letter(self, sequence_list):
21 self.sequence_list = list(sequence_list)
22
23 - def set_from_fragments(self, fragments):
24 self.sequence_list = [frag.res_name for frag in fragments]
25
26 - def __iter__(self):
27 return iter(self.sequence_list)
28
29 - def iter_three_letter(self):
30 return iter(self)
31
32 - def one_letter_code(self):
33 """Return the one letter code representation of the sequence as a string. 34 """ 35 seqlist = list() 36 for threeletter in self.sequence_list: 37 mdesc = Library.library_get_monomer_desc(threeletter) 38 if mdesc is not None and mdesc.one_letter_code: 39 seqlist.append(mdesc.one_letter_code) 40 else: 41 seqlist.append("X") 42 return "".join(seqlist)
43