-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCheckPeter.py
More file actions
171 lines (144 loc) · 4.9 KB
/
CheckPeter.py
File metadata and controls
171 lines (144 loc) · 4.9 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import os
import fnmatch
from fractions import Fraction
import matplotlib.pyplot as plt
PathCue = "C:/Users/admin_local/Dropbox/2017Pattern/cues/Daar_ging_een_heer_1.txt"
CueFile = open(PathCue,'r')
Cues = []
for i, CRaw in enumerate(CueFile):
CueI=CRaw.split('\t')[0]
Filename = CRaw.split('\t')[1]
try:
CueT=float(CueI)
except:
CueT=float(Fraction(CueI))
Cues.append(CueT)
PathAnno = "C:/Users/admin_local/Desktop/filesboot/nlb/AnnotatedMotifs/discovery"
# Plot ground truth in sparate files
# Plot ground truth in concatenate version
# Plot discovered patterns in sparate files
singleFpath = "C:/Users/admin_local/Desktop/filesboot/nlb/AnnotatedMotifs/discovery/Daar_ging_een_heer_1+NLB072587_01.txt"
path = "C:/Users/admin_local/Desktop/filesboot/nlb/AnnotatedMotifs/discovery/"
path2 = "C:/Users/admin_local/Desktop/filesboot/nlb/InterOpusDiscoveryClassTask/SIATECAlgorithm/false_true_0_3_0.7_5/discovery/"
oneFamilyPath = []
twoFamilyPath = []
for root, dirs, files in os.walk(path):
for fileiter in files:
if fnmatch.fnmatch(fileiter, "Daar_ging_een_heer_1*"):
address= os.path.join(root, fileiter)
oneFamilyPath.append(address)
for root, dirs, files in os.walk(path2):
for fileiter in files:
if fnmatch.fnmatch(fileiter, "Daar_ging_een_heer_1*"):
address= os.path.join(root, fileiter)
twoFamilyPath.append(address)
familyData=[]
# Plot discovered patterns in concatenate version
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
familyData2 = []
for path in oneFamilyPath:
startendpat = outputtimes(open(path,'r').readlines())
familyData.append(startendpat)
for path in twoFamilyPath:
startendpat = outputtimes(open(path,'r').readlines())
familyData2.append(startendpat)
plt.figure()
height=5
starttime=0
index = 0
for Data in familyData:
for patterns in Data:
# c=numpy.random.rand(3,1)
height = height + 10
for occur in patterns:
# print(occur)
plt.plot((occur[0]+starttime, occur[1]+starttime), (height, height), color = 'red', lw=2, alpha=0.5)
cuetime = Cues[index]
starttime = cuetime
index += 1
index = 0
for Data in familyData2:
for patterns in Data:
# c=numpy.random.rand(3,1)
height = height + 10
for occur in patterns:
# print(occur)
plt.plot((occur[0]+starttime, occur[1]+starttime), (height, height), color = 'black', lw=2, alpha=0.5)
cuetime = Cues[index]
starttime = cuetime
index += 1
plt.plot((0,0), (0,0), color='white', label="GT")
for cue in Cues:
plt.axvline(cue, lw = 1)
plt.ylabel('Pattern Number & Ground Truth Patterns')
plt.xlabel('Time')
# plt.title('The polling curve')
plt.tight_layout()
plt.show()