forked from garudlab/Harris_etal_response
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convertFile.py
81 lines (48 loc) · 1.56 KB
/
convertFile.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
76
77
78
79
80
81
#! /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
####################################################################################
# path psyco
####################################################################################
#sys.path.append("/home/jsp/prog/utillities/py_modules")
# to speed things up
#import psyco
#psyco.full()
#import bed
######################
def clusterHaplotypes(inFile, outFile):
for line in inFile:
line=line.strip('\n')
s=''
for i in range(1, len(line.split('\t'))):
s+= line.split('\t')[i]+ ','
outFile.write(s+ '\n')
###############
def mkOptionParser():
""" Defines options and returns parser """
usage = """%prog <input.bed> <output.bed> <threshold>
%prog filters out the lines that don't meet a certain threshold. """
parser = OptionParser(usage)
return parser
def main():
""" see usage in mkOptionParser. """
parser = mkOptionParser()
options, args= parser.parse_args()
if len(args) != 2:
parser.error("Incorrect number of arguments")
inFN = args[0]
outFN = args[1]
if inFN == '-':
inFile = sys.stdin
else:
inFile = open(inFN, 'r')
if outFN == '-':
outFile = sys.stdout
else:
outFile = open(outFN, 'w')
clusterHaplotypes(inFile, outFile)
#run main
if __name__ == '__main__':
main()