Investigating bilateral symmetry¶
This notebook uses cect, the C. elegans Connectome Toolbox, to investigate how bilateral symmetry in C. elegans changes over development. Source of this file on GitHub
1) Install the cect package using pip¶
If the package has not already been installed, use pip to install it.
In [1]:
Copied!
!pip install -q cect # use this line to install the latest version of cect from PyPI if you haven't already
print(f"cect version: {__import__('cect').__version__} is installed")
!pip install -q cect # use this line to install the latest version of cect from PyPI if you haven't already
print(f"cect version: {__import__('cect').__version__} is installed")
cect version: 0.3.2 is installed
2) Import methods from cect¶
In [2]:
Copied!
# Helper method to load data sets by name
from cect.Utils import get_connectome_dataset
# Helper method to apply a specific "view" (e.g. only Sensory or motor neurons) to a connectome dataset
from cect.ConnectomeView import get_view
# Method to convert a connectivity matrix into a binary array indicating symmetric connections
from cect.Analysis import convert_to_symmetry_array
# Helper method to load data sets by name
from cect.Utils import get_connectome_dataset
# Helper method to apply a specific "view" (e.g. only Sensory or motor neurons) to a connectome dataset
from cect.ConnectomeView import get_view
# Method to convert a connectivity matrix into a binary array indicating symmetric connections
from cect.Analysis import convert_to_symmetry_array
cect >>> -- Registering connectome dataset: White_A cect >>> -- Registering connectome dataset: White_L4 cect >>> -- Registering connectome dataset: White_whole cect >>> -- Registering connectome dataset: Witvliet1 cect >>> -- Registering connectome dataset: Witvliet2 cect >>> -- Registering connectome dataset: Witvliet3 cect >>> -- Registering connectome dataset: Witvliet4 cect >>> -- Registering connectome dataset: Witvliet5 cect >>> -- Registering connectome dataset: Witvliet6 cect >>> -- Registering connectome dataset: Witvliet7 cect >>> -- Registering connectome dataset: Witvliet8 cect >>> -- Registering connectome dataset: Varshney cect >>> -- Registering connectome dataset: Cook2019Herm cect >>> -- Registering connectome dataset: Cook2019Male cect >>> Opened file: /Users/padraig/git/ConnectomeToolbox/cect/readers/../data/cne24932-sup-0004-supinfo4.csv cect >>> Opened file: /Users/padraig/git/ConnectomeToolbox/cect/readers/../data/cne24932-sup-0004-supinfo4.csv cect >>> Preexisting connection (96 conns already) w: 15.000000 at (14,14) - new one: Connection from M4 to M4 (15 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 30.000000 cect >>> Preexisting connection (105 conns already) w: 2.000000 at (17,30) - new one: Connection from I4 to NSMR (13.5 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 15.500000 cect >>> Preexisting connection (106 conns already) w: 29.000000 at (37,15) - new one: Connection from NSML to pm5D (9 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 38.000000 cect >>> Preexisting connection (107 conns already) w: 50.000000 at (30,31) - new one: Connection from NSMR to bm (11 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 61.000000 cect >>> Preexisting connection (112 conns already) w: 1.000000 at (30,15) - new one: Connection from NSMR to pm5D (8.5 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 9.500000 cect >>> Preexisting connection (113 conns already) w: 15.000000 at (30,32) - new one: Connection from NSMR to M3R (7.5 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 22.500000 cect >>> Preexisting connection (117 conns already) w: 58.000000 at (37,18) - new one: Connection from NSML to pm5VL (5 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 63.000000 cect >>> Preexisting connection (120 conns already) w: 6.000000 at (17,18) - new one: Connection from I4 to pm5VL (4.5 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 10.500000 cect >>> Preexisting connection (122 conns already) w: 78.000000 at (37,31) - new one: Connection from NSML to bm (5 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 83.000000 cect >>> Preexisting connection (124 conns already) w: 1.000000 at (17,34) - new one: Connection from I4 to M2L (4 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 5.000000 cect >>> Preexisting connection (154 conns already) w: 1.000000 at (32,8) - new one: Connection from M3R to g1AR (1.5 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 2.500000 cect >>> Preexisting connection (156 conns already) w: 8.000000 at (6,14) - new one: Connection from I5 to M4 (18.5 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 26.500000 cect >>> Preexisting connection (157 conns already) w: 3.000000 at (6,30) - new one: Connection from I5 to NSMR (17.5 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 20.500000 cect >>> Preexisting connection (163 conns already) w: 3.000000 at (37,16) - new one: Connection from NSML to pm5VR (7 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 10.000000 cect >>> Preexisting connection (165 conns already) w: 14.000000 at (37,38) - new one: Connection from NSML to M3L (6.5 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 20.500000 cect >>> Preexisting connection (175 conns already) w: 8.000000 at (6,16) - new one: Connection from I5 to pm5VR (3.5 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 11.500000 cect >>> Preexisting connection (182 conns already) w: 5.000000 at (25,41) - new one: Connection from I1R to I2R (3 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 8.000000 cect >>> Preexisting connection (211 conns already) w: 3.000000 at (9,15) - new one: Connection from M1 to pm5D (1 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 4.000000 cect >>> Preexisting connection (214 conns already) w: 4.000000 at (6,8) - new one: Connection from I5 to g1AR (1 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 5.000000 cect >>> Preexisting connection (215 conns already) w: 7.000000 at (6,7) - new one: Connection from I5 to g1AL (1 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 8.000000 cect >>> Preexisting connection (221 conns already) w: 10.000000 at (33,27) - new one: Connection from I1L to I2L (1 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 11.000000 cect >>> Preexisting connection (227 conns already) w: 1.000000 at (14,6) - new one: Connection from M4 to I5 (0.5 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 1.500000 cect >>> Preexisting connection (242 conns already) w: 3.000000 at (36,14) - new one: Connection from I6 to M4 (9.5 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 12.500000 cect >>> Preexisting connection (243 conns already) w: 13.000000 at (36,37) - new one: Connection from I6 to NSML (8 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 21.000000 cect >>> Preexisting connection (244 conns already) w: 9.000000 at (35,16) - new one: Connection from M2R to pm5VR (3 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 12.000000 cect >>> Preexisting connection (245 conns already) w: 2.000000 at (34,7) - new one: Connection from M2L to g1AL (3 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 5.000000 cect >>> Preexisting connection (248 conns already) w: 10.000000 at (42,43) - new one: Connection from MCL to mc2V (2.5 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 12.500000 cect >>> Preexisting connection (263 conns already) w: 6.000000 at (9,23) - new one: Connection from M1 to I3 (1 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 7.000000 cect >>> Preexisting connection (264 conns already) w: 2.000000 at (9,27) - new one: Connection from M1 to I2L (1 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 3.000000 cect >>> Preexisting connection (267 conns already) w: 2.000000 at (25,9) - new one: Connection from I1R to M1 (1 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 3.000000 cect >>> Preexisting connection (268 conns already) w: 5.000000 at (25,23) - new one: Connection from I1R to I3 (1 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 6.000000 cect >>> Preexisting connection (271 conns already) w: 1.000000 at (32,14) - new one: Connection from M3R to M4 (1 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 2.000000 cect >>> Preexisting connection (273 conns already) w: 3.000000 at (36,30) - new one: Connection from I6 to NSMR (1 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 4.000000 cect >>> Preexisting connection (274 conns already) w: 14.000000 at (36,15) - new one: Connection from I6 to pm5D (1 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 15.000000 cect >>> Preexisting connection (275 conns already) w: 4.000000 at (14,17) - new one: Connection from M4 to I4 (0.5 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 4.500000 cect >>> Preexisting connection (279 conns already) w: 4.000000 at (9,19) - new one: Connection from M1 to g1P (0.5 times, type: Chemical, neurotransmitter: Generic_CS)... cect >>> ++++ New, appended weight is: 4.500000 cect >>> Preexisting connection (324 conns already) w: 1.000000 at (0,0) - new one: Connection from M5 to M5 (1 times, type: GapJunction, neurotransmitter: Generic_GJ)... cect >>> ++++ New, appended weight is: 2.000000 cect >>> Preexisting connection (330 conns already) w: 1.000000 at (14,14) - new one: Connection from M4 to M4 (1 times, type: GapJunction, neurotransmitter: Generic_GJ)... cect >>> ++++ New, appended weight is: 2.000000 cect >>> Preexisting connection (490 conns already) w: 3.000000 at (60,49) - new one: Connection from mc1DR to pm4VR (3 times, type: GapJunction, neurotransmitter: Generic_GJ)... cect >>> ++++ New, appended weight is: 6.000000 cect >>> Preexisting connection (491 conns already) w: 3.000000 at (49,60) - new one: Connection from pm4VR to mc1DR (3 times, type: GapJunction, neurotransmitter: Generic_GJ)... cect >>> ++++ New, appended weight is: 6.000000 cect >>> -- Registering connectome dataset: Cook2020 cect >>> -- Registering connectome dataset: Brittin cect >>> -- Registering connectome dataset: RipollSanchezShortRangeReader cect >>> -- Registering connectome dataset: RipollSanchezMidRangeReader cect >>> -- Registering connectome dataset: RipollSanchezLongRangeReader cect >>> -- Registering connectome dataset: Yim2024 cect >>> -- Registering connectome dataset: Yim2024NonNorm cect >>> Opened the Excel file for Ripoll Sanchez et al: /Users/padraig/git/ConnectomeToolbox/cect/readers/../data/1-s2.0-S0896627323007560-mmc7.xlsx
3) Specify connectome datasets to use, views to examine, and extract symmetry info¶
In [3]:
Copied!
datasets = ["Witvliet1", "Witvliet2", "Witvliet3", "Witvliet4", "Witvliet5", \
"Witvliet6", "Yim2024", "White_L4", "Witvliet7", "Witvliet8", "Cook2019Herm"]
views = ["SensorySomaticH", "MotorSomaticH", "InterneuronsSomaticH", "Neurons"]
synclass = "Chemical"
symmetries = {} # to store the percentage of symmetric connections
for dataset_name in datasets:
cds = get_connectome_dataset(dataset_name, from_cache=True)
for view in views:
v = get_view(view) # get the ConnectomeView object for the current view name
if v.name not in symmetries: symmetries[v.name] = []
cds_view = cds.get_connectome_view(v)
conns, percentage, sym_info = convert_to_symmetry_array(cds_view, [synclass])
symmetries[v.name].append(percentage)
datasets = ["Witvliet1", "Witvliet2", "Witvliet3", "Witvliet4", "Witvliet5", \
"Witvliet6", "Yim2024", "White_L4", "Witvliet7", "Witvliet8", "Cook2019Herm"]
views = ["SensorySomaticH", "MotorSomaticH", "InterneuronsSomaticH", "Neurons"]
synclass = "Chemical"
symmetries = {} # to store the percentage of symmetric connections
for dataset_name in datasets:
cds = get_connectome_dataset(dataset_name, from_cache=True)
for view in views:
v = get_view(view) # get the ConnectomeView object for the current view name
if v.name not in symmetries: symmetries[v.name] = []
cds_view = cds.get_connectome_view(v)
conns, percentage, sym_info = convert_to_symmetry_array(cds_view, [synclass])
symmetries[v.name].append(percentage)
4) Plot bilateral symmetry across datasets¶
In [4]:
Copied!
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(10, 5))
ax.set_ylabel("Symmetry (%)", fontsize=12)
for view in symmetries:
ax.plot(datasets, symmetries[view], marker="o", linestyle="-", \
label=view, linewidth=3 if view == "Neurons" else 1,)
plt.setp(ax.get_xticklabels(), rotation=45, ha="right")
ax.legend()
plt.show()
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(10, 5))
ax.set_ylabel("Symmetry (%)", fontsize=12)
for view in symmetries:
ax.plot(datasets, symmetries[view], marker="o", linestyle="-", \
label=view, linewidth=3 if view == "Neurons" else 1,)
plt.setp(ax.get_xticklabels(), rotation=45, ha="right")
ax.legend()
plt.show()