-
Notifications
You must be signed in to change notification settings - Fork 1
/
cleanOutput.py
75 lines (50 loc) · 1.49 KB
/
cleanOutput.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
64
65
66
67
68
69
70
71
72
73
74
75
#! /bin/env python
# bedTileElements - tile each record in input.bed with potentially shorter elements which are written to output.bed
import sys
from optparse import OptionParser
import copy
import csv
#import numpy
import linecache
import random
######################
def isFloat(value):
try:
float(value)
return True
except:
return False
def count_fields(inFile, outFile, num_fields):
for line in inFile:
line_list = line.strip().split()
if isFloat(line_list[0]) and isFloat(line_list[1]):
if float(line_list[0]) <=1 and float(line_list[0]) >=0:
outFile.write(line)
###############
def mkOptionParser():
""" Defines options and returns parser """
usage = """%prog <input file> <output file>
%prog converts MS output to genotypes (0/1 to A/G). """
parser = OptionParser(usage)
return parser
def main():
""" see usage in mkOptionParser. """
parser = mkOptionParser()
options, args= parser.parse_args()
if len(args) != 3:
parser.error("Incorrect number of arguments")
inFN = args[0]
outFN = args[1]
num_fields = int(args[2])
if inFN == '-':
inFile = sys.stdin
else:
inFile = open(inFN, 'r')
if outFN == '-':
outFile = sys.stdout
else:
outFile = open(outFN, 'w')
count_fields(inFile, outFile, num_fields)
#run main
if __name__ == '__main__':
main()