Skip to content

NeuroMLDataReader

NeuroMLDataReader

Bases: ConnectomeDataset

Reader of data from a NeuroML file

Source code in cect/NeuroMLDataReader.py
 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
class NeuroMLDataReader(ConnectomeDataset):
    """
    Reader of data from a NeuroML file
    """

    verbose = False

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

        nml_doc = pynml.read_neuroml2_file(get_file_location(neuroml_filename))
        self.nml_net = nml_doc.networks[0]
        print_("Opened the NeuroML file: " + neuroml_filename)

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

        for conn in conns:
            self.add_connection_info(conn)

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

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

    cell_names = {}

    def _get_cell_name(self, pop, index, pop_size=None):
        ref = "%s%i" % (pop, index)
        if ref in self.cell_names:
            return self.cell_names[ref]
        if pop_size is not None:
            if pop_size > 1:
                cell_name = "%s%s" % (pop[3:] if "Pop" in pop else pop, index + 1)
            else:
                cell_name = pop
        else:
            raise Exception(
                f"Cannot determine cell name for cell {index} in population {pop} (size: {pop_size})\nCells: {self.cell_names}"
            )

        self.cell_names[ref] = cell_name
        print_(f" - Adding {ref}: cell {index} in population {pop} (size: {pop_size}))")
        return cell_name

    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 pop in self.nml_net.populations:
            for inst in pop.instances:
                cell_name = self._get_cell_name(pop.id, inst.id, len(pop.instances))
                print_("Adding cell: %s" % cell_name)
                if is_known_muscle(cell_name):
                    muscles.add(cell_name)
                else:
                    neurons.add(cell_name)

        for cont_proj in self.nml_net.continuous_projections:
            print_("Adding proj: %s" % cont_proj.id)
            pre_pop = cont_proj.presynaptic_population
            post_pop = cont_proj.postsynaptic_population
            for conn in cont_proj.continuous_connection_instance_ws:
                # print_(" - Adding conn: %s" % conn)
                pre = self._get_cell_name(pre_pop, conn.get_pre_cell_id())
                post = self._get_cell_name(post_pop, conn.get_post_cell_id())
                w = conn.get_weight()
                synclass = "Acetylcholine"
                if w < 0:
                    w = -1 * w
                    synclass = "GABA"
                ci = ConnectionInfo(pre, post, w, "???", synclass)

                # print_("Conn: %s" % (ci))
                conns.append(ci)

        for elec_proj in self.nml_net.electrical_projections:
            print_("Adding proj: %s" % elec_proj.id)
            pre_pop = elec_proj.presynaptic_population
            post_pop = elec_proj.postsynaptic_population
            for conn in elec_proj.electrical_connection_instance_ws:
                # print_(" - Adding conn: %s" % conn)
                pre = self._get_cell_name(pre_pop, conn.get_pre_cell_id())
                post = self._get_cell_name(post_pop, conn.get_post_cell_id())
                w = conn.get_weight()
                synclass = GENERIC_ELEC_SYN
                ci = ConnectionInfo(pre, post, w, "???", synclass)

                # print_("Conn: %s" % (ci))
                conns.append(ci)

        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/NeuroMLDataReader.py
 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
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 pop in self.nml_net.populations:
        for inst in pop.instances:
            cell_name = self._get_cell_name(pop.id, inst.id, len(pop.instances))
            print_("Adding cell: %s" % cell_name)
            if is_known_muscle(cell_name):
                muscles.add(cell_name)
            else:
                neurons.add(cell_name)

    for cont_proj in self.nml_net.continuous_projections:
        print_("Adding proj: %s" % cont_proj.id)
        pre_pop = cont_proj.presynaptic_population
        post_pop = cont_proj.postsynaptic_population
        for conn in cont_proj.continuous_connection_instance_ws:
            # print_(" - Adding conn: %s" % conn)
            pre = self._get_cell_name(pre_pop, conn.get_pre_cell_id())
            post = self._get_cell_name(post_pop, conn.get_post_cell_id())
            w = conn.get_weight()
            synclass = "Acetylcholine"
            if w < 0:
                w = -1 * w
                synclass = "GABA"
            ci = ConnectionInfo(pre, post, w, "???", synclass)

            # print_("Conn: %s" % (ci))
            conns.append(ci)

    for elec_proj in self.nml_net.electrical_projections:
        print_("Adding proj: %s" % elec_proj.id)
        pre_pop = elec_proj.presynaptic_population
        post_pop = elec_proj.postsynaptic_population
        for conn in elec_proj.electrical_connection_instance_ws:
            # print_(" - Adding conn: %s" % conn)
            pre = self._get_cell_name(pre_pop, conn.get_pre_cell_id())
            post = self._get_cell_name(post_pop, conn.get_post_cell_id())
            w = conn.get_weight()
            synclass = GENERIC_ELEC_SYN
            ci = ConnectionInfo(pre, post, w, "???", synclass)

            # print_("Conn: %s" % (ci))
            conns.append(ci)

    return list(neurons), list(muscles), list(other_cells), conns

get_instance(from_cache=LOAD_READERS_FROM_CACHE_BY_DEFAULT)

Uses NeuroMLDataReader to load data on connectome

Returns:

Name Type Description
NeuroMLDataReader

The initialised connectome reader

Source code in cect/NeuroMLDataReader.py
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
def get_instance(from_cache=LOAD_READERS_FROM_CACHE_BY_DEFAULT):
    """Uses ``NeuroMLDataReader`` to load data on connectome

    Returns:
        NeuroMLDataReader: The initialised connectome reader
    """
    if from_cache and False:
        from cect.ConnectomeDataset import (
            load_connectome_dataset_file,
            get_cache_filename,
        )

        return load_connectome_dataset_file(
            get_cache_filename(__file__.split("/")[-1].split(".")[0])
        )
    else:
        return NeuroMLDataReader("c302_C2_FW.net.nml")