forked from SeedlingsBabylab/clancomments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpinfo_table.py
166 lines (134 loc) · 3.88 KB
/
pinfo_table.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
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
import csv
import sys
import os
import collections
filtered_csv = ""
filter_set_file = ""
all_files = []
file_set = None
counter = None
# bunch of misspelled versions of "personal"
personal_string = ["personal",
"prsonal",
"pwrsonal",
"persanal",
"personl",
"pursanal",
"pesonal",
"PI",
"p.i."]
personal_clans = []
personal_dictionary = []
def init_personalinfo_dictionary():
for i in range(47):
personal_dictionary.append(["npi"]*13)
def fill_list_of_personal_clans():
with open(filtered_csv, "rU") as personal_comms:
reader = csv.reader(personal_comms)
reader.next()
for row in reader:
personal_clans.append(row[0])
def generate_nopersonalinfo_files():
for file in set(personal_clans):
prefix = file[0:5].split("_")
#print "original: {}".format(prefix)
prefix = [int(prefix[0]), prefix_to_array(prefix[1])]
#print "new: {}".format(prefix)
personal_dictionary[prefix[0]][prefix[1]] = "pi"
with open(output_file, "wb") as table:
writer = csv.writer(table)
writer.writerow(["subject-visit", "06", "07", "08", "09", "10",
"11", "12", "13", "14", "15", "16", "17", "18"])
for index, subject in enumerate(personal_dictionary[1:]):
writer.writerow([index+1] + subject)
def fill_pidictionary_with_nofile():
subj_prefix = ""
visit_prefix = ""
nofile_count = 0
all_files = list_of_all_files()
for i, subject in enumerate(personal_dictionary[1:]):
#print "i: {}".format(i)
for j, visit in enumerate(subject):
if i <9:
subj_prefix = '0'+str(i+1)
else:
subj_prefix = str(i+1)
visit_prefix = str(array_to_prefix(j))
prefix = subj_prefix+"_"+visit_prefix
if not any(prefix in x for x in all_files):
#print "prefix: {}".format(subj_prefix+"_"+visit_prefix)
#print "no file"
personal_dictionary[i+1][j] = "nf"
nofile_count += 1
#print "\n\nnofile_count: {}".format(nofile_count)
def prefix_to_array(prefix):
if prefix == '06':
return 0
elif prefix == '07':
return 1
elif prefix == '08':
return 2
elif prefix == '09':
return 3
elif prefix == '10':
return 4
elif prefix == '11':
return 5
elif prefix == '12':
return 6
elif prefix == '13':
return 7
elif prefix == '14':
return 8
elif prefix == '15':
return 9
elif prefix == '16':
return 10
elif prefix == '17':
return 11
elif prefix == '18':
return 12
def array_to_prefix(array):
if array == 0:
return '06'
elif array == 1:
return '07'
elif array == 2:
return '08'
elif array == 3:
return '09'
elif array == 4:
return '10'
elif array == 5:
return '11'
elif array == 6:
return '12'
elif array == 7:
return '13'
elif array == 8:
return '14'
elif array == 9:
return '15'
elif array == 10:
return '16'
elif array == 11:
return '17'
elif array == 12:
return '18'
def list_of_all_files():
files = []
with open(unfiltered_csv, "rU") as file:
reader = csv.reader(file)
reader.next()
for row in reader:
files.append(row[0])
return list(set(files))
if __name__ == "__main__":
unfiltered_csv = sys.argv[1]
filtered_csv = sys.argv[2]
output_file = sys.argv[3]
all_files = list_of_all_files()
fill_list_of_personal_clans()
init_personalinfo_dictionary()
fill_pidictionary_with_nofile()
generate_nopersonalinfo_files()