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

Source Code for Module Bio.Align.FormatConvert

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