forked from argriffing/xgcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
20100603c.py
54 lines (43 loc) · 1.18 KB
/
20100603c.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
44
45
46
47
48
49
50
51
52
53
54
"""
Convert a .hud genotype file to a .geno genotype file.
The output file is in eigenstrat format;
it has one line per SNP
and each line has one character per individual.
"""
import sys
import os
import argparse
from SnippetUtil import HandlingError
import Form
import FormOut
import hud
g_tags = ['pca:convert']
g_hud_string = """
IC1 1 1 1 0
IC2 1 1 1 0
IC3 1 0 1 0
""".strip()
def get_form():
"""
@return: the body of a form
"""
form_objects = [
Form.MultiLine('hud',
'a list of OTUs names and binary character vectors',
g_hud_string)]
return form_objects
def get_form_out():
return FormOut.EigenstratGeno('out')
def get_response_content(fs):
return process(fs.hud.splitlines()) + '\n'
def process(raw_hud_lines):
names, data = hud.decode(raw_hud_lines)
columns = zip(*data)
return '\n'.join(''.join(str(x) for x in c) for c in columns)
def main(args):
with open(os.path.expanduser(args.hud)) as fin_hud:
print process(fin_hud)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--hud', help='.hud file')
main(parser.parse_args())