Skip to content

ConnectomeView

NodeSet

Set of nodes (can be single cells or lists of cells) to use in a View. Can specify the color, shape, position or size to use in graphical depictions.

Source code in cect/ConnectomeView.py
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
class NodeSet:
    """Set of nodes (can be single cells or lists of cells) to use in a ``View``. Can specify the `color`, `shape`, `position` or `size` to use in graphical depictions."""

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

    def is_one_cell(self):
        return len(self.cells) == 1 and self.name == self.cells[0]

    def __repr__(self):
        info = "NodeSet: %s\t(" % self.name
        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):
        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
 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
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,
    ):
        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

    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