Package Bio :: Package Align :: Module FormatConvert
[hide private]
[frames] | no frames]

Source Code for Module Bio.Align.FormatConvert

 1  """ 
 2  Utility for conversion between different formats for representing alignments. 
 3   
 4  classes: 
 5  FormatConverter 
 6  """ 
 7   
 8  # biopython 
 9  from Bio.Fasta.FastaAlign import FastaAlignment 
10  from Bio.Clustalw import ClustalAlignment 
11   
12   
13 -class FormatConverter:
14 """Convert between different alignment representation formats. 15 16 The basic idea behind the converter is that it takes a given format, 17 converts it into the base Alignment class, and then can return an object 18 in any other supported format with the info from the basal alignment. 19 20 Supported formats are: 21 o Clustal format (*.aln) 22 o Fasta format (*.fasta) 23 """
24 - def __init__(self, to_convert):
25 """Initialize a converter with a given object. 26 27 Arguments: 28 o to_convert - The class which we are going to be converting. 29 """ 30 self.orig_format = to_convert 31 32 self._base_alphabet, self._base_records = self._get_base_info()
33
34 - def _get_base_info(self):
35 """Retrieve all of the basal (ie Generic.Alignment) info. 36 37 The idea is that this info is present in all of the classes and 38 this is the information that will be retained in a conversion. 39 Format specific information will be lost. 40 """ 41 return self.orig_format._alphabet, self.orig_format._records
42
43 - def to_fasta(self):
44 """Convert the current info into a FastaAlignment object. 45 """ 46 return_format = FastaAlignment(self._base_alphabet) 47 return_format._records = self._base_records 48 49 return return_format
50
51 - def to_clustal(self):
52 """Convert the current info into a ClustalAlignment object. 53 """ 54 return_format = ClustalAlignment(self._base_alphabet) 55 return_format._records = self._base_records 56 57 return return_format
58