File size: 2,879 Bytes
aecbd27 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 | """Structural check of the three input -> readout chains in MaleCNS v1.0.
Counts direct synapses and a crude two-hop estimate (sum over intermediate
neurons of in-count x out-count, signed by the intermediate's transmitter)
from each stimulated LC population to each descending-neuron readout.
This is a pre-simulation sanity check, not a substitute for the chain tests.
Usage: python -I connectome_paths.py <dir with the three MaleCNS feather files>
"""
import sys
import numpy as np
import pandas as pd
import pyarrow as pa
import pyarrow.compute as pc
import pyarrow.feather as pf
SOURCES = ["LC4", "LC16", "LC9"]
READOUTS = ["DNp01", "MDN", "DNp09"]
SIGN = {"acetylcholine": 1, "gaba": -1, "glutamate": -1, "histamine": -1}
def main(d: str) -> None:
ann = pf.read_table(
f"{d}/body-annotations-male-cns-v1.0-minconf-0.5.feather",
columns=["bodyId", "type", "status"],
).to_pandas()
ann = ann[ann.status == "Traced"]
nt = (
pf.read_table(
f"{d}/body-neurotransmitters-male-cns-v1.0.feather",
columns=["body", "consensus_nt", "predicted_nt"],
)
.to_pandas()
.set_index("body")
)
nt_of = nt.consensus_nt.fillna(nt.predicted_nt)
traced = set(ann.bodyId)
type_of = ann.set_index("bodyId").type
ids = {t: set(ann.bodyId[ann.type == t]) for t in SOURCES + READOUTS}
w = pf.read_table(
f"{d}/connectome-weights-male-cns-v1.0-minconf-0.5.feather", memory_map=True
)
all_src = pa.array(list(set().union(*(ids[t] for t in SOURCES))))
all_dst = pa.array(list(set().union(*(ids[t] for t in READOUTS))))
into = w.filter(pc.is_in(w.column("body_post"), all_dst)).to_pandas()
out = w.filter(pc.is_in(w.column("body_pre"), all_src)).to_pandas()
into = into[into.body_pre.isin(traced)]
out = out[out.body_post.isin(traced)]
for s in SOURCES:
for t in READOUTS:
direct = into[into.body_pre.isin(ids[s]) & into.body_post.isin(ids[t])].weight.sum()
o = out[out.body_pre.isin(ids[s])].groupby("body_post").weight.sum()
i = into[into.body_post.isin(ids[t])].groupby("body_pre").weight.sum()
mids = o.index.intersection(i.index)
sg = np.array([SIGN.get(str(nt_of.get(m, "")).lower(), 0) for m in mids])
val = o[mids].values * i[mids].values
top = (
pd.Series(val * sg, index=[type_of.get(m, "?") for m in mids])
.groupby(level=0)
.sum()
.sort_values()
)
print(
f"{s:5}->{t:6} direct={direct:6} 2hop_mids={len(mids):4} "
f"exc={val[sg > 0].sum():.3g} inh={val[sg < 0].sum():.3g} "
f"top+={list(top.tail(3).index)} top-={list(top.head(2).index)}"
)
if __name__ == "__main__":
main(sys.argv[1])
|