-
Notifications
You must be signed in to change notification settings - Fork 1
/
20100525a.py
63 lines (52 loc) · 1.37 KB
/
20100525a.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
55
56
57
58
59
60
61
62
63
"""
Convert a .hud file to a .snp file.
The input file gives a binary character vector for each OTU.
The output file is in Eigenstrat format.
Note that only the first line of the input file is used.
"""
from StringIO import StringIO
import sys
import argparse
from SnippetUtil import HandlingError
import Form
import FormOut
import Util
import hud
g_tags = ['pca:convert']
g_default_string = """
foo 1 1 1
bar 1 1 1
baz 1 0 1
""".strip()
def process(lines):
"""
@param lines: lines of a .hud file
"""
names, data = hud.decode(lines)
out = StringIO()
for i, genotype in enumerate(data[0]):
name = 'SNP_%d' % i
chromosome = '1'
morgans = '0.0'
bases = i+1
row = [name, chromosome, morgans, bases]
print >> out, '\t'.join(str(x) for x in row)
return out.getvalue().rstrip()
def get_form():
"""
@return: the body of a form
"""
form_objects = [
Form.MultiLine('data',
'a list of OTUs names and binary character vectors',
g_default_string)]
return form_objects
def get_form_out():
return FormOut.EigenstratSnp('out')
def get_response_content(fs):
return process(fs.data.splitlines()) + '\n'
def main(args):
print process(sys.stdin)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
main(parser.parse_args())