Back to index

python-biopython  1.60
Public Member Functions
Bio.AlignIO.ClustalIO.ClustalWriter Class Reference
Inheritance diagram for Bio.AlignIO.ClustalIO.ClustalWriter:
Inheritance graph
[legend]
Collaboration diagram for Bio.AlignIO.ClustalIO.ClustalWriter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def write_alignment

Detailed Description

Clustalw alignment writer.

Definition at line 18 of file ClustalIO.py.


Member Function Documentation

def Bio.AlignIO.ClustalIO.ClustalWriter.write_alignment (   self,
  alignment 
)
Use this to write (another) single alignment to an open file.

Definition at line 20 of file ClustalIO.py.

00020 
00021     def write_alignment(self, alignment):
00022         """Use this to write (another) single alignment to an open file."""
00023 
00024         if len(alignment) == 0:
00025             raise ValueError("Must have at least one sequence")
00026         if alignment.get_alignment_length() == 0:
00027             #This doubles as a check for an alignment object    
00028             raise ValueError("Non-empty sequences are required")
00029 
00030         #Old versions of the parser in Bio.Clustalw used a ._version property,
00031         try:
00032             version = str(alignment._version)
00033         except AttributeError:
00034             version = ""
00035         if not version:
00036             version = '1.81'
00037         if version.startswith("2."):
00038             #e.g. 2.0.x
00039             output = "CLUSTAL %s multiple sequence alignment\n\n\n" % version
00040         else:
00041             #e.g. 1.81 or 1.83
00042             output = "CLUSTAL X (%s) multiple sequence alignment\n\n\n" % version
00043         
00044         cur_char = 0
00045         max_length = len(alignment[0])
00046 
00047         if max_length <= 0:
00048             raise ValueError("Non-empty sequences are required")
00049 
00050         # keep displaying sequences until we reach the end
00051         while cur_char != max_length:
00052             # calculate the number of sequences to show, which will
00053             # be less if we are at the end of the sequence
00054             if (cur_char + 50) > max_length:
00055                 show_num = max_length - cur_char
00056             else:
00057                 show_num = 50
00058 
00059             # go through all of the records and print out the sequences
00060             # when we output, we do a nice 80 column output, although this
00061             # may result in truncation of the ids.
00062             for record in alignment:
00063                 #Make sure we don't get any spaces in the record
00064                 #identifier when output in the file by replacing
00065                 #them with underscores:
00066                 line = record.id[0:30].replace(" ","_").ljust(36)
00067                 line += record.seq[cur_char:(cur_char + show_num)].tostring()
00068                 output += line + "\n"
00069 
00070             # now we need to print out the star info, if we've got it
00071             # This was stored by Bio.Clustalw using a ._star_info property.
00072             if hasattr(alignment, "_star_info") and alignment._star_info != '':
00073                 output += (" " * 36) + \
00074                      alignment._star_info[cur_char:(cur_char + show_num)] + "\n"
00075 
00076             output += "\n"
00077             cur_char += show_num
00078 
00079         # Want a trailing blank new line in case the output is concatenated
00080         self.handle.write(output + "\n")

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: