forked from fak/mapChEMBLPfam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.py
executable file
·112 lines (89 loc) · 2.38 KB
/
parse.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""
Function: parse
--------------------
assembly of functions to parse text files
"""
def col2fltlist(path, col, header):
i = 0
if header == True:
i =1
infile = open(path, 'r')
lines = infile.readlines()
ll = []
for line in lines[i:]:
elements = line.split('\t')
element = elements[col].rstrip('\n')
ll.append(float(element))
return ll
def col2intlist(path, col, header):
i = 0
if header == True:
i =1
infile = open(path, 'r')
lines = infile.readlines()
ll = []
for line in lines[i:]:
elements = line.split('\t')
element = elements[col].rstrip('\n')
ll.append(int(element))
return ll
def col2intlist(path, col, header):
i = 0
if header == True:
i =1
infile = open(path, 'r')
lines = infile.readlines()
ll = []
for line in lines[i:]:
elements = line.split('\t')
element = elements[col].rstrip('\n')
ll.append(int(element))
return ll
def col2keys(path,col, header):
i = 0
if header == True:
i =1
infile = open(path, 'r')
lines = infile.readlines()
keyDict = {}
for line in lines[i:]:
x = line.split('\t')
x = x[col].rstrip('\n')
keyDict[x] = 0
return keyDict
def col2list(path, col, header):
i = 0
if header == True:
i =1
infile = open(path, 'r')
lines = infile.readlines()
ll = []
for line in lines[i:]:
elements = line.split('\t')
element = elements[col].rstrip('\n')
ll.append(element)
return ll
def rdstatLogs(path):
infile = open(path, 'r')
lines = infile.readlines()
elements = lines[0].split('\t')
al = float(elements[2])
minx = int(elements[4])
return(al, minx)
def parse2col(path, header, keyIndex, valIndex):
dctn = {}
i = 0
if header == True:
i =1
infile = open(path, 'r')
lines = infile.readlines()
for line in lines[i:]:
elements = line.split('\t')
key = elements[keyIndex].rstrip('\n')
try:
value = int(elements[valIndex])
except ValueError:
value = elements[valIndex].rstrip('\n')
dctn[key] = value
return dctn