Skip to content

CellInfo

cds = cds_src.get_connectome_view(view) module-attribute

for cell in ['I3']: print(cds.nodes) print(cds.connections.keys()) index = cds.nodes.index(cell) print('Conns from %s (index: %i): %s'%(cell,index,cds.get_connections_from(cell, syntype))) matrix = cds.connections[syntype] print(matrix[index]) print('Conns to %s (index: %i): %s'%(cell,index,cds.get_connections_to(cell, syntype))) print(matrix.T[index])

cds_src = get_instance() module-attribute

from cect.RipollSanchezMidRangeReader import get_instance cds_src = get_instance()

generate_cell_info_pages(connectomes)

Generates the individual cell pages

Parameters:

Name Type Description Default
connectomes list

The list of connectome readers to use

required
Source code in cect/CellInfo.py
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
def generate_cell_info_pages(connectomes):
    """Generates the individual cell pages

    Args:
        connectomes (list): The list of connectome readers to use
    """
    cell_data = load_individual_neuron_info()
    cell_classification = get_primary_classification()

    all_cell_info = [["Cell name", "Type", "Name details", "Lineage", "Classification"]]

    for cell in ALL_PREFERRED_CELL_NAMES:
        print_("Generating individual cell page for: %s" % cell)

        cell_info = '---\ntitle: "Cell: %s"\n---\n\n' % cell

        cell_ref = (
            cell
            if not ((cell.startswith("CA") or cell.startswith("CP")) and cell[2] == "0")
            else "%s%s" % (cell[:2], cell[-1])
        )  # CA04 -> CA4 etc.

        # TODO: investigate  DX1, DX2, DX3, EF1, EF2, EF3
        if is_any_neuron(cell) and "DX" not in cell and "EF" not in cell:
            acronym = cell_data[cell_ref][0]
            lineage = cell_data[cell_ref][1]
            desc = cell_data[cell_ref][2]
            from_ = 0
            for c in cell:
                # print('Replacing %s (from %s) in %s'%(c,from_,acronym))
                if c in acronym:
                    ii = acronym.index(c, from_)
                    acronym = "%s<u>%s</u>%s" % (
                        acronym[:ii],
                        acronym[ii],
                        acronym[ii + 1 :],
                    )
                    from_ = ii + 1

            cell_info += '!!! question "**%s: %s**"\n\n' % (
                cell,
                acronym,
            )
            cell_info += (
                '    <p class="subtext"><b>%s</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
                % (desc)
            )
            cell_info += "Lineage: <b>%s</b></p>\n\n" % (lineage)

            all_cell_info.append(
                [
                    cell,
                    get_cell_notes(cell),
                    cell_data[cell_ref][0],
                    lineage,
                    desc,
                ]
            )

        else:
            cell_info += '!!! question "**%s: %s**"\n\n' % (cell, get_cell_notes(cell))
            cc = cell_classification[cell]
            all_cell_info.append(
                [
                    cell,
                    get_cell_notes(cell),
                    cell_data[cell_ref][0]
                    if cell_ref in cell_data
                    else "- To be added... - ",
                    get_cell_notes(cell),
                    "- To be added... - ",
                    cc[0].upper() + cc[1:],
                ]
            )

        cell_info += (
            '    <p class="subtext"><a href="../Cook_2019">Cook 2019</a> classification: <b>%s</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
            % (get_cell_notes(cell))
        )
        cc = cell_classification[cell]
        color = get_standard_color(cell)

        cell_info += (
            'All cells of type: <a href="../Cells/#%s"><b><span style="color:%s">%s</span></b></a></p>\n\n'
            % (
                cc.lower().replace(" ", "-").replace("(", "").replace(")", ""),
                color,
                cc[0].upper() + cc[1:],
            )
        )

        cell_info += "    %s " % (
            get_cell_wormatlas_link(cell, text="Info on WormAtlas", button=True)
        )

        cell_info += "%s\n\n" % get_cell_osbv1_link(
            cell, text="View in 3D on Open Source Brain", button=True
        )

        all_synclasses = [
            GENERIC_CHEM_SYN,
            GENERIC_ELEC_SYN,
        ]  # ensure these 2 are at the start...

        for cds_name in connectomes:
            cds = connectomes[cds_name]
            for synclass in cds.connections:
                if synclass not in all_synclasses:
                    all_synclasses.append(synclass)

        cell_link = get_cell_internal_link(
            cell, html=True, use_color=True, individual_cell_page=True
        )

        reference_cs = "Cook2019Male" if is_male_specific_cell(cell) else "Cook2019Herm"
        # reference_cs = "White_whole"

        reference_gj = reference_cs
        reference_mono = "Bentley2016_MA"
        reference_pep = "RipollSanchezShortRange"
        reference_func = "Randi2023"
        reference_cont = "Brittin2021"
        max_conn_cells = 5
        conns_from_cs = "???"
        conns_to_cs = "???"
        conns_from_mono = "???"
        conns_to_mono = "???"
        conns_from_pep = "???"
        conns_to_pep = "???"
        conns_from_func = "???"
        conns_to_func = "???"
        conns_cont = "???"
        conns_gj = "???"

        tables_md = ""

        for synclass in all_synclasses:
            synclass_info = synclass
            if synclass == GENERIC_CHEM_SYN:
                synclass_info = "Chemical synaptic"
            if synclass == GENERIC_ELEC_SYN:
                synclass_info = "Electrical synaptic"

            header = "### %s connections %s %s  { data-search-exclude }\n\n" % (
                synclass_info,
                "to" if not synclass == GENERIC_ELEC_SYN else "from/to",
                cell_link,
            )

            w = {}
            for cds_name in connectomes:
                r_name = get_dataset_link(cds_name)
                w[r_name] = {}
                cds = connectomes[cds_name]

                connection_symbol = "↔" if synclass == GENERIC_ELEC_SYN else "→"

                if synclass in cds.connections:
                    conns = cds.get_connections_to(cell, synclass)

                    if cds_name == reference_cs and synclass == GENERIC_CHEM_SYN:
                        conns_to_cs = _get_top_list(conns, max_conn_cells)
                    if cds_name == reference_gj and synclass == GENERIC_ELEC_SYN:
                        conns_gj = _get_top_list(conns, max_conn_cells)
                    if cds_name == reference_mono:
                        conns_to_mono = _get_top_list(conns, max_conn_cells)
                    if cds_name == reference_pep:
                        conns_to_pep = _get_top_list(conns, max_conn_cells)
                    if cds_name == reference_func:
                        conns_to_func = _get_top_list(conns, max_conn_cells)
                    if cds_name == reference_cont:
                        conns_cont = _get_top_list(conns, max_conn_cells)

                    for c in conns:
                        cc = get_cell_internal_link(
                            c, html=True, use_color=True, individual_cell_page=True
                        )
                        template = (
                            "<b><i>%s%s%s</i></b>"
                            if cell == c
                            else (
                                "<b>%s%s%s</b>"
                                if are_bilateral_pair(cell, c)
                                else "%s%s%s"
                            )
                        )
                        w[r_name][template % (cc, connection_symbol, cell_link)] = (
                            conns[c]
                        )

            w_md = get_weight_table_markdown(w)

            if "No connections" not in w_md:
                tables_md += "%s\n%s\n\n" % (header, w_md)

            if not synclass == GENERIC_ELEC_SYN:
                header = "### %s connections %s %s  { data-search-exclude }\n\n" % (
                    synclass_info,
                    "from",
                    cell_link,
                )

                w = {}
                for cds_name in connectomes:
                    r_name = get_dataset_link(cds_name)
                    w[r_name] = {}

                    cds = connectomes[cds_name]
                    if synclass in cds.connections:
                        conns = cds.get_connections_from(cell, synclass)

                        if cds_name == reference_cs and synclass == GENERIC_CHEM_SYN:
                            conns_from_cs = _get_top_list(conns, max_conn_cells)
                        if cds_name == reference_mono:
                            conns_from_mono = _get_top_list(conns, max_conn_cells)
                        if cds_name == reference_pep:
                            conns_from_pep = _get_top_list(conns, max_conn_cells)
                        if cds_name == reference_func:
                            conns_from_func = _get_top_list(conns, max_conn_cells)
                        if cds_name == reference_cont:
                            pass  # same as to...

                        for c in conns:
                            cc = get_cell_internal_link(
                                c, html=True, use_color=True, individual_cell_page=True
                            )
                            template = (
                                "<b><i>%s%s</i></b>"
                                if cell == c
                                else (
                                    "<b>%s%s</b>"
                                    if are_bilateral_pair(cell, c)
                                    else "%s%s"
                                )
                            )
                            w[r_name][template % (cell_link, cc)] = conns[c]

                w_md = get_weight_table_markdown(w)

                if "No connections" not in w_md:
                    tables_md += "%s\n%s\n\n" % (header, w_md)

        cell_info += f"""

### Summary of connections

<p class="subtext">Top {max_conn_cells} connections of specified types to/from this cell (based on {get_dataset_link(reference_cs)}, {get_dataset_link(reference_mono)}, {get_dataset_link(reference_pep)}, {get_dataset_link(reference_func)} & {get_dataset_link(reference_cont)})</p>

<table style="width:700px">
<tr>
    <td><b><a href="#electrical-synaptic-connections-fromto-{cell.lower()}" title="Electrical connectivity from {reference_cs}">Electrical</a></b></td> <td colspan="5" align="middle">{conns_gj}</td> 
</tr><tr>
    <td>&nbsp;</td> <td colspan="5" align="middle">\u2195</td> 
</tr><tr>
    <td><b><a href="#chemical-synaptic-connections-to-{cell.lower()}" title="Chemical synaptic connectivity from {reference_cs}">Chemical</a></b></td>
    <td style="width:40%">{conns_to_cs}</td>
    <td style="width:5%" style="vertical-align:bottom;text-align:center;">\u2198</td>
    <td rowspan="5" style="vertical-align:middle;text-align:center;"><b>{cell_link}</b></td>
    <td style="width:5%" style="vertical-align:bottom;text-align:center;">\u2197</td>
    <td style="width:40%">{conns_from_cs}</td>
</tr><tr>
    <td><b><a href="#monoaminergic-connections-to-{cell.lower()}" title="Monoaminergic connectivity from {reference_mono}">Monoaminergic</a></b></td><td>{conns_to_mono}</td><td align="middle">→</td><td align="middle">→</td><td>{conns_from_mono}</td>
</tr><tr>
    <td><b><a href="#peptidergic-connections-to-{cell.lower()}" title="Peptidergic connectivity from {reference_pep}">Peptidergic</a></b></td>  <td>{conns_to_pep}</td><td align="middle">→</td><td align="middle">→</td><td>{conns_from_pep}</td>
</tr><tr>
    <td><b><a href="#functional-connections-to-{cell.lower()}" title="Functional connectivity from {reference_func}">Functional</a></b></td>   <td>{conns_to_func}</td><td align="middle">→</td><td align="middle">→</td><td>{conns_from_func}</td>
</tr><tr>
    <td>&nbsp;</td> <td colspan="5" align="middle">\u2195</td> 
</tr><tr>
    <td><b><a href="#membrane-contacts-to-{cell.lower()}" title="Contactome from {reference_cont}">Contactomic</a></b></td>  <td colspan="5" align="middle">{conns_cont}</td>
</tr>
</table>

"""
        cell_info += tables_md

        cell_filename = "docs/%s.md" % cell
        with open(cell_filename, "w") as cell_file:
            print_(f"Writing info on cell {cell} to {cell_filename}")
            cell_file.write(cell_info)

    cell_info_filename = "cect/data/all_cell_info.csv"
    with open(cell_info_filename, "w") as csv_file:
        print_(f"Writing info on all cells to {cell_info_filename}")
        csv_writer = csv.writer(csv_file, delimiter=",", quotechar='"')
        for line in all_cell_info:
            csv_writer.writerow(line)

Helper method to generate an internal link to the page for a dataset

Parameters:

Name Type Description Default
dataset str

The dataset to link to

required

Returns:

Name Type Description
str

A hyperlink to the dataset

Source code in cect/CellInfo.py
26
27
28
29
30
31
32
33
34
35
36
37
def get_dataset_link(dataset):
    """Helper method to generate an internal link to the page for a dataset

    Args:
        dataset (str): The dataset to link to

    Returns:
        str: A hyperlink to the dataset
    """
    # return dataset+'--'
    dataset_text = dataset.replace("Herm", " Herm").replace("Male", " Male")
    return f'<a href="../{dataset}_data">{dataset_text}</a>'