Skip to content

Cook2019DataReader

Cook2019DataReader

Bases: ConnectomeDataset

Reader of data from Cook et al. 2019 - Whole-animal connectomes of both Caeonrhabditis elegans sexes

Source code in cect/Cook2019DataReader.py
 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
class Cook2019DataReader(ConnectomeDataset):
    """
    Reader of data from Cook et al. 2019 - Whole-animal connectomes of both Caeonrhabditis elegans sexes
    """

    spreadsheet_location = os.path.dirname(os.path.abspath(__file__)) + "/data/"
    filename = "%sSI 5 Connectome adjacency matrices.xlsx" % spreadsheet_location

    verbose = False

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

        wb = load_workbook(self.filename)
        print_("Opened the Excel file: " + self.filename)

        self.pre_cells = {}
        self.post_cells = {}
        self.conn_nums = {}

        for conn_type in SEX_SPECIFIC_SHEETS[self.sex]:
            sheet = wb.get_sheet_by_name(conn_type)
            print_("Looking at sheet: %s" % conn_type)

            self.pre_cells[conn_type] = []
            self.post_cells[conn_type] = []

            for i in pre_range[conn_type]:
                self.pre_cells[conn_type].append(sheet["C%i" % i].value)

            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]:
                self.post_cells[conn_type].append(sheet.cell(row=3, column=i).value)

            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_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 num > 0:
                        syntype = "Send" if "chemical" in conn_type else "GapJunction"
                        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

read_all_data()

Returns:

Type Description

Tuple[list, list, list, list]: List of neurons, muscles), other cells and connections which have been read in

Source code in cect/Cook2019DataReader.py
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
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 num > 0:
                    syntype = "Send" if "chemical" in conn_type else "GapJunction"
                    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