forked from argriffing/xgcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
20100916a.py
35 lines (29 loc) · 932 Bytes
/
20100916a.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
"""Convert a .hud file to an R table.
"""
from SnippetUtil import HandlingError
import Form
import FormOut
import hud
import Phylip
g_tags = ['pca:convert']
g_lines = [
'IC31 2 0 0 2 0 0 2 0 0 0 1 1 0 2 0 0 2 0',
'IC32 0 2 0 0 2 0 0 2 0 0 1 1 0 2 0 0 2 0',
'IC33 0 0 2 0 0 2 0 0 1 1 0 0 2 0 1 1 0 2']
def get_form():
"""
@return: the body of a form
"""
form_objects = [
Form.MultiLine('table', 'table', '\n'.join(g_lines))]
return form_objects
def get_form_out():
return FormOut.RTable('out')
def get_response_content(fs):
headers, data_rows = hud.decode(fs.table.splitlines())
rtable_header_line = '\t'.join(headers)
rows = []
for i, row in enumerate(zip(*data_rows)):
rows.append([i] + list(row))
rtable_data_lines = ['\t'.join(str(x) for x in row) for row in rows]
return '\n'.join([rtable_header_line] + rtable_data_lines) + '\n'