Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randi et al. 2023 Func connectome reader #18

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ __pycache__
/cect/.DS_Store
/.DS_Store
/cect/data/~$*
/pdfs/*.pdf
65 changes: 59 additions & 6 deletions cect/Cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
from cect.WormAtlasInfo import WA_COLORS
from cect import print_


ALL_KNOWN_CHEMICAL_NEUROTRANSMITTERS = [
"Acetylcholine",
"Acetylcholine_Tyramine",
"Dopamine",
"FMRFamide",
"GABA",
"Glutamate",
"Octapamine",
"Serotonin",
"Serotonin_Acetylcholine",
"Serotonin_Glutamate",
]

cell_notes = {}

connectomes = None
Expand Down Expand Up @@ -1410,6 +1424,42 @@
MALE_RAY_STRUCTURAL_CELLS + PROCTODEUM_CELL + GONAD_CELL
)

ALL_PREFERRED_CELL_NAMES = (
PREFERRED_NEURON_NAMES + PREFERRED_MUSCLE_NAMES + KNOWN_OTHER_CELLS
)


def is_bilateral_left(cell):
if (
cell in ALL_PREFERRED_CELL_NAMES
and cell.endswith("L")
and cell[:-1] + "R" in ALL_PREFERRED_CELL_NAMES
):
return True
else:
return False


def is_bilateral_right(cell):
if (
cell in ALL_PREFERRED_CELL_NAMES
and cell.endswith("R")
and cell[:-1] + "L" in ALL_PREFERRED_CELL_NAMES
):
return True
else:
return False


def are_bilateral_pair(cell_a, cell_b):
if cell_a[:-1] == cell_b[:-1] and (
(cell_a[-1] == "L" and cell_b[-1] == "R")
or (cell_b[-1] == "L" and cell_a[-1] == "R")
):
return True
else:
return False


def get_standard_color(cell):
from cect.WormAtlasInfo import WA_COLORS
Expand Down Expand Up @@ -1645,13 +1695,15 @@ def _generate_cell_table(cell_type, cells):
print_(" - Adding table for %s" % cell_type)

syn_summaries = {
"Chemical conns in": ["Acetylcholine", "Generic_CS", "GABA"],
"Chemical conns out": ["Acetylcholine", "Generic_CS", "GABA"],
"Chemical conns in": ["Generic_CS"] + ALL_KNOWN_CHEMICAL_NEUROTRANSMITTERS,
"Chemical conns out": ["Generic_CS"] + ALL_KNOWN_CHEMICAL_NEUROTRANSMITTERS,
"Electrical conns": ["Generic_GJ"],
}

fig_md = ""

verbose = False

for syn_summary in syn_summaries:
fig = go.Figure()
fig.layout.showlegend = True
Expand All @@ -1673,10 +1725,11 @@ def _generate_cell_table(cell_type, cells):
conns_here = connectome.get_connections_from(cell, syn_type)
else:
conns_here = connectome.get_connections_to(cell, syn_type)
print_(
"Conns: %i for %s of type %s (%s)"
% (len(conns_here), cell, syn_type, syn_summary)
)
if verbose:
print_(
"Conns: %i for %s of type %s (%s)"
% (len(conns_here), cell, syn_type, syn_summary)
)
total_y += len(conns_here)

y.append(total_y)
Expand Down
63 changes: 29 additions & 34 deletions cect/Comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"Cook2019Herm": "Cook2019Herm_data",
"Cook2019Male": "Cook2019Male_data",
"Cook2020": "Cook2020_data",
"Randi2023": "Randi2023_data",
"SSData": "SSDR_data",
"UpdSSData": "UpdSSData_data",
"UpdSSData2": "UpdSSData2_data",
}

all_data[""] = [
Expand Down Expand Up @@ -64,6 +68,9 @@ def _format_json(json_str):
def get_2d_graph_markdown(reader_name, view, connectome, synclass, indent=" "):
view_name = view.name

if np.sum(connectome.connections[synclass]) == 0:
return None

fig = connectome.to_plotly_graph_fig(synclass, view)

asset_filename = "assets/%s_%s_%s_graph.json" % (
Expand All @@ -75,14 +82,6 @@ def get_2d_graph_markdown(reader_name, view, connectome, synclass, indent=" "
with open("./docs/%s" % asset_filename, "w") as asset_file:
asset_file.write(_format_json(fig.to_json()))

if np.sum(connectome.connections[synclass]) == 0:
return "\n%sNo connections of type **%s** in the **%s** for **%s**...\n" % (
indent,
synclass,
view_name,
reader_name,
)

return '\n%s```plotly\n%s---8<-- "./%s"\n%s```\n' % (
indent,
indent,
Expand All @@ -94,6 +93,9 @@ def get_2d_graph_markdown(reader_name, view, connectome, synclass, indent=" "
def get_matrix_markdown(reader_name, view, connectome, synclass, indent=" "):
view_name = view.name

if np.sum(connectome.connections[synclass]) == 0:
return None

fig = connectome.to_plotly_matrix_fig(synclass, view)

asset_filename = "assets/%s_%s_%s.json" % (
Expand All @@ -105,14 +107,6 @@ def get_matrix_markdown(reader_name, view, connectome, synclass, indent=" "):
with open("./docs/%s" % asset_filename, "w") as asset_file:
asset_file.write(_format_json(fig.to_json()))

if np.sum(connectome.connections[synclass]) == 0:
return "\n%sNo connections of type **%s** in the **%s** for **%s**...\n" % (
indent,
synclass,
view_name,
reader_name,
)

return '\n%s```plotly\n%s---8<-- "./%s"\n%s```\n' % (
indent,
indent,
Expand All @@ -121,7 +115,7 @@ def get_matrix_markdown(reader_name, view, connectome, synclass, indent=" "):
)


def generate_comparison_page(quick: bool, color_table=False):
def generate_comparison_page(quick: bool, color_table=True):
connectomes = {}
all_connectomes = {}

Expand All @@ -136,6 +130,8 @@ def generate_comparison_page(quick: bool, color_table=False):
"Witvliet1": ["cect.WitvlietDataReader1", "Witvliet_2021"],
}

readers["Randi2023"] = ["cect.WormNeuroAtlasFuncReader", "Randi_2023"]

if not quick:
readers["Witvliet2"] = ["cect.WitvlietDataReader2", "Witvliet_2021"]
readers["Witvliet3"] = ["cect.WitvlietDataReader3", "Witvliet_2021"]
Expand Down Expand Up @@ -218,28 +214,27 @@ def generate_comparison_page(quick: bool, color_table=False):
f.write('=== "%s"\n' % view.name)

for sc in view.synclass_sets:
f.write(indent + '=== "%s"\n' % sc)

if matrix:
f.write(
get_matrix_markdown(
reader_name,
view,
cv,
sc,
indent=indent + indent,
)
mkdown_fig = get_matrix_markdown(
reader_name,
view,
cv,
sc,
indent=indent + indent,
)

else:
mkdown_fig = get_2d_graph_markdown(
reader_name,
view,
cv,
sc,
indent=indent + indent,
)

if mkdown_fig is not None:
f.write(
get_2d_graph_markdown(
reader_name,
view,
cv,
sc,
indent=indent + indent,
)
indent + '=== "%s"\n%s\n' % (sc, mkdown_fig)
)

cell_types = {
Expand Down
Loading