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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250 | class Cook2019DataReader(ConnectomeDataset):
"""
Reader of data from Cook et al. 2019 - Whole-animal connectomes of both Caenorhabditis elegans sexes
"""
spreadsheet_location = os.path.dirname(os.path.abspath(__file__)) + "/../data/"
filename = "%s%s" % (spreadsheet_location, ORIGINAL_SUPP_INFO_5)
filename = "%s%s" % (spreadsheet_location, WORMWIRING_ADJ_MATRICES)
filename = "%s%s" % (spreadsheet_location, WORMWIRING_ADJ_MATRICES_CORRECTED)
verbose = False
def __init__(self, sex):
ConnectomeDataset.__init__(self)
self.sex = sex
wb = load_workbook(self.filename)
print_(
f"Opened the Excel file for Cook et al. 2019 (sex: {self.sex}): {self.filename}"
)
self.pre_cells = {}
self.post_cells = {}
self.conn_nums = {}
for conn_type in SEX_SPECIFIC_SHEETS[self.sex]:
sheet_name = conn_type
if "corrected" in self.filename:
if sheet_name == HERM_GAP_SYMM:
sheet_name = HERM_GAP_SYMM_CORRECTED
pre_range[HERM_GAP_SYMM] = range(4, 473)
post_range[HERM_CHEM] = range(4, 458)
post_range[HERM_GAP_SYMM] = range(4, 473)
sheet = wb.get_sheet_by_name(sheet_name)
print_("Looking at the sheet: %s" % conn_type)
self.pre_cells[conn_type] = []
self.post_cells[conn_type] = []
for i in pre_range[conn_type]:
pre_cell = _check_ray_st_cell(sheet["C%i" % i].value)
self.pre_cells[conn_type].append(pre_cell)
if self.verbose:
print_(
" - Pre cells for %s (%i):\n%s"
% (
conn_type,
len(self.pre_cells[conn_type]),
self.pre_cells[conn_type],
)
)
for i in post_range[conn_type]:
post_cell = _check_ray_st_cell(sheet.cell(row=3, column=i).value)
self.post_cells[conn_type].append(post_cell)
if self.verbose:
print_(
" - Post cells for %s (%i):\n%s"
% (
conn_type,
len(self.post_cells[conn_type]),
self.post_cells[conn_type],
)
)
self.conn_nums[conn_type] = np.zeros(
[len(self.pre_cells[conn_type]), len(self.post_cells[conn_type])],
dtype=int,
)
for i in range(len(self.pre_cells[conn_type])):
for j in range(len(self.post_cells[conn_type])):
row = 4 + i
col = 4 + j
val = sheet.cell(row=row, column=col).value
# print("Cell (%i,%i) [row %i, col %i] = %s" % (i, j, row, col, val))
if val is not None:
self.conn_nums[conn_type][i, j] = int(val)
if self.verbose:
print_(
" - Conns for %s (%s):\n%s"
% (
conn_type,
self.conn_nums[conn_type].shape,
self.conn_nums[conn_type],
)
)
neurons, muscles, other_cells, conns = self.read_all_data()
for conn in conns:
self.add_connection_info(conn)
def read_data(self):
return self._read_data()
def read_muscle_data(self):
return self._read_muscle_data()
def read_all_data(self):
"""
Returns:
(tuple[list, list, list, list]): List of neurons, muscles, other cells and connections which have been read in
"""
neurons = set([])
muscles = set([])
other_cells = set([])
conns = []
for conn_type in SEX_SPECIFIC_SHEETS[self.sex]:
for pre_index in range(len(self.pre_cells[conn_type])):
for post_index in range(len(self.post_cells[conn_type])):
num = self.conn_nums[conn_type][pre_index, post_index]
pre = remove_leading_index_zero(
self.pre_cells[conn_type][pre_index]
)
post = remove_leading_index_zero(
self.post_cells[conn_type][post_index]
)
if self.verbose and num > 0:
print_("Conn %s -> %s #%i" % (pre, post, num))
if is_potential_muscle(pre):
pre = convert_to_preferred_muscle_name(pre)
if is_potential_muscle(post):
post = convert_to_preferred_muscle_name(post)
if is_marginal_epithelial_gland_cell(post):
post = convert_to_preferred_phar_cell_name(post)
if num > 0:
syntype = (
CHEMICAL_SYN_TYPE
if "chemical" in conn_type
else ELECTRICAL_SYN_TYPE
)
synclass = get_synclass(pre, syntype)
ci = ConnectionInfo(pre, post, num, syntype, synclass)
if self.verbose:
print_("Conn: %s" % (ci))
conns.append(ci)
for p in [pre, post]:
if is_any_neuron(p):
neurons.add(pre)
elif is_known_muscle(p):
muscles.add(pre)
else:
other_cells.add(p)
return list(neurons), list(muscles), list(other_cells), conns
|