Reproducing Martel et al. (2025) from dandiset 001174: activity, task responses and coactivation¶

Paper. Martel A-C, Pittard D, Devergnas A, Risk B, Nassi JJ, Yu W, Downer JD, Wichmann T, Galvan A (2025). Microendoscopic calcium imaging in motor cortices of macaques during rest and movement. iScience 28, 112767. doi:10.1016/j.isci.2025.112767. The claims file (claims/001174/10.1016-j.isci.2025.112767.yaml) was written from the version of record as served by Europe PMC (PMC12192352), with the STAR Methods and figure legends; the supplement (Figures S1 to S3, Tables S1 to S3) was not in the text read.

Dandiset. DANDI:001174, version 0.250331.2218. This is the version the paper's key resources table cites (doi:10.48324/dandi.001174/0.250331.2218) and the only published version; the data check compares it with the draft.

What the dandiset holds. 45 NWB files, one per session and condition: the miniscope movie, the footprints of the accepted cells, one trace per cell (the CNMFe denoised trace, see the data check) and the deconvolved events as a frame by cell array of amplitudes. It holds no TTL or trial data and no raw (undenoised) traces.

Outside inputs. The paper's per-cell descriptors table (Zenodo doi:10.5281/zenodo.14727695) supplies the cells' first occurrences, which the dandiset does not mark; the link claim tests it. The paper's Jaccard output table (Zenodo doi:10.5281/zenodo.15116617) is shown next to this attempt's values, and decides nothing. The paper's table of z-scored trial windows (Zenodo doi:10.5281/zenodo.14976651) is used for a check of the Figure 2 classification on the paper's own processed data, which decides nothing. Method details come from the paper's code (Zenodo doi:10.5281/zenodo.14963213 and doi:10.5281/zenodo.14977106), as the claims file cites it. The sequence claims (Figure 4) are in the second notebook, sequences_martel_2025.ipynb.

Claim Tested here
zenodo-descriptors-link tested
cell-counts tested
cells-tracked-18pct blocked: metadata insufficient
fig1d-rate-no-change tested
fig1e-ieicv-no-change tested
fig1f-amplitude-u-sma-spont-higher tested
fig1d-rate-m1-above-sma-u tested
fig1f-amplitude-m1-above-sma-u-task tested
fig2-q-sma-modulated-34pct, fig2c-q-sma-direction, fig2-q-magnitude-no-difference blocked: data missing (no TTL, no raw traces)
figs1-u-sma-direction, figs1-u-m1-target-onset, figs1-u-m1-movement-onset blocked: data missing
fig3-synchronized-pairs-exist tested
fig3ab-synchrony-not-distance tested
fig3c-sync-no-condition-change tested
fig4a, fig4b, fig4d, fig4c (sequences) in sequences_martel_2025.ipynb
histology-lens-placement, histology-gcamp-not-gabaergic blocked: other (an anatomist's reading of slide scans)
In [1]:
import json, urllib.request
import numpy as np
import pandas as pd
from scipy import stats
import matplotlib.pyplot as plt
import sma_m1 as h

pd.set_option("display.width", 200)
pd.set_option("display.max_columns", 30)
print("dandiset", h.DANDISET, "version", h.VERSION)
files = h.load_all()
ses = h.sessions(files)
print(len(files), "files loaded")
dandiset 001174 version 0.250331.2218
45 files loaded

Data check¶

What was loaded, per file: subject, site (from session_description), date, condition, frames, sampling rate, duration and cells. Then the checks of the description against the values.

In [2]:
inv = pd.DataFrame([{
    "path": x["path"], "subject": x["subject"], "region": x["region"], "date": x["date"],
    "condition": x["condition"], "frames": x["events"].shape[0], "rate_Hz": round(x["rate_ea"], 4),
    "imaging_rate_Hz": x["imaging_rate"], "minutes": round((x["events"].shape[0] - 1) / x["rate_ea"] / 60, 2),
    "cells": x["events"].shape[1], "movie": "x".join(map(str, x["movie_shape"][1:])),
    "mask": "x".join(map(str, x["mask_shape"][1:])), "events": int((x["events"] > 0).sum()),
} for x in files])
print(inv.drop(columns="path").to_string())
print()
print(inv.groupby(["subject", "region", "condition"]).agg(files=("cells", "size"), cells=("cells", "sum"),
      minutes_min=("minutes", "min"), minutes_max=("minutes", "max")).to_string())
print()
print("subjects:", {x["subject"]: (x["sex"], x["age"]) for x in files})
print("indicator field:", sorted({x["indicator"] for x in files}), " location field:", sorted({x["location"] for x in files}))
print("file names without a session label:", [x["path"] for x in files if "ses-" not in x["path"]])
   subject region        date    condition  frames  rate_Hz  imaging_rate_Hz  minutes  cells     movie     mask  events
0        F    SMA  2024-02-13  spontaneous    6026  10.0037            10.00    10.04      6  1280x800  318x198     144
1        F    SMA  2024-02-20  spontaneous   12056  10.0037            10.00    20.08     16  1280x800  318x198    2844
2        F    SMA  2024-02-23  spontaneous   12059  10.0037            10.00    20.09     15  1280x800  318x197    2754
3        F    SMA  2024-02-27  spontaneous   12042  10.0037            10.00    20.06     14  1280x800  320x200    2163
4        F    SMA  2024-02-29  spontaneous   12065  10.0037            10.00    20.10     14  1280x800  320x200    2876
5        F    SMA  2024-03-05  spontaneous   12021  10.0037            10.00    20.03     12  1280x800  320x200    1313
6        F    SMA  2024-03-07  spontaneous   12692  10.0037            10.00    21.14      6  1280x800  320x200     903
7        F    SMA  2024-03-12  spontaneous    6114  10.0037            10.00    10.18      4  1280x800  320x200     184
8        F    SMA  2024-03-19  spontaneous    6143  10.0038            10.00    10.23      1  1280x800  320x200      42
9        Q    SMA  2022-09-15  spontaneous    6041  10.0137            10.01    10.05     40   320x200  292x179    1419
10       Q    SMA  2022-09-15         task    9041  10.0037            10.00    15.06     40   320x200  292x179    2021
11       Q    SMA  2022-09-22  spontaneous    6030  10.0120            10.01    10.04     38   320x200  299x168    1831
12       Q    SMA  2022-09-22         task   12089  10.0037            10.00    20.14     38   320x200  299x168    2499
13       Q    SMA  2022-10-03  spontaneous   13107  10.0083            10.01    21.83     18   320x200  298x160     575
14       Q    SMA  2022-10-03         task   12058  10.0037            10.00    20.09     18   320x200  298x160     747
15       Q    SMA  2022-10-28  spontaneous   12019  10.0054            10.01    20.02     21   320x200  313x181     642
16       Q    SMA  2022-10-28         task    8617  10.0037            10.00    14.35     21   320x200  313x181     729
17       Q    SMA  2022-12-01  spontaneous   12819  10.0037            10.00    21.36     13   320x200  295x160    1680
18       Q    SMA  2022-12-01         task    6453  10.0076            10.01    10.75     13   320x200  295x160     821
19       Q    SMA  2022-12-02  spontaneous   12133  10.0037            10.00    20.21     12   320x200  318x196    1837
20       Q    SMA  2022-12-02         task    7014  10.0037            10.00    11.68     12   320x200  318x196     748
21       Q    SMA  2022-12-06  spontaneous   12218  10.0037            10.00    20.35     18  1280x800  310x186    4684
22       Q    SMA  2022-12-06         task    6943  10.0066            10.01    11.56     18   320x200  310x186    2596
23       U     M1  2023-02-24  spontaneous   12010  10.0038            10.00    20.01      8  1280x800  318x198    4086
24       U     M1  2023-02-24         task    4747  10.0038            10.00     7.91      8  1280x800  318x198    1298
25       U    SMA  2023-02-27  spontaneous   12024  10.0038            10.00    20.03     16  1280x800  318x198     844
26       U    SMA  2023-02-27         task    7317  10.0038            10.00    12.19     16  1280x800  318x198     478
27       U     M1  2023-03-01  spontaneous   12052  10.0038            10.00    20.08     21  1280x800  312x179    5926
28       U     M1  2023-03-01         task    6000  10.0063            10.01     9.99     21  1280x800  312x179    2734
29       U    SMA  2023-03-07  spontaneous   12010  10.0037            10.00    20.01     10  1280x800  318x198      34
30       U    SMA  2023-03-07         task    9308  10.0037            10.00    15.51     10  1280x800  318x198     378
31       U    SMA  2023-03-14  spontaneous   24063  20.0152            20.02    20.04     20  1280x800  318x198     136
32       U    SMA  2023-03-14         task   16725  20.0152            20.02    13.93     20  1280x800  318x198      67
33       U     M1  2023-03-16  spontaneous    3019  10.0037            10.00     5.03      8  1280x800  318x198     311
34       U     M1  2023-03-16         task   11569  10.0037            10.00    19.27      8  1280x800  318x198    1963
35       U    SMA  2023-03-21  spontaneous   12023  10.0038            10.00    20.03     25  1280x800  318x198     550
36       U    SMA  2023-03-21         task    6771  10.0038            10.00    11.28     25  1280x800  318x198     376
37       U     M1  2023-03-23  spontaneous   12109  10.0037            10.00    20.17      6  1280x800  318x198    1729
38       U     M1  2023-03-23         task    7710  10.0037            10.00    12.84      6  1280x800  318x198     890
39       U    SMA  2023-03-28  spontaneous   12026  10.0038            10.00    20.03     14  1280x800  318x198     227
40       U    SMA  2023-03-28         task    7497  10.0038            10.00    12.49     14  1280x800  318x198     171
41       V     M1  2023-03-09  spontaneous   12035  10.0037            10.00    20.05     11  1280x800  318x197    1145
42       V     M1  2023-03-09         task    5185  10.0037            10.00     8.64     11  1280x800  318x197     455
43       V     M1  2023-03-16  spontaneous   12035  10.0037            10.00    20.05     14  1280x800  318x191    3835
44       V     M1  2023-03-16         task    4984  10.0037            10.00     8.30     14  1280x800  318x191    1358

                            files  cells  minutes_min  minutes_max
subject region condition                                          
F       SMA    spontaneous      9     88        10.04        21.14
Q       SMA    spontaneous      7    160        10.04        21.83
               task             7    160        10.75        20.14
U       M1     spontaneous      4     43         5.03        20.17
               task             4     43         7.91        19.27
        SMA    spontaneous      5     85        20.01        20.04
               task             5     85        11.28        15.51
V       M1     spontaneous      2     25        20.05        20.05
               task             2     25         8.30         8.64

subjects: {'F': ('F', 'P5Y'), 'Q': ('F', 'P5Y'), 'U': ('M', 'P4Y'), 'V': ('M', 'P4Y')}
indicator field: ['N/A']  location field: ['N/A']
file names without a session label: ['sub-Q/sub-Q_ophys.nwb']
In [3]:
# Draft against the pinned version: same assets?
def asset_list(v):
    url = f"{h.API}/dandisets/{h.DANDISET}/versions/{v}/assets/?page_size=500"
    with urllib.request.urlopen(url) as r:
        return {a["path"]: (a["size"], a["blob"] if "blob" in a else None) for a in json.load(r)["results"]}
pub, draft = asset_list(h.VERSION), asset_list("draft")
print("published assets", len(pub), " draft assets", len(draft))
print("same paths and sizes in draft:", {k: v[0] for k, v in pub.items()} == {k: v[0] for k, v in draft.items()})
published assets 45  draft assets 45
same paths and sizes in draft: True
In [4]:
# Pairs of files of a session: the two conditions share the footprints (same cells), and no
# recording is deposited twice (identical event arrays across files).
rows = []
for key, d in sorted(ses.items()):
    sp, ta = d.get("spontaneous"), d.get("task")
    rows.append({"subject": key[0], "region": key[1], "date": key[2], "spont": sp is not None, "task": ta is not None,
                 "cells": (sp or ta)["events"].shape[1],
                 "same_footprints": (sp["mask_hash"] == ta["mask_hash"]) if (sp and ta) else None})
pairs = pd.DataFrame(rows)
print(pairs.to_string())
hashes = {}
for x in files:
    hashes.setdefault(hash(x["events"].tobytes()), []).append(x["path"])
print("files with identical event arrays:", [v for v in hashes.values() if len(v) > 1])
fp = {}
for x in files:
    fp.setdefault((x["subject"], x["region"], x["mask_hash"]), []).append(x["date"])
print("footprint sets shared across dates:", {k[:2]: v for k, v in fp.items() if len(set(v)) > 1})
   subject region        date  spont   task  cells same_footprints
0        F    SMA  2024-02-13   True  False      6            None
1        F    SMA  2024-02-20   True  False     16            None
2        F    SMA  2024-02-23   True  False     15            None
3        F    SMA  2024-02-27   True  False     14            None
4        F    SMA  2024-02-29   True  False     14            None
5        F    SMA  2024-03-05   True  False     12            None
6        F    SMA  2024-03-07   True  False      6            None
7        F    SMA  2024-03-12   True  False      4            None
8        F    SMA  2024-03-19   True  False      1            None
9        Q    SMA  2022-09-15   True   True     40            True
10       Q    SMA  2022-09-22   True   True     38            True
11       Q    SMA  2022-10-03   True   True     18            True
12       Q    SMA  2022-10-28   True   True     21            True
13       Q    SMA  2022-12-01   True   True     13            True
14       Q    SMA  2022-12-02   True   True     12            True
15       Q    SMA  2022-12-06   True   True     18            True
16       U     M1  2023-02-24   True   True      8            True
17       U     M1  2023-03-01   True   True     21            True
18       U     M1  2023-03-16   True   True      8            True
19       U     M1  2023-03-23   True   True      6            True
20       U    SMA  2023-02-27   True   True     16            True
21       U    SMA  2023-03-07   True   True     10            True
22       U    SMA  2023-03-14   True   True     20            True
23       U    SMA  2023-03-21   True   True     25            True
24       U    SMA  2023-03-28   True   True     14            True
25       V     M1  2023-03-09   True   True     11            True
26       V     M1  2023-03-16   True   True     14            True
files with identical event arrays: []
footprint sets shared across dates: {}
In [5]:
# Which trace is in Fluorescence/RoiResponseSeries? A raw trace is noisy; the CNMFe denoised trace
# decays by one constant factor per frame between events (an AR(1) model). Ratios of successive
# samples, per file: the share of ratios equal (to 1e-4) to the cell's modal decay factor.
def decay_share(x):
    d = x["denoised"]
    out = []
    for c in range(d.shape[1]):
        v = d[:, c]
        r = v[1:] / np.where(v[:-1] > 0, v[:-1], np.nan)
        r = r[np.isfinite(r)]
        if len(r) < 10:
            continue
        mode = np.median(r[r < 1])
        out.append(np.mean(np.abs(r - mode) < 1e-4))
    return np.median(out)
sh = np.array([decay_share(x) for x in files])
print("median share of samples that decay by the cell's constant factor, per file: min %.3f, median %.3f" % (sh.min(), np.median(sh)))
x = files[0]
print("example", x["path"], "cell 0, first 12 samples:", np.round(x["denoised"][:12, 0], 3))
print("NaN samples in the traces: %d files have some, at most %.2f%% of samples" %
      (sum(np.isnan(x["denoised"]).any() for x in files), 100 * max(np.isnan(x["denoised"]).mean() for x in files)))
ev_amp = np.concatenate([x["events"][x["events"] > 0] for x in files])
print("event amplitudes: n=%d, range %.2f to %.2f, median %.2f (unit 'fluorescence')" % (len(ev_amp), ev_amp.min(), ev_amp.max(), np.median(ev_amp)))
cen = np.concatenate([x["centroid"] for x in files])
print("centroids (pixels): x %.1f to %.1f, y %.1f to %.1f" % (cen[:, 0].min(), cen[:, 0].max(), cen[:, 1].min(), cen[:, 1].max()))
median share of samples that decay by the cell's constant factor, per file: min 0.770, median 0.898
example sub-F/sub-F_ses-20240213T110430_ophys.nwb cell 0, first 12 samples: [0.    0.    0.057 0.046 0.037 0.03  0.024 0.02  0.016 0.013 0.01  0.008]
NaN samples in the traces: 40 files have some, at most 0.13% of samples
event amplitudes: n=65043, range 0.69 to 107.45, median 3.77 (unit 'fluorescence')
centroids (pixels): x 1.6 to 291.8, y 3.2 to 195.8
/tmp/ipykernel_2265/999454393.py:9: RuntimeWarning: overflow encountered in divide
  r = v[1:] / np.where(v[:-1] > 0, v[:-1], np.nan)
In [6]:
# Shared clock of events and traces. Both are per frame in the same file; an event should fall where
# the denoised trace jumps up. Contrast: the share of event frames where the trace rises by more than
# 5% against the same with the events shifted by k frames.
def rise_share(x, k):
    d, e = x["denoised"], x["events"] > 0
    up = np.zeros_like(e)
    up[1:] = (d[1:] > 1.05 * d[:-1]) & np.isfinite(d[1:]) & np.isfinite(d[:-1])
    es = np.roll(e, k, axis=0)
    return up[es].mean()
lag = pd.DataFrame({k: [rise_share(x, k) for x in files] for k in (-2, -1, 0, 1, 2, 10)})
print("share of event frames on a rise of the denoised trace, by shift of the events (frames):")
print(lag.describe().loc[["min", "50%", "max"]].round(3).to_string())
print("files where the unshifted share is not the largest:", int((lag.idxmax(axis=1) != 0).sum()))
share of event frames on a rise of the denoised trace, by shift of the events (frames):
       -2     -1      0      1      2      10
min  0.151  0.163  0.436  0.407  0.116  0.028
50%  0.337  0.423  0.686  0.642  0.313  0.117
max  0.551  0.593  0.941  0.762  0.492  0.185
files where the unshifted share is not the largest: 6
In [7]:
# What the NWB files hold besides the imaging: no trial table, no TTL or behavioural channel, and no
# cross-session cell identity. Every one of the 45 files is opened (groups and table columns only),
# and the archive's per-asset metadata (variableMeasured) is listed.
import h5py, remfile
from concurrent.futures import ThreadPoolExecutor
def contents(row):
    with h5py.File(remfile.File(h._s3_url(row["asset_id"])), "r") as f:
        ps = f["processing/ophys/ImageSegmentation/PlaneSegmentation"]
        return {"path": row["path"],
                "acquisition": ",".join(sorted(f["acquisition"].keys())),
                "processing": ",".join(sorted(f["processing"].keys())),
                "ophys": ",".join(sorted(f["processing/ophys"].keys())),
                "stimulus": ",".join(sorted(k for g in ("stimulus/presentation", "stimulus/templates") if g in f for k in f[g].keys())),
                "analysis": ",".join(sorted(f["analysis"].keys())) if "analysis" in f else "",
                "intervals": "intervals" in f,
                "plane_segmentation_columns": ",".join(sorted(k for k in ps.keys())),
                "colnames": ps.attrs.get("colnames").tolist() if "colnames" in ps.attrs else None}
assets = h.list_assets()
with ThreadPoolExecutor(12) as ex:
    CT = pd.DataFrame(list(ex.map(contents, [r for _, r in assets.iterrows()])))
for col in ["acquisition", "processing", "ophys", "stimulus", "analysis", "intervals", "plane_segmentation_columns"]:
    print(col, "->", CT[col].value_counts().to_dict())
print("PlaneSegmentation colnames:", {str(v) for v in CT.colnames})
print("files whose PlaneSegmentation ids are 0..n-1:", sum(bool((x["roi_ids"] == np.arange(len(x["roi_ids"]))).all()) for x in files), "of", len(files))
def var_measured(aid):
    with urllib.request.urlopen(f"{h.API}/dandisets/{h.DANDISET}/versions/{h.VERSION}/assets/{aid}/") as r:
        return tuple(sorted(v.get("value", str(v)) if isinstance(v, dict) else str(v) for v in json.load(r).get("variableMeasured", [])))
with ThreadPoolExecutor(12) as ex:
    vm = list(ex.map(var_measured, assets.asset_id))
print("archive variableMeasured over the 45 assets:", pd.Series(vm).value_counts().to_dict())
acquisition -> {'OnePhotonSeries': 45}
processing -> {'ophys': 45}
ophys -> {'EventAmplitude,Fluorescence,ImageSegmentation': 45}
stimulus -> {'': 45}
analysis -> {'': 45}
intervals -> {False: 45}
plane_segmentation_columns -> {'id,image_mask,imaging_plane,reference_images': 45}
PlaneSegmentation colnames: {"['image_mask']"}
files whose PlaneSegmentation ids are 0..n-1: 45 of 45
archive variableMeasured over the 45 assets: {('ImagingPlane', 'OnePhotonSeries', 'OpticalChannel', 'PlaneSegmentation', 'ProcessingModule'): 44, ('ImagingPlane', 'OpticalChannel', 'PlaneSegmentation', 'ProcessingModule'): 1}

Checks of the description against the data.

  • The dandiset holds 45 files over the sessions the claims file lists: each session of Q, U and V has a spontaneous and an arm-reaching file, F has spontaneous files only, and the 2022-09-15 spontaneous file of Q is named sub-Q/sub-Q_ophys.nwb, without a session label (counts printed above).
  • The two files of a session share their footprints (column same_footprints), so their cells are the same cells in the same order. No two files hold identical event arrays.
  • V's sessions have arm-reaching files, while the paper says only Q and U performed the task.
  • The Methods give 10 Hz; the U SMA session of 2023-03-14 is sampled at 20 Hz (both files).
  • The trace in Fluorescence/RoiResponseSeries decays by one constant factor per frame between events: it is the denoised CNMFe trace, though the files call it "Fluorescence data". The raw traces that Figure 2 uses are not in the dandiset.
  • Event frames fall on rises of the denoised trace, and much less often when the events are shifted, which is consistent with a shared clock of events and traces.
  • indicator and location are "N/A" in every file; the site is only in session_description.
  • None of the 45 files has a trial table, an intervals group, a stimulus or a TTL or behavioural channel, and the archive's metadata lists only imaging variables for every asset, so the task events of Figure 2 and Figure S1 cannot be located in the recordings.
  • The ids of PlaneSegmentation are 0..n-1 in every file and it has no other column that could name a cell across sessions, so the dandiset carries no cross-session identity.

zenodo-descriptors-link¶

The per-cell descriptors computed from the dandiset (event rate, IEI CV, mean amplitude, spontaneous and task) agree with the per-cell table the paper deposited on Zenodo, so that table can give the cells' first occurrences.

Cells are matched by subject, site, date and the index of the accepted cell (the table's cells column). The match of identity is checked with the centroids, which the table also gives; the criterion judges the descriptors.

In [8]:
z, z_md5 = h.zenodo_descriptors()
print("Zenodo table:", z_md5, len(z), "rows,", z["Global_cell_ID"].nunique(), "global cell ids")
D = h.descriptor_table(files)
m = z.merge(D, on=["subject", "region", "date", "condition", "cell"], how="left", indicator=True)
print("table rows matched to a dandiset cell:", (m["_merge"] == "both").sum(), "of", len(m))
print("unmatched table rows (no such file):")
print(m[m["_merge"] == "left_only"].groupby(["subject", "region", "condition"]).size().to_string())
mm = m[m["_merge"] == "both"].copy()
mm["d_x"] = mm["X_centroid"] - mm["cx"]
mm["d_y"] = mm["Y_centroid"] - mm["cy"]
print("centroid differences (pixels), table minus dandiset: x median %.2f, |x| 95th pct %.2f; y median %.2f, |y| 95th pct %.2f"
      % (mm.d_x.median(), mm.d_x.abs().quantile(.95), mm.d_y.median(), mm.d_y.abs().quantile(.95)))
print("cells with both centroid differences under 3 pixels: %.3f" % ((mm.d_x.abs() < 3) & (mm.d_y.abs() < 3)).mean())
Zenodo table: md5:60bd8689b867b55bb680f2a3a1658b46 626 rows, 313 global cell ids
table rows matched to a dandiset cell: 565 of 626
unmatched table rows (no such file):
subject  region  condition
F        SMA     task         61
centroid differences (pixels), table minus dandiset: x median -0.52, |x| 95th pct 2.74; y median -0.45, |y| 95th pct 2.79
cells with both centroid differences under 3 pixels: 0.938
In [9]:
def rel(a, b):
    a, b = np.asarray(a, float), np.asarray(b, float)
    with np.errstate(divide="ignore", invalid="ignore"):
        r = np.abs(a - b) / np.abs(a)
    r[(a == 0) & (b == 0)] = 0
    return r
mm["rate_rel"] = rel(mm["Event Rate"], mm["rate"])
mm["amp_rel"] = rel(mm["Mean_Amplitude"], mm["amplitude"])
mm["n_table"] = mm["Event Rate"] * mm["duration_s"]
both = mm[mm["Mean_Amplitude"].notna() & mm["amplitude"].notna()]
ok = (mm["rate_rel"] < 0.01) & ((mm["amp_rel"] < 0.01) | (mm["Mean_Amplitude"].isna() & mm["amplitude"].isna()))
cells_ok = mm.assign(ok=ok).groupby(["subject", "region", "date", "cell"])["ok"].all()
print("cell-conditions with rate within 1%%: %.3f; amplitude within 1%% (both defined, n=%d): %.3f"
      % ((mm.rate_rel < 0.01).mean(), len(both), (both.amp_rel < 0.01).mean()))
print("matched cells with rate and amplitude within 1%% in every condition: %d of %d = %.3f"
      % (cells_ok.sum(), len(cells_ok), cells_ok.mean()))
print("table rate / dandiset rate: median %.3f, 5th to 95th pct %.3f to %.3f"
      % ((mm["Event Rate"] / mm["rate"]).replace(np.inf, np.nan).median(),
         *(mm["Event Rate"] / mm["rate"]).replace(np.inf, np.nan).quantile([.05, .95])))
print("table CV / dandiset CV: median %.3f" % (mm["CV"] / mm["iei_cv"]).median())
per = mm.assign(ok=ok, ratio=mm["Event Rate"] / mm["rate"]).groupby(["subject", "region", "date", "condition"]).agg(
    cells=("ok", "size"), within_1pct=("ok", "mean"), median_rate_ratio=("ratio", "median"))
print(per.round(3).to_string())
cell-conditions with rate within 1%: 0.409; amplitude within 1% (both defined, n=513): 0.663
matched cells with rate and amplitude within 1% in every condition: 86 of 313 = 0.275
table rate / dandiset rate: median 1.042, 5th to 95th pct 0.999 to 1.499
table CV / dandiset CV: median 1.029
                                       cells  within_1pct  median_rate_ratio
subject region date       condition                                         
F       SMA    2024-02-13 spontaneous      6        0.333              1.036
               2024-02-20 spontaneous     15        0.067              1.206
               2024-02-23 spontaneous      7        0.286              1.022
               2024-02-27 spontaneous      8        0.500              1.011
               2024-02-29 spontaneous     11        0.273              1.042
               2024-03-05 spontaneous     12        0.333              1.064
               2024-03-12 spontaneous      1        1.000              1.000
               2024-03-19 spontaneous      1        0.000              1.238
Q       SMA    2022-09-15 spontaneous     40        0.400              1.152
                          task            40        0.325              1.117
               2022-09-22 spontaneous     24        0.417              1.041
                          task            24        0.250              1.144
               2022-10-03 spontaneous     15        0.667              1.000
                          task            15        0.400              1.040
               2022-10-28 spontaneous     21        0.476              1.015
                          task            21        0.381              1.039
               2022-12-01 spontaneous     11        0.273              1.125
                          task            11        0.909              0.999
               2022-12-02 spontaneous      5        0.400              1.034
                          task             5        0.600              0.999
               2022-12-06 spontaneous     13        0.231              1.055
                          task            13        0.846              0.999
U       M1     2023-02-24 spontaneous      8        0.125              1.065
                          task             8        0.125              1.119
               2023-03-01 spontaneous     16        0.312              1.024
                          task            16        0.438              1.017
               2023-03-16 spontaneous      8        0.625              1.005
                          task             8        0.625              1.000
               2023-03-23 spontaneous      5        0.200              1.021
                          task             5        0.400              1.029
        SMA    2023-02-27 spontaneous     16        0.562              1.010
                          task            16        0.562              1.010
               2023-03-07 spontaneous      5        0.000             19.999
                          task             5        0.000              2.646
               2023-03-14 spontaneous     15        0.000              3.833
                          task            15        0.467              0.042
               2023-03-21 spontaneous     19        0.789              1.000
                          task            19        0.737              1.000
               2023-03-28 spontaneous      8        0.750              1.000
                          task             8        0.375              1.044
V       M1     2023-03-09 spontaneous     10        0.100              1.090
                          task            10        0.100              1.142
               2023-03-16 spontaneous     13        0.308              1.042
                          task            13        0.538              1.029
In [10]:
# Where the event counts differ: one-frame inter-event intervals. The table's median IEI is one frame
# for many cells; compare the share of cells whose median IEI is one frame (0.1 s) in each source.
mm["med_isi_dandi"] = np.nan
for (s, r, d, c), g in mm.groupby(["subject", "region", "date", "condition"]):
    x = ses[(s, r, d)][c]
    for i, row in g.iterrows():
        idx = np.flatnonzero(x["events"][:, row["cell"]] > 0)
        if len(idx) > 1:
            mm.loc[i, "med_isi_dandi"] = np.median(np.diff(idx)) / x["rate_ea"]
one = lambda v: (np.abs(v - 0.1) < 0.02)
sel = mm["Median_ISI"].notna() & mm["med_isi_dandi"].notna()
print("cell-conditions with a median IEI of one frame: table %.3f, dandiset %.3f (n=%d)"
      % (one(mm.loc[sel, "Median_ISI"]).mean(), one(mm.loc[sel, "med_isi_dandi"]).mean(), sel.sum()))
cell-conditions with a median IEI of one frame: table 0.119, dandiset 0.039 (n=486)
In [11]:
# The two U SMA sessions where the table and the dandiset differ most (2023-03-07 and 2023-03-14, the
# 20 Hz session), cell by cell: the table's event count (its rate times the file's duration) against the
# dandiset's, and the mean amplitudes. A swap of conditions would make the table's spontaneous counts
# follow the dandiset's task counts; the rank correlation is given for the same and the swapped condition.
for d in ("2023-03-07", "2023-03-14", "2023-02-27"):
    g = mm[(mm.subject == "U") & (mm.region == "SMA") & (mm.date == d)]
    pv = g.pivot_table(index="cell", columns="condition", values=["n_table", "n_events", "Mean_Amplitude", "amplitude"])
    print(f"U SMA {d}: cells {len(pv)}; table events (rate x duration) and dandiset events per condition, summed:",
          {c: (round(pv["n_table"][c].sum()), int(pv["n_events"][c].sum())) for c in ("spontaneous", "task")})
    for c, cs in (("spontaneous", "spontaneous"), ("spontaneous", "task"), ("task", "task"), ("task", "spontaneous")):
        a, b = pv["n_table"][c], pv["n_events"][cs]
        print(f"   table {c:11s} against dandiset {cs:11s}: Spearman %.3f" % stats.spearmanr(a, b)[0])
    amp = g.dropna(subset=["Mean_Amplitude", "amplitude"])
    print("   amplitude, table against dandiset: median %.3f and %.3f, dandiset higher in %d of %d cell-conditions"
          % (amp.Mean_Amplitude.median(), amp.amplitude.median(), int((amp.amplitude > amp.Mean_Amplitude).sum()), len(amp)))
print(mm[(mm.subject == "U") & (mm.region == "SMA") & mm.date.isin(["2023-03-07", "2023-03-14"])][
    ["date", "condition", "cell", "Event Rate", "rate", "n_table", "n_events", "Mean_Amplitude", "amplitude"]].round(4).to_string())
U SMA 2023-03-07: cells 5; table events (rate x duration) and dandiset events per condition, summed: {'spontaneous': (133, 4), 'task': (44, 23)}
   table spontaneous against dandiset spontaneous: Spearman -0.354
   table spontaneous against dandiset task       : Spearman 0.205
   table task        against dandiset task       : Spearman 0.975
   table task        against dandiset spontaneous: Spearman 0.354
   amplitude, table against dandiset: median 3.080 and 3.702, dandiset higher in 9 of 9 cell-conditions
U SMA 2023-03-14: cells 15; table events (rate x duration) and dandiset events per condition, summed: {'spontaneous': (246, 78), 'task': (5, 30)}
   table spontaneous against dandiset spontaneous: Spearman 0.829
   table spontaneous against dandiset task       : Spearman 0.462
   table task        against dandiset task       : Spearman 0.786
   table task        against dandiset spontaneous: Spearman -0.163
   amplitude, table against dandiset: median 2.987 and 3.488, dandiset higher in 16 of 16 cell-conditions
U SMA 2023-02-27: cells 16; table events (rate x duration) and dandiset events per condition, summed: {'spontaneous': (948, 844), 'task': (520, 478)}
   table spontaneous against dandiset spontaneous: Spearman 0.999
   table spontaneous against dandiset task       : Spearman 0.809
   table task        against dandiset task       : Spearman 0.997
   table task        against dandiset spontaneous: Spearman 0.811
   amplitude, table against dandiset: median 3.271 and 3.270, dandiset higher in 13 of 28 cell-conditions
           date    condition  cell  Event Rate    rate  n_table  n_events  Mean_Amplitude  amplitude
290  2023-03-07  spontaneous     0      0.0067  0.0008   7.9998       1.0          2.7713     3.0812
291  2023-03-07         task     0      0.0104  0.0054   9.7036       5.0          3.1868     3.7147
292  2023-03-07  spontaneous     3      0.0117  0.0008  13.9996       1.0          3.0798     3.7018
293  2023-03-07         task     3      0.0095  0.0032   8.8207       3.0          2.7928     3.1689
294  2023-03-07  spontaneous     4      0.0167  0.0008  19.9995       1.0          3.2879     4.7870
295  2023-03-07         task     4      0.0076  0.0021   7.0567       2.0          3.0095     4.0697
296  2023-03-07  spontaneous     5      0.0242  0.0000  29.0005       0.0          3.2210        NaN
297  2023-03-07         task     5      0.0085  0.0032   7.9387       3.0          2.8496     3.1891
298  2023-03-07  spontaneous     7      0.0516  0.0008  61.9996       1.0          3.3951     4.3947
299  2023-03-07         task     7      0.0114  0.0107  10.5855      10.0          3.4050     3.5443
300  2023-03-14  spontaneous     1      0.0299  0.0067  35.9995       8.0          2.9882     3.4598
301  2023-03-14         task     1      0.0048  0.0144   3.9965      12.0          3.6250     3.7494
302  2023-03-14  spontaneous     2      0.0075  0.0000   8.9996       0.0          2.9238        NaN
303  2023-03-14         task     2      0.0006  0.0024   0.4997       2.0          2.7713     3.4399
304  2023-03-14  spontaneous     3      0.0017  0.0000   2.0004       0.0          2.6455        NaN
305  2023-03-14         task     3      0.0000  0.0000   0.0000       0.0             NaN        NaN
306  2023-03-14  spontaneous     4      0.0116  0.0042  13.9995       5.0          3.0582     3.4570
307  2023-03-14         task     4      0.0000  0.0024   0.0000       2.0             NaN     3.0735
308  2023-03-14  spontaneous     6      0.0025  0.0008   2.9995       1.0          3.1100     3.7602
309  2023-03-14         task     6      0.0000  0.0000   0.0000       0.0             NaN        NaN
310  2023-03-14  spontaneous     7      0.0158  0.0091  19.0006      11.0          3.6632     4.2616
311  2023-03-14         task     7      0.0000  0.0000   0.0000       0.0             NaN        NaN
312  2023-03-14  spontaneous     8      0.0092  0.0008  11.0000       1.0          2.8107     3.1747
313  2023-03-14         task     8      0.0000  0.0000   0.0000       0.0             NaN        NaN
314  2023-03-14  spontaneous    10      0.0075  0.0025   8.9996       3.0          2.7946     3.2661
315  2023-03-14         task    10      0.0000  0.0000   0.0000       0.0             NaN        NaN
316  2023-03-14  spontaneous    12      0.0158  0.0091  19.0006      11.0          3.3502     3.7379
317  2023-03-14         task    12      0.0000  0.0012   0.0000       1.0             NaN     3.2798
318  2023-03-14  spontaneous    13      0.0116  0.0008  13.9995       1.0          2.9860     3.5184
319  2023-03-14         task    13      0.0006  0.0072   0.4997       6.0          2.5145     3.2360
320  2023-03-14  spontaneous    14      0.0008  0.0000   1.0002       0.0          2.5385        NaN
321  2023-03-14         task    14      0.0000  0.0000   0.0000       0.0             NaN        NaN
322  2023-03-14  spontaneous    15      0.0308  0.0166  36.9998      20.0          3.3929     3.8327
323  2023-03-14         task    15      0.0000  0.0000   0.0000       0.0             NaN        NaN
324  2023-03-14  spontaneous    16      0.0150  0.0067  18.0004       8.0          3.3755     3.7928
325  2023-03-14         task    16      0.0000  0.0012   0.0000       1.0             NaN     3.9585
326  2023-03-14  spontaneous    18      0.0258  0.0025  30.9996       3.0          2.8260     3.5161
327  2023-03-14         task    18      0.0006  0.0048   0.4997       4.0          2.7820     3.1359
328  2023-03-14  spontaneous    19      0.0191  0.0050  23.0003       6.0          2.9651     3.4438
329  2023-03-14         task    19      0.0000  0.0024   0.0000       2.0             NaN     3.2597

Result: not reproduced. The table's cells are found in the dandiset: 565 of 626 table rows match a cell by session and index (the 61 unmatched are F task rows, and F has no task files), and 93.8% of the matched cells have both centroid coordinates within 3 pixels of the dandiset's footprint centroids, so the identity of the cells holds. The descriptors do not agree to the criterion's 1%: 86 of 313 matched cells (27.5%) have rate and amplitude within 1% in every condition, below the 50% the criterion asks. The table's rates are higher than the dandiset's by a median factor of 1.042 (5th to 95th percentile 0.999 to 1.499), and agree within 1% for 40.9% of cell-conditions; amplitudes agree within 1% for 66.3%. Two U SMA sessions differ by large factors (2023-03-07 spontaneous 19.999, 2023-03-14 task 0.042). One-frame inter-event intervals are rarer in the dandiset (median IEI of one frame in 3.9% of cell-conditions, against 11.9% in the table), consistent with events missing from the dandiset's event arrays. The two U SMA sessions that differ most are not a swap of conditions: in 2023-03-07 the table's task counts follow the dandiset's task counts (Spearman 0.975) while its spontaneous counts follow neither file (-0.354 and 0.205), and in 2023-03-14 each condition follows its own file best (0.829 and 0.786). In both, the dandiset has fewer spontaneous events (4 against 133 and 78 against 246, over the first-occurrence cells) and a higher amplitude in every cell-condition (medians 3.702 against 3.080 and 3.488 against 2.987), which looks like a different event detection in those files; the well-matched 2023-02-27 has amplitudes higher in 13 of 28. The table is still used below for the cells' first occurrences, which rest on the identity, not on the descriptors.

cell-counts¶

In SMA 129, 61 and 63 cells were identified in monkeys Q, F and U, and in M1 37 and 23 cells in monkeys U and V.

Reading (i): unique cells, each counted once, which needs the first occurrences of the Zenodo table (through the link above). Reading (ii): the sum of accepted cells over the sessions the claims file lists (F without 2024-03-19, which the Jaccard code leaves out with one cell; F with it is shown).

In [12]:
expected = {("Q", "SMA"): 129, ("F", "SMA"): 61, ("U", "SMA"): 63, ("U", "M1"): 37, ("V", "M1"): 23}
first = mm[mm.condition == "spontaneous"]
uniq = first.groupby(["subject", "region"])["cell"].size()
uniq_no319 = first[~((first.subject == "F") & (first.date == "2024-03-19"))].groupby(["subject", "region"])["cell"].size()
summed = pd.Series({k[:2]: 0 for k in ses})
summed_no319 = summed.copy()
for k, d in ses.items():
    n = (d.get("spontaneous") or d.get("task"))["events"].shape[1]
    summed[k[:2]] += n
    if k != ("F", "SMA", "2024-03-19"):
        summed_no319[k[:2]] += n
tab = pd.DataFrame({"paper": pd.Series(expected), "unique (i)": uniq, "unique (i), F without 03-19": uniq_no319,
                    "sum over sessions (ii)": summed, "sum (ii), F without 03-19": summed_no319})
tab["tolerance"] = tab["paper"] * 0.1
for c in ["unique (i)", "unique (i), F without 03-19", "sum over sessions (ii)", "sum (ii), F without 03-19"]:
    tab["ok " + c] = (tab[c] - tab["paper"]).abs() <= tab["tolerance"]
print(tab.to_string())
print("all five within tolerance: reading (i)", tab["ok unique (i), F without 03-19"].all(), "| reading (ii)", tab["ok sum (ii), F without 03-19"].all())
print("unique cells in total:", int(uniq.sum()), "| accepted cells summed over sessions:", int(summed.sum()))
       paper  unique (i)  unique (i), F without 03-19  sum over sessions (ii)  sum (ii), F without 03-19  tolerance  ok unique (i)  ok unique (i), F without 03-19  ok sum over sessions (ii)  ok sum (ii), F without 03-19
F SMA     61          61                           60                      88                         87        6.1           True                            True                      False                         False
Q SMA    129         129                          129                     160                        160       12.9           True                            True                      False                         False
U M1      37          37                           37                      43                         43        3.7           True                            True                      False                         False
  SMA     63          63                           63                      85                         85        6.3           True                            True                      False                         False
V M1      23          23                           23                      25                         25        2.3           True                            True                       True                          True
all five within tolerance: reading (i) True | reading (ii) False
unique cells in total: 313 | accepted cells summed over sessions: 401

Result: reproduced. Under reading (i), unique cells counted once, the counts are Q SMA 129, F SMA 61 (60 without 2024-03-19), U SMA 63, U M1 37 and V M1 23, all within tolerance. These counts come from the first occurrences in the paper's Zenodo table, matched to the dandiset's cells (link above); the dandiset alone does not say which cells repeat, so this reading compares the paper's table with the paper's text more than it tests the dandiset. Under reading (ii), the only count the dandiset gives by itself, accepted cells summed over sessions, the counts are 160, 87, 85, 43 and 25, and only V is within tolerance.

cells-tracked-18pct (blocked)¶

About 18% of cells were tracked across up to three recording sessions.

The dandiset carries no cross-session identity (the PlaneSegmentation ids are 0..n-1 in every file, data check), and the Zenodo table lists each cell only at its first occurrence: the later occurrences of a cell are not named. What can be computed is a bound. Each session's accepted cells minus the cells first seen in it are repeat occurrences; with at most three sessions per cell, the number of cells seen more than once is between half the repeats and all of them.

In [13]:
rep = 0
per_s = []
for k, d in sorted(ses.items()):
    n = (d.get("spontaneous") or d.get("task"))["events"].shape[1]
    new = ((first.subject == k[0]) & (first.region == k[1]) & (first.date == k[2])).sum()
    per_s.append((k, n, new, n - new))
    rep += n - new
U = int(uniq.sum())
print(pd.DataFrame(per_s, columns=["session", "accepted", "first seen here", "repeats"]).to_string())
print("repeat occurrences %d; unique cells %d; cells seen in 2 or more sessions between %d and %d, a fraction of %.3f to %.3f"
      % (rep, U, int(np.ceil(rep / 2)), rep, np.ceil(rep / 2) / U, rep / U))
                 session  accepted  first seen here  repeats
0   (F, SMA, 2024-02-13)         6                6        0
1   (F, SMA, 2024-02-20)        16               15        1
2   (F, SMA, 2024-02-23)        15                7        8
3   (F, SMA, 2024-02-27)        14                8        6
4   (F, SMA, 2024-02-29)        14               11        3
5   (F, SMA, 2024-03-05)        12               12        0
6   (F, SMA, 2024-03-07)         6                0        6
7   (F, SMA, 2024-03-12)         4                1        3
8   (F, SMA, 2024-03-19)         1                1        0
9   (Q, SMA, 2022-09-15)        40               40        0
10  (Q, SMA, 2022-09-22)        38               24       14
11  (Q, SMA, 2022-10-03)        18               15        3
12  (Q, SMA, 2022-10-28)        21               21        0
13  (Q, SMA, 2022-12-01)        13               11        2
14  (Q, SMA, 2022-12-02)        12                5        7
15  (Q, SMA, 2022-12-06)        18               13        5
16   (U, M1, 2023-02-24)         8                8        0
17   (U, M1, 2023-03-01)        21               16        5
18   (U, M1, 2023-03-16)         8                8        0
19   (U, M1, 2023-03-23)         6                5        1
20  (U, SMA, 2023-02-27)        16               16        0
21  (U, SMA, 2023-03-07)        10                5        5
22  (U, SMA, 2023-03-14)        20               15        5
23  (U, SMA, 2023-03-21)        25               19        6
24  (U, SMA, 2023-03-28)        14                8        6
25   (V, M1, 2023-03-09)        11               10        1
26   (V, M1, 2023-03-16)        14               13        1
repeat occurrences 88; unique cells 313; cells seen in 2 or more sessions between 44 and 88, a fraction of 0.141 to 0.281

Figure 1D to 1F: event rate, IEI CV and amplitude¶

Cells are counted once, in the session where they were first identified (Methods, "Cell identification": "We only report results for the first session in which cells were identified"), taken from the Zenodo table. Descriptors are computed from the dandiset's events (method D). The claims file's reading D (ii), the median of a cell over the sessions it appears in, cannot be run, as the later occurrences are not identified (see above); only reading D (i) is run.

Per cell: rate (all cells), amplitude (cells with an event), IEI CV (cells with two or more intervals). Spontaneous against task, a two-sided Wilcoxon signed-rank test paired by cell (scipy's default, zero differences dropped, a standard choice), over cells with the measure defined in both parts.

In [14]:
fc = first.drop(columns=["condition"])[["subject", "region", "date", "cell", "Global_cell_ID"]].drop_duplicates()
W = []
for _, r in fc.iterrows():
    d = ses[(r.subject, r.region, r.date)]
    rec = {"subject": r.subject, "region": r.region, "date": r.date, "cell": r.cell}
    for c in ("spontaneous", "task"):
        if c in d:
            row = D[(D.subject == r.subject) & (D.region == r.region) & (D.date == r.date) & (D.condition == c) & (D.cell == r.cell)].iloc[0]
            for meas in ("rate", "iei_cv", "amplitude"):
                rec[f"{meas}_{c}"] = row[meas]
    W.append(rec)
W = pd.DataFrame(W)
W["site"] = W.subject + " " + W.region
print("first-occurrence cells per site:", W.groupby("site").size().to_dict())
print("with a task part:", W.dropna(subset=["rate_task"]).groupby("site").size().to_dict())
summ = []
for site, g in W.groupby("site"):
    for meas in ("rate", "iei_cv", "amplitude"):
        for c in ("spontaneous", "task"):
            v = g[f"{meas}_{c}"].dropna() if f"{meas}_{c}" in g else pd.Series(dtype=float)
            summ.append({"site": site, "measure": meas, "condition": c, "n": len(v),
                         "median": v.median() if len(v) else np.nan, "min": v.min() if len(v) else np.nan, "max": v.max() if len(v) else np.nan})
print(pd.DataFrame(summ).round(4).to_string())
first-occurrence cells per site: {'F SMA': 61, 'Q SMA': 129, 'U M1': 37, 'U SMA': 63, 'V M1': 23}
with a task part: {'Q SMA': 129, 'U M1': 37, 'U SMA': 63, 'V M1': 23}
     site    measure    condition    n  median     min      max
0   F SMA       rate  spontaneous   61  0.0382  0.0033   0.6041
1   F SMA       rate         task    0     NaN     NaN      NaN
2   F SMA     iei_cv  spontaneous   61  1.7661  0.0000   5.7025
3   F SMA     iei_cv         task    0     NaN     NaN      NaN
4   F SMA  amplitude  spontaneous   61  4.5304  2.9433   9.2225
5   F SMA  amplitude         task    0     NaN     NaN      NaN
6   Q SMA       rate  spontaneous  129  0.0205  0.0000   1.1832
7   Q SMA       rate         task  129  0.0243  0.0000   0.9946
8   Q SMA     iei_cv  spontaneous  108  1.7895  0.1811   4.8588
9   Q SMA     iei_cv         task  116  1.7193  0.0862   5.0433
10  Q SMA  amplitude  spontaneous  118  3.5875  2.5878   6.5799
11  Q SMA  amplitude         task  121  3.6543  2.3889   7.5134
12   U M1       rate  spontaneous   37  0.0891  0.0000   1.1671
13   U M1       rate         task   37  0.1151  0.0000   1.1888
14   U M1     iei_cv  spontaneous   34  1.7527  0.6335   3.0270
15   U M1     iei_cv         task   35  1.4231  0.8722   3.4639
16   U M1  amplitude  spontaneous   35  3.3643  2.7783  10.3525
17   U M1  amplitude         task   36  3.3838  1.9758   9.2058
18  U SMA       rate  spontaneous   63  0.0042  0.0000   0.1731
19  U SMA       rate         task   63  0.0089  0.0000   0.2305
20  U SMA     iei_cv  spontaneous   42  1.6087  0.2206   3.1462
21  U SMA     iei_cv         task   42  1.4121  0.2116   3.6954
22  U SMA  amplitude  spontaneous   53  3.3895  2.4898  11.8703
23  U SMA  amplitude         task   52  3.1927  2.6571   8.0641
24   V M1       rate  spontaneous   23  0.0856  0.0000   0.9443
25   V M1       rate         task   23  0.0810  0.0000   0.9235
26   V M1     iei_cv  spontaneous   20  1.7099  1.0090   9.0201
27   V M1     iei_cv         task   16  1.8314  0.7993   3.9857
28   V M1  amplitude  spontaneous   22  4.0215  2.5864  22.7932
29   V M1  amplitude         task   19  3.6910  2.6416  23.7337
In [15]:
def signrank(g, meas):
    a, b = g[f"{meas}_spontaneous"], g[f"{meas}_task"]
    ok = a.notna() & b.notna()
    a, b = a[ok], b[ok]
    if (a - b).abs().sum() == 0 or ok.sum() < 2:
        return ok.sum(), np.nan, a.median(), b.median()
    return ok.sum(), stats.wilcoxon(a, b).pvalue, a.median(), b.median()

groupings = {
    "(i) region": {"SMA": W[W.region == "SMA"], "M1": W[W.region == "M1"]},
    "(ii) site": {s: g for s, g in W.groupby("site") if g["rate_task"].notna().any()},
}
T = []
for gname, groups in groupings.items():
    for grp, g in groups.items():
        for meas in ("rate", "iei_cv", "amplitude"):
            n, p, ms, mt = signrank(g, meas)
            T.append({"grouping": gname, "group": grp, "measure": meas, "n": n, "p": p, "median_spont": ms, "median_task": mt})
T = pd.DataFrame(T)
for gname in groupings:
    sel = T.grouping == gname
    T.loc[sel, "q_family_a"] = h.bh(T.loc[sel, "p"])          # all measures of the grouping
    for meas in ("rate", "iei_cv", "amplitude"):
        s2 = sel & (T.measure == meas)
        T.loc[s2, "q_family_b"] = h.bh(T.loc[s2, "p"])        # this measure only
T["effect_r"] = np.nan
for i, r in T.iterrows():
    g = groupings[r.grouping][r.group]
    a, b = g[f"{r.measure}_spontaneous"], g[f"{r.measure}_task"]
    ok = a.notna() & b.notna()
    d = (a[ok] - b[ok])
    T.loc[i, "frac_spont_higher"] = (d > 0).mean() if ok.sum() else np.nan
print(T.drop(columns="effect_r").round(4).to_string())
      grouping  group    measure    n       p  median_spont  median_task  q_family_a  q_family_b  frac_spont_higher
0   (i) region    SMA       rate  192  0.8624        0.0149       0.0166      0.8624      0.8624             0.4688
1   (i) region    SMA     iei_cv  127  0.7471        1.7525       1.5958      0.8624      0.7731             0.5591
2   (i) region    SMA  amplitude  155  0.0033        3.5322       3.4431      0.0198      0.0066             0.6323
3   (i) region     M1       rate   60  0.4414        0.0874       0.0865      0.8624      0.8624             0.5667
4   (i) region     M1     iei_cv   47  0.7731        1.7568       1.6010      0.8624      0.7731             0.4681
5   (i) region     M1  amplitude   53  0.3881        3.7642       3.6101      0.8624      0.3881             0.5283
6    (ii) site  Q SMA       rate  129  0.4538        0.0205       0.0243      0.7779      0.6050             0.4884
7    (ii) site  Q SMA     iei_cv   97  0.5563        1.7777       1.7094      0.8345      0.8904             0.5361
8    (ii) site  Q SMA  amplitude  111  0.1108        3.5950       3.6967      0.3323      0.2216             0.5946
9    (ii) site   U M1       rate   37  0.9406        0.0891       0.1151      0.9406      0.9406             0.4865
10   (ii) site   U M1     iei_cv   32  0.7190        1.7527       1.5358      0.9290      0.8904             0.5000
11   (ii) site   U M1  amplitude   34  0.7742        3.3692       3.4478      0.9290      0.7742             0.5000
12   (ii) site  U SMA       rate   63  0.2671        0.0042       0.0089      0.6248      0.5342             0.4286
13   (ii) site  U SMA     iei_cv   30  0.0841        1.6083       1.3899      0.3323      0.3363             0.6333
14   (ii) site  U SMA  amplitude   44  0.0017        3.4093       3.1662      0.0204      0.0068             0.7273
15   (ii) site   V M1       rate   23  0.0666        0.0856       0.0810      0.3323      0.2664             0.6957
16   (ii) site   V M1     iei_cv   15  0.8904        1.7703       2.0268      0.9406      0.8904             0.4000
17   (ii) site   V M1  amplitude   19  0.3124        4.1063       3.6910      0.6248      0.4165             0.5789

fig1d-rate-no-change¶

Calcium event rates did not differ between the spontaneous and reaching task conditions in either SMA or M1.

In [16]:
r = T[T.measure == "rate"]
print(r[["grouping", "group", "n", "p", "q_family_a", "q_family_b", "median_spont", "median_task", "frac_spont_higher"]].round(4).to_string())
print("readings with a significant difference (q < 0.05): family a", int((r.q_family_a < 0.05).sum()), "| family b", int((r.q_family_b < 0.05).sum()),
      "| uncorrected p < 0.05:", int((r.p < 0.05).sum()), "of", len(r))
      grouping  group    n       p  q_family_a  q_family_b  median_spont  median_task  frac_spont_higher
0   (i) region    SMA  192  0.8624      0.8624      0.8624        0.0149       0.0166             0.4688
3   (i) region     M1   60  0.4414      0.8624      0.8624        0.0874       0.0865             0.5667
6    (ii) site  Q SMA  129  0.4538      0.7779      0.6050        0.0205       0.0243             0.4884
9    (ii) site   U M1   37  0.9406      0.9406      0.9406        0.0891       0.1151             0.4865
12   (ii) site  U SMA   63  0.2671      0.6248      0.5342        0.0042       0.0089             0.4286
15   (ii) site   V M1   23  0.0666      0.3323      0.2664        0.0856       0.0810             0.6957
readings with a significant difference (q < 0.05): family a 0 | family b 0 | uncorrected p < 0.05: 0 of 6

Result: reproduced. No reading finds a difference in event rate between the spontaneous and task parts: over the six tests (SMA and M1 pooled, and Q SMA, U SMA, U M1, V M1), the smallest uncorrected p is 0.0666 (V M1) and no corrected q is below 0.05 in either family. Median rates are, for example, 0.0149 and 0.0166 events/s in pooled SMA and 0.0874 and 0.0865 in pooled M1. Only the first-session reading of a cell's value (D, i) could be run.

fig1e-ieicv-no-change¶

The IEI CV did not differ between the spontaneous and reaching task conditions in either SMA or M1.

In [17]:
r = T[T.measure == "iei_cv"]
print(r[["grouping", "group", "n", "p", "q_family_a", "q_family_b", "median_spont", "median_task", "frac_spont_higher"]].round(4).to_string())
print("readings with a significant difference (q < 0.05): family a", int((r.q_family_a < 0.05).sum()), "| family b", int((r.q_family_b < 0.05).sum()),
      "| uncorrected p < 0.05:", int((r.p < 0.05).sum()), "of", len(r))
print("cells left out for fewer than two intervals in a part:", (W.iei_cv_spontaneous.isna() | W.iei_cv_task.isna())[W.rate_task.notna()].sum(),
      "of", W.rate_task.notna().sum())
      grouping  group    n       p  q_family_a  q_family_b  median_spont  median_task  frac_spont_higher
1   (i) region    SMA  127  0.7471      0.8624      0.7731        1.7525       1.5958             0.5591
4   (i) region     M1   47  0.7731      0.8624      0.7731        1.7568       1.6010             0.4681
7    (ii) site  Q SMA   97  0.5563      0.8345      0.8904        1.7777       1.7094             0.5361
10   (ii) site   U M1   32  0.7190      0.9290      0.8904        1.7527       1.5358             0.5000
13   (ii) site  U SMA   30  0.0841      0.3323      0.3363        1.6083       1.3899             0.6333
16   (ii) site   V M1   15  0.8904      0.9406      0.8904        1.7703       2.0268             0.4000
readings with a significant difference (q < 0.05): family a 0 | family b 0 | uncorrected p < 0.05: 0 of 6
cells left out for fewer than two intervals in a part: 78 of 252

Result: reproduced. No reading finds a difference in IEI CV between the parts: the smallest uncorrected p is 0.0841 (U SMA) and no corrected q is below 0.05. 78 of 252 cells with a task part are left out for fewer than two intervals in a part.

fig1f-amplitude-u-sma-spont-higher¶

In monkey U's SMA, event amplitude was significantly higher in the spontaneous state than during the reaching task.

In [18]:
r = T[(T.measure == "amplitude") & (T.group == "U SMA")]
print(r[["grouping", "group", "n", "p", "q_family_a", "q_family_b", "median_spont", "median_task", "frac_spont_higher"]].round(4).to_string())
g = groupings["(ii) site"]["U SMA"]
ok = g.amplitude_spontaneous.notna() & g.amplitude_task.notna()
print("U SMA, by session: median spontaneous and task amplitude, and cells")
print(g[ok].groupby("date").agg(n=("cell", "size"), spont=("amplitude_spontaneous", "median"), task=("amplitude_task", "median")).round(3).to_string())
     grouping  group   n       p  q_family_a  q_family_b  median_spont  median_task  frac_spont_higher
14  (ii) site  U SMA  44  0.0017      0.0204      0.0068        3.4093       3.1662             0.7273
U SMA, by session: median spontaneous and task amplitude, and cells
             n  spont   task
date                        
2023-02-27  12  3.389  3.161
2023-03-07   4  4.048  3.629
2023-03-14   7  3.516  3.260
2023-03-21  15  3.181  3.112
2023-03-28   6  3.387  3.089

Result: reproduced. In U's SMA the spontaneous amplitude is higher than the task amplitude (medians 3.409 and 3.166, spontaneous higher in 72.7% of 44 cells), signed-rank p = 0.0017, q = 0.0204 with all measures in the family (a) and 0.0068 with this measure only (b); the paper gives p = 0.032. The spontaneous median is higher in each of the five U SMA sessions. The pooled SMA test is also significant here (q = 0.0198 and 0.0066), while Q's SMA alone is not (p = 0.1108); the paper reports only U. The paper's own table gives p = 0.0074 for its 42 cells with amplitudes in both parts. Without the two U SMA sessions whose events differ most from the table (2023-03-07 and 2023-03-14), the test gives p = 0.0078 over 33 cells (medians 3.272 and 3.123), so the result does not rest on them.

fig1d-rate-m1-above-sma-u and fig1f-amplitude-m1-above-sma-u-task¶

Monkey U, M1 cells against SMA cells, two-sided Wilcoxon rank-sum test (Mann-Whitney U) per condition, uncorrected and with Benjamini-Hochberg over the two conditions of the measure.

In [19]:
U_ = W[W.subject == "U"]
R = []
for meas in ("rate", "amplitude", "iei_cv"):
    for c in ("spontaneous", "task"):
        a = U_[U_.region == "M1"][f"{meas}_{c}"].dropna()
        b = U_[U_.region == "SMA"][f"{meas}_{c}"].dropna()
        p = stats.mannwhitneyu(a, b, alternative="two-sided").pvalue
        auc = stats.mannwhitneyu(a, b).statistic / (len(a) * len(b))
        R.append({"measure": meas, "condition": c, "n_M1": len(a), "n_SMA": len(b), "median_M1": a.median(), "median_SMA": b.median(),
                  "p": p, "P(M1 > SMA)": auc})
R = pd.DataFrame(R)
for meas in ("rate", "amplitude", "iei_cv"):
    s = R.measure == meas
    R.loc[s, "q_two_conditions"] = h.bh(R.loc[s, "p"])
print(R.round(5).to_string())
# by session, for the rate
print(W[W.subject == "U"].groupby(["region", "date"]).agg(n=("cell", "size"), rate_spont=("rate_spontaneous", "median"), rate_task=("rate_task", "median")).round(4).to_string())
     measure    condition  n_M1  n_SMA  median_M1  median_SMA        p  P(M1 > SMA)  q_two_conditions
0       rate  spontaneous    37     63    0.08913     0.00416  0.00000      0.82196           0.00000
1       rate         task    37     63    0.11509     0.00887  0.00000      0.85864           0.00000
2  amplitude  spontaneous    35     53    3.36431     3.38953  0.38919      0.55472           0.38919
3  amplitude         task    36     52    3.38382     3.19274  0.09880      0.60417           0.19761
4     iei_cv  spontaneous    34     42    1.75272     1.60875  0.32868      0.56583           0.34400
5     iei_cv         task    35     42    1.42311     1.41210  0.34400      0.56327           0.34400
                    n  rate_spont  rate_task
region date                                 
M1     2023-02-24   8      0.3132     0.2435
       2023-03-01  16      0.0760     0.1151
       2023-03-16   8      0.0199     0.0277
       2023-03-23   5      0.1570     0.0908
SMA    2023-02-27  16      0.0171     0.0157
       2023-03-07   5      0.0008     0.0032
       2023-03-14  15      0.0025     0.0012
       2023-03-21  19      0.0075     0.0103
       2023-03-28   8      0.0071     0.0173
In [20]:
# Which side a difference comes from: the same tests on the paper's own per-cell values (Zenodo table),
# for the same first-occurrence cells. Shown, not used to decide.
zt = first[first.subject == "U"][["region", "cell", "date"]].copy()
Zt = z[z.subject == "U"]
Rz = []
for meas, col in (("rate", "Event Rate"), ("amplitude", "Mean_Amplitude"), ("iei_cv", "CV")):
    for c, cz in (("spontaneous", "spontaneous"), ("task", "task")):
        a = Zt[(Zt.region == "M1") & (Zt.condition == cz)][col].dropna()
        b = Zt[(Zt.region == "SMA") & (Zt.condition == cz)][col].dropna()
        Rz.append({"measure": meas, "condition": c, "n_M1": len(a), "n_SMA": len(b), "median_M1": a.median(), "median_SMA": b.median(),
                   "p": stats.mannwhitneyu(a, b, alternative="two-sided").pvalue})
print("paper's table, U M1 against U SMA (rank-sum):")
print(pd.DataFrame(Rz).round(5).to_string())
zs = Zt[(Zt.region == "SMA")].pivot_table(index=["date", "cell"], columns="condition", values="Mean_Amplitude").dropna()
print("paper's table, U SMA amplitude spontaneous against task (signed-rank): n=%d, p=%.4f, medians %.3f and %.3f"
      % (len(zs), stats.wilcoxon(zs.spontaneous, zs.task).pvalue, zs.spontaneous.median(), zs.task.median()))
paper's table, U M1 against U SMA (rank-sum):
     measure    condition  n_M1  n_SMA  median_M1  median_SMA        p
0       rate  spontaneous    37     63    0.10496     0.01166  0.00000
1       rate         task    37     63    0.11500     0.00886  0.00000
2  amplitude  spontaneous    35     57    3.37405     3.19107  0.00723
3  amplitude         task    36     48    3.40693     3.12417  0.01378
4     iei_cv  spontaneous    35     54    1.80000     1.73500  0.94642
5     iei_cv         task    36     43    1.49500     1.41000  0.22591
paper's table, U SMA amplitude spontaneous against task (signed-rank): n=42, p=0.0074, medians 3.223 and 3.110
In [21]:
# The U SMA tests without the two sessions whose events differ most from the paper's table
# (2023-03-07 and 2023-03-14, cell above), to see whether they decide the result.
drop = ["2023-03-07", "2023-03-14"]
Wx = W[~((W.subject == "U") & (W.region == "SMA") & W.date.isin(drop))]
g = Wx[Wx.site == "U SMA"]
n, p, ms, mt = signrank(g, "amplitude")
print("U SMA amplitude, spontaneous against task, without %s: n=%d, p=%.4f, medians %.3f and %.3f" % (drop, n, p, ms, mt))
Ux = Wx[Wx.subject == "U"]
for meas in ("rate", "amplitude"):
    for c in ("spontaneous", "task"):
        a, b = Ux[Ux.region == "M1"][f"{meas}_{c}"].dropna(), Ux[Ux.region == "SMA"][f"{meas}_{c}"].dropna()
        print("U M1 against U SMA without the two sessions, %s %s: n %d and %d, medians %.4f and %.4f, rank-sum p=%.2g"
              % (meas, c, len(a), len(b), a.median(), b.median(), stats.mannwhitneyu(a, b, alternative="two-sided").pvalue))
U SMA amplitude, spontaneous against task, without ['2023-03-07', '2023-03-14']: n=33, p=0.0078, medians 3.272 and 3.123
U M1 against U SMA without the two sessions, rate spontaneous: n 37 and 43, medians 0.0891 and 0.0108, rank-sum p=1.9e-05
U M1 against U SMA without the two sessions, rate task: n 37 and 43, medians 0.1151 and 0.0123, rank-sum p=2e-06
U M1 against U SMA without the two sessions, amplitude spontaneous: n 35 and 37, medians 3.3643 and 3.2329, rank-sum p=0.11
U M1 against U SMA without the two sessions, amplitude task: n 36 and 39, medians 3.3838 and 3.1331, rank-sum p=0.041

fig1d-rate-m1-above-sma-u¶

In monkey U the event rate was higher in M1 than in SMA, in both the spontaneous and the reaching task conditions.

Result: reproduced. In monkey U the event rate is higher in M1 than in SMA in both conditions: spontaneous medians 0.0891 and 0.0042 events/s, task 0.1151 and 0.0089, rank-sum p below 1e-5 for both, with or without correction over the two conditions (P(M1 > SMA) 0.82 and 0.86). Without U SMA 2023-03-07 and 2023-03-14 the p-values are 1.9e-05 and 2e-06.

fig1f-amplitude-m1-above-sma-u-task¶

In monkey U, event amplitude during the task was higher in M1 than in SMA.

Result: not reproduced. The task amplitude is higher in U's M1 than in its SMA (medians 3.384 and 3.193), but the rank-sum test gives p = 0.0988 uncorrected and q = 0.1976 corrected over the two conditions, so no reading reaches p < 0.05 (the paper gives p = 0.03). The paper's own per-cell table gives p = 0.0138 for the same comparison (medians 3.407 and 3.124), so the difference comes from the dandiset's event amplitudes, which differ from the table's (link above), not from the test. Two U SMA sessions, 2023-03-07 and 2023-03-14, where every dandiset amplitude is above the table's, account for most of the gap in the SMA task median (3.193 with them, 3.133 without, 3.124 in the table) but for less than half of it in the p-value on a log scale (0.0988 with them, 0.041 without, 0.0138 in the table). Without them the task test gives p = 0.041 (medians 3.384 and 3.133, 36 and 39 cells), below 0.05 uncorrected, while the corrected q over the two conditions is 0.082 (spontaneous p = 0.11). Leaving out sessions is not the claims file's method, so the outcome stays on all cells.

Figure 2 and Figure S1: task-aligned responses (blocked)¶

Six claims (fig2-q-sma-modulated-34pct, fig2c-q-sma-direction, fig2-q-magnitude-no-difference, figs1-u-sma-direction, figs1-u-m1-target-onset, figs1-u-m1-movement-onset) need the times of target onset and movement onset, which the paper took from TTL pulses recorded on extra channels (Methods, "Alignment to behavioral events"), and the raw traces. The data check shows the files hold neither: no trial table, no TTL channel, and only the denoised trace. The Zenodo record of activity aligned to behavioural events (doi:10.5281/zenodo.14976651) holds the paper's z-scored trial windows, its output, not the event times, so it cannot place the trials in the dandiset's recordings. These claims are blocked as data_missing.

The cell below runs the classification on the paper's z-scored windows. It tests the paper's statistics on its own processed output, not the dandiset, and decides nothing.

In [22]:
# A check on the paper's own processed data, which decides nothing: the Zenodo table of z-scored
# trial windows (doi:10.5281/zenodo.14976651), the output of the paper's alignment of raw traces to
# TTL events. Its columns are listed; then method Z's test on it: per cell and condition (target side),
# a signed-rank test across trials of the mean z in 0 to 0.9 s against the mean z in -1 to -0.1 s
# (the table's samples), with Benjamini-Hochberg over each chamber and alignment (main), per
# condition column (the code's FDR_correction.m), and uncorrected.
AL, al_md5 = h.read_zenodo_csv("14976651", "Event alignment-consolidated table.csv")
print("Zenodo aligned-activity table", al_md5, AL.shape)
print("columns:", list(AL.columns[:5]), "+", len(AL.columns) - 5, "z-scored samples from", AL.columns[5], "to", AL.columns[-1])
AL.columns = ["monkey", "gid", "trial", "side", "aligned"] + list(AL.columns[5:])
AL["gid"] = AL.gid.str.strip("' ")
AL["side"] = AL.side.astype(str)
AL["chamber"] = AL.gid.str.rsplit(" ", n=1).str[0]
zc = [c for c in AL.columns if c.startswith("z-scored")]
AL["pre"], AL["post"] = AL[zc[:10]].mean(axis=1), AL[zc[10:20]].mean(axis=1)
print(AL.groupby(["chamber", "aligned"]).agg(cells=("gid", "nunique"), trials=("trial", "size"), sides=("side", lambda v: sorted(v.unique()))).to_string())
F2 = []
for (ch, al), g in AL.groupby(["chamber", "aligned"]):
    R2 = []
    for (gid, side), gg in g.groupby(["gid", "side"]):
        R2.append({"gid": gid, "side": side, "trials": len(gg), "p": stats.wilcoxon(gg.post, gg.pre).pvalue})
    R2 = pd.DataFrame(R2)
    R2["q_all"] = h.bh(R2.p)
    R2["q_col"] = np.nan
    for s, idx in R2.groupby("side").groups.items():
        R2.loc[idx, "q_col"] = h.bh(R2.loc[idx, "p"])
    for col in ("q_all", "q_col", "p"):
        k = R2[R2[col] < 0.05].groupby("gid").size()
        F2.append({"chamber": ch, "aligned": al, "fdr": {"q_all": "chamber", "q_col": "per condition", "p": "none"}[col],
                   "cells": R2.gid.nunique(), "tests": len(R2), "modulated": len(k), "direction_related": int((k == 1).sum()),
                   "not_direction_related": int((k >= 2).sum())})
print(pd.DataFrame(F2).to_string())
/home/runner/work/encore/encore/entries/001174-martel-2025/sma_m1.py:177: DtypeWarning: Columns (3: Side of target) have mixed types. Specify dtype option on import or set low_memory=False.
  df = pd.read_csv(f["links"]["self"], encoding="latin-1")
Zenodo aligned-activity table md5:3826e7afab34289f31e82a8838c992dc (18127, 35)
columns: ['Monkey', 'Global cell ID', 'Trial number', 'Side of target', 'Aligned to'] + 30 z-scored samples from z-scored data -1s to z-scored data 1.9s
                         cells  trials                  sides
chamber aligned                                              
Q SMA   Rewarded target    129   14051  [center, left, right]
U M1    Movement onset       6     666                 [1, 2]
        Rewarded target      6     666                 [1, 2]
U SMA   Movement onset      14    1372                 [1, 2]
        Rewarded target     14    1372          [left, right]
   chamber          aligned            fdr  cells  tests  modulated  direction_related  not_direction_related
0    Q SMA  Rewarded target        chamber    129    387         20                 14                      6
1    Q SMA  Rewarded target  per condition    129    387         21                 15                      6
2    Q SMA  Rewarded target           none    129    387         42                 24                     18
3     U M1   Movement onset        chamber      6     12          6                  3                      3
4     U M1   Movement onset  per condition      6     12          6                  3                      3
5     U M1   Movement onset           none      6     12          6                  3                      3
6     U M1  Rewarded target        chamber      6     12          6                  3                      3
7     U M1  Rewarded target  per condition      6     12          6                  3                      3
8     U M1  Rewarded target           none      6     12          6                  2                      4
9    U SMA   Movement onset        chamber     14     28          6                  6                      0
10   U SMA   Movement onset  per condition     14     28          6                  6                      0
11   U SMA   Movement onset           none     14     28          7                  7                      0
12   U SMA  Rewarded target        chamber     14     28          5                  5                      0
13   U SMA  Rewarded target  per condition     14     28          6                  6                      0
14   U SMA  Rewarded target           none     14     28          6                  4                      2

Figure 3: coactivation (method J)¶

Every session and condition, all cells. Events binned at 0.2 s, forward smoothed over 1 s; Jaccard per pair, null from 1000 circular shifts of one cell (Methods); Z-Jaccard. A pair with a cell without events has no Z-Jaccard and is left out, as the code does (na.rm=TRUE in 1_JaccardIndexAnalysisAllSessions.R). Each condition is a file of its own, so each file is binned on its own (see the helper). The paper's code, 1_JaccardIndexAnalysisAllSessions.R, defines the proportion as pairs with Z-Jaccard above 1.96 plus pairs below -1.96, that is |Z| > 1.96, as the claims file has it; the share above 1.96 alone (the code's prop_sync) is shown as a variant.

In [23]:
JAC = []
rng = np.random.default_rng(20250527)
for key, d in sorted(ses.items()):
    for c, x in sorted(d.items()):
        ys = h.binned_logical(x)
        P = h.zjaccard(ys, n_shift=1000, rng=rng)
        P["dist_um"] = h.pair_distances(x["centroid"], P)
        P["subject"], P["region"], P["date"], P["condition"], P["bins"] = key[0], key[1], key[2], c, ys.shape[0]
        JAC.append(P)
JAC = pd.concat(JAC, ignore_index=True)
prop = JAC.groupby(["subject", "region", "date", "condition"]).agg(
    pairs=("z", "size"), defined=("z", lambda v: v.notna().sum()), bins=("bins", "first"),
    prop_abs=("z", lambda v: (v.dropna().abs() > 1.96).mean()),
    prop_pos=("z", lambda v: (v.dropna() > 1.96).mean()),
    prop_abs_all_pairs=("z", lambda v: (v.abs() > 1.96).sum() / len(v))).reset_index()
print(prop.round(4).to_string())
print("bins per file: spontaneous %d to %d (median %d), task %d to %d (median %d); the Methods give 1508 to 6547 (median 6012) and 2371 to 6041 (median 3700)"
      % (prop[prop.condition == "spontaneous"].bins.min(), prop[prop.condition == "spontaneous"].bins.max(), prop[prop.condition == "spontaneous"].bins.median(),
         prop[prop.condition == "task"].bins.min(), prop[prop.condition == "task"].bins.max(), prop[prop.condition == "task"].bins.median()))
   subject region        date    condition  pairs  defined  bins  prop_abs  prop_pos  prop_abs_all_pairs
0        F    SMA  2024-02-13  spontaneous     15       15  3008    0.0000    0.0000              0.0000
1        F    SMA  2024-02-20  spontaneous    120      120  6022    0.0667    0.0583              0.0667
2        F    SMA  2024-02-23  spontaneous    105      105  6023    0.1048    0.0857              0.1048
3        F    SMA  2024-02-27  spontaneous     91       91  6015    0.1099    0.0879              0.1099
4        F    SMA  2024-02-29  spontaneous     91       91  6026    0.2088    0.1429              0.2088
5        F    SMA  2024-03-05  spontaneous     66       66  6004    0.1212    0.0909              0.1212
6        F    SMA  2024-03-07  spontaneous     15       15  6340    0.0667    0.0667              0.0667
7        F    SMA  2024-03-12  spontaneous      6        6  3052    0.1667    0.1667              0.1667
8        Q    SMA  2022-09-15  spontaneous    780      629  3012    0.0795    0.0795              0.0641
9        Q    SMA  2022-09-15         task    780      740  4515    0.0743    0.0703              0.0705
10       Q    SMA  2022-09-22  spontaneous    703      630  3007    0.1143    0.1079              0.1024
11       Q    SMA  2022-09-22         task    703      630  6038    0.0635    0.0635              0.0569
12       Q    SMA  2022-10-03  spontaneous    153      104  6544    0.0385    0.0385              0.0261
13       Q    SMA  2022-10-03         task    153      120  6023    0.0750    0.0667              0.0588
14       Q    SMA  2022-10-28  spontaneous    210      190  6002    0.0632    0.0632              0.0571
15       Q    SMA  2022-10-28         task    210      210  4303    0.0810    0.0810              0.0810
16       Q    SMA  2022-12-01  spontaneous     78       45  6403    0.1111    0.0889              0.0641
17       Q    SMA  2022-12-01         task     78       66  3220    0.0455    0.0455              0.0385
18       Q    SMA  2022-12-02  spontaneous     66       66  6060    0.1515    0.1515              0.1515
19       Q    SMA  2022-12-02         task     66       66  3502    0.1061    0.0909              0.1061
20       Q    SMA  2022-12-06  spontaneous    153      153  6103    0.1438    0.0980              0.1438
21       Q    SMA  2022-12-06         task    153       91  3465    0.0659    0.0659              0.0392
22       U     M1  2023-02-24  spontaneous     28       28  5999    0.1786    0.1786              0.1786
23       U     M1  2023-02-24         task     28       28  2369    0.2143    0.2143              0.2143
24       U     M1  2023-03-01  spontaneous    210      210  6020    0.1286    0.1048              0.1286
25       U     M1  2023-03-01         task    210      190  2994    0.1421    0.1105              0.1286
26       U     M1  2023-03-16  spontaneous     28       15  1505    0.0667    0.0667              0.0357
27       U     M1  2023-03-16         task     28       28  5778    0.1786    0.1786              0.1786
28       U     M1  2023-03-23  spontaneous     15       15  6048    0.0667    0.0667              0.0667
29       U     M1  2023-03-23         task     15       15  3850    0.2667    0.2667              0.2667
30       U    SMA  2023-02-27  spontaneous    120       91  6006    0.0549    0.0549              0.0417
31       U    SMA  2023-02-27         task    120       91  3653    0.0659    0.0659              0.0500
32       U    SMA  2023-03-07  spontaneous     45       28  5999    0.0000    0.0000              0.0000
33       U    SMA  2023-03-07         task     45       45  4648    0.0444    0.0444              0.0444
34       U    SMA  2023-03-14  spontaneous    190      135  6007    0.0444    0.0444              0.0316
35       U    SMA  2023-03-14         task    190       78  4174    0.0256    0.0256              0.0105
36       U    SMA  2023-03-21  spontaneous    300      231  6005    0.0693    0.0693              0.0533
37       U    SMA  2023-03-21         task    300      231  3380    0.0433    0.0433              0.0333
38       U    SMA  2023-03-28  spontaneous     91       66  6007    0.0758    0.0758              0.0549
39       U    SMA  2023-03-28         task     91       91  3743    0.0549    0.0549              0.0549
40       V     M1  2023-03-09  spontaneous     55       55  6011    0.0727    0.0727              0.0727
41       V     M1  2023-03-09         task     55       36  2588    0.1389    0.1389              0.0909
42       V     M1  2023-03-16  spontaneous     91       78  6011    0.2564    0.1923              0.2198
43       V     M1  2023-03-16         task     91       55  2487    0.1818    0.1636              0.1099
bins per file: spontaneous 1505 to 6544 (median 6009), task 2369 to 6038 (median 3698); the Methods give 1508 to 6547 (median 6012) and 2371 to 6041 (median 3700)
In [24]:
# The paper's Jaccard table, next to this attempt's proportions (shown, not used to decide).
Jz, j_md5 = h.read_zenodo_csv(h.ZENODO_JACCARD, "Jaccard_data_table (fig 3)_Tidy version.csv")
Jz["date"] = pd.to_datetime(Jz.iloc[:, 0], format="%d-%b-%y").dt.strftime("%Y-%m-%d")
Jz["condition"] = Jz["condition"].map({"Spontaneous": "spontaneous", "Reaching_task": "task"})
Jz = Jz.rename(columns={"structure": "region"})
pz = Jz.groupby(["subject", "region", "date", "condition"]).agg(pairs_paper=("z.jaccard", "size"),
       prop_abs_paper=("z.jaccard", lambda v: (v.dropna().abs() > 1.96).mean())).reset_index()
cmp_ = prop.merge(pz, on=["subject", "region", "date", "condition"], how="outer")
print("Zenodo Jaccard table", j_md5)
print(cmp_[["subject", "region", "date", "condition", "pairs", "pairs_paper", "prop_abs", "prop_abs_paper"]].round(4).to_string())
ok = cmp_.dropna(subset=["prop_abs", "prop_abs_paper"])
# cells per session in the paper's Jaccard table (from its pairs) against the dandiset's accepted cells
import math
cells_paper = Jz.groupby(["subject", "region", "date", "condition"]).size().apply(lambda n: int(round((1 + math.sqrt(1 + 8 * n)) / 2))).rename("cells_paper")
cells_here = pd.Series({(x["subject"], x["region"], x["date"], x["condition"]): x["events"].shape[1] for x in files}, name="cells_here")
cc = pd.concat([cells_paper, cells_here], axis=1).dropna()
print("session-conditions where the dandiset has more accepted cells than the paper's Jaccard table:")
print(cc[cc.cells_here != cc.cells_paper].astype(int).to_string())
print("sessions in both: %d; correlation of proportions %.3f; median |difference| %.4f"
      % (len(ok), np.corrcoef(ok.prop_abs, ok.prop_abs_paper)[0, 1], (ok.prop_abs - ok.prop_abs_paper).abs().median()))
Zenodo Jaccard table md5:6a7bfc28406dd82e08920f8b747a2782
   subject region        date    condition  pairs  pairs_paper  prop_abs  prop_abs_paper
0        F    SMA  2023-02-20  spontaneous    NaN        105.0       NaN          0.0762
1        F    SMA  2024-02-13  spontaneous   15.0         15.0    0.0000          0.0000
2        F    SMA  2024-02-20  spontaneous  120.0          NaN    0.0667             NaN
3        F    SMA  2024-02-23  spontaneous  105.0        105.0    0.1048          0.1333
4        F    SMA  2024-02-27  spontaneous   91.0         91.0    0.1099          0.1209
5        F    SMA  2024-02-29  spontaneous   91.0         91.0    0.2088          0.2308
6        F    SMA  2024-03-05  spontaneous   66.0         66.0    0.1212          0.1061
7        F    SMA  2024-03-07  spontaneous   15.0         15.0    0.0667          0.0667
8        F    SMA  2024-03-12  spontaneous    6.0          6.0    0.1667          0.1667
9        Q    SMA  2022-09-15  spontaneous  780.0        780.0    0.0795          0.0825
10       Q    SMA  2022-09-15         task  780.0        780.0    0.0743          0.0810
11       Q    SMA  2022-09-22  spontaneous  703.0        703.0    0.1143          0.1048
12       Q    SMA  2022-09-22         task  703.0        703.0    0.0635          0.0714
13       Q    SMA  2022-10-03  spontaneous  153.0        136.0    0.0385          0.0385
14       Q    SMA  2022-10-03         task  153.0        136.0    0.0750          0.0583
15       Q    SMA  2022-10-28  spontaneous  210.0        210.0    0.0632          0.0691
16       Q    SMA  2022-10-28         task  210.0        210.0    0.0810          0.0810
17       Q    SMA  2022-12-01  spontaneous   78.0         55.0    0.1111          0.1111
18       Q    SMA  2022-12-01         task   78.0         55.0    0.0455          0.0364
19       Q    SMA  2022-12-02  spontaneous   66.0         66.0    0.1515          0.1515
20       Q    SMA  2022-12-02         task   66.0         66.0    0.1061          0.1061
21       Q    SMA  2022-12-06  spontaneous  153.0        153.0    0.1438          0.1569
22       Q    SMA  2022-12-06         task  153.0        153.0    0.0659          0.0659
23       U     M1  2023-02-24  spontaneous   28.0         28.0    0.1786          0.1429
24       U     M1  2023-02-24         task   28.0         28.0    0.2143          0.1786
25       U     M1  2023-03-01  spontaneous  210.0        210.0    0.1286          0.1381
26       U     M1  2023-03-01         task  210.0        210.0    0.1421          0.1526
27       U     M1  2023-03-16  spontaneous   28.0         28.0    0.0667          0.0667
28       U     M1  2023-03-16         task   28.0         28.0    0.1786          0.1429
29       U     M1  2023-03-23  spontaneous   15.0         15.0    0.0667          0.0667
30       U     M1  2023-03-23         task   15.0         15.0    0.2667          0.2667
31       U    SMA  2023-02-27  spontaneous  120.0        120.0    0.0549          0.0440
32       U    SMA  2023-02-27         task  120.0        120.0    0.0659          0.0549
33       U    SMA  2023-03-07  spontaneous   45.0         45.0    0.0000          0.0667
34       U    SMA  2023-03-07         task   45.0         45.0    0.0444          0.0667
35       U    SMA  2023-03-14  spontaneous  190.0        190.0    0.0444          0.0895
36       U    SMA  2023-03-14         task  190.0        190.0    0.0256          0.0667
37       U    SMA  2023-03-21  spontaneous  300.0        300.0    0.0693          0.0693
38       U    SMA  2023-03-21         task  300.0        300.0    0.0433          0.0476
39       U    SMA  2023-03-28  spontaneous   91.0         91.0    0.0758          0.0606
40       U    SMA  2023-03-28         task   91.0         91.0    0.0549          0.0549
41       V     M1  2023-03-09  spontaneous   55.0         45.0    0.0727          0.0667
42       V     M1  2023-03-09         task   55.0         45.0    0.1389          0.1667
43       V     M1  2023-03-16  spontaneous   91.0         78.0    0.2564          0.2564
44       V     M1  2023-03-16         task   91.0         78.0    0.1818          0.1636
session-conditions where the dandiset has more accepted cells than the paper's Jaccard table:
                              cells_paper  cells_here
Q SMA 2022-10-03 spontaneous           17          18
                 task                  17          18
      2022-12-01 spontaneous           11          13
                 task                  11          13
V M1  2023-03-09 spontaneous           10          11
                 task                  10          11
      2023-03-16 spontaneous           13          14
                 task                  13          14
sessions in both: 43; correlation of proportions 0.950; median |difference| 0.0091

fig3-synchronized-pairs-exist¶

Pairs of neurons with synchronous activity occur in both SMA and M1, in both the spontaneous and the task conditions.

In [25]:
ex = prop.groupby(["region", "condition"]).agg(sessions=("pairs", "size"), with_sync_pairs=("prop_abs", lambda v: int((v > 0).sum())),
                                              median_prop=("prop_abs", "median"), min_prop=("prop_abs", "min"), max_prop=("prop_abs", "max"))
ex["null_rate_two_sided_1.96"] = 0.05
print(ex.round(4).to_string())
print("sessions with a proportion at or below the 0.05 of the null:")
print(prop[prop.prop_abs <= 0.05].groupby(["region", "condition"]).agg(sessions=("prop_abs", "size"), props=("prop_abs", lambda v: sorted(np.round(v, 3)))).to_string())
print("synchronized pairs in total:", int((JAC.z.abs() > 1.96).sum()), "of", int(JAC.z.notna().sum()), "defined pairs")
                    sessions  with_sync_pairs  median_prop  min_prop  max_prop  null_rate_two_sided_1.96
region condition                                                                                        
M1     spontaneous         6                6       0.1006    0.0667    0.2564                      0.05
       task                6                6       0.1802    0.1389    0.2667                      0.05
SMA    spontaneous        20               18       0.0776    0.0000    0.2088                      0.05
       task               12               12       0.0647    0.0256    0.1061                      0.05
sessions with a proportion at or below the 0.05 of the null:
                    sessions                         props
region condition                                          
SMA    spontaneous         4      [0.0, 0.0, 0.038, 0.044]
       task                4  [0.026, 0.043, 0.044, 0.045]
synchronized pairs in total: 542 of 6089 defined pairs

Result: reproduced. Every site and condition has sessions with synchronized pairs (|Z-Jaccard| > 1.96): M1 6 of 6 sessions in each condition, SMA 18 of 20 spontaneous sessions and 12 of 12 task sessions, 542 of 6089 defined pairs in all. The median proportions per session (SMA 0.0776 spontaneous and 0.0647 task; M1 0.1006 and 0.1802) are to be read against the 0.05 that a two-sided 1.96 threshold gives under the null, which the criterion reports and does not use. Eight SMA session-conditions are at or below 0.05 (spontaneous 0, 0, 0.038 and 0.044; task 0.026, 0.043, 0.044 and 0.045), so in SMA synchrony exists in the sense the criterion asks for, and in the task it is at about the chance rate in the median session (0.0647).

fig3ab-synchrony-not-distance¶

Synchrony between cell pairs was not related to the distance between their centroids, in SMA or M1.

Pearson (i) and Spearman (ii) correlation of Z-Jaccard with centroid distance (um), per session and condition, two-sided p < 0.05. The example sessions of Figure 3A,B are not named: each U SMA and each U M1 session is a reading. All sessions of all monkeys are shown, with the loess curves (span 1) for U.

In [26]:
C = []
for k, g in JAC.dropna(subset=["z"]).groupby(["subject", "region", "date", "condition"]):
    dd, zz = g.dist_um.to_numpy(float), g.z.to_numpy(float)
    pr = stats.pearsonr(dd, zz) if len(g) > 2 else (np.nan, np.nan)
    sr = stats.spearmanr(dd, zz) if len(g) > 2 else (np.nan, np.nan)
    C.append({"subject": k[0], "region": k[1], "date": k[2], "condition": k[3], "pairs": len(g),
              "pearson_r": pr[0], "pearson_p": pr[1], "spearman_rho": sr[0], "spearman_p": sr[1],
              "dist_min": g.dist_um.min(), "dist_max": g.dist_um.max()})
C = pd.DataFrame(C)
print(C.round(4).to_string())
for test in ("pearson_p", "spearman_p"):
    sig = C[C.subject == "U"].assign(sig=lambda d: d[test] < 0.05).groupby(["region", "date"])["sig"].any()
    print(test, "- U sessions where neither condition is significant:", {r: list(sig[r][~sig[r]].index) for r in ("SMA", "M1")})
print("all sessions, significant correlations: pearson %d, spearman %d of %d" % ((C.pearson_p < 0.05).sum(), (C.spearman_p < 0.05).sum(), len(C)))
   subject region        date    condition  pairs  pearson_r  pearson_p  spearman_rho  spearman_p  dist_min  dist_max
0        F    SMA  2024-02-13  spontaneous     15    -0.0258     0.9272       -0.1786      0.5243   52.7369  354.2669
1        F    SMA  2024-02-20  spontaneous    120    -0.1053     0.2524       -0.0703      0.4455   21.1557  505.5089
2        F    SMA  2024-02-23  spontaneous    105    -0.3376     0.0004       -0.3874      0.0000   18.0427  479.6397
3        F    SMA  2024-02-27  spontaneous     91    -0.1167     0.2706       -0.0957      0.3668   19.9980  534.4821
4        F    SMA  2024-02-29  spontaneous     91     0.1078     0.3092        0.0853      0.4214   18.7518  424.7809
5        F    SMA  2024-03-05  spontaneous     66    -0.0320     0.7987       -0.1573      0.2072   25.2918  517.9453
6        F    SMA  2024-03-07  spontaneous     15     0.2058     0.4618        0.3071      0.2655   44.6650  517.3509
7        F    SMA  2024-03-12  spontaneous      6    -0.0732     0.8904       -0.2571      0.6228   35.7570  160.6657
8        Q    SMA  2022-09-15  spontaneous    629    -0.0159     0.6912       -0.0165      0.6789   15.3136  838.3060
9        Q    SMA  2022-09-15         task    740    -0.0171     0.6421       -0.0081      0.8260   15.3136  838.3060
10       Q    SMA  2022-09-22  spontaneous    630    -0.0872     0.0286       -0.0912      0.0221   16.6807  900.2024
11       Q    SMA  2022-09-22         task    630    -0.0114     0.7747        0.0190      0.6347   16.6807  900.2024
12       Q    SMA  2022-10-03  spontaneous    104     0.2024     0.0394        0.1289      0.1923   50.5818  804.2295
13       Q    SMA  2022-10-03         task    120    -0.0198     0.8299        0.0070      0.9392   50.5818  804.2295
14       Q    SMA  2022-10-28  spontaneous    190    -0.0633     0.3856       -0.0441      0.5462   25.0239  762.6924
15       Q    SMA  2022-10-28         task    210     0.0453     0.5140        0.0206      0.7661   25.0239  762.6924
16       Q    SMA  2022-12-01  spontaneous     45     0.4330     0.0030        0.3887      0.0083   32.6092  630.5879
17       Q    SMA  2022-12-01         task     66    -0.1680     0.1775       -0.0761      0.5435   26.6809  630.5879
18       Q    SMA  2022-12-02  spontaneous     66    -0.1783     0.1520       -0.0601      0.6317   16.5574  652.4962
19       Q    SMA  2022-12-02         task     66    -0.0578     0.6447        0.1021      0.4148   16.5574  652.4962
20       Q    SMA  2022-12-06  spontaneous    153     0.0203     0.8038       -0.0191      0.8146   26.4002  897.4725
21       Q    SMA  2022-12-06         task     91    -0.0597     0.5741        0.0054      0.9596   37.2019  876.4387
22       U     M1  2023-02-24  spontaneous     28     0.2312     0.2364        0.2906      0.1335   86.2271  633.2714
23       U     M1  2023-02-24         task     28     0.0546     0.7826        0.0000      1.0000   86.2271  633.2714
24       U     M1  2023-03-01  spontaneous    210    -0.0109     0.8757       -0.0411      0.5539   15.4777  616.4262
25       U     M1  2023-03-01         task    190     0.0280     0.7013        0.0022      0.9764   15.4777  616.4262
26       U     M1  2023-03-16  spontaneous     15    -0.1592     0.5710       -0.2607      0.3480   13.0453  540.8875
27       U     M1  2023-03-16         task     28    -0.1622     0.4097       -0.2195      0.2618   13.0453  785.8069
28       U     M1  2023-03-23  spontaneous     15     0.0777     0.7832       -0.0500      0.8595   54.2655  550.4006
29       U     M1  2023-03-23         task     15    -0.1751     0.5325       -0.0286      0.9195   54.2655  550.4006
30       U    SMA  2023-02-27  spontaneous     91     0.0505     0.6342        0.1109      0.2954   46.4485  743.2975
31       U    SMA  2023-02-27         task     91     0.1122     0.2898        0.0099      0.9255   46.4485  699.4335
32       U    SMA  2023-03-07  spontaneous     28     0.3428     0.0742        0.2414      0.2158   60.4152  678.7750
33       U    SMA  2023-03-07         task     45     0.0049     0.9747        0.1607      0.2915   60.4152  748.8703
34       U    SMA  2023-03-14  spontaneous    135    -0.0747     0.3890        0.0228      0.7926   18.7506  857.6698
35       U    SMA  2023-03-14         task     78    -0.0603     0.6001       -0.1517      0.1849   46.9571  805.4004
36       U    SMA  2023-03-21  spontaneous    231     0.0290     0.6614        0.0548      0.4071   39.1882  892.6648
37       U    SMA  2023-03-21         task    231    -0.1469     0.0256       -0.0704      0.2868   31.0451  854.7081
38       U    SMA  2023-03-28  spontaneous     66     0.0060     0.9617       -0.1675      0.1788   36.5838  757.4023
39       U    SMA  2023-03-28         task     91     0.0115     0.9135        0.0439      0.6795   36.5838  785.0289
40       V     M1  2023-03-09  spontaneous     55     0.0171     0.9016        0.0008      0.9954   22.3434  456.9052
41       V     M1  2023-03-09         task     36     0.0909     0.5979        0.0777      0.6523   22.3434  456.9052
42       V     M1  2023-03-16  spontaneous     78    -0.1662     0.1460       -0.1155      0.3141   36.8634  670.5591
43       V     M1  2023-03-16         task     55    -0.1194     0.3854       -0.1818      0.1840   36.8634  439.9554
pearson_p - U sessions where neither condition is significant: {'SMA': ['2023-02-27', '2023-03-07', '2023-03-14', '2023-03-28'], 'M1': ['2023-02-24', '2023-03-01', '2023-03-16', '2023-03-23']}
spearman_p - U sessions where neither condition is significant: {'SMA': ['2023-02-27', '2023-03-07', '2023-03-14', '2023-03-21', '2023-03-28'], 'M1': ['2023-02-24', '2023-03-01', '2023-03-16', '2023-03-23']}
all sessions, significant correlations: pearson 5, spearman 3 of 44
In [27]:
from statsmodels.nonparametric.smoothers_lowess import lowess
Ug = JAC[(JAC.subject == "U")].dropna(subset=["z"])
keys = sorted(Ug.groupby(["region", "date", "condition"]).groups)
fig, axes = plt.subplots(3, 6, figsize=(18, 8), sharey=True)
for ax, k in zip(axes.flat, keys):
    g = Ug[(Ug.region == k[0]) & (Ug.date == k[1]) & (Ug.condition == k[2])]
    ax.scatter(g.dist_um, g.z, s=6, alpha=.5)
    lo = lowess(g.z, g.dist_um, frac=1.0)
    ax.plot(lo[:, 0], lo[:, 1], color="C1")
    ax.set_title(f"U {k[0]} {k[1]} {k[2][:5]}", fontsize=8)
    ax.set_ylim(-4, 12)
for ax in axes.flat[len(keys):]:
    ax.axis("off")
fig.supxlabel("centroid distance (um)")
fig.supylabel("Z-Jaccard")
plt.tight_layout()
plt.show()
print("U pairs plotted: %d; Z-Jaccard range %.2f to %.2f, %d points outside the axes (-4 to 12)"
      % (len(Ug), Ug.z.min(), Ug.z.max(), int(((Ug.z < -4) | (Ug.z > 12)).sum())))
No description has been provided for this image
U pairs plotted: 1616; Z-Jaccard range -5.52 to 13.22, 4 points outside the axes (-4 to 12)

Result: reproduced. Under both test readings there are U sessions without a significant correlation of Z-Jaccard with distance in either condition: with Pearson, 4 U SMA sessions and all 4 U M1 sessions; with Spearman, 5 U SMA and 4 U M1 sessions. Over all 44 session-conditions of all monkeys, 5 Pearson and 3 Spearman correlations reach p < 0.05 (|r| up to 0.433, Q 2022-12-01 spontaneous).

fig3c-sync-no-condition-change¶

The proportion of synchronized cell pairs did not differ between spontaneous and task conditions in SMA (p = 0.07) or M1 (p = 0.22).

Per region, two-sided Wilcoxon signed-rank test of spontaneous against task proportions, paired by session, over sessions with both conditions; R's wilcox.test (paired) gives exact p-values for these sample sizes without ties, which scipy's default also uses. The claims file asks for the code's 10-shift null for SMA as well (its SMA loop passes nperm=10).

In [28]:
def fig3c(pr, col):
    out = []
    for reg in ("SMA", "M1"):
        w = pr[pr.region == reg].pivot_table(index=["subject", "date"], columns="condition", values=col).dropna()
        p = stats.wilcoxon(w.spontaneous, w.task).pvalue
        out.append({"region": reg, "sessions": len(w), "p": p, "median_spont": w.spontaneous.median(), "median_task": w.task.median(),
                    "median_change_task_minus_spont": (w.task - w.spontaneous).median(), "sessions_task_lower": int((w.task < w.spontaneous).sum())})
    return pd.DataFrame(out)
print("main, |Z| > 1.96 over defined pairs, 1000 shifts")
print(fig3c(prop, "prop_abs").round(4).to_string())
print("variant, Z > 1.96 only (the code's prop_sync)")
print(fig3c(prop, "prop_pos").round(4).to_string())
print("variant, |Z| > 1.96 over all pairs, undefined counted as not synchronized")
print(fig3c(prop, "prop_abs_all_pairs").round(4).to_string())
# the code's 10-shift null for SMA
rng10 = np.random.default_rng(10)
P10 = []
for key, d in sorted(ses.items()):
    if key[1] != "SMA":
        continue
    for c, x in sorted(d.items()):
        P = h.zjaccard(h.binned_logical(x), n_shift=10, rng=rng10)
        P10.append({"subject": key[0], "region": key[1], "date": key[2], "condition": c, "prop_abs": (P.z.dropna().abs() > 1.96).mean()})
P10 = pd.DataFrame(P10)
mix = pd.concat([P10, prop[prop.region == "M1"][["subject", "region", "date", "condition", "prop_abs"]]])
print("variant, SMA with a 10-shift null (M1 with 1000)")
print(fig3c(mix, "prop_abs").round(4).to_string())
print("paper's own table, |Z| > 1.96 over defined pairs")
print(fig3c(pz.rename(columns={"prop_abs_paper": "prop_abs"}), "prop_abs").round(4).to_string())
main, |Z| > 1.96 over defined pairs, 1000 shifts
  region  sessions       p  median_spont  median_task  median_change_task_minus_spont  sessions_task_lower
0    SMA        12  0.1514        0.0725       0.0647                         -0.0198                    8
1     M1         6  0.2188        0.1006       0.1802                          0.0509                    1
variant, Z > 1.96 only (the code's prop_sync)
  region  sessions       p  median_spont  median_task  median_change_task_minus_spont  sessions_task_lower
0    SMA        12  0.2036        0.0725       0.0647                         -0.0198                    8
1     M1         6  0.0938        0.0887       0.1711                          0.0509                    1
variant, |Z| > 1.96 over all pairs, undefined counted as not synchronized
  region  sessions       p  median_spont  median_task  median_change_task_minus_spont  sessions_task_lower
0    SMA        12  0.4131        0.0560       0.0525                         -0.0100                    6
1     M1         6  0.3125        0.1006       0.1536                          0.0269                    1
variant, SMA with a 10-shift null (M1 with 1000)
  region  sessions       p  median_spont  median_task  median_change_task_minus_spont  sessions_task_lower
0    SMA        12  0.0771        0.0960       0.0905                         -0.0121                    9
1     M1         6  0.2188        0.1006       0.1802                          0.0509                    1
paper's own table, |Z| > 1.96 over defined pairs
  region  sessions       p  median_spont  median_task  median_change_task_minus_spont  sessions_task_lower
0    SMA        12  0.0674        0.0759       0.0663                         -0.0137                    8
1     M1         6  0.2188        0.1024       0.1652                          0.0560                    1

Result: reproduced. The proportion of synchronized pairs does not differ between the conditions: SMA p = 0.1514 over 12 sessions (median change -0.0198, task lower in 8), M1 p = 0.2188 over 6 sessions (median change +0.0509, task lower in 1). The variants agree: the positive tail only (0.2036 and 0.0938), all pairs as the denominator (0.4131 and 0.3125), and the code's 10-shift null for SMA (0.0771). The paper's own Jaccard table gives 0.0674 and 0.2188, the paper's 0.07 and 0.22; this attempt's per-session proportions correlate with the table's at 0.950 over 43 session-conditions (median absolute difference 0.0091).

Histology (blocked)¶

histology-lens-placement and histology-gcamp-not-gabaergic rest on the histology images on Zenodo (doi:10.5281/zenodo.15328390): whole-slide scans of MAP2, GFP and GABA labelling (13 files, about 8.6 GB, in .ndpi, .svs and .vsi formats). Judging where a lens track ends against an atlas, and whether labelled cell bodies are double labelled, is an anatomist's reading of the images that no computation in this notebook can make. The claims are blocked as other: the data are public and readable, and no software is missing; what is missing is an anatomist's judgement.

Summary¶

Claim Outcome
zenodo-descriptors-link not reproduced (cells match by centroid; rates and amplitudes differ)
cell-counts reproduced (through the Zenodo first occurrences)
cells-tracked-18pct blocked: metadata insufficient (14.1% to 28.1% possible)
fig1d-rate-no-change reproduced
fig1e-ieicv-no-change reproduced
fig1f-amplitude-u-sma-spont-higher reproduced
fig1d-rate-m1-above-sma-u reproduced
fig1f-amplitude-m1-above-sma-u-task not reproduced
fig2 and figs1 claims (six) blocked: data missing
fig3-synchronized-pairs-exist reproduced
fig3ab-synchrony-not-distance reproduced
fig3c-sync-no-condition-change reproduced
histology claims (two) blocked: other (an anatomist's reading)
sequence claims (four) see sequences_martel_2025.ipynb

A failure to reproduce here may be a failure of this attempt, not of the paper: see the reasoning and the differences from the paper's method.

Differences from the paper's method. Each condition is a separate file in the dandiset, so each is analysed on its own, with durations from its frames. The cells' first occurrences come from the paper's Zenodo table; the median over a cell's sessions (the claims file's reading D, ii) cannot be computed. The Jaccard null is drawn from all circular shifts at once (an FFT), with 1000 shifts drawn as the Methods say. For Figure 2 and Figure S1, a check on the paper's own z-scored windows (Zenodo) finds 20 Q SMA cells modulated under the chamber-wide FDR, against 43 in the paper, and 42 uncorrected; it decides nothing, but suggests that the claims file's method Z is not the paper's procedure, which is put to a reader (questions/001174.yaml).

What was found about the dataset. The dandiset holds no TTL or trial data and no raw traces, so Figure 2 and Figure S1 cannot be tested; the trace it holds is the denoised one, without saying so. It carries no cross-session cell identity. Its event rates and amplitudes differ from the paper's per-cell table for most cells, and by large factors in two U SMA sessions, while the cells themselves match. In two U SMA sessions (2023-03-07 and 2023-03-14) the dandiset has far fewer spontaneous events than the table and a higher amplitude in every cell, and without them the U task amplitude test of M1 against SMA gives p = 0.041 uncorrected. The paper's Jaccard table counts fewer cells than the dandiset has in four sessions, and its Figure 4D table in three (Q 2022-10-03, Q 2022-12-01 and V 2023-03-16). One U SMA session is sampled at 20 Hz where the Methods give 10 Hz; V has arm-reaching files though the paper says only Q and U did the task; the 2022-09-15 spontaneous file of Q has no session label; indicator and location are "N/A".