-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpat2dat.py
More file actions
119 lines (101 loc) · 3.25 KB
/
pat2dat.py
File metadata and controls
119 lines (101 loc) · 3.25 KB
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
111
112
113
114
115
116
117
118
119
from __future__ import division
import os
import fnmatch
def outputtimes(text):
pitches=[]
pairs=[]
occurtimes=[]
pattimes=[]
times=[]
total=[]
for line in text:
if "," in line:
pairs.append([float(i) for i in line.split(',')])
total.append([float(i) for i in line.split(',')])
if "o" in line:
total.append('o')
if pairs != []:
times=zip(*pairs)[0]
occurtimes.append(times)
pairs=[]
if "p" in line:
total.append('p')
pattimes.append(occurtimes)
# print(len(occurtimes))
occurtimes=[]
# print(total)
olist=[]
plist=[]
for index in range(0,len(total)):
item = total[index]
if item == 'p':
plist.append(index)
if item =='o':
olist.append(index)
occurtimes=[]
pattimes=[]
record=0
for pindex in range(1,len(plist)):
for oindex in range(0,len(olist)-1):
if plist[pindex]-olist[oindex+1]>1 and oindex>=record:
occurtimes.append(zip(*total[olist[oindex]+1:olist[oindex+1]])[0])
if plist[pindex]-olist[oindex+1]==-1:
occurtimes.append(zip(*total[olist[oindex]+1:olist[oindex+1]-1])[0])
record=oindex+1
# print(record)
sub=[]
pattimes.append(occurtimes)
occurtimes=[]
# print(olist)
# print(plist)
pindex=plist[-1]
occurtimes=[]
for oindex in range(0,len(olist)-1):
if olist[oindex]>pindex:
occurtimes.append(zip(*total[olist[oindex]+1:olist[-1]])[0])
oindex=olist[-1]
occurtimes.append(zip(*total[oindex+1:])[0])
pattimes.append(occurtimes)
# print(pattimes[1])
# taking the onset and offset
startend=[]
startendpat=[]
for occtime in pattimes:
for time in occtime:
start=time[0]
end=time[-1]
startend.append([start,end])
startendpat.append(startend)
startend=[]
# print(startendpat[-1])
return startendpat
f={}
m=0
c=0
prefamily=0
memory=[]
familyindex=[]
for files in os.listdir("C:/Users/admin_local/Desktop/filesboot/NLB/AnnotatedMotifs/discovery/"):
address=os.path.join("C:/Users/admin_local/Desktop/filesboot/NLB/AnnotatedMotifs/discovery", files)
if fnmatch.fnmatch(files, "*.txt"):
f[m] = open(address, 'r')
m += 1
for s in files:
if s == '+':
break
memory.append(s)
family=''.join(memory)
if m != 0:
if family != prefamily:
c += 1
prefamily=family
memory=[]
familyindex.append(c)
print(familyindex)
d={}
startendpat={}
for i in range(0,m-1):
d[i]=f[i].readlines()
if d[i] != []:
startendpat[i]=outputtimes(d[i])
print(startendpat)