-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathConvert_fastPHASE_to_PHASE.py
executable file
·44 lines (39 loc) · 1.5 KB
/
Convert_fastPHASE_to_PHASE.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
#!/usr/bin/env python
"""Convert from the fastPHASE input to PHASE. It assumes that all loci are
SNPs (S). This is designed to work with PLINK 1.9 --recode fastphase files.
Prints the PHASE input file to stdout. Takes 1 argument:
1) fastphase.inp file
"""
import sys
def main(fp):
"""Main function."""
with open(fp, 'r') as f:
for index, line in enumerate(f):
if index == 0:
# First line is the number of individuals - print it out
print line.strip()
elif index == 1:
# Second line is the number of loci. Also print it out.
nloci = int(line.strip())
print line.strip()
elif index == 2:
# Third line is the positions - print it out
print line.strip()
# Also print out the locus type!
print nloci * 'S'
else:
# For the rest of the lines, print them out unmodified, except
# replace the # ID ... with just #...
if line.startswith('#'):
print line.strip().replace(' ID ', '')
else:
print line.strip()
return
if len(sys.argv) != 2:
print """Convert from the fastPHASE input to PHASE. It assumes that all loci are
SNPs (S). This is designed to work with PLINK 1.9 --recode fastphase files.
Prints the PHASE input file to stdout. Takes 1 argument:
1) fastphase.inp file"""
exit(1)
else:
main(sys.argv[1])