Skip to content

BrittinDataReader

BrittinDataReader

Bases: ConnectomeDataset

Reader for datasets from Brittin et al. 2021

Source code in cect/BrittinDataReader.py
 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
class BrittinDataReader(ConnectomeDataset):
    """Reader for datasets from [Brittin et al. 2021](../../Brittin_2021.md)"""

    verbose = False

    def __init__(self, reference_graph):
        ConnectomeDataset.__init__(self)
        self.reference_graph = reference_graph

        cells, neuron_conns = self.read_data()
        for conn in neuron_conns:
            self.add_connection_info(conn, check_overwritten_connections=True)

    def read_data(self):
        cells = []
        conns = []

        wb = load_workbook(filename)

        sheet = wb.get_sheet_by_name(self.reference_graph)

        bilaterals = []
        single_cells = []

        print_("Opened sheet %s in Excel file: %s" % (sheet, filename))
        # print(dir(sheet))

        for row in sheet.rows:
            # print(row[0].value)
            if "cell_1" not in row[0].value:
                delta = int(row[3].value)
                if delta == 4:
                    pre = row[0].value
                    post = row[1].value
                    num = float(row[2].value)
                    syntype = "Contact"
                    synclass = "%s%s" % (self.reference_graph, row[3].value)
                    synclass = "Contact"

                    ci = ConnectionInfo(pre, post, num, syntype, synclass)
                    conns.append(ci)
                    ci = ConnectionInfo(post, pre, num, syntype, synclass)
                    conns.append(ci)

                    if pre not in cells:
                        cells.append(pre)
                    if post not in cells:
                        cells.append(post)

                    pre_ = get_contralateral_neuron(pre)
                    post_ = get_contralateral_neuron(post)
                    ci_ = ConnectionInfo(pre_, post_, num, syntype, synclass)
                    conns.append(ci_)
                    ci_ = ConnectionInfo(post_, pre_, num, syntype, synclass)
                    conns.append(ci_)

                    if pre_ not in cells:
                        cells.append(pre_)
                    if post_ not in cells:
                        cells.append(post_)

        for cell in cells:
            if is_one_of_bilateral_pair(cell):
                bilaterals.append(cell)
            else:
                single_cells.append(cell)

        print_(
            "Finished processing %i cells, %i bilateral and %i single cells: %s"
            % (len(cells), len(bilaterals), len(single_cells), sorted(single_cells))
        )

        return cells, conns