Skip to content

ConnectomeView

NodeSet

Set of nodes (each of which can contain single cells or lists of cells) to use in a ConnectomeView. An optional text description can be provided, and the color, shape, position or size of the NodeSets to use in graphical depictions can be set.

Source code in cect/ConnectomeView.py
 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
class NodeSet:
    """Set of nodes (each of which can contain single cells or lists of cells) to use in a ``ConnectomeView``.
    An optional text `description` can be provided, and the `color`, `shape`, `position` or `size` of the NodeSets to use in graphical depictions can be set."""

    def __init__(
        self,
        name,
        cells,
        color=None,
        shape=None,
        position=None,
        size=None,
        description=None,
    ):
        self.name = name
        self.color = color
        self.cells = cells
        self.shape = shape
        self.position = position
        self.size = size
        self.description = description

    def is_one_cell(self):
        """
        Returns True if the NodeSet contains only one cell, and the name of the NodeSet is the same as that cell.
        """
        return len(self.cells) == 1 and self.name == self.cells[0]

    def __repr__(self):
        """
        Returns a string representation of the NodeSet, including its name, description, color, shape, position, and the list of cells it contains.
        """
        info = "NodeSet: %s" % self.name
        if self.description is not None:
            info += " (%s)" % self.description
        info += "\t"
        if self.color is not None:
            info += "%s " % self.color
        if self.shape is not None:
            info += "%s " % self.shape
        if self.position is not None:
            info += "%s " % (str(self.position))
        info += "\t%s" % self.cells

        return info

    def to_markdown(self):
        """
        Returns a HTML <span> element for use in markdown or HTML for a representation of the NodeSet, including its name colored by the set color.
        """
        return (
            f'<span style="color:{self.color};">{self.name}</span>'
            if self.color
            else self.name
        )

__repr__()

Returns a string representation of the NodeSet, including its name, description, color, shape, position, and the list of cells it contains.

Source code in cect/ConnectomeView.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def __repr__(self):
    """
    Returns a string representation of the NodeSet, including its name, description, color, shape, position, and the list of cells it contains.
    """
    info = "NodeSet: %s" % self.name
    if self.description is not None:
        info += " (%s)" % self.description
    info += "\t"
    if self.color is not None:
        info += "%s " % self.color
    if self.shape is not None:
        info += "%s " % self.shape
    if self.position is not None:
        info += "%s " % (str(self.position))
    info += "\t%s" % self.cells

    return info

is_one_cell()

Returns True if the NodeSet contains only one cell, and the name of the NodeSet is the same as that cell.

Source code in cect/ConnectomeView.py
83
84
85
86
87
def is_one_cell(self):
    """
    Returns True if the NodeSet contains only one cell, and the name of the NodeSet is the same as that cell.
    """
    return len(self.cells) == 1 and self.name == self.cells[0]

to_markdown()

Returns a HTML element for use in markdown or HTML for a representation of the NodeSet, including its name colored by the set color.

Source code in cect/ConnectomeView.py
107
108
109
110
111
112
113
114
115
def to_markdown(self):
    """
    Returns a HTML <span> element for use in markdown or HTML for a representation of the NodeSet, including its name colored by the set color.
    """
    return (
        f'<span style="color:{self.color};">{self.name}</span>'
        if self.color
        else self.name
    )

View

A view of a ConnectomeDataset specifying subsets of cells (or lists of cells) as NodeSets, e.g. can be used to just show the connections between the pharyngeal neurons in a whole connectome dataset, or to group the sensory neurons, interneuron, etc. together.

Source code in cect/ConnectomeView.py
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
class View:
    """A view of a ``ConnectomeDataset`` specifying subsets of cells (or lists of cells) as ``NodeSet``s, e.g. can be used to just show the connections between the pharyngeal neurons in a whole connectome dataset, or to group the sensory neurons, interneuron, etc. together."""

    def __init__(
        self,
        id,
        name,
        description,
        node_sets,
        synclass_sets={},
        colormap=DEFAULT_COLORMAP,
        only_show_existing_nodes=False,
        text_scale=1.0,
    ):
        self.id = id
        self.name = name
        self.description = description
        self.node_sets = node_sets
        self.synclass_sets = synclass_sets
        self.colormap = colormap
        self.only_show_existing_nodes = only_show_existing_nodes
        self.text_scale = text_scale  # scale for text size for nodes in plots etc.

    def __repr__(self):
        info = "ConnectomeView: %s (%s)" % (
            self.name,
            self.id,
        )
        if self.description is not None:
            info += "\n  %s" % self.description
        for n in self.node_sets:
            info += "\n    %s" % n
        for s in self.synclass_sets:
            info += "\n    Synclass set: %s (%s)" % (s, self.synclass_sets[s])
        return info

    def to_markdown(self):
        info = "**%s** (%s)\n" % (
            self.name,
            self.id,
        )
        if self.description is not None:
            info += "_%s_\n\n" % self.description

        total_cells = sum([len(n.cells) for n in self.node_sets])
        info += f"| Nodes ({len(self.node_sets)} total)| Num cells in node | Cells ({total_cells} total)|\n| --- | --- | --- |\n"

        for n in self.node_sets:
            node_colored = f'<span style="color:{n.color};">{n.name}</span>'
            cells_linked = [
                get_cell_internal_link(
                    c, individual_cell_page=True, html=True, use_color=True
                )
                for c in n.cells
            ]
            info += "|**%s** |%i | %s|\n" % (
                node_colored,
                len(n.cells),
                ", ".join(cells_linked),
            )
        return info

    def has_color(self):
        for ns in self.node_sets:
            if ns.color is not None:
                return True
        return False

    def has_multicell_nodes(self):
        for ns in self.node_sets:
            if not ns.is_one_cell():
                return True
        return False

    def get_node_set(self, node_set_name):
        for ns in self.node_sets:
            if ns.name == node_set_name:
                return ns
        return None

    def get_index_of_cell(self, cell):
        for i in range(len(self.node_sets)):
            if cell in self.node_sets[i].cells:
                return i
        return -1