Skip to content

WitvlietDataReader

WitvlietDataReader

Bases: ConnectomeDataset

Reader for datasets from Witvliet et al. 2021

Source code in cect/readers/WitvlietDataReader.py
 33
 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
107
108
109
110
111
112
class WitvlietDataReader(ConnectomeDataset):
    """Reader for datasets from [Witvliet et al. 2021](../../Witvliet_2021.md)"""

    verbose = False

    def __init__(self, spreadsheet):
        ConnectomeDataset.__init__(self)
        self.filename = get_filename_from_spreadsheet(spreadsheet)

        neurons, muscles, other_cells, conns = self.read_all_data()

        for conn in conns:
            self.add_connection_info(
                conn,
                append_existing_connections=False,
                check_overwritten_connections=True,
            )

    def read_data(self):
        return self._read_data()

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

    def read_all_data(self):
        neurons = set([])
        muscles = set([])
        other_cells = set([])
        conns = []

        wb = load_workbook(self.filename)
        sheet = wb.worksheets[0]
        print_("Opened the Excel file (Witvliet data): " + self.filename)

        for row in sheet.iter_rows(
            min_row=2, values_only=True
        ):  # Assuming data starts from the second row
            pre = str(row[0])
            post = str(row[1])

            pre = fix_witvliet_cell_naming(remove_leading_index_zero(pre))
            post = fix_witvliet_cell_naming(remove_leading_index_zero(post))

            if is_potential_muscle(pre):
                pre = convert_to_preferred_muscle_name(pre)

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

            syntype_here = str(row[2])
            num = int(row[3])

            if syntype_here == "electrical":
                syntype = ELECTRICAL_SYN_TYPE
            elif syntype_here == "chemical":
                syntype = CHEMICAL_SYN_TYPE

            if self.verbose and num > 0:
                print_("Conn %s -> %s #%i" % (pre, post, num))

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

            # Add the reverse connection for electrical synapses, since they are bidirectional
            if synclass == GENERIC_ELEC_SYN_CLASS:
                conns.append(ConnectionInfo(post, pre, num, syntype, synclass))
            conns.append(ConnectionInfo(pre, post, num, syntype, synclass))

            for p in [pre, post]:
                if is_herm_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