Skip to content

HaspelODonovanDataReader

HaspelODonovanDataReader

Bases: ConnectomeDataset

Reader for HaspelODonovan connectivity dataset

Source code in cect/readers/HaspelODonovanDataReader.py
 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
class HaspelODonovanDataReader(ConnectomeDataset):
    """Reader for HaspelODonovan connectivity dataset"""

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

        self.full_or_one_seg = full_or_one_seg

        cells, conns = self.read_all_data()

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

    def read_all_data(self):

        cells = set([])
        conns = []

        import scipy.io

        print_("Loading data from: %s" % filename)
        mat = scipy.io.loadmat(filename)

        names = [
            str(n[0]) for n in mat["Names_conn_%s" % self.full_or_one_seg].flatten()
        ]
        A = mat["A_conn_%s" % self.full_or_one_seg]
        J = mat["J_conn_%s" % self.full_or_one_seg]

        for i, pre in enumerate(names):
            pre = _standardise_cell_name(pre)[0]
            cells.add(pre)
            for j, post in enumerate(names):
                posts = _standardise_cell_name(post)
                for post in posts:
                    cells.add(post)
                    w = A[j, i]
                    if w != 0:
                        print_("%s -> %s: A=%d" % (pre, post, w))
                        conns.append(
                            ConnectionInfo(
                                pre,
                                post,
                                w if w > 0 else -w,
                                CHEMICAL_SYN_TYPE,
                                GENERIC_EXCITATORY_CHEM_SYN_CLASS
                                if w > 0
                                else GENERIC_INHIBITORY_CHEM_SYN_CLASS,
                            )
                        )

                    if J[j, i] != 0:
                        print_("%s -> %s: J=%d" % (pre, post, J[j, i]))
                        conns.append(
                            ConnectionInfo(
                                pre,
                                post,
                                J[j, i],
                                ELECTRICAL_SYN_TYPE,
                                GENERIC_ELEC_SYN_CLASS,
                            )
                        )

        print_("Loaded %d cells and %d connections" % (len(cells), len(conns)))

        return cells, conns

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

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