Okuno et al. (2025): connectome-only claims from the paper's deposits¶

A companion to reproduce_okuno_2025.ipynb. It tests the claims that rest on the FlyWire connectome alone (data elsewhere), or the FlyWire half of a claim, from the paper's Zenodo record 10.5281/zenodo.15532272 (version of 2025-05-28). The record holds the PPSSI the paper computed for each FlyWire neuron (data/flywire783_neuron_sepidx0sr140_3000mi1.mat, stored as int16 times 10,000, negative where no value; plotNeuralFC.m reads it so), the DBSCAN clusters behind it (results/neuralsc/wire0sr140_neuralDBScan3000mi1.mat), the closest reciprocal synapse distances (results/neuralsc/wire0sr140_reciprocalDistances.mat) and the FlyWire synapse table with locations (data/flywire783_synapse.mat, data/flywire783_sypreloc.mat, data/flywire783_sypostloc.mat). Each analysis follows the paper's code (github takuto-okuno-riken/flywalk at commit 4b92add), and the cited lines are printed from it. Cell types come from the FlyWire annotation table of Schlegel et al. (2024), Supplemental_file1_neuron_annotations.tsv of github flyconnectome/flywire_annotations at commit a83b277, which the deposits do not hold. The FlyEM halves need a hemibrain DBSCAN that is not deposited and are not tested here. No random numbers are drawn.

Claim Data Status
fig4b-ppssi-distribution elsewhere tested on the paper's per-neuron PPSSI
fig4h-reciprocal-distances elsewhere tested on the deposited reciprocal distances
fig4a-unsegregated-ranking elsewhere FlyWire half tested; FlyEM half not deposited
fig4c-segregated-ranking elsewhere FlyWire half tested; FlyEM half not deposited
figs4-1ij-segregation-index-biased elsewhere FlyWire half tested; FlyEM half not deposited
fig5-wagn elsewhere tested on the deposited PPSSI and synapse table
In [1]:
import io, warnings
import numpy as np
import scipy.io as sio
import matplotlib.pyplot as plt
import flyfc
warnings.filterwarnings("ignore")
m = sio.loadmat(io.BytesIO(flyfc.zenodo_member("data/flywire783_neuron_sepidx0sr140_3000mi1.mat")), variable_names=["Nspidx"])
nr = sio.loadmat(io.BytesIO(flyfc.zenodo_member("data/flywire783_neuron.mat")))
raw = m["Nspidx"].ravel()
print("neurons in the PPSSI table", raw.size, "| in the neuron table", nr["Nid"].size, "| stored range", raw.min(), "to", raw.max(), raw.dtype)
neurons in the PPSSI table 139255 | in the neuron table 139255 | stored range -1 to 10000 int16

fig4b-ppssi-distribution¶

Over the 139,255 FlyWire neurons the PPSSI histogram resembles a normal distribution with a mean near 0.5, so many neurons have unsegregated synapses.

Reproduced when the neuron count matches (139,255, tolerance 0) and the mean PPSSI is within 0.4 to 0.6.

In [2]:
x = raw.astype(float) / 10000
valid = x >= 0
print("neurons with a PPSSI", int(valid.sum()), "| without (stored negative)", int((~valid).sum()), "| expected 139,255")
v = x[valid]
print(f"PPSSI mean {v.mean():.4f}, median {np.median(v):.4f}, SD {v.std():.4f}, skewness {((v - v.mean())**3).mean() / v.std()**3:.3f}")
readme = flyfc.code_file("README.md").decode()
print("code README line:", [l for l in readme.splitlines() if "full separation" in l])
print("neurons with PPSSI exactly 1 (fully segregated)", int((v == 1).sum()), "| exactly 0", int((v == 0).sum()))
h, e = np.histogram(v, bins=np.arange(0, 1.0001, 0.05))
for a, b in zip(e[:-1], h):
    print(f"{a:.2f}-{a + 0.05:.2f} {b}")
plt.figure(figsize=(6, 3)); plt.bar(e[:-1] + 0.025, h, width=0.05); plt.xlabel("PPSSI"); plt.ylabel("neurons"); plt.show()
print("all", int(valid.sum()), "values in [0, 1] are shown")
neurons with a PPSSI 138144 | without (stored negative) 1111 | expected 139,255
PPSSI mean 0.4713, median 0.4511, SD 0.2354, skewness 0.433
code README line: ['full separation neuron rate=0.044548 (6154/138144)']
neurons with PPSSI exactly 1 (fully segregated) 6154 | exactly 0 70
0.00-0.05 1356
0.05-0.10 3995
0.10-0.15 6368
0.15-0.20 6405
0.20-0.25 6746
0.25-0.30 8476
0.30-0.35 10738
0.35-0.40 11854
0.40-0.45 12820
0.45-0.50 12657
0.50-0.55 11186
0.55-0.60 9556
0.60-0.65 7477
0.65-0.70 5845
0.70-0.75 4441
0.75-0.80 3533
0.80-0.85 2960
0.85-0.90 2423
0.90-0.95 2046
0.95-1.00 7262
No description has been provided for this image
all 138144 values in [0, 1] are shown

Result: partially reproduced. The table holds 139,255 neurons, the paper's count, but 1,111 of them carry no PPSSI, so 138,144 neurons have one (the README of the paper's code prints 6154/138144 for the fully segregated neurons, the same denominator). The mean PPSSI is 0.471 (median 0.451), within 0.4 to 0.6. The mean holds; the count of neurons with a PPSSI is 0.8% below the stated number, which the tolerance of 0 does not allow.

In [3]:
import csv, h5py, time
t_start = time.time()

def member(name, tries=4):
    """A member of the Zenodo zip; the range reads time out now and then, so retry before failing."""
    for k in range(tries):
        try:
            return flyfc.zenodo_member(name)
        except Exception as e:
            print("retry", name, type(e).__name__)
            flyfc._zip = None
    raise RuntimeError("could not read " + name)

def cells_of(f, name):
    """The cells of a MATLAB v7.3 cell array, None where empty, each raveled."""
    out = []
    for r in f[name][()].ravel():
        x = f[r]
        out.append(None if x.attrs.get("MATLAB_empty") else x[()])
    return out

def code_lines(path, lines):
    src = flyfc.code_file(path).decode().splitlines()
    for a, b in lines:
        for k in range(a, b + 1):
            print(f"{path}:{k}: {src[k - 1]}")

tlabels = ["Unknown", "DA", "SER", "GABA", "GLUT", "ACH", "OCT"]  # plotNeuralFC.m order of Ntype
Nid = nr["Nid"].ravel().astype(np.int64)
Ntype = nr["Ntype"].ravel()
ANN_URL = ("https://raw.githubusercontent.com/flyconnectome/flywire_annotations/"
           "a83b2776d60d5764cef36b927f5f9679c16c47a2/supplemental_files/Supplemental_file1_neuron_annotations.tsv")
ann_rows = list(csv.DictReader(io.StringIO(flyfc.requests.get(ANN_URL, timeout=300).text), delimiter="\t"))
ann = {int(r["root_id"]): r for r in ann_rows}
def ctype(nid):
    r = ann.get(int(nid))
    return "not annotated" if r is None else f"{r['cell_type']} ({r['super_class']}, {r['side']})"
print("annotation rows", len(ann_rows), "| FlyWire neurons of the deposit found there", int(np.isin(Nid, list(ann)).sum()), "of", Nid.size)
annotation rows 139248 | FlyWire neurons of the deposit found there 139241 of 139255

fig4h-reciprocal-distances¶

Reciprocal synapses are particularly abundant within 2 um, and most are cholinergic or GABAergic.

Criterion: histogram of each reciprocal pair's shortest distance (code checkReciprocalSynapseDistanceFw). Reproduced when the histogram's mode lies at or below 2 um and acetylcholine plus GABA make up more than half of the pairs.

checkReciprocalSynapseDistanceFw (makeNeuralSC.m) stores, for each neuron, the closest distance from each of its reciprocal output synapses to an input synapse from the same partner (rcpreCloseDist) and the reverse (rcpostCloseDist). showReciprocalDistanceGraphFw (plotNeuralFC.m, Figure 4h) pools both lists over all neurons and labels every entry with the transmitter of the neuron that holds the list, then bins them at 1 um up to 20 um. So each reciprocal synapse is counted once from each of its two neurons. The cell below follows that and also gives the transmitter split for the output lists alone (the presynaptic neuron's transmitter), as a second reading.

In [4]:
code_lines("plotNeuralFC.m", [(911, 922), (936, 942)])
code_lines("makeNeuralSC.m", [(1325, 1331)])
f = h5py.File(io.BytesIO(member("results/neuralsc/wire0sr140_reciprocalDistances.mat")), "r")
pre_d = cells_of(f, "rcpreCloseDist"); post_d = cells_of(f, "rcpostCloseDist")
del f
allDs, allTypes, preDs, preTypes, nrec = [], [], [], [], 0
for i in range(len(pre_d)):
    if pre_d[i] is None:  # the code skips neurons without reciprocal synapses
        continue
    nrec += 1
    a, b = pre_d[i].ravel(), post_d[i].ravel()
    allDs += [a, b]; allTypes.append(np.full(a.size + b.size, Ntype[i]))
    preDs.append(a); preTypes.append(np.full(a.size, Ntype[i]))
allDs = np.concatenate(allDs); allTypes = np.concatenate(allTypes)
preDs = np.concatenate(preDs); preTypes = np.concatenate(preTypes)
del pre_d, post_d
print("neurons with reciprocal synapses", nrec, "| entries", allDs.size, "| NaN", int(np.isnan(allDs).sum()))
h, e = np.histogram(allDs, bins=np.arange(0, 20001, 1000))  # edges = 0:1000:20000 (plotNeuralFC.m:936)
for a, c in zip(e[:-1], h):
    print(f"{a / 1000:.0f}-{a / 1000 + 1:.0f} um {c}")
m = h.argmax()
print(f"mode bin {e[m] / 1000:.0f}-{e[m + 1] / 1000:.0f} um with {h[m]} entries; second {np.sort(h)[-2]}")
h10, e10 = np.histogram(allDs, bins=np.arange(0, 600001, 10000))  # full-range edges (plotNeuralFC.m:925)
print("full-range histogram (10 um bins): mode bin", e10[h10.argmax()] / 1000, "to", e10[h10.argmax() + 1] / 1000, "um,", h10.max(), "entries")
print(f"entries within 2 um {(allDs < 2000).mean():.3f}, median distance {np.median(allDs) / 1000:.2f} um")
for name, T in [("as the code labels them (both lists, neuron holding the list)", allTypes),
                ("output lists only (presynaptic neuron)", preTypes)]:
    fr = np.bincount(T, minlength=7) / T.size
    print(name + ": " + ", ".join(f"{tlabels[k]} {fr[k]:.3f}" for k in range(7)) + f" | ACh + GABA {fr[5] + fr[3]:.3f}")
N = np.stack([np.histogram(allDs[allTypes == k], bins=e)[0] for k in range(7)], 1)
plt.figure(figsize=(6, 3)); bottom = np.zeros(len(h))
for k in range(7):
    plt.bar(e[:-1] / 1000 + 0.5, N[:, k], width=1, bottom=bottom, label=tlabels[k]); bottom += N[:, k]
plt.xlabel("closest reciprocal distance (um)"); plt.ylabel("synapse count"); plt.legend(fontsize=6); plt.show()
print("entries beyond 20 um, not in the plot:", int((allDs >= 20000).sum()))
del allDs, allTypes, preDs, preTypes, N
plotNeuralFC.m:911:     for i=1:length(Nid)
plotNeuralFC.m:912:         if isempty(rcpreSidx{i}), continue; end
plotNeuralFC.m:913: 
plotNeuralFC.m:914:         presidxs = rcpreSidx{i};         % reciprocal pre-synapse on Nid(i)
plotNeuralFC.m:915:         postsidxs = rcpostSidx{i};
plotNeuralFC.m:916:         rcDs1 = rcpreCloseDist{i};
plotNeuralFC.m:917:         rcDs2 = rcpostCloseDist{i};
plotNeuralFC.m:918:         allDs = [allDs; rcDs1; rcDs2];
plotNeuralFC.m:919: 
plotNeuralFC.m:920:         allTypes = [allTypes; ones(length(rcDs1)+length(rcDs2),1,'uint16') * Ntype(i)];
plotNeuralFC.m:921:         rcprenum = length(unique(presidxs)); rcpostnum = length(unique(postsidxs));
plotNeuralFC.m:922:     end
plotNeuralFC.m:936:     edges = 0:1000:20000;
plotNeuralFC.m:937:     N = [];
plotNeuralFC.m:938:     for i=1:length(tlabels)
plotNeuralFC.m:939:         idx = find(allTypes==(i-1));
plotNeuralFC.m:940:         h = histcounts(allDs(idx),edges);
plotNeuralFC.m:941:         N = [N, h'];
plotNeuralFC.m:942:     end
makeNeuralSC.m:1325:         % find minimum distance of pre and post (should be same reciprocal target neuron)
makeNeuralSC.m:1326:         [minD, idxD] = min(D,[],2,'omitnan');
makeNeuralSC.m:1327:         rcpreCloseDist{i} = minD;
makeNeuralSC.m:1328:         rcpreCloseSidx{i} = rcpostSidx{i}(idxD);
makeNeuralSC.m:1329: 
makeNeuralSC.m:1330:         [minD2, idxD2] = min(D,[],1,'omitnan');
makeNeuralSC.m:1331:         rcpostCloseDist{i} = minD2';
neurons with reciprocal synapses 126699 | entries 18119414 | NaN 0
0-1 um 2086812
1-2 um 2188552
2-3 um 1481035
3-4 um 1212599
4-5 um 1009802
5-6 um 831807
6-7 um 681807
7-8 um 578001
8-9 um 500906
9-10 um 443225
10-11 um 398079
11-12 um 364260
12-13 um 332960
13-14 um 306952
14-15 um 283312
15-16 um 265008
16-17 um 247669
17-18 um 233888
18-19 um 218705
19-20 um 205897
mode bin 1-2 um with 2188552 entries; second 2086812
full-range histogram (10 um bins): mode bin 0.0 to 10.0 um, 11014546 entries
entries within 2 um 0.236, median distance 6.35 um
as the code labels them (both lists, neuron holding the list): Unknown 0.068, DA 0.011, SER 0.009, GABA 0.290, GLUT 0.154, ACH 0.466, OCT 0.002 | ACh + GABA 0.756
output lists only (presynaptic neuron): Unknown 0.068, DA 0.006, SER 0.009, GABA 0.275, GLUT 0.154, ACH 0.485, OCT 0.002 | ACh + GABA 0.761
No description has been provided for this image
entries beyond 20 um, not in the plot: 4248138

Result: reproduced. Over 126,699 neurons with reciprocal synapses the deposit holds 18,119,414 closest distances. With the code's 1 um bins the mode is the 1 to 2 um bin (2,188,552 entries, ahead of 2,086,812 in the 0 to 1 um bin), at or below 2 um. Labelled as the code labels them, acetylcholine makes up 0.466 and GABA 0.290 of the entries, together 0.756; with the presynaptic neuron's transmitter alone the two make up 0.761. The histogram counts reciprocal synapses from both of their neurons, which the code does, and the claim calls pairs. Within 2 um lie 0.236 of the entries; the median distance is 6.35 um.

fig4a-unsegregated-ranking¶

The unsegregated ranking puts APL and CT1 cells in the top four places in FlyWire, and APL first in FlyEM.

Criterion: ranking by (1 - PPSSI) log10(W) (M7). Reproduced when ranks 1 to 4 in FlyWire are all APL or CT1 cells and rank 1 in FlyEM is APL.

In the code W is the neuron's synapse count in its DBSCAN clusters, synumall = sum(cmat,'all') (makeNeuralSC.m, checkSeparateIndexFw), the pre plus post synapses at cleft score 140. The scores are stored as half precision (NsywMixScore, NsywSepScore), which scipy cannot read, so they are recomputed here from the deposited DBSCAN counts and rounded to half precision as the code does; plotNeuralFC.m sorts them in descending order. The FlyEM half needs a hemibrain DBSCAN that is not deposited.

In [5]:
code_lines("makeNeuralSC.m", [(492, 496), (506, 516)])
code_lines("plotNeuralFC.m", [(333, 335), (372, 372), (395, 395)])
code_lines("plotNeuralFC.m", [(287, 303)])
f = h5py.File(io.BytesIO(member("results/neuralsc/wire0sr140_neuralDBScan3000mi1.mat")), "r")
DBcount = cells_of(f, "DBcount")
del f
n = len(DBcount)
W = np.zeros(n); P = np.full(n, np.nan); H = np.full(n, np.nan); Hconv = np.zeros(n, bool)
for i, c in enumerate(DBcount):
    if c is None:
        continue
    cm = c.T.astype(float)            # MATLAB cmat: one row per cluster, columns pre and post counts
    Ni = cm.sum(1); W[i] = cm.sum()
    P[i] = np.sum(((cm[:, 0] - cm[:, 1]) / Ni) ** 2 * (Ni / W[i]))   # makeNeuralSC.m:509-510
    with np.errstate(divide="ignore", invalid="ignore"):              # plotNeuralFC.m:291-303
        Pi = cm[:, 1] / Ni
        Si = -(Pi * np.log(Pi) + (1 - Pi) * np.log(1 - Pi)); Si[np.isnan(Si)] = 0
        S = np.sum(Ni * Si) / W[i]; Fi = np.sum(Pi * Ni) / W[i]
        Snorm = -(Fi * np.log(Fi) + (1 - Fi) * np.log(1 - Fi))
    Hconv[i] = np.isnan(Snorm)
    H[i] = 1.0 if Hconv[i] else 1 - S / Snorm
del DBcount
x = raw.astype(float) / 10000
has = raw >= 0
print("neurons with clusters", int((W > 0).sum()), "| with a stored PPSSI", int(has.sum()), "| same set", bool(np.array_equal(W > 0, has)))
print("synapses in clusters", int(W.sum()), "(README of the code prints 61553596 clustered of 61553590 valid)")
print("recomputed PPSSI against the stored int16: largest difference", np.nanmax(np.abs(np.round(P[has] * 10000) - raw[has])), "in units of 1e-4")
mix = np.where(has, ((1 - P) * np.log10(np.where(W > 0, W, 1))).astype(np.float16), np.float16(-1))
sep = np.where(has, (P * np.log10(np.where(W > 0, W, 1))).astype(np.float16), np.float16(-1))
def show(score, label):
    order = np.argsort(-score.astype(float), kind="stable")[:5]   # MATLAB sort 'descend' keeps ties in index order
    for r, k in enumerate(order, 1):
        print(f"{label} {r}) k={k + 1} nid={Nid[k]} ({tlabels[Ntype[k]]}) W={int(W[k])} PPSSI={P[k]:.4f} score={float(score[k]):.4f} | {ctype(Nid[k])}")
    return order
top_mix = show(mix, "unsegregated")
print("code README:", [l for l in flyfc.code_file("README.md").decode().splitlines() if "syMIXscore" in l])
print("code comments name 720575940613583001 APL-R and 720575940628908548 CT1-R (plotNeuralFC.m:62-63)")
makeNeuralSC.m:492:         if isempty(DBcount{i}), continue; end
makeNeuralSC.m:493: 
makeNeuralSC.m:494:         cmat = double(DBcount{i});
makeNeuralSC.m:495:         synumall = sum(cmat,'all');
makeNeuralSC.m:496: 
makeNeuralSC.m:506:         s = sum(cmat,2);
makeNeuralSC.m:507: %        spidx = sum(((cmat(:,1)-cmat(:,2))./s).^2) / size(cmat,1);    % squared version (cluster equal weight)
makeNeuralSC.m:508: %        spidx = sum(abs(cmat(:,1)-cmat(:,2))./s) / size(cmat,1);      % linear version (cluster equal weight)
makeNeuralSC.m:509:         syspidx = ((cmat(:,1)-cmat(:,2))./s).^2;
makeNeuralSC.m:510:         spidx = sum(syspidx .* (s./synumall));                         % squared version (cluster synaptic weight)
makeNeuralSC.m:511: %        spidx = abs(cmat(:,1)-cmat(:,2))./s .* (s./synumall);         % linear version (cluster synaptic weight)
makeNeuralSC.m:512:         msco = (1-spidx) * log10(synumall);       % synapse weighted mixing score
makeNeuralSC.m:513:         ssco = spidx * log10(synumall);           % synapse weighted separation score
makeNeuralSC.m:514:         Nspidx(i) = int16(round(10000 * spidx));  % reduce memory
makeNeuralSC.m:515:         NsywMixScore(i) = half(msco);
makeNeuralSC.m:516:         NsywSepScore(i) = half(ssco);
plotNeuralFC.m:333:     Nspidx(isnan(Nspidx)) = -1;
plotNeuralFC.m:334:     NsywMixScore(isnan(NsywMixScore)) = -1;
plotNeuralFC.m:335:     NsywSepScore(isnan(NsywSepScore)) = -1;
plotNeuralFC.m:372:     [dsyMdbs,dIdx] = sort(NsywMixScore,'descend');
plotNeuralFC.m:395:     [dsySdbs,dIdx] = sort(NsywSepScore,'descend');
plotNeuralFC.m:287:         Ni = sum(cmat,2);
plotNeuralFC.m:288:         Ldbs(i) = sum(abs(cmat(:,1)-cmat(:,2))./Ni .* (Ni./syCount(i,1))) ;   % linear version (cluster synaptic weight)
plotNeuralFC.m:289: 
plotNeuralFC.m:290:         % segregation index (Schneider-mizell et al., 2016)
plotNeuralFC.m:291:         Pi = cmat(:,2) ./ Ni;
plotNeuralFC.m:292:         Si = -(Pi.*log(Pi) + (1-Pi).*log(1-Pi)); % this could be NaN
plotNeuralFC.m:293:         Si(isnan(Si)) = 0; % segregated 
plotNeuralFC.m:294:         S = nansum(Ni .* Si) / syCount(i,1);
plotNeuralFC.m:295:         Fi = sum(Pi.*Ni) / syCount(i,1);
plotNeuralFC.m:296: %        Fi = syCount(i,2) / syCount(i,1);
plotNeuralFC.m:297:         Snorm = -(Fi*log(Fi) + (1-Fi)*log(1-Fi));
plotNeuralFC.m:298:         if isnan(Snorm)
plotNeuralFC.m:299:             H(i) = 1; % segregated
plotNeuralFC.m:300:         else
plotNeuralFC.m:301:             H(i) = 1 - S/Snorm;
plotNeuralFC.m:302:         end
plotNeuralFC.m:303:     end
neurons with clusters 138144 | with a stored PPSSI 138144 | same set True
synapses in clusters 61553590 (README of the code prints 61553596 clustered of 61553590 valid)
recomputed PPSSI against the stored int16: largest difference 1.0 in units of 1e-4
unsegregated 1) k=67233 nid=720575940624547622 (GABA) W=75804 PPSSI=0.0122 score=4.8203 | APL (central, left)
unsegregated 2) k=79893 nid=720575940626979621 (GABA) W=91235 PPSSI=0.0364 score=4.7812 | CT1 (optic, left)
unsegregated 3) k=17922 nid=720575940613583001 (GABA) W=71663 PPSSI=0.0217 score=4.7500 | APL (central, right)
unsegregated 4) k=91298 nid=720575940628908548 (GABA) W=90148 PPSSI=0.0448 score=4.7344 | CT1 (optic, right)
unsegregated 5) k=83187 nid=720575940627497244 (GABA) W=49577 PPSSI=0.0166 score=4.6172 | Li33 (optic, left)
code README: ['1) k=67233 nid=720575940624547622 (GABA) sycount=75804 (34221/41583;95), PPSSI=0.0122, syMIXscore=4.8203', '2) k=79893 nid=720575940626979621 (GABA) sycount=91235 (53534/37701;105), PPSSI=0.0364, syMIXscore=4.7812']
code comments name 720575940613583001 APL-R and 720575940628908548 CT1-R (plotNeuralFC.m:62-63)

Result: blocked (data_missing for the FlyEM half); the FlyWire half holds. The recomputed PPSSI matches the stored table for all 138,144 neurons with clusters (largest difference one unit of 1e-4). The FlyWire unsegregated ranks 1 to 4 are 720575940624547622 (APL, left, score 4.8203, W = 75,804), 720575940626979621 (CT1, left, 4.7812), 720575940613583001 (APL, right, 4.7500) and 720575940628908548 (CT1, right, 4.7344), all APL or CT1 cells in the FlyWire annotation; ranks 1 and 2 and their scores match the lines printed in the code's README. Rank 5 is 720575940627497244 (Li33). The FlyEM ranking needs the hemibrain DBSCAN, which is not deposited.

fig4c-segregated-ranking¶

The segregated ranking puts OA-AL2b2 cells first and second in FlyWire, and AOTU019_R first and DNa02_R second in FlyEM.

Criterion: ranking by PPSSI log10(W) (M7). Reproduced when the two top FlyWire cells are OA-AL2b2 and the two top FlyEM cells are AOTU019_R and DNa02_R. The scores come from the cell above.

In [6]:
top_sep = show(sep, "segregated")
print("scores of ranks 2 and 3 in full precision:", [round(float(P[k] * np.log10(W[k])), 5) for k in top_sep[1:3]])
segregated 1) k=110504 nid=720575940632777320 (ACH) W=17692 PPSSI=0.9728 score=4.1328 | OA-AL2b2 (visual_centrifugal, right)
segregated 2) k=72248 nid=720575940625525740 (ACH) W=15892 PPSSI=0.9750 score=4.0977 | OA-AL2b2 (visual_centrifugal, left)
segregated 3) k=74948 nid=720575940626044942 (ACH) W=16293 PPSSI=0.9727 score=4.0977 | OA-AL2b2 (visual_centrifugal, right)
segregated 4) k=86018 nid=720575940627996285 (ACH) W=15314 PPSSI=0.9656 score=4.0430 | OA-AL2b2 (visual_centrifugal, left)
segregated 5) k=16287 nid=720575940613065130 (GABA) W=17758 PPSSI=0.9353 score=3.9746 | cL21 (visual_centrifugal, right)
scores of ranks 2 and 3 in full precision: [4.09631, 4.0969]

Result: blocked (data_missing for the FlyEM half); the FlyWire half holds. The FlyWire segregated ranks 1 and 2 are 720575940632777320 (score 4.1328, W = 17,692) and 720575940625525740 (4.0977), both OA-AL2b2 in the FlyWire annotation; ranks 3 and 4 are OA-AL2b2 as well. Ranks 2 and 3 tie at 4.0977 in half precision, so their order follows the neuron index, as MATLAB's sort does; in full precision (4.09631 and 4.0969) they would swap. Both are OA-AL2b2, so the FlyWire half holds either way. The FlyEM ranking needs the hemibrain DBSCAN, which is not deposited.

figs4-1ij-segregation-index-biased¶

The segregation index of Schneider-Mizell et al. is heavily biased toward 0, with a mean much closer to 0 than to 0.5, in both connectomes.

Criterion: segregation index on the DBSCAN clusters as plotNeuralFC.m computes it (1 - S/Snorm, with entropy terms; 1 for neurons with only inputs or only outputs). Reproduced when the mean is below 0.25 in both connectomes and below the PPSSI mean of fig4b-ppssi-distribution. The index was computed in the cell under fig4a-unsegregated-ranking, from the deposited FlyWire DBSCAN clusters.

In [7]:
v = np.isfinite(H)
print("neurons with an index", int(v.sum()), "| set to 1 because they have only inputs or only outputs", int(Hconv.sum()))
print(f"segregation index mean {H[v].mean():.4f}, median {np.median(H[v]):.4f}")
print(f"mean without the neurons set to 1 by convention {H[v & ~Hconv].mean():.4f}")
print(f"PPSSI mean (stored table, fig4b) {x[has].mean():.4f}")
hh, ee = np.histogram(H[v], bins=np.arange(0, 1.0001, 0.05))
for a, c in zip(ee[:-1], hh):
    print(f"{a:.2f}-{a + 0.05:.2f} {c}")
print("fraction below 0.1", round(float((H[v] < 0.1).mean()), 4), "| exactly 1", int((H[v] == 1).sum()))
plt.figure(figsize=(6, 3)); plt.bar(ee[:-1] + 0.025, hh, width=0.05); plt.xlabel("segregation index"); plt.ylabel("neurons"); plt.show()
print("all", int(v.sum()), "values in [0, 1] are shown")
neurons with an index 138144 | set to 1 because they have only inputs or only outputs 4392
segregation index mean 0.3631, median 0.3256
mean without the neurons set to 1 by convention 0.3422
PPSSI mean (stored table, fig4b) 0.4713
0.00-0.05 7808
0.05-0.10 9834
0.10-0.15 9856
0.15-0.20 10348
0.20-0.25 11985
0.25-0.30 12786
0.30-0.35 12477
0.35-0.40 11556
0.40-0.45 9950
0.45-0.50 8342
0.50-0.55 6994
0.55-0.60 5542
0.60-0.65 4319
0.65-0.70 3047
0.70-0.75 2292
0.75-0.80 1736
0.80-0.85 1269
0.85-0.90 873
0.90-0.95 667
0.95-1.00 6410
fraction below 0.1 0.1281 | exactly 1 6154
No description has been provided for this image
all 138144 values in [0, 1] are shown

Result: not reproduced for FlyWire; the FlyEM half is not deposited. Over 138,144 FlyWire neurons the code's segregation index has a mean of 0.363 (median 0.326), above the 0.25 bound, though below the PPSSI mean of 0.471. 4,392 neurons with only inputs or only outputs are set to 1, as the code does; without them the mean is 0.342, still above 0.25. The histogram peaks in the 0.25 to 0.30 bin (12,786 neurons) and 0.128 of the neurons lie below 0.1, so it is not heavily biased toward 0. Since the FlyWire half fails the bound, no FlyEM value could make the claim hold.

fig5-wagn¶

The left Wedge-AVLP GABA neuron has unsegregated synapses (PPSSI 0.133), receives 212 synapses from 22 ascending neurons and sends 65 to WPNb, and its closest WPNb output to AN input distance is 852.3 nm.

Criterion: the PPSSI is M7 on FlyWire sc140. The 22 ANs are from the network graph of Figure 5d (codex, sc50, connection threshold above 5). Readings for the synapse counts and the distance: (a) sc50 with the connection threshold of Figure 5d, (b) sc140. Reproduced when every value is within tolerance under one reading.

The paper's code (makeNeuralSC.m, lines 85 to 94) lists the WAGN, 22 AN ids and 7 WPNb tier 2/3 ids, collects the synapses between them with checkSynapticListBetweenNeuronsFw at sc140 with no connection threshold, and takes the closest WAGN-to-WPNb output to AN-to-WAGN input distance with checkSynapseDistanceBetweenGroupsFw. The deposited synapse table holds every FlyWire synapse at cleft score 50 or more, so both readings can be run. The connection threshold is applied as the code does for codex compatibility (numsyn >= synTh, synTh = 5, makeNeuralSC.m:834-838); "above 5" read strictly is printed too. Whether the 22 neurons are ascending neurons, and whether the WAGN has other AN partners, is checked against the FlyWire annotation table.

In [8]:
code_lines("makeNeuralSC.m", [(85, 94), (1116, 1125), (1163, 1173)])
code_lines("getSCconfig.m", [(38, 39)])
src = flyfc.code_file("makeNeuralSC.m").decode().splitlines()
ids = lambda line: [int(s) for s in __import__("re").findall(r"int64\((\d+)\)", line)]
wagn = ids(src[85])[0]; wpnb = ids(src[86]); ans = ids(src[90])
print("WAGN", wagn, "| WPNb ids", len(wpnb), "| AN ids", len(ans))
kw = int(np.flatnonzero(Nid == wagn)[0])
print(f"WAGN: k={kw + 1}, transmitter {tlabels[Ntype[kw]]}, {ctype(wagn)}, PPSSI {raw[kw] / 10000:.4f} (stored int16 {raw[kw]})")
print("AN ids by FlyWire super class:", {s: sum(ann[a]["super_class"] == s for a in ans) for s in {ann[a]["super_class"] for a in ans}})

f = h5py.File(io.BytesIO(member("data/flywire783_synapse.mat")), "r")
preN = f["preNidx"][0]; postN = f["postNidx"][0]; score = f["cleftScore"][0]
del f
print("synapses in the table", preN.size, "| lowest cleft score", int(score.min()))
w1 = kw + 1                                     # 1-based neuron index, as preNidx/postNidx
valid = (preN > 0) & (postN > 0)
s_in = np.flatnonzero((postN == w1) & valid)    # synapses onto the WAGN
s_out = np.flatnonzero((preN == w1) & valid)    # synapses from the WAGN
del valid
idx1 = {int(v): i + 1 for i, v in enumerate(Nid)}
A = np.array([idx1[a] for a in ans]); B = np.array([idx1[b] for b in wpnb])
asc = np.array([ann.get(int(v), {}).get("super_class") == "ascending" for v in Nid])

def locs(name, s):
    g = h5py.File(io.BytesIO(member(name)), "r")
    d = g[list(g.keys())[0]]                    # (3, synapses), nm
    o = np.argsort(s); out = np.empty((s.size, 3))
    out[o] = d[:, s[o]].T
    return out

res = {}
for th in (50, 140):
    i_an = s_in[np.isin(preN[s_in], A) & (score[s_in] >= th)]
    o_wp = s_out[np.isin(postN[s_out], B) & (score[s_out] >= th)]
    per_an = np.array([(preN[i_an] == a).sum() for a in A])
    print(f"\ncleft score >= {th}: synapses from the 22 listed ANs {i_an.size}; to the 7 WPNb {o_wp.size}")
    print("  per AN:", sorted(per_an.tolist()))
    print(f"  listed ANs with >= 5 synapses {(per_an >= 5).sum()} ({per_an[per_an >= 5].sum()} synapses); with more than 5 {(per_an > 5).sum()}")
    u, c = np.unique(preN[s_in][score[s_in] >= th], return_counts=True)
    a_u = asc[u - 1]
    print(f"  all ascending partners of the WAGN: any synapse {a_u.sum()}, >= 5 synapses {(a_u & (c >= 5)).sum()}, "
          f"of them in the code's list {np.isin(u[a_u & (c >= 5)], A).sum()}")
    res[th] = (i_an, o_wp)
del preN, postN, score, s_in, s_out
for th in (50, 140):
    i_an, o_wp = res[th]
    Pl = locs("data/flywire783_sypreloc.mat", o_wp)    # WAGN output synapses onto WPNb (code: Spreloc(sidx1))
    Ql = locs("data/flywire783_sypostloc.mat", i_an)   # AN input synapses onto the WAGN (code: Spostloc(sidx2))
    D = np.sqrt(((Pl[:, None, :] - Ql[None, :, :]) ** 2).sum(-1))
    print(f"cleft score >= {th}: closest WPNb-output to AN-input distance {D.min():.1f} nm over {D.size} pairs")
print(f"notebook time so far {(time.time() - t_start) / 60:.1f} min")
makeNeuralSC.m:85: %%{
makeNeuralSC.m:86:     g1 = [int64(720575940644632087)]; % WAGN figure.5
makeNeuralSC.m:87:     g2 = [int64(720575940635831438),int64(720575940635863214),int64(720575940613099493),int64(720575940628370732),int64(720575940622529574),int64(720575940621558762),int64(720575940624473918)]; % WPN Tier2/3
makeNeuralSC.m:88:     [spreloc1, spresidx1, spostloc1, spostsidx1] = checkSynapticListBetweenNeuronsFw(conf, g1, g2);
makeNeuralSC.m:89: 
makeNeuralSC.m:90:     g1 = [int64(720575940644632087)]; % WAGN figure.5
makeNeuralSC.m:91:     g2 = [int64(720575940618260500),int64(720575940654220193),int64(720575940635668622),int64(720575940611932842),int64(720575940632015699),int64(720575940611904296),int64(720575940629901047),int64(720575940630151455),int64(720575940603882174),int64(720575940632118479),int64(720575940628894251),int64(720575940623817776),int64(720575940623755312),int64(720575940609984881),int64(720575940621106977),int64(720575940629264938),int64(720575940629630520),int64(720575940633209996),int64(720575940634627214),int64(720575940626651691),int64(720575940611603502),int64(720575940623685193)]; % AN neurons
makeNeuralSC.m:92:     [spreloc2, spresidx2, spostloc2, spostsidx2] = checkSynapticListBetweenNeuronsFw(conf, g1, g2);
makeNeuralSC.m:93:     checkSynapseDistanceBetweenGroupsFw(conf, spresidx1, spostsidx2); % WPNb<-WAGN<-ANs
makeNeuralSC.m:94:     checkSynapseDistanceBetweenGroupsFw(conf, spresidx1, spostsidx1); % WPNb<-WAGN<-WPNb Tier2/3
makeNeuralSC.m:1116:     prelogi = ismember(preNidx,g1idx);
makeNeuralSC.m:1117:     postlogi = ismember(postNidx,g2idx);
makeNeuralSC.m:1118:     spreloc = double(Spreloc(prelogi & postlogi & valid & score,:)) ./ conf.voxelSize;
makeNeuralSC.m:1119:     spresidx = Sidx(prelogi & postlogi & valid & score);
makeNeuralSC.m:1120: 
makeNeuralSC.m:1121:     % get g1 post-synapse
makeNeuralSC.m:1122:     postlogi = ismember(postNidx,g1idx);
makeNeuralSC.m:1123:     prelogi = ismember(preNidx,g2idx);
makeNeuralSC.m:1124:     spostloc = double(Spostloc(postlogi & prelogi & valid & score,:)) ./ conf.voxelSize;
makeNeuralSC.m:1125:     spostsidx = Sidx(prelogi & postlogi & valid & score);
makeNeuralSC.m:1163:     prelocs = single(Spreloc(sidx1,:)) ./ conf.swcSize .* conf.voxelSize;   % pre-synapse on group1; FlyWire original space (unit is nano meter) (int32)
makeNeuralSC.m:1164:     postlocs = single(Spostloc(sidx2,:)) ./ conf.swcSize .* conf.voxelSize; % post-synapse on group2; 
makeNeuralSC.m:1165:     preP = reshape(prelocs,[size(prelocs,1) 1 3]);
makeNeuralSC.m:1166:     postP = reshape(postlocs,[1 size(postlocs,1) 3]);
makeNeuralSC.m:1167:     preP = repmat(preP,[1 size(postP,2) 1]);
makeNeuralSC.m:1168:     postP = repmat(postP,[size(preP,1) 1 1]);
makeNeuralSC.m:1169:     D = sqrt(sum((preP-postP).^2,3));
makeNeuralSC.m:1170:     clear preP; clear postP;
makeNeuralSC.m:1171: 
makeNeuralSC.m:1172:     % find minimum distance of pre and post (should be same reciprocal target neuron)
makeNeuralSC.m:1173:     [minD, idxD] = min(D,[],2,'omitnan');
getSCconfig.m:38:         conf.swcSize = [4 4 40];   % swc unit is nano meter
getSCconfig.m:39:         conf.voxelSize = [4 4 40]; % nano meter
WAGN 720575940644632087 | WPNb ids 7 | AN ids 22
WAGN: k=133938, transmitter GABA, AVLP083 (central, left), PPSSI 0.1332 (stored int16 1332)
AN ids by FlyWire super class: {'ascending': 22}
synapses in the table 54492970 | lowest cleft score 51
cleft score >= 50: synapses from the 22 listed ANs 323; to the 7 WPNb 133
  per AN: [5, 5, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 10, 10, 20, 34, 40, 44, 65]
  listed ANs with >= 5 synapses 22 (323 synapses); with more than 5 17
  all ascending partners of the WAGN: any synapse 61, >= 5 synapses 22, of them in the code's list 22

cleft score >= 140: synapses from the 22 listed ANs 212; to the 7 WPNb 65
  per AN: [2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 6, 6, 8, 8, 9, 11, 22, 26, 27, 46]
  listed ANs with >= 5 synapses 12 (179 synapses); with more than 5 10
  all ascending partners of the WAGN: any synapse 51, >= 5 synapses 12, of them in the code's list 12
cleft score >= 50: closest WPNb-output to AN-input distance 852.3 nm over 42959 pairs
cleft score >= 140: closest WPNb-output to AN-input distance 852.3 nm over 13780 pairs
notebook time so far 15.2 min

Result: reproduced under reading (b), sc140. The WAGN (720575940644632087, GABA, AVLP083 in the FlyWire annotation) has a stored PPSSI of 0.1332. At cleft score 140 the 22 ANs the code lists give it 212 synapses, it gives the 7 WPNb tier 2/3 neurons 65, and the closest WPNb output to AN input distance is 852.3 nm, all three as stated. All 22 listed neurons are ascending neurons in the FlyWire annotation, and at sc50 with at least 5 synapses per connection the WAGN has exactly 22 ascending partners, the same 22 (17 if "above 5" is read strictly). Under reading (a), sc50, the counts are 323 and 133, outside the tolerance, and the distance is the same 852.3 nm.