Skip to content

Commit

Permalink
Merge pull request #28 from pgleeson/main
Browse files Browse the repository at this point in the history
Cells pages
  • Loading branch information
pgleeson authored Nov 1, 2024
2 parents b478b23 + 2d8e765 commit 6e41f2a
Show file tree
Hide file tree
Showing 69 changed files with 3,175 additions and 2,349 deletions.
648 changes: 648 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

201 changes: 201 additions & 0 deletions cect/CellInfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
from cect.Cells import ALL_PREFERRED_CELL_NAMES
from cect.Cells import GENERIC_CHEM_SYN
from cect.Cells import GENERIC_ELEC_SYN

from cect.Cells import get_cell_notes
from cect.Cells import get_cell_internal_link
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 import print_
# from pprint import pprint

import pandas as pd

pd.options.plotting.backend = "plotly"


def get_dataset_link(dataset):
# return dataset+'--'
dataset_text = dataset.replace("Herm", " Herm").replace("Male", " Male")
return f'<a href="../{dataset}_data">{dataset_text}</a>'


def get_weight_table_markdown(w):
ww = {}
tot_conns = 0

for dataset in w:
# print(dataset)
# print(w[dataset].values())
if (
len(w[dataset]) > 0
and sum(w[dataset].values()) > 0
and "SSData" not in dataset
):
ww[dataset] = w[dataset]
tot_conns += sum(w[dataset].values())

if tot_conns == 0:
return "No connections found!"

sort_by = (
get_dataset_link("Cook2019Herm")
if get_dataset_link("Cook2019Herm") in ww
else get_dataset_link("White_whole")
if get_dataset_link("White_whole") in ww
else get_dataset_link("Randi2023")
if get_dataset_link("Randi2023") in ww
else get_dataset_link("RipollSanchezShortRange")
if get_dataset_link("RipollSanchezShortRange") in ww
else list(ww.keys())[0]
)

# print_("Sorting the following data by %s" % sort_by)
# pprint(ww)

df_all = pd.DataFrame(ww).fillna(0).sort_values(sort_by, ascending=False)

if df_all is not None:
fig = df_all.plot(
labels=dict(index="Connection", value="Weight", variable="Dataset")
)
fig.update_traces(
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"
else:
fig_md = ""

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


def generate_cell_info_pages(connectomes):
for cell in ALL_PREFERRED_CELL_NAMES:
cell_info = '---\ntitle: "Cell: %s"\n---\n\n' % cell

cell_info += "**%s**\n\n" % (get_cell_notes(cell))
cell_info += "%s " % (
get_cell_wormatlas_link(cell, text="Info on WormAtlas", button=True)
)

cell_info += "%s\n\n" % get_cell_osbv1_link(
cell, text="View in 3D on Open Source Brain", button=True
)
all_synclasses = [
GENERIC_CHEM_SYN,
GENERIC_ELEC_SYN,
] # ensure these 2 are at the start...

for cds_name in connectomes:
cds = connectomes[cds_name]
for synclass in cds.connections:
if synclass not in all_synclasses:
all_synclasses.append(synclass)

for synclass in all_synclasses:
synclass_info = synclass
if synclass == GENERIC_CHEM_SYN:
synclass_info = "Chemical synaptic"
if synclass == GENERIC_ELEC_SYN:
synclass_info = "Electrical synaptic"

cell_link = get_cell_internal_link(
cell, html=True, use_color=True, individual_cell_page=True
)
header = "### %s connections %s %s { data-search-exclude }\n\n" % (
synclass_info,
"from" if not synclass == GENERIC_ELEC_SYN else "from/to",
cell_link,
)

w = {}
for cds_name in connectomes:
r_name = get_dataset_link(cds_name)
w[r_name] = {}
cds = connectomes[cds_name]

connection_symbol = "↔" if synclass == GENERIC_ELEC_SYN else "→"
if synclass in cds.connections:
conns = cds.get_connections_from(cell, synclass)
for c in conns:
cc = get_cell_internal_link(
c, html=True, use_color=True, individual_cell_page=True
)
template = (
"<b><i>%s%s%s</i></b>"
if cell == c
else (
"<b>%s%s%s</b>"
if are_bilateral_pair(cell, c)
else "%s%s%s"
)
)
w[r_name][template % (cell_link, connection_symbol, cc)] = (
conns[c]
)

w_md = get_weight_table_markdown(w)

if "No connections" not in w_md:
cell_info += "%s\n%s\n\n" % (header, w_md)

if not synclass == GENERIC_ELEC_SYN:
cell_link = get_cell_internal_link(
cell, html=True, use_color=True, individual_cell_page=True
)
header = "### %s connections %s %s { data-search-exclude }\n\n" % (
synclass_info,
"to",
cell_link,
)

w = {}
for cds_name in connectomes:
r_name = get_dataset_link(cds_name)
w[r_name] = {}

cds = connectomes[cds_name]
if synclass in cds.connections:
conns = cds.get_connections_to(cell, synclass)
for c in conns:
cc = get_cell_internal_link(
c, html=True, use_color=True, individual_cell_page=True
)
template = (
"<b><i>%s→%s</i></b>"
if cell == c
else (
"<b>%s→%s</b>"
if are_bilateral_pair(cell, c)
else "%s→%s"
)
)
w[r_name][template % (cc, cell_link)] = conns[c]

w_md = get_weight_table_markdown(w)

if "No connections" not in w_md:
cell_info += "%s\n%s\n\n" % (header, w_md)

cell_filename = "docs/%s.md" % cell
with open(cell_filename, "w") as cell_file:
print_(f"Writing info on cell {cell} to {cell_filename}")
cell_file.write(cell_info)


if __name__ == "__main__":
from cect.White_whole import get_instance

cds_white = get_instance()

from cect.WitvlietDataReader8 import get_instance

cds_w8 = get_instance()

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

generate_cell_info_pages(connectomes)
52 changes: 39 additions & 13 deletions cect/Cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
connectomes = None


def get_cell_notes(cell):
desc = cell_notes[cell] if cell in cell_notes else "???"
desc = desc[0].upper() + desc[1:]
return desc


SENSORY_NEURONS_1_COOK = [
"IL2DL",
"IL2DR",
Expand Down Expand Up @@ -1467,10 +1473,10 @@ def get_SIM_class(cell):
PROVISIONAL method to return whether a cell is Sensory/Interneuron/Motorneuron (or Other)
Parameters:
cell: which cell to assess
cell: which cell to assess
Returns:
str: whether a cell is Sensory/Interneuron/Motorneuron (or Other)
str: whether a cell is Sensory/Interneuron/Motorneuron (or Other)
"""

pharyngeal_polymodal_to_class_motor = [
Expand Down Expand Up @@ -1832,9 +1838,14 @@ def get_short_description(cell):
"""


def get_cell_internal_link(cell_name, html=False, text=None, use_color=False):
def get_cell_internal_link(
cell_name, html=False, text=None, use_color=False, individual_cell_page=False
):
url = "../Cells/index.html#%s" % cell_name

if individual_cell_page:
url = "../%s" % cell_name

if html:
link_text = cell_name if text is None else text
if use_color:
Expand All @@ -1854,7 +1865,15 @@ def get_cell_internal_link(cell_name, html=False, text=None, use_color=False):
)


def get_cell_link(cell_name, html=False, text=None):
def get_cell_osbv1_link(cell, text="OSB 3D", button=False):
osbv1_link = f"https://v1.opensourcebrain.org/projects/c302/repository/revisions/development/show/examples/cells?explorer=https%253A%252F%252Fraw.githubusercontent.com%252Fopenworm%252Fc302%252Fdevelopment%252Fexamples%252Fcells%252F{cell}.cell.nml"

if button:
return f"[{text}]({osbv1_link}){{ .md-button }}" if is_herm_neuron(cell) else ""
return f'<a href="{osbv1_link}">{text}</a>' if is_herm_neuron(cell) else ""


def get_cell_wormatlas_link(cell_name, html=False, text=None, button=False):
url = None

known_other = {
Expand Down Expand Up @@ -1965,7 +1984,7 @@ def get_cell_link(cell_name, html=False, text=None):
except Exception as err:
error = err

print(
print_(
"URL for %s (%s): %s"
% (cell_name, url, "SUCCESS" if error is None else "ERROR (%s)" % error)
)
Expand All @@ -1974,6 +1993,11 @@ def get_cell_link(cell_name, html=False, text=None):

if html:
return '<a href="%s">%s</a>' % (url, cell_name if text is None else text)
elif button:
return "[%s](%s){ .md-button }" % (
cell_name if text is None else text,
url,
)
else:
return "[%s](%s)" % (cell_name if text is None else text, url)
else:
Expand Down Expand Up @@ -2082,16 +2106,14 @@ def _generate_cell_table(cell_type, cells):
if cell in conn.nodes:
datasets += "%s, " % _get_dataset_link(reader_name)

osbv1_link = f"https://v1.opensourcebrain.org/projects/c302/repository/revisions/development/show/examples/cells?explorer=https%253A%252F%252Fraw.githubusercontent.com%252Fopenworm%252Fc302%252Fdevelopment%252Fexamples%252Fcells%252F{cell}.cell.nml"
all_data[f'<a name="{cell}"></a>{cell}'] = [
cell_link = get_cell_internal_link(
cell, html=True, use_color=True, individual_cell_page=True
)
all_data[f'<a name="{cell}"></a>{cell_link}'] = [
desc,
datasets[:-2],
get_cell_link(cell, text="WormAtlas")
+ (
f'<br/><a href="{osbv1_link}">OSB 3D</a>'
if is_herm_neuron(cell)
else ""
),
get_cell_wormatlas_link(cell, text="WormAtlas")
+ ("<br/>%s" % get_cell_osbv1_link(cell)),
]

df_all = pd.DataFrame(all_data).transpose()
Expand All @@ -2116,6 +2138,10 @@ def _generate_cell_table(cell_type, cells):

connectomes = generate_comparison_page(quick)

from cect.CellInfo import generate_cell_info_pages

generate_cell_info_pages(connectomes)

filename = "docs/Cells.md"

with open(filename, "w") as f:
Expand Down
25 changes: 20 additions & 5 deletions cect/Comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,15 @@ def generate_comparison_page(quick: bool, color_table=True):
if not quick:
readers["Bentley2016_MA"] = ["cect.WormNeuroAtlasMAReader", "Bentley_2016"]
readers["Bentley2016_PEP"] = ["cect.WormNeuroAtlasPepReader", "Bentley_2016"]
readers["Cook2019Herm"] = ["cect.Cook2019HermReader", "Cook_2019"]

readers["Cook2019Herm"] = ["cect.Cook2019HermReader", "Cook_2019"]

if not quick:
readers["Cook2019Male"] = ["cect.Cook2019MaleReader", "Cook_2019"]
readers["Cook2020"] = ["cect.Cook2020DataReader", "Cook_2020"]

readers["Cook2020"] = ["cect.Cook2020DataReader", "Cook_2020"]

if not quick:
readers["Witvliet1"] = ["cect.WitvlietDataReader1", "Witvliet_2021"]
readers["Witvliet2"] = ["cect.WitvlietDataReader2", "Witvliet_2021"]
readers["Witvliet3"] = ["cect.WitvlietDataReader3", "Witvliet_2021"]
Expand All @@ -176,8 +181,10 @@ def generate_comparison_page(quick: bool, color_table=True):

if not quick:
readers["WormNeuroAtlas"] = ["cect.WormNeuroAtlasReader", "Randi_2023"]

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

if not quick:
readers["RipollSanchezShortRange"] = [
"cect.RipollSanchezShortRangeReader",
"RipollSanchez_2023",
Expand Down Expand Up @@ -260,7 +267,10 @@ def generate_comparison_page(quick: bool, color_table=True):
hiveplot = "hiveplot" in filename
matrix = not graph and not hiveplot

f.write('---\ntitle: "Dataset: %s"\n---\n\n' % reader_name)
f.write(
'---\ntitle: "Dataset: %s"\nsearch:\n exclude: true\n---\n\n'
% reader_name
)

desc_full = ""

Expand Down Expand Up @@ -442,7 +452,10 @@ def generate_comparison_page(quick: bool, color_table=True):
"%s"
% (
get_cell_internal_link(
n, html=True, use_color=True
n,
html=True,
use_color=True,
individual_cell_page=True,
)
)
)
Expand Down Expand Up @@ -539,6 +552,7 @@ def generate_comparison_page(quick: bool, color_table=True):
better_name = (
reader_name.replace("_", " ")
.replace("201", " 201")
.replace("202", " 202")
.replace("chez", "chez ")
.replace("19", "19 ")
.replace("liet", "liet ")
Expand All @@ -548,7 +562,7 @@ def generate_comparison_page(quick: bool, color_table=True):
table_html += f' <th style={STYLE}><span style="font-size:150%">{better_name}</span></th>\n'

for group in COOK_GROUPING_1:
table_html += f' <tr>\n<td ><b><span style="font-size:150%">{group}</span></b></th>\n'
table_html += f' <tr>\n<td><b><span style="font-size:150%;text-align:center;padding:3px;">{group}</span></b></th>\n'

for reader_name in readers_to_include:
connectome = all_connectomes[reader_name]
Expand All @@ -560,6 +574,7 @@ def generate_comparison_page(quick: bool, color_table=True):
text=VERTICAL_ELLIPSE,
html=True,
use_color=True,
individual_cell_page=True,
)
else:
pass # cells_here+='<s>%s</s>&nbsp;'%cell
Expand Down
Loading

0 comments on commit 6e41f2a

Please sign in to comment.