Skip to content

Cook2020DataReader

my_instance = get_instance() module-attribute

read_data = my_instance.read_data read_muscle_data = my_instance.read_muscle_data

Cook2020DataReader

Bases: ConnectomeDataset

Reader of data from Cook et al. 2020 - The connectome of the Caenorhabditis elegans pharynx

Returns:

Type Description
Cook2020DataReader

The initialized Cook et al 2020 pharyngeal connectome reader

Source code in cect/readers/Cook2020DataReader.py
 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
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
class Cook2020DataReader(ConnectomeDataset):
    """
    Reader of data from Cook et al. 2020 - The connectome of the Caenorhabditis elegans pharynx

    Returns:
        (Cook2020DataReader): The initialized Cook et al 2020 pharyngeal connectome reader
    """

    cells = []
    conns = []

    def __init__(self):
        ConnectomeDataset.__init__(self)

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

    def read_data(self):
        """
        Returns:
            (tuple[list, list]): List of cells (str) and list of connections (``ConnectionInfo``) which have been read in
        """
        with open(filename, "r") as f:
            reader = csv.DictReader(f)
            print_("Opened file: " + filename)

            for row in reader:
                pre = str.strip(row["Source"])
                if is_potential_muscle(pre):
                    pre = convert_to_preferred_muscle_name(pre)
                post = str.strip(row["Target"])
                if is_potential_muscle(post):
                    post = convert_to_preferred_muscle_name(post)
                if is_marginal_cell(post):
                    post = convert_to_preferred_phar_cell_name(post)
                num = float(row["Weight"])
                syntype = str.strip(row["Type"])

                if syntype == "Electrical":
                    syntype = ELECTRICAL_SYN_TYPE
                else:
                    syntype = CHEMICAL_SYN_TYPE

                synclass = (
                    GENERIC_ELEC_SYN_CLASS
                    if syntype == ELECTRICAL_SYN_TYPE
                    else GENERIC_CHEM_SYN_CLASS
                )

                self.conns.append(ConnectionInfo(pre, post, num, syntype, synclass))
                # Add post -> pre conn for gap junction connections
                if syntype == ELECTRICAL_SYN_TYPE:
                    self.conns.append(ConnectionInfo(post, pre, num, syntype, synclass))

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

        with open(filename2, "r") as f:
            reader = csv.DictReader(f)
            print_("Opened file: " + filename)

            for row in reader:
                pre = str.strip(row["Source"])
                if is_potential_muscle(pre):
                    pre = convert_to_preferred_muscle_name(pre)
                if is_marginal_cell(pre):
                    pre = convert_to_preferred_phar_cell_name(pre)
                post = str.strip(row["Target"])

                if is_potential_muscle(post):
                    post = convert_to_preferred_muscle_name(post)
                if is_marginal_cell(post):
                    post = convert_to_preferred_phar_cell_name(post)

                num = float(row["Weight"])

                syntype = ELECTRICAL_SYN_TYPE
                synclass = GENERIC_ELEC_SYN_CLASS

                self.conns.append(ConnectionInfo(pre, post, num, syntype, synclass))
                # Add post -> pre conn for gap junction connections
                self.conns.append(ConnectionInfo(post, pre, num, syntype, synclass))

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

        return self.cells, self.conns

    '''def read_muscle_data(self):
        """
        Returns:
            neurons (:obj:`list` of :obj:`str`): List of motor neurons. Each neuron has at least one connection with a post-synaptic muscle cell.
            muscles (:obj:`list` of :obj:`str`): List of muscle cells.
            conns (:obj:`list` of :obj:`ConnectionInfo`): List of neuron-muscle connections.
        """

        neurons = []
        muscles = []
        conns = []

        with open(filename, "r") as f:
            reader = csv.DictReader(f)
            print_("Opened file: " + filename)

            for row in reader:
                pre = str.strip(row["Source"])
                if is_potential_muscle(pre):
                    pre = convert_to_preferred_muscle_name(pre)
                if is_marginal_cell(pre):
                    pre = convert_to_preferred_phar_cell_name(pre)
                post = str.strip(row["Target"])
                if is_potential_muscle(post):
                    post = convert_to_preferred_muscle_name(post)
                if is_marginal_cell(post):
                    post = convert_to_preferred_phar_cell_name(post)
                num = float(row["Weight"])
                syntype = str.strip(row["Type"])

                if syntype == "Electrical":
                    syntype = ELECTRICAL_SYN_TYPE

                synclass = (
                    GENERIC_ELEC_SYN_CLASS
                    if syntype  == ELECTRICAL_SYN_TYPE 
                    else GENERIC_CHEM_SYN_CLASS
                )

                conns.append(ConnectionInfo(pre, post, num, syntype, synclass))
                # Add post -> pre conn for gap junction connections
                if syntype == ELECTRICAL_SYN_TYPE:
                    conns.append(ConnectionInfo(post, pre, num, syntype, synclass))

                if is_known_muscle(post):
                    if post in PREFERRED_MUSCLE_NAMES and post not in muscles:
                        muscles.append(post)
                    if pre in PREFERRED_HERM_NEURON_NAMES and pre not in neurons:
                        neurons.append(pre)

        with open(filename2, "r") as f:
            reader = csv.DictReader(f)
            print_("Opened file: " + filename2)

            for row in reader:
                pre = str.strip(row["Source"])
                if is_potential_muscle(pre):
                    pre = convert_to_preferred_muscle_name(pre)
                if is_marginal_cell(pre):
                    pre = convert_to_preferred_phar_cell_name(pre)
                post = str.strip(row["Target"])
                if is_potential_muscle(post):
                    post = convert_to_preferred_muscle_name(post)
                if is_marginal_cell(post):
                    post = convert_to_preferred_phar_cell_name(post)
                num = float(row["Weight"])

                syntype = "Electrical"

                synclass = (
                    GENERIC_ELEC_SYN_CLASS
                    if "Electrical" in syntype
                    else GENERIC_CHEM_SYN_CLASS
                )

                if syntype == "Electrical":

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

                if is_known_muscle(post):
                    if post in PREFERRED_MUSCLE_NAMES and post not in muscles:
                        muscles.append(post)
                    if pre in PREFERRED_HERM_NEURON_NAMES and pre not in neurons:
                        neurons.append(pre)

        return neurons, muscles, conns'''

    def read_muscle_data(self):
        return self._read_muscle_data()

read_data()

Returns:

Type Description
tuple[list, list]

List of cells (str) and list of connections (ConnectionInfo) which have been read in

Source code in cect/readers/Cook2020DataReader.py
 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
def read_data(self):
    """
    Returns:
        (tuple[list, list]): List of cells (str) and list of connections (``ConnectionInfo``) which have been read in
    """
    with open(filename, "r") as f:
        reader = csv.DictReader(f)
        print_("Opened file: " + filename)

        for row in reader:
            pre = str.strip(row["Source"])
            if is_potential_muscle(pre):
                pre = convert_to_preferred_muscle_name(pre)
            post = str.strip(row["Target"])
            if is_potential_muscle(post):
                post = convert_to_preferred_muscle_name(post)
            if is_marginal_cell(post):
                post = convert_to_preferred_phar_cell_name(post)
            num = float(row["Weight"])
            syntype = str.strip(row["Type"])

            if syntype == "Electrical":
                syntype = ELECTRICAL_SYN_TYPE
            else:
                syntype = CHEMICAL_SYN_TYPE

            synclass = (
                GENERIC_ELEC_SYN_CLASS
                if syntype == ELECTRICAL_SYN_TYPE
                else GENERIC_CHEM_SYN_CLASS
            )

            self.conns.append(ConnectionInfo(pre, post, num, syntype, synclass))
            # Add post -> pre conn for gap junction connections
            if syntype == ELECTRICAL_SYN_TYPE:
                self.conns.append(ConnectionInfo(post, pre, num, syntype, synclass))

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

    with open(filename2, "r") as f:
        reader = csv.DictReader(f)
        print_("Opened file: " + filename)

        for row in reader:
            pre = str.strip(row["Source"])
            if is_potential_muscle(pre):
                pre = convert_to_preferred_muscle_name(pre)
            if is_marginal_cell(pre):
                pre = convert_to_preferred_phar_cell_name(pre)
            post = str.strip(row["Target"])

            if is_potential_muscle(post):
                post = convert_to_preferred_muscle_name(post)
            if is_marginal_cell(post):
                post = convert_to_preferred_phar_cell_name(post)

            num = float(row["Weight"])

            syntype = ELECTRICAL_SYN_TYPE
            synclass = GENERIC_ELEC_SYN_CLASS

            self.conns.append(ConnectionInfo(pre, post, num, syntype, synclass))
            # Add post -> pre conn for gap junction connections
            self.conns.append(ConnectionInfo(post, pre, num, syntype, synclass))

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

    return self.cells, self.conns