Skip to content

Commit

Permalink
Merge pull request #29 from pgleeson/main
Browse files Browse the repository at this point in the history
Improved cell pages
  • Loading branch information
pgleeson authored Nov 5, 2024
2 parents 6e41f2a + 6d64b66 commit 018d751
Show file tree
Hide file tree
Showing 8 changed files with 1,553 additions and 17 deletions.
67 changes: 65 additions & 2 deletions cect/CellInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
from cect.Cells import get_cell_wormatlas_link
from cect.Cells import get_cell_osbv1_link
from cect.Cells import are_bilateral_pair
from cect.Cells import is_any_neuron
from cect.Cells import get_primary_classification


from cect import print_
# from pprint import pprint

import pandas as pd
import csv

pd.options.plotting.backend = "plotly"

Expand Down Expand Up @@ -66,18 +69,77 @@ def get_weight_table_markdown(w):
marker=dict(size=4), marker_symbol="circle", mode="lines+markers"
)
indent = ""
fig_md = f"\n{indent}<br/>\n{indent}```plotly\n{indent}{fig.to_json()}\n{indent}```\n"
fig_md = f"\n{indent}```plotly\n{indent}{fig.to_json()}\n{indent}```\n"
else:
fig_md = ""

return "%s\n\n%s" % (df_all.to_markdown(), fig_md)


def load_individual_neuron_info():
# From https://wormatlas.org/neurons/Individual%20Neurons/Neuronframeset.html
filename = "cect/data/IndividualNeurons.csv"
cell_info = {}
with open(filename) as csvfile:
reader = csv.reader(csvfile, delimiter=";")
print(reader)

for row in reader:
print(", ".join(row))
if not row[0].startswith("#"):
cell_info[row[0]] = (row[1].strip(), row[2].strip(), row[3].strip())

return cell_info


def generate_cell_info_pages(connectomes):
cell_data = load_individual_neuron_info()
cell_classification = get_primary_classification()

for cell in ALL_PREFERRED_CELL_NAMES:
print_("Generating individual cell page for: %s" % cell)

cell_info = '---\ntitle: "Cell: %s"\n---\n\n' % cell

cell_info += "**%s**\n\n" % (get_cell_notes(cell))
# TODO: investigate DX1, DX2, DX3, EF1, EF2, EF3
if is_any_neuron(cell) and "DX" not in cell and "EF" not in cell:
cell_ref = (
cell
if not (
(cell.startswith("CA") or cell.startswith("CP")) and cell[2] == "0"
)
else "%s%s" % (cell[:2], cell[-1])
) # CA04 -> CA4 etc.
ackr = cell_data[cell_ref][0]
from_ = 0
for c in cell:
# print('Replacing %s (from %s) in %s'%(c,from_,ackr))
if c in ackr:
ii = ackr.index(c, from_)
ackr = "%s<b>%s</b>%s" % (ackr[:ii], ackr[ii], ackr[ii + 1 :])
from_ = ii + 1

cell_info += "**%s**\n\n" % (cell_data[cell_ref][2])
cell_info += '<p class="subtext">%s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' % (
ackr
)
cell_info += "Lineage: <b>%s</b></p>\n\n" % (cell_data[cell_ref][1])
else:
cell_info += "**%s**\n\n" % (get_cell_notes(cell))

cell_info += (
'<p class="subtext"><a href="../Cook_2019">Cook 2019</a> classification: <b>%s</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
% (get_cell_notes(cell))
)
cc = cell_classification[cell]
cell_info += (
'All cells of type: <a href="../Cells/#%s"><b>%s</b></a></p>\n\n'
% (
cc.replace(" ", "-").replace("(", "").replace(")", ""),
cc[0].upper() + cc[1:],
)
)

cell_info += "%s " % (
get_cell_wormatlas_link(cell, text="Info on WormAtlas", button=True)
)
Expand Down Expand Up @@ -198,4 +260,5 @@ def generate_cell_info_pages(connectomes):

connectomes = {"White_whole": cds_white, "Witvliet8": cds_w8}

# load_individual_neuron_info()
generate_cell_info_pages(connectomes)
231 changes: 222 additions & 9 deletions cect/Cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,14 +1109,6 @@ def get_cell_notes(cell):

VULVAL_MUSCLE_NAMES = [
"MVULVA",
"um2AL",
"um2AR",
"um1AL",
"um1AR",
"um1PL",
"um1PR",
"um2PL",
"um2PR",
"vm1AL",
"vm1PL",
"vm1PR",
Expand All @@ -1129,6 +1121,19 @@ def get_cell_notes(cell):
for cell in VULVAL_MUSCLE_NAMES:
cell_notes[cell] = "vulval muscle"

UTERINE_MUSCLE_NAMES = [
"um2AL",
"um2AR",
"um1AL",
"um1AR",
"um1PL",
"um1PR",
"um2PL",
"um2PR",
]
for cell in UTERINE_MUSCLE_NAMES:
cell_notes[cell] = "uterine muscle"

ODD_PHARYNGEAL_MUSCLE_NAMES = [
"pm1",
"pm3D",
Expand Down Expand Up @@ -1308,6 +1313,7 @@ def get_cell_notes(cell):
BODY_WALL_MUSCLE_NAMES
+ PHARYNGEAL_MUSCLE_NAMES
+ VULVAL_MUSCLE_NAMES
+ UTERINE_MUSCLE_NAMES
+ ANAL_SPHINCTER_MUSCLES
+ MALE_SPECIFIC_MUSCLES
+ INTESTINAL_MUSCLES
Expand All @@ -1319,6 +1325,7 @@ def get_cell_notes(cell):
COOK_GROUPING_1["Other muscles"] = (
PHARYNGEAL_MUSCLE_NAMES
+ VULVAL_MUSCLE_NAMES
+ UTERINE_MUSCLE_NAMES
+ ANAL_SPHINCTER_MUSCLES
+ UNSPECIFIED_BODY_WALL_MUSCLES
)
Expand All @@ -1343,7 +1350,7 @@ def get_cell_notes(cell):
]

for cell in CEPSH_CELLS:
cell_notes[cell] = "glial"
cell_notes[cell] = "sheath cell other than amphid sheath and phasmid"

GLIAL_CELLS = GLR_CELLS + CEPSH_CELLS

Expand Down Expand Up @@ -1464,6 +1471,172 @@ def get_cell_notes(cell):
)


def get_primary_classification():
classification = {}

for sex in WA_COLORS:
for cell_class in WA_COLORS[sex]:
for cell_type in WA_COLORS[sex][cell_class]:
print_(" - %s/%s/%s" % (sex, cell_class, cell_type))

if cell_type == "body wall muscle":
for cell in BODY_WALL_MUSCLE_NAMES + UNSPECIFIED_BODY_WALL_MUSCLES:
classification[cell] = cell_type
elif cell_type == "vulval muscle":
for cell in VULVAL_MUSCLE_NAMES:
classification[cell] = cell_type
elif cell_type == "uterine muscle":
for cell in UTERINE_MUSCLE_NAMES:
classification[cell] = cell_type
elif cell_type == "interneuron":
for cell in (
INTERNEURONS_COOK + MALE_HEAD_INTERNEURONS + MALE_INTERNEURONS
):
classification[cell] = cell_type
elif cell_type == "motor neuron":
for cell in MOTORNEURONS_COOK:
classification[cell] = cell_type
elif cell_type == "sensory neuron":
for cell in (
SENSORY_NEURONS_COOK
+ MALE_HEAD_SENSORY_NEURONS
+ MALE_SENSORY_NEURONS
):
classification[cell] = cell_type
elif cell_type == "odd numbered pharyngeal muscle":
for cell in ODD_PHARYNGEAL_MUSCLE_NAMES:
classification[cell] = cell_type
elif cell_type == "even numbered pharyngeal muscle":
for cell in EVEN_PHARYNGEAL_MUSCLE_NAMES:
classification[cell] = cell_type
elif cell_type == "polymodal neuron":
for cell in PHARYNGEAL_POLYMODAL_NEURONS:
classification[cell] = cell_type
elif cell_type == "marginal cells (mc) of the pharynx":
for cell in PHARYNGEAL_MARGINAL_CELLS:
classification[cell] = cell_type
elif cell_type == "pharyngeal epithelium":
for cell in PHARYNGEAL_EPITHELIUM + PHARYNGEAL_GLIAL_CELL:
classification[cell] = cell_type # TODO: check!
elif cell_type == "basement membrane":
for cell in PHARYNGEAL_BASEMENT_MEMBRANE:
classification[cell] = cell_type # TODO: check!
elif cell_type == "neuron with unknown function":
for cell in UNKNOWN_FUNCTION_NEURONS:
classification[cell] = cell_type
elif cell_type == "sheath cell other than amphid sheath and phasmid":
for cell in CEPSH_CELLS:
classification[cell] = cell_type
elif cell_type == "excretory cell":
for cell in EXCRETORY_CELL:
classification[cell] = cell_type
elif cell_type == "sphincter and anal depressor muscle":
for cell in ANAL_SPHINCTER_MUSCLES:
classification[cell] = cell_type
elif cell_type == "gland cell":
for cell in EXCRETORY_GLAND:
classification[cell] = cell_type
elif cell_type == "head mesodermal cell":
for cell in HEAD_MESODERMAL_CELL:
classification[cell] = cell_type
elif cell_type == "hypodermis":
for cell in HYPODERMIS:
classification[cell] = cell_type
elif cell_type == "intestinal cells":
for cell in INTESTINE:
classification[cell] = cell_type
elif cell_type == "intestinal muscle":
for cell in INTESTINAL_MUSCLES:
classification[cell] = cell_type
elif cell_type == "GLR cell":
for cell in GLR_CELLS:
classification[cell] = cell_type
elif cell_type == "diagonal muscles":
for cell in MALE_DIAGONAL_MUSCLES:
classification[cell] = cell_type
elif cell_type == "posterior outer longitudinal muscles":
for cell in MALE_POSTERIOR_OUTER_LONGITUDINAL_MUSCLES:
classification[cell] = cell_type
elif cell_type == "anterior inner longitudinal muscles":
for cell in MALE_ANTERIOR_INNER_LONGITUDINAL_MUSCLES:
classification[cell] = cell_type
elif cell_type == "posterior inner longitudinal muscles":
for cell in MALE_POSTERIOR_INNER_LONGITUDINAL_MUSCLES:
classification[cell] = cell_type
elif cell_type == "caudal inner longitudinal muscles":
for cell in MALE_CAUDAL_LONGITUDINAL_MUSCLES:
classification[cell] = cell_type
elif cell_type == "spicule retractor muscles":
for cell in (
MALE_VENTRAL_SPICULE_RETRACTOR + MALE_DORSAL_SPICULE_RETRACTOR
):
classification[cell] = cell_type
elif cell_type == "spicule protractor muscles":
for cell in (
MALE_VENTRAL_SPICULE_PROTRACTOR + MALE_DORSAL_SPICULE_PROTRACTOR
):
classification[cell] = cell_type
elif cell_type == "gubernacular retractor muscles":
for cell in MALE_GUBERNACULAR_RETRACTOR_MUSCLES:
classification[cell] = cell_type
elif cell_type == "gubernacular erector muscles":
for cell in MALE_GUBERNACULAR_ERECTOR_MUSCLES:
classification[cell] = cell_type
elif cell_type == "anterior oblique muscles":
for cell in MALE_ANTERIOR_OBLIQUE_MUSCLES:
classification[cell] = cell_type
elif cell_type == "posterior oblique muscles":
for cell in MALE_POSTERIOR_OBLIQUE_MUSCLES:
classification[cell] = cell_type
elif cell_type == "vas deferens":
for cell in GONAD_CELL:
classification[cell] = cell_type
elif cell_type == "proctodeum":
for cell in PROCTODEUM_CELL:
classification[cell] = cell_type
elif cell_type == "diagonal muscles":
for cell in MALE_DIAGONAL_MUSCLES:
classification[cell] = cell_type
elif cell_type == "ray structural cell":
for cell in MALE_RAY_STRUCTURAL_CELLS:
classification[cell] = cell_type
elif cell_type in [
"General code for neuronal tissue if subtype is unspecified",
"vulval epithelium",
"germline",
"DTC and somatic gonad",
"embryo",
"uterus",
"spermatheca",
"spermatheca-uterine valve",
"excretory pore cell",
"duct cell",
"excretory duct",
"seam cell",
"socket cell, XXX cells",
"amphid sheath and phasmid sheath",
"pharyngeal-intestinal valve, intestinal rectal valve",
"arcade cell",
"rectal epithelium (U, F, K, K', Y, B)",
"rectal gland, pharyngeal glands",
"pseudocoelomic space",
"coeloemocyte",
"anterior outer longitudinal muscles",
"seminal vesicle",
"sheath cell (spicules, hook or post-cloacal sensilla)",
"socket cell (spicules, hook or post-cloacal sensilla)",
]:
print_(
"No synaptic connnections to cells of type %s..?" % cell_type
)
else:
raise Exception("Cell type %s not handled" % cell_type)
for cell in ALL_PREFERRED_CELL_NAMES:
assert cell in classification

return classification


def is_known_cell(cell):
return cell in ALL_PREFERRED_CELL_NAMES

Expand Down Expand Up @@ -1705,6 +1878,8 @@ def get_standard_color(cell):
return WA_COLORS["Hermaphrodite"]["Muscle"]["body wall muscle"]
elif cell in VULVAL_MUSCLE_NAMES:
return WA_COLORS["Hermaphrodite"]["Muscle"]["vulval muscle"]
elif cell in UTERINE_MUSCLE_NAMES:
return WA_COLORS["Hermaphrodite"]["Muscle"]["uterine muscle"]
elif cell in ODD_PHARYNGEAL_MUSCLE_NAMES:
return WA_COLORS["Hermaphrodite"]["Muscle"]["odd numbered pharyngeal muscle"]
elif cell in EVEN_PHARYNGEAL_MUSCLE_NAMES:
Expand Down Expand Up @@ -1906,6 +2081,9 @@ def get_cell_wormatlas_link(cell_name, html=False, text=None, button=False):
elif cell_name in VULVAL_MUSCLE_NAMES:
url = "https://www.wormatlas.org/hermaphrodite/egglaying%20apparatus/Eggframeset.html"

elif cell_name in UTERINE_MUSCLE_NAMES:
url = "https://www.wormatlas.org/hermaphrodite/egglaying%20apparatus/jump.html?newLink=mainframe.htm&newAnchor=Theuterus2"

elif cell_name in ANAL_SPHINCTER_MUSCLES:
url = "https://www.wormatlas.org/hermaphrodite/excretory/Excframeset.html"

Expand Down Expand Up @@ -2165,6 +2343,10 @@ def _generate_cell_table(cell_type, cells):
f.write(
_generate_cell_table(cell_type, VULVAL_MUSCLE_NAMES)
)
elif cell_type == "uterine muscle":
f.write(
_generate_cell_table(cell_type, UTERINE_MUSCLE_NAMES)
)
elif cell_type == "interneuron":
f.write(
_generate_cell_table(
Expand Down Expand Up @@ -2338,3 +2520,34 @@ def _generate_cell_table(cell_type, cells):
cell_type, MALE_RAY_STRUCTURAL_CELLS
)
)
elif cell_type in [
"vulval epithelium",
"germline",
"DTC and somatic gonad",
"embryo",
"uterus",
"spermatheca",
"spermatheca-uterine valve",
"excretory pore cell",
"duct cell",
"excretory duct",
"seam cell",
"socket cell, XXX cells",
"amphid sheath and phasmid sheath",
"pharyngeal-intestinal valve, intestinal rectal valve",
"arcade cell",
"rectal epithelium (U, F, K, K', Y, B)",
"rectal gland, pharyngeal glands",
"pseudocoelomic space",
"coeloemocyte",
"anterior outer longitudinal muscles",
"seminal vesicle",
"sheath cell (spicules, hook or post-cloacal sensilla)",
"socket cell (spicules, hook or post-cloacal sensilla)",
]:
print_(
"No synaptic connnections to cells of type %s..?"
% cell_type
)
else:
raise Exception("Cell type %s not handled" % cell_type)
Loading

0 comments on commit 018d751

Please sign in to comment.