annotate corebio/seq_io/clustal_io.py @ 4:4d47ab2b7bcc

Uploaded
author davidmurphy
date Fri, 13 Jan 2012 07:18:19 -0500
parents c55bdc2fb9fa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
1
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
2 # Copyright (c) 2005 Gavin E. Crooks <gec@threeplusone.com>
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
3 #
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
4 # This software is distributed under the MIT Open Source License.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
5 # <http://www.opensource.org/licenses/mit-license.html>
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
6 #
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
7 # Permission is hereby granted, free of charge, to any person obtaining a
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
8 # copy of this software and associated documentation files (the "Software"),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
9 # to deal in the Software without restriction, including without limitation
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
10 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
11 # and/or sell copies of the Software, and to permit persons to whom the
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
12 # Software is furnished to do so, subject to the following conditions:
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
13 #
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
14 # The above copyright notice and this permission notice shall be included
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
15 # in all copies or substantial portions of the Software.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
16 #
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
23 # THE SOFTWARE.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
24 #
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
25
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
26 """ Read and write the CLUSTAL sequence file format.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
27
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
28 See :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
29 - http://www.cmpharm.ucsf.edu/~goh/Treecorr/sampleAlignment.html
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
30 - http://www.bioperl.org/wiki/ClustalW_multiple_alignment_format
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
31
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
32 Ref :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
33 - Higgins D., Thompson J., Gibson T., Thompson J.D., Higgins D.G., Gibson
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
34 T.J. (1994). CLUSTAL W: improving the sensitivity of progressive multiple
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
35 sequence alignment through sequence weighting, position-specific gap
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
36 penalties and weight matrix choice. Nucleic Acids Res. 22:4673-4680.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
37 """
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
38
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
39 # TODO: What happens if CLUSTAL is not the first line of the file?
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
40
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
41
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
42 import re
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
43
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
44 from corebio.utils import *
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
45 from corebio.seq import *
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
46 from corebio.seq_io import *
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
47
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
48 __all__ = ('example', 'names', 'extensions', 'read')
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
49
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
50 example = """
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
51 CLUSTAL W (1.81) multiple sequence alignment
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
52
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
53
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
54 CXCR3_MOUSE --------------------------LENSTSPYDYGENESD-------FSDSPPCPQDF
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
55 BLR_HUMAN --------------------------LENLEDLF-WELDRLD------NYNDTSLVENH-
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
56 CXCR1_HUMAN --------------------------MSNITDPQMWDFDDLN-------FTGMPPADEDY
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
57 CXCR4_MURINE -----------------------------------YTSDN---------YSGSGDYDSNK
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
58 : : :.. ..
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
59
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
60 CXCR3_MOUSE -SL-------NFDRTFLPALYSLLFLLGLLGNGAVAAVLLSQRTALSSTDTFLLHLAVAD
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
61 BLR_HUMAN --LC-PATMASFKAVFVPVAYSLIFLLGVIGNVLVLVILERHRQTRSSTETFLFHLAVAD
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
62 CXCR1_HUMAN -SPC-MLETETLNKYVVIIAYALVFLLSLLGNSLVMLVILYSRVGRSVTDVYLLNLALAD
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
63 CXCR4_MURINE -EPC-RDENVHFNRIFLPTIYFIIFLTGIVGNGLVILVMGYQKKLRSMTDKYRLHLSVAD
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
64 :. .: * ::** .::** * :: : * *: : ::*::**
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
65
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
66 CXCR3_MOUSE VLLVLTLPLWAVDAA-VQWVFGPGLCKVAGALFNINFYAGAFLLACISFDRYLSIVHATQ
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
67 BLR_HUMAN LLLVFILPFAVAEGS-VGWVLGTFLCKTVIALHKVNFYCSSLLLACIAVDRYLAIVHAVH
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
68 CXCR1_HUMAN LLFALTLPIWAASKV-NGWIFGTFLCKVVSLLKEVNFYSGILLLACISVDRYLAIVHATR
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
69 CXCR4_MURINE LLFVITLPFWAVDAM-ADWYFGKFLCKAVHIIYTVNLYSSVLILAFISLDRYLAIVHATN
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
70 :*:.: **: ... * :* ***.. : :*:*.. ::** *:.****:****..
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
71 """
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
72
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
73
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
74
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
75 names = ("clustal", "clustalw",)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
76 extensions = ('aln',)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
77
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
78
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
79 header_line = re.compile(r'(CLUSTAL.*)$')
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
80
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
81 # (sequence_id) (Sequence) (Optional sequence number)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
82 seq_line = re.compile(r'(\s*\S+\s+)(\S+)\s*(\d*)$')
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
83
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
84 # Saved group includes variable length leading space.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
85 # Must consult a seq_line to figure out how long the leading spoace is since
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
86 # the maximum CLUSTAL ids length (normally 10 characters) can be changed.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
87 match_line = re.compile(r'([\s:\.\*]*)$')
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
88
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
89
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
90 def iterseq(fin, alphabet=None):
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
91 """Iterate over the sequences in the file."""
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
92 # Default implementation
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
93 return iter(read(fin, alphabet) )
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
94
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
95
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
96 def read(fin, alphabet=None) :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
97 alphabet = Alphabet(alphabet)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
98 seq_ids = []
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
99 seqs = []
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
100 block_count = 0
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
101
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
102
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
103 for token in _scan(fin):
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
104 if token.typeof== "begin_block":
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
105 block_count = 0
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
106 elif token.typeof == "seq_id":
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
107 if len(seqs) <= block_count :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
108 seq_ids.append(token.data)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
109 seqs.append([])
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
110 elif token.typeof == "seq":
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
111 if not alphabet.alphabetic(token.data) :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
112 raise ValueError(
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
113 "Character on line: %d not in alphabet: %s : %s" % (
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
114 token.lineno, alphabet, token.data) )
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
115 seqs[block_count].append(token.data)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
116 block_count +=1
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
117
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
118
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
119 seqs = [ Seq("".join(s), alphabet, name= i) for s,i in zip(seqs,seq_ids)]
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
120 return SeqList(seqs)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
121
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
122
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
123 # 1) The word "CLUSTAL" should be the first word on the first line of the file.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
124 # (But sometimes isn't.)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
125 # 2) The alignment is displayed in blocks of fixed length.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
126 # 3) Each line in the block corresponds to one sequence.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
127 # 4) Each sequence line starts with a sequence name followed by at least one
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
128 # space and then the sequence.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
129
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
130 def _scan( fin ):
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
131 """Scan a clustal format MSA file and yeild tokens.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
132 The basic file structure is
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
133 begin_document
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
134 header?
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
135 (begin_block
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
136 (seq_id seq seq_index?)+
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
137 match_line?
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
138 end_block)*
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
139 end_document
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
140
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
141 Usage:
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
142 for token in scan(clustal_file):
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
143 do_somthing(token)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
144 """
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
145 header, body, block = range(3)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
146
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
147 yield Token("begin")
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
148 leader_width = -1
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
149 state = header
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
150 for L, line in enumerate(fin):
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
151 if state==header :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
152 if line.isspace() : continue
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
153 m = header_line.match(line)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
154 state = body
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
155 if m is not None :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
156 yield Token("header", m.group() )
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
157 continue
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
158 else :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
159 raise ValueError("Cannot find required header")
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
160
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
161
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
162 if state == body :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
163 if line.isspace() : continue
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
164 yield Token("begin_block")
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
165 state = block
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
166 # fall through to block
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
167
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
168 if state == block:
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
169 if line.isspace() :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
170 yield Token("end_block")
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
171 state = body
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
172 continue
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
173
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
174 m = match_line.match(line)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
175 if m is not None :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
176 yield Token("match_line", line[leader_width:-1])
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
177 continue
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
178
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
179 m = seq_line.match(line)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
180 if m is None:
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
181 raise ValueError("Parse error on line: %d" % L)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
182 leader_width = len(m.group(1))
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
183 yield Token("seq_id", m.group(1).strip() )
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
184 yield Token("seq", m.group(2).strip() )
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
185 if m.group(3) :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
186 yield Token("seq_num", m.group(3))
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
187 continue
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
188
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
189 # END state blocks. If I ever get here something has gone terrible wrong
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
190 raise RuntimeError()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
191
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
192 if state==block:
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
193 yield Token("end_block")
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
194 yield Token("end")
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
195 return
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
196
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
197 def write(fout, seqs) :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
198 """Write 'seqs' to 'fout' as text in clustal format"""
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
199 header = "CLUSTAL W (1.81) multiple sequence alignment"
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
200 name_width = 17
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
201 seq_width = 60
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
202
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
203 print >>fout, header
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
204 print >>fout
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
205 print >>fout
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
206
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
207 L = 0
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
208 for s in seqs: L = max(L, len(s))
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
209
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
210 for block in range(0, L, seq_width):
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
211 for s in seqs :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
212 start = min(block, len(s))
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
213 end = min( start+seq_width, len(s))
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
214 print >>fout, s.name.ljust(name_width),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
215 print >>fout, s[start:end]
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
216 print >>fout
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
217
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
218
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
219
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
220
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
221
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
222