-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path20080119b.py
43 lines (38 loc) · 1.45 KB
/
20080119b.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Given a fasta alignment, check it for syntax errors and briefly summarize it.
"""
from StringIO import StringIO
from SnippetUtil import HandlingError
import Fasta
import Form
import FormOut
def get_form():
"""
@return: the body of a form
"""
alignment_string = Fasta.brown_example_alignment.strip()
return [Form.MultiLine('fasta', 'fasta alignment', alignment_string)]
def get_form_out():
return FormOut.Report()
def get_response_content(fs):
out = StringIO()
try:
alignment = Fasta.Alignment(fs.fasta.splitlines())
print >> out, 'This is a valid alignment.'
except Fasta.AlignmentError as e:
alignment = None
print >> out, 'This is not a valid alignment:', e
if alignment:
try:
old_column_count = len(alignment.columns)
alignment.force_nucleotide()
removed_column_count = old_column_count - len(alignment.columns)
if removed_column_count:
print >> out, ('After removing %d' % removed_column_count),
print >> out, 'columns this is a valid nucleotide alignment.'
else:
print >> out, 'This is a valid nucleotide alignment.'
except Fasta.AlignmentError as e:
print >> out, 'This is not a valid nucleotide alignment:', e
for header, seq in Fasta.gen_header_sequence_pairs(StringIO(fs.fasta)):
print >> out, '%s: %d' % (header, len(seq))
return out.getvalue()