Dana et al. (2016), red calcium indicators: Figure 4 on CRCNS cai-2¶
Paper: Dana, Mohar, Sun et al. (2016), "Sensitive red protein calcium indicators for imaging
neural activity", eLife 5:e12727, doi:10.7554/elife.12727. The claims file
(claims/dana-2016.yaml) was written from the version of record (PMC4846379) with its Methods,
figure legends and Supplementary files 1 and 2.
Dataset: CRCNS cai-2 (doi:10.6080/K0W37T87), read anonymously from the public S3 bucket
crcnsarchive under cai-2/live/. CRCNS data sets are not versioned, so the version is recorded
as unversioned (docs/archives.md). cai-2/live/ is the only published copy of the data (the
bucket also has cai-2/orig/, which holds only an older description document), so it is the one
pinned. The data set's checksums.md5 gives e0bdb7e619b82a99fbe594ef62f647cf for
data/jRGECO1a_data.tar.gz and d29a21d0d4a40ebc774ca9edb1079228 for data/jRCAMP1a_data.tar.gz;
the data check below computes the MD5 of each archive as it streams it and compares the two, so a
later change to the files can be seen. The data set's description is version 0.8 (April 19, 2016).
Outside inputs: Supplementary files 1 and 2 of the paper (doi:10.7554/eLife.12727.030 and .031),
streamed from the eLife CDN, for the three data: elsewhere claims on the culture screen; and
Supplementary Tables 1 and 3 of Chen et al. (2013b), Nature 499:295 (doi:10.1038/nature12354),
read from the Supplementary Information PDF of the author manuscript in the PMC open-access
bucket (pmc-oa-opendata, PMC3777791.1), for the GCaMP6 values of fig4g-kinetics-like-gcamp6.
The data set holds only the simultaneous imaging and cell-attached recordings of Figure 4. Claims on the paper's other experiments are blocked, as the record says.
| Claim | Tested here |
|---|---|
| screen-single-mutations-improved | tested, on Supplementary files 1 and 2 (elsewhere) |
| culture-jrgeco1a-sensitivity | tested, on Supplementary file 2 (elsewhere) |
| culture-jrcamp1-sensitivity | tested, on Supplementary file 1 (elsewhere) |
| fig4-recorded-cells | tested |
| fig4d-event-counts | tested |
| fig4e-jrgeco1a-1ap-detection | tested |
| fig4e-jrgeco1a-2ap-detection | tested |
| fig4e-jrcamp1a-detection | tested |
| fig4df-jrgeco1a-better-than-jrcamp1a | tested |
| fig4g-jrgeco1a-faster | tested |
| fig4g-kinetics-like-gcamp6 | tested, against Chen et al. (2013b) Supplementary Table 3 (elsewhere) |
| culture, purified protein, V1 grating, Drosophila, zebrafish and C. elegans claims (24) | blocked: data missing (not in cai-2, not deposited elsewhere) |
Method details that the claims file does not give are taken from the paper's Methods or from the
data set's own analysis script data_analysis_for_CRCNS_jRGECO1a.m (with find_no_event.m and
find_nspike_event.m, in cai-2/live/scripts/), which the data description says produced the
Figure 4 data. Each is cited in cai2.py, and the scripts are printed below so that each rule
can be checked against them. Where the script and the Methods disagree, the Methods give the main
reading (claims file header): the main event isolation is reading (a), more than 1 s on each side,
as the Methods say, and the script's 0.8 s after the event is shown as a variant.
import os
os.environ.setdefault("OMP_NUM_THREADS", "1")
import io, re, time, resource, itertools
import numpy as np
import pandas as pd
import yaml
import fsspec
import matplotlib.pyplot as plt
import cai2
DATASET = "crcns:cai-2/unversioned" # CRCNS data set cai-2, doi:10.6080/K0W37T87, not versioned
T0 = time.time()
CLAIMS = {c["id"]: c for c in yaml.safe_load(open("../../claims/dana-2016.yaml"))["claims"]}
def expected(cid):
e = CLAIMS[cid].get("expected", [])
return e if isinstance(e, list) else [e]
def within(value, e):
return abs(value - e["value"]) <= e["tolerance"] + 1e-9
Data check¶
The bucket's listing, the published checksums, and every recording file in the two archives. The archives are streamed and decompressed as they are read; each MATLAB file is reduced to the soma and neuropil fluorescence, the frame times and the spike times, and the 10 kHz ephys traces are dropped after their range and hash are kept.
with fsspec.open("https://crcnsarchive.s3-us-west-2.amazonaws.com/?list-type=2&prefix=cai-2/", "rt") as f:
listing = f.read()
keys = re.findall(r"<Key>(.*?)</Key>\s*<LastModified>(.*?)</LastModified>.*?<Size>(\d+)</Size>", listing, re.S)
print("truncated listing:", re.findall(r"<IsTruncated>(.*?)</IsTruncated>", listing))
for k, mod, size in keys:
print(f"{int(size):>12} {mod} {k}")
published = cai2.published_md5()
t = time.time()
streamed = {ind: cai2.stream_archive(ind) for ind in cai2.ARCHIVES}
print(f"streamed both archives in {time.time() - t:.0f} s")
truncated listing: ['false']
0 2026-02-11T00:41:37.000Z cai-2/
0 2026-02-11T00:41:37.000Z cai-2/live/
509 2026-02-11T01:09:40.000Z cai-2/live/checksums.md5
0 2026-02-11T00:41:37.000Z cai-2/live/data/
1119097829 2026-02-11T01:08:46.000Z cai-2/live/data/jRCAMP1a_data.tar.gz
1307920040 2026-02-11T01:08:34.000Z cai-2/live/data/jRGECO1a_data.tar.gz
0 2026-02-11T00:41:42.000Z cai-2/live/docs/
66326 2026-02-11T01:09:42.000Z cai-2/live/docs/crcns_cai-2_data_description.docx
107718 2026-02-11T01:09:32.000Z cai-2/live/docs/crcns_cai-2_data_description.pdf
646 2026-02-11T01:09:39.000Z cai-2/live/filelist.txt
0 2026-02-11T00:41:45.000Z cai-2/live/scripts/
8009 2026-02-11T01:09:36.000Z cai-2/live/scripts/data_analysis_for_CRCNS_jRGECO1a.m
328 2026-02-11T01:09:40.000Z cai-2/live/scripts/find_no_event.m
847 2026-02-11T01:09:39.000Z cai-2/live/scripts/find_nspike_event.m
0 2026-02-11T00:41:43.000Z cai-2/orig/
67068 2026-02-11T01:09:46.000Z cai-2/orig/crcns_data_description.docx
streamed both archives in 118 s
print("== checksums")
for ind, (recs, md5, nbytes, others) in streamed.items():
path = cai2.ARCHIVES[ind]
print(f"{path}: streamed {nbytes} bytes, MD5 {md5}, published {published[path]}, match {md5 == published[path]}; "
f"{len(recs)} .mat files, other files {others}")
all_recs = [r for recs, *_ in streamed.values() for r in recs]
r0 = all_recs[0]
print("\n== contents of each file (first file shown; all files checked below)")
print("time series keys:", r0["keys"])
print("descriptions:", r0["descr"])
print("time units of the five series (2 = second):", sorted({tuple(r["time_units"]) for r in all_recs}),
"; trialTimeUnit:", sorted({r["trial_time_unit"] for r in all_recs}))
print("indicator field by archive:", {ind: sorted({r["indicator"] for r in recs}) for ind, (recs, *_) in streamed.items()})
print("values of detected_spikes:", sorted({v for r in all_recs for v in r["spike_values"]}))
print("fluorescence and neuropil share a time base in every file:", all(r["tf_neuropil_same"] for r in all_recs))
print("raw, filtered ephys and spikes share a time base in every file:", all(r["ephys_same_clock"] for r in all_recs))
print("ephys sample interval (s), min and max over files:",
min(r["ephys_dt"][0] for r in all_recs), max(r["ephys_dt"][1] for r in all_recs))
rows = []
for r in all_recs:
isi = np.diff(r["spikes"])
rows.append(dict(indicator=r["indicator"], file=r["file"], cell=r["cell"], date=r["date"],
frames=len(r["tf"]), fps=round(cai2.fps(r), 2), frame_t0=round(r["tf"][0], 3),
frame_t1=round(r["tf"][-1], 2), ephys_t0=round(r["ephys_t0"], 4), ephys_t1=round(r["ephys_t1"], 2),
spikes=len(r["spikes"]), rate_hz=round(len(r["spikes"]) / (r["ephys_t1"] - r["ephys_t0"]), 2),
min_isi_ms=round(isi.min() * 1000, 1) if len(isi) else np.nan,
roi=f"{r['roi'].min():.0f}-{r['roi'].max():.0f}", neuropil=f"{r['neuropil'].min():.0f}-{r['neuropil'].max():.0f}",
raw_ephys=f"{r['raw_ephys_range'][0]:.2f} to {r['raw_ephys_range'][1]:.2f}"))
table = pd.DataFrame(rows)
pd.set_option("display.width", 250, "display.max_columns", 30, "display.max_rows", 100)
print(table.to_string(index=False))
print("\nframe rate range by indicator:", table.groupby("indicator")["fps"].agg(["min", "max"]).to_dict("index"))
print("ISIs under 1 ms:", {r["file"]: int((np.diff(r["spikes"]) < 0.001).sum()) for r in all_recs if (np.diff(r["spikes"]) < 0.001).any()})
== checksums
data/jRGECO1a_data.tar.gz: streamed 1307920040 bytes, MD5 e0bdb7e619b82a99fbe594ef62f647cf, published e0bdb7e619b82a99fbe594ef62f647cf, match True; 27 .mat files, other files []
data/jRCAMP1a_data.tar.gz: streamed 1119097829 bytes, MD5 d29a21d0d4a40ebc774ca9edb1079228, published d29a21d0d4a40ebc774ca9edb1079228, match True; 20 .mat files, other files []
== contents of each file (first file shown; all files checked below)
time series keys: ['fmean_roi', 'fmean_neuropil', 'raw_ephys', 'filtered ephys', 'detected_spikes']
descriptions: ['average fluorescence of ROI', 'average fluorescence of surrounding neuopil', 'raw ephys trace', 'high pass filtered ephys', 'detected spikes']
time units of the five series (2 = second): [(2, 2, 2, 2, 2)] ; trialTimeUnit: [2]
indicator field by archive: {'jRGECO1a': ['jRGECO1a'], 'jRCaMP1a': ['jRCaMP1a']}
values of detected_spikes: [0, 1]
fluorescence and neuropil share a time base in every file: True
raw, filtered ephys and spikes share a time base in every file: True
ephys sample interval (s), min and max over files: 9.999999997489795e-05 0.00010000000003174137
indicator file cell date frames fps frame_t0 frame_t1 ephys_t0 ephys_t1 spikes rate_hz min_isi_ms roi neuropil raw_ephys
jRGECO1a data_20150529_cell2_001.mat 20150529_cell2 20150529 9600 30.03 0.016 319.65 0.0001 320.0 39 0.12 5.0 104-390 87-151 0.15 to 5.17
jRGECO1a data_20150529_cell2_002.mat 20150529_cell2 20150529 9600 30.03 0.016 319.66 0.0001 320.0 31 0.10 4.1 93-199 82-118 1.37 to 7.03
jRGECO1a data_20150529_cell9_001.mat 20150529_cell9 20150529 9600 30.03 0.016 319.63 0.0001 320.0 457 1.43 2.2 57-144 25-35 -1.30 to 6.23
jRGECO1a data_20150601_cell2_001.mat 20150601_cell2 20150601 9600 30.03 0.016 319.59 0.0001 320.0 278 0.87 3.7 73-168 58-79 -0.06 to 4.01
jRGECO1a data_20150601_cell2_002.mat 20150601_cell2 20150601 5857 30.03 5.010 199.97 5.0001 200.0 122 0.63 3.9 121-192 128-153 -1.75 to 2.71
jRGECO1a data_20150601_cell2_003.mat 20150601_cell2 20150601 9600 30.03 0.016 319.61 0.0001 320.0 402 1.26 3.2 90-275 98-156 0.84 to 3.71
jRGECO1a data_20150601_cell6_001.mat 20150601_cell6 20150601 9600 30.03 0.016 319.64 0.0001 320.0 292 0.91 3.4 55-224 47-65 -3.70 to -1.25
jRGECO1a data_20150601_cell6_002.mat 20150601_cell6 20150601 9600 30.03 0.016 319.64 0.0001 320.0 374 1.17 3.3 73-244 65-99 -5.14 to -0.50
jRGECO1a data_20150601_cell6_003.mat 20150601_cell6 20150601 9600 30.03 0.016 319.65 0.0001 320.0 363 1.13 2.9 73-264 65-99 -4.58 to -0.96
jRGECO1a data_20150601_cell6_004.mat 20150601_cell6 20150601 9600 30.03 0.016 319.67 0.0001 320.0 707 2.21 2.0 107-362 95-163 -4.07 to 0.32
jRGECO1a data_20150601_cell8_001.mat 20150601_cell8 20150601 9600 30.03 0.016 319.67 0.0001 320.0 178 0.56 2.3 80-358 60-109 -1.21 to 3.31
jRGECO1a data_20150601_cell8_002.mat 20150601_cell8 20150601 9600 30.03 0.016 319.67 0.0001 320.0 164 0.51 2.0 64-177 57-91 0.02 to 4.46
jRGECO1a data_20150708_cell1_001.mat 20150708_cell1 20150708 9538 29.81 0.016 319.95 0.0001 318.0 2362 7.43 3.7 17-58 11-19 1.42 to 13.27
jRGECO1a data_20150714_cell1_001.mat 20150714_cell1 20150714 9600 29.72 0.016 323.24 0.0001 320.0 304 0.95 4.5 54-106 35-45 -1.00 to 9.07
jRGECO1a data_20150728_cell1_001.mat 20150728_cell1 20150728 9600 29.67 0.016 323.28 0.0001 320.0 351 1.10 11.2 71-152 61-103 -0.14 to 6.80
jRGECO1a data_20150804_cell2_001_part1.mat 20150804_cell2 20150804 3255 29.59 40.004 150.00 40.0001 150.0 295 2.68 5.4 20-80 15-38 -3.80 to 6.73
jRGECO1a data_20150804_cell2_001_part2.mat 20150804_cell2 20150804 2870 29.59 223.013 319.99 223.0001 320.0 282 2.91 6.0 33-91 25-48 -4.15 to 6.96
jRGECO1a data_20150804_cell2_002_part1.mat 20150804_cell2 20150804 3000 29.59 0.016 101.39 0.0001 100.0 336 3.36 4.9 21-101 17-54 -4.40 to 6.49
jRGECO1a data_20150804_cell2_002_part2.mat 20150804_cell2 20150804 5473 29.59 135.027 320.00 135.0001 320.0 409 2.21 4.1 30-122 24-64 -4.67 to 6.53
jRGECO1a data_20150804_cell2_003_part1.mat 20150804_cell2 20150804 3900 29.59 0.016 131.81 0.0001 130.0 423 3.25 5.4 41-123 31-63 -4.64 to 6.38
jRGECO1a data_20150804_cell2_003_part2.mat 20150804_cell2 20150804 1630 29.59 264.996 320.06 265.0000 320.0 123 2.24 6.1 37-86 29-50 -4.32 to 5.85
jRGECO1a data_20150804_cell3_001.mat 20150804_cell3 20150804 9600 29.59 0.016 324.49 0.0001 320.0 78 0.24 2.7 39-106 21-38 -1.33 to 5.38
jRGECO1a data_20150804_cell3_002.mat 20150804_cell3 20150804 5550 29.59 0.016 187.59 0.0001 185.0 412 2.23 2.7 18-89 16-25 -1.83 to 2.65
jRGECO1a data_20150804_cell5_001_part1.mat 20150804_cell5 20150804 6658 29.59 0.016 225.05 0.0001 225.0 48 0.21 4.2 49-162 36-65 -0.86 to 1.52
jRGECO1a data_20150804_cell5_002.mat 20150804_cell5 20150804 9592 29.59 0.286 324.50 0.0001 320.0 118 0.37 4.0 20-85 15-37 -0.72 to 3.07
jRGECO1a data_20150804_cell5_003.mat 20150804_cell5 20150804 9600 29.59 0.016 324.51 0.0001 320.0 95 0.30 4.0 47-97 41-68 -0.57 to 3.99
jRGECO1a data_20150804_cell5_004.mat 20150804_cell5 20150804 9600 29.59 0.016 324.52 0.0001 320.0 37 0.12 4.7 42-81 37-56 -0.53 to 4.76
jRCaMP1a data_20150526_cell2_001.mat 20150526_cell2 20150526 4800 15.02 0.033 319.58 0.0001 320.0 75 0.23 2.7 97-245 78-128 -2.21 to 1.66
jRCaMP1a data_20150526_cell2_002.mat 20150526_cell2 20150526 4800 15.02 0.033 319.58 0.0001 320.0 75 0.23 2.7 97-245 78-128 -2.21 to 1.66
jRCaMP1a data_20150527_cell1_001.mat 20150527_cell1 20150527 4800 15.02 0.033 319.62 0.0001 320.0 5 0.02 14.4 36-60 25-35 1.75 to 10.59
jRCaMP1a data_20150605_cell1_001.mat 20150605_cell1 20150605 2325 15.02 0.033 154.78 0.0001 155.0 58 0.37 5.4 127-191 108-122 -6.44 to -1.35
jRCaMP1a data_20150605_cell3_001.mat 20150605_cell3 20150605 4800 15.02 0.033 319.59 0.0001 320.0 33 0.10 10.8 133-182 109-148 -3.69 to 2.82
jRCaMP1a data_20150605_cell3_002.mat 20150605_cell3 20150605 4800 15.02 0.033 319.59 0.0001 320.0 25 0.08 9.5 119-162 101-128 -2.26 to 4.21
jRCaMP1a data_20150605_cell6_001.mat 20150605_cell6 20150605 4800 15.02 0.033 319.60 0.0001 320.0 105 0.33 7.1 99-147 99-112 0.30 to 9.05
jRCaMP1a data_20150605_cell6_002.mat 20150605_cell6 20150605 3600 15.02 0.033 239.69 0.0001 240.0 99 0.41 7.3 123-187 113-142 -3.14 to 5.41
jRCaMP1a data_20150605_cell6_003.mat 20150605_cell6 20150605 4800 15.02 0.033 319.61 0.0001 320.0 121 0.38 3.3 158-194 162-206 0.52 to 8.24
jRCaMP1a data_20150605_cell6_004.mat 20150605_cell6 20150605 975 15.02 0.033 64.89 0.0001 65.0 43 0.66 8.0 205-251 206-257 -28.25 to -0.62
jRCaMP1a data_20150605_cell7_001.mat 20150605_cell7 20150605 4800 15.02 0.033 319.60 0.0001 320.0 67 0.21 4.6 100-169 82-104 -0.63 to 10.11
jRCaMP1a data_20150605_cell7_002.mat 20150605_cell7 20150605 4800 15.02 0.033 319.60 0.0001 320.0 26 0.08 4.4 92-133 85-99 1.87 to 14.33
jRCaMP1a data_20150605_cell7_003.mat 20150605_cell7 20150605 4800 15.02 0.033 319.61 0.0001 320.0 15 0.05 4.4 138-178 128-153 9.65 to 21.16
jRCaMP1a data_20150701_cell2_001.mat 20150701_cell2 20150701 4769 14.90 0.033 319.93 0.0001 318.0 227 0.71 6.0 115-167 112-143 -4.24 to 7.01
jRCaMP1a data_20150701_cell2_002.mat 20150701_cell2 20150701 4769 14.90 0.033 319.94 0.0001 318.0 1014 3.19 4.4 134-266 132-194 -3.37 to 7.36
jRCaMP1a data_20150707_cell1_001.mat 20150707_cell1 20150707 4751 14.85 0.033 319.94 0.0001 317.0 304 0.96 4.6 163-289 115-134 -2.36 to -0.29
jRCaMP1a data_20150707_cell3_001.mat 20150707_cell3 20150707 4751 14.85 0.033 319.94 0.0001 317.0 64 0.20 3.1 101-169 73-94 -1.00 to 1.98
jRCaMP1a data_20150707_cell3_002.mat 20150707_cell3 20150707 4751 14.85 0.033 319.95 0.0001 317.0 273 0.86 2.5 92-215 70-93 -1.05 to 4.00
jRCaMP1a data_20150707_cell3_003.mat 20150707_cell3 20150707 4751 14.85 0.033 319.94 0.0001 317.0 538 1.70 0.2 86-163 68-86 -6.44 to 2.46
jRCaMP1a data_20150707_cell8_001.mat 20150707_cell8 20150707 4751 14.85 0.033 319.95 0.0001 317.0 457 1.44 6.0 76-159 82-131 -2.75 to 6.14
frame rate range by indicator: {'jRCaMP1a': {'min': 14.85, 'max': 15.02}, 'jRGECO1a': {'min': 29.59, 'max': 30.03}}
ISIs under 1 ms: {'data_20150707_cell3_003.mat': 2}
Recordings deposited twice¶
Files are compared by the MD5 of their soma fluorescence and of their raw ephys trace. A pair with
both identical is the same recording deposited twice, and only the first file of the pair is kept.
Files split into _part1 and _part2 are parts of one recording; their time ranges are checked
for overlap.
groups = {}
for r in all_recs:
groups.setdefault((r["md5_roi"], r["md5_raw_ephys"]), []).append(r["file"])
dups = [v for v in groups.values() if len(v) > 1]
print("identical recordings:", dups)
for k in {r["md5_roi"] for r in all_recs}:
files = [r["file"] for r in all_recs if r["md5_roi"] == k]
if len(files) > 1:
same_member = len({r["md5_member"] for r in all_recs if r["md5_roi"] == k}) == 1
print(" same fluorescence in", files, "; whole MATLAB files identical:", same_member)
drop = {f for v in dups for f in v[1:]}
recs = {ind: [r for r in rs if r["file"] not in drop] for ind, (rs, *_) in streamed.items()}
print("dropped as duplicates:", sorted(drop))
# Shared stretches between any two files: 100-frame windows of soma fluorescence with the same bytes.
win = {}
for r in all_recs:
for s in range(0, len(r["roi"]) - 100, 100):
win.setdefault(r["roi"][s:s + 100].tobytes(), set()).add(r["file"])
shared = {}
for files in win.values():
if len(files) > 1:
key = tuple(sorted(files)); shared[key] = shared.get(key, 0) + 1
print("pairs of files sharing identical 100-frame windows:", shared)
parts = [r for r in all_recs if r["part"]]
for r in sorted(parts, key=lambda r: (r["cell"], r["recording"], r["part"])):
print(f" {r['file']}: ephys {r['ephys_t0']:.1f} to {r['ephys_t1']:.1f} s, frames {r['tf'][0]:.1f} to {r['tf'][-1]:.1f} s")
for ind, rs in recs.items():
print(f"{ind}: {len(rs)} recordings kept, {len({r['cell'] for r in rs})} cells, {len({r['date'] for r in rs})} recording dates, "
f"{sum(len(r['spikes']) for r in rs)} spikes, {sum(r['ephys_t1'] - r['ephys_t0'] for r in rs) / 60:.1f} min of recording")
identical recordings: [['data_20150526_cell2_001.mat', 'data_20150526_cell2_002.mat']]
same fluorescence in ['data_20150526_cell2_001.mat', 'data_20150526_cell2_002.mat'] ; whole MATLAB files identical: False
dropped as duplicates: ['data_20150526_cell2_002.mat']
pairs of files sharing identical 100-frame windows: {('data_20150526_cell2_001.mat', 'data_20150526_cell2_002.mat'): 47}
data_20150804_cell2_001_part1.mat: ephys 40.0 to 150.0 s, frames 40.0 to 150.0 s
data_20150804_cell2_001_part2.mat: ephys 223.0 to 320.0 s, frames 223.0 to 320.0 s
data_20150804_cell2_002_part1.mat: ephys 0.0 to 100.0 s, frames 0.0 to 101.4 s
data_20150804_cell2_002_part2.mat: ephys 135.0 to 320.0 s, frames 135.0 to 320.0 s
data_20150804_cell2_003_part1.mat: ephys 0.0 to 130.0 s, frames 0.0 to 131.8 s
data_20150804_cell2_003_part2.mat: ephys 265.0 to 320.0 s, frames 265.0 to 320.1 s
data_20150804_cell5_001_part1.mat: ephys 0.0 to 225.0 s, frames 0.0 to 225.0 s
jRGECO1a: 27 recordings kept, 11 cells, 6 recording dates, 9080 spikes, 117.3 min of recording
jRCaMP1a: 19 recordings kept, 10 cells, 5 recording dates, 3549 spikes, 92.7 min of recording
Shared clock of spikes and fluorescence¶
The spikes (10 kHz ephys clock) and the fluorescence frames (frame times) are on one time base by the description ("the times are relative session start"). This is checked per recording: the correlation of the spike count in each frame with the frame-to-frame rise of the corrected fluorescence, at lags of -15 to +15 frames. A shared clock puts the peak at lag 0 or +1. As a null, the same correlation with the spike train circularly shifted by a random amount (at least 300 frames; 20 shifts, seed 0) gives the size expected without a relation.
rng = np.random.default_rng(0)
LAGS = np.arange(-15, 16)
clock = []
for ind, rs in recs.items():
for r in rs:
F = cai2.corrected_f(r); tf = r["tf"]
edges = np.concatenate([tf, [tf[-1] + np.median(np.diff(tf))]])
cnt = np.histogram(r["spikes"], edges)[0].astype(float)[:-1]
dF = np.diff(F)
xc = np.array([np.corrcoef(np.roll(cnt, l), dF)[0, 1] for l in LAGS])
null = [np.nanmax([np.corrcoef(np.roll(np.roll(cnt, rng.integers(300, len(cnt) - 300)), l), dF)[0, 1] for l in LAGS])
for _ in range(20)]
clock.append(dict(indicator=ind, file=r["file"], spikes=len(r["spikes"]), peak_lag=int(LAGS[np.nanargmax(xc)]),
r_peak=round(float(np.nanmax(xc)), 3), r_lag0=round(float(xc[LAGS == 0][0]), 3),
null_max=round(float(np.max(null)), 3)))
clock = pd.DataFrame(clock)
clock["above_null"] = clock.r_peak > clock.null_max
print(clock.to_string(index=False))
print("\npeak lag counts:", clock.peak_lag.value_counts().to_dict())
print("recordings whose peak is not above the shifted null:", clock.loc[~clock.above_null, "file"].tolist())
indicator file spikes peak_lag r_peak r_lag0 null_max above_null
jRGECO1a data_20150529_cell2_001.mat 39 0 0.306 0.306 0.030 True
jRGECO1a data_20150529_cell2_002.mat 31 0 0.183 0.183 0.033 True
jRGECO1a data_20150529_cell9_001.mat 457 -1 0.179 0.177 0.038 True
jRGECO1a data_20150601_cell2_001.mat 278 0 0.348 0.348 0.035 True
jRGECO1a data_20150601_cell2_002.mat 122 0 0.211 0.211 0.034 True
jRGECO1a data_20150601_cell2_003.mat 402 0 0.293 0.293 0.045 True
jRGECO1a data_20150601_cell6_001.mat 292 0 0.552 0.552 0.053 True
jRGECO1a data_20150601_cell6_002.mat 374 0 0.522 0.522 0.028 True
jRGECO1a data_20150601_cell6_003.mat 363 0 0.571 0.571 0.047 True
jRGECO1a data_20150601_cell6_004.mat 707 0 0.495 0.495 0.038 True
jRGECO1a data_20150601_cell8_001.mat 178 0 0.460 0.460 0.049 True
jRGECO1a data_20150601_cell8_002.mat 164 0 0.307 0.307 0.057 True
jRGECO1a data_20150708_cell1_001.mat 2362 1 0.198 0.185 0.027 True
jRGECO1a data_20150714_cell1_001.mat 304 0 0.092 0.092 0.028 True
jRGECO1a data_20150728_cell1_001.mat 351 0 0.138 0.138 0.036 True
jRGECO1a data_20150804_cell2_001_part1.mat 295 0 0.544 0.544 0.058 True
jRGECO1a data_20150804_cell2_001_part2.mat 282 0 0.552 0.552 0.069 True
jRGECO1a data_20150804_cell2_002_part1.mat 336 0 0.500 0.500 0.056 True
jRGECO1a data_20150804_cell2_002_part2.mat 409 0 0.514 0.514 0.041 True
jRGECO1a data_20150804_cell2_003_part1.mat 423 0 0.560 0.560 0.049 True
jRGECO1a data_20150804_cell2_003_part2.mat 123 0 0.481 0.481 0.078 True
jRGECO1a data_20150804_cell3_001.mat 78 0 0.169 0.169 0.026 True
jRGECO1a data_20150804_cell3_002.mat 412 0 0.405 0.405 0.039 True
jRGECO1a data_20150804_cell5_001_part1.mat 48 0 0.316 0.316 0.063 True
jRGECO1a data_20150804_cell5_002.mat 118 0 0.249 0.249 0.029 True
jRGECO1a data_20150804_cell5_003.mat 95 0 0.195 0.195 0.025 True
jRGECO1a data_20150804_cell5_004.mat 37 0 0.100 0.100 0.029 True
jRCaMP1a data_20150526_cell2_001.mat 75 0 0.205 0.205 0.035 True
jRCaMP1a data_20150527_cell1_001.mat 5 1 0.048 0.024 0.041 True
jRCaMP1a data_20150605_cell1_001.mat 58 0 0.202 0.202 0.059 True
jRCaMP1a data_20150605_cell3_001.mat 33 0 0.180 0.180 0.045 True
jRCaMP1a data_20150605_cell3_002.mat 25 0 0.115 0.115 0.042 True
jRCaMP1a data_20150605_cell6_001.mat 105 0 0.276 0.276 0.059 True
jRCaMP1a data_20150605_cell6_002.mat 99 0 0.189 0.189 0.063 True
jRCaMP1a data_20150605_cell6_003.mat 121 0 0.116 0.116 0.045 True
jRCaMP1a data_20150605_cell6_004.mat 43 0 0.292 0.292 0.112 True
jRCaMP1a data_20150605_cell7_001.mat 67 0 0.270 0.270 0.059 True
jRCaMP1a data_20150605_cell7_002.mat 26 1 0.086 0.085 0.035 True
jRCaMP1a data_20150605_cell7_003.mat 15 0 0.047 0.047 0.048 False
jRCaMP1a data_20150701_cell2_001.mat 227 0 0.317 0.317 0.056 True
jRCaMP1a data_20150701_cell2_002.mat 1014 0 0.189 0.189 0.039 True
jRCaMP1a data_20150707_cell1_001.mat 304 14 0.028 0.016 0.050 False
jRCaMP1a data_20150707_cell3_001.mat 64 0 0.180 0.180 0.043 True
jRCaMP1a data_20150707_cell3_002.mat 273 0 0.266 0.266 0.038 True
jRCaMP1a data_20150707_cell3_003.mat 538 0 0.340 0.340 0.035 True
jRCaMP1a data_20150707_cell8_001.mat 457 0 0.218 0.218 0.040 True
peak lag counts: {0: 41, 1: 3, -1: 1, 14: 1}
recordings whose peak is not above the shifted null: ['data_20150605_cell7_003.mat', 'data_20150707_cell1_001.mat']
Supplementary-file claims (data elsewhere)¶
Supplementary files 1 (RCaMP1h variants) and 2 (R-GECO1 variants) of the paper are streamed from the eLife CDN. Each row is a variant; the screen values are relative to the parent.
SUPP = {1: "https://cdn.elifesciences.org/articles/12727/elife-12727-supp1-v2.xlsx", # doi:10.7554/eLife.12727.030
2: "https://cdn.elifesciences.org/articles/12727/elife-12727-supp2-v2.xlsx"} # doi:10.7554/eLife.12727.031
supp = {}
for i, url in SUPP.items():
with fsspec.open(url, "rb") as f:
raw = f.read()
x = pd.read_excel(io.BytesIO(raw), header=1)
x.columns = [str(c).strip() for c in x.columns]
x = x.rename(columns={x.columns[0]: "variant", x.columns[2]: "mutations"})
x["variant"] = x["variant"].astype(str).str.strip().str.strip('"')
x["mutations"] = x["mutations"].astype(str).str.strip()
supp[i] = x
print(f"Supplementary file {i}: {len(raw)} bytes, {len(x)} rows; columns {list(x.columns)}")
print(" first rows:", x["variant"].head(5).tolist())
/home/runner/work/encore/encore/executed/dana-2016/.venv/lib/python3.13/site-packages/openpyxl/worksheet/_reader.py:329: UserWarning: Unknown extension is not supported and will be removed warn(msg)
Supplementary file 1: 269721 bytes, 1072 rows; columns ['variant', 'Number of wells', 'mutations', '1 AP ∆F/F0', '3 AP ∆F/F0', '10 AP ∆F/F0', '160 AP ∆F/F0', 'Decay half time (10 AP)', 'F0 normalized to GFP fluorescence', '1 AP p-value', '3 AP p-value', '10 AP p-value', '160 AP p-value', 'Decay half time (10 AP) p-value', 'F0 normalized to GFP fluorescence p-value'] first rows: ['RCaMP1h', 'R-CaMP2', 'jRCaMP1a', 'jRCaMP1b', '206.3']
Supplementary file 2: 200816 bytes, 857 rows; columns ['variant', 'Number of wells', 'mutations', '1 AP ∆F/F0', '3 AP ∆F/F0', '10 AP ∆F/F0', '160 AP ∆F/F0', 'Decay half time (10 AP)', 'F0 normalized to GFP fluorescence', '1 AP p-value', '3 AP p-value', '10 AP p-value', '160 AP p-value', 'Decay half time (10 AP) p-value', 'F0 normalized to GFP fluorescence p-value'] first rows: ['R-GECO1', 'R-CaMP2', 'jRGECO1a', 'jRGECO1b', '106.13']
/home/runner/work/encore/encore/executed/dana-2016/.venv/lib/python3.13/site-packages/openpyxl/worksheet/_reader.py:329: UserWarning: Unknown extension is not supported and will be removed warn(msg)
screen-single-mutations-improved¶
In the neuronal culture screen, 353 of 934 single-mutation RCaMP1h variants and 187 of 689 single-mutation R-GECO1 variants had a higher 1 AP dF/F0 amplitude than their parent.
A single-mutation variant is a row whose "Mutations added" column holds one mutation (the parent's own row, marked "base", is not a mutation); improved is 1 AP dF/F0 ratio above 1 with 1 AP p-value below 0.01 (criterion). Variants with other rules are printed for reference.
cid = "screen-single-mutations-improved"
ex = expected(cid)
res = {}
for i, parent in ((1, "RCaMP1h"), (2, "R-GECO1")):
x = supp[i]
nmut = x["mutations"].str.split().str.len()
single = x[(nmut == 1) & (x["mutations"] != "base")]
a1, p1 = single["1 AP ∆F/F0"], single["1 AP p-value"]
res[parent] = dict(single=len(single), improved=int(((a1 > 1) & (p1 < 0.01)).sum()))
print(f"{parent}: rows {len(x)}, mutation-count distribution {nmut.value_counts().sort_index().to_dict()}")
print(f" single-mutation variants {len(single)}; improved (ratio > 1, p < 0.01) {res[parent]['improved']}")
print(" variants:", {
"ratio > 1 alone": int((a1 > 1).sum()),
"ratio > 1, p < 0.05": int(((a1 > 1) & (p1 < 0.05)).sum()),
"p < 0.01 either direction": int((p1 < 0.01).sum()),
"ratio > 1, p < 0.01 at any of 1, 3, 10, 160 AP": int(np.any([(single[f"{n} AP ∆F/F0"] > 1) & (single[f"{n} AP p-value"] < 0.01)
for n in (1, 3, 10, 160)], axis=0).sum()),
"missing 1 AP values": int(a1.isna().sum())})
allrows = x[x["mutations"] != "base"]
print(f" over all {len(allrows)} variant rows: improved {int(((allrows['1 AP ∆F/F0'] > 1) & (allrows['1 AP p-value'] < 0.01)).sum())}")
measured = [res["RCaMP1h"]["improved"], res["RCaMP1h"]["single"], res["R-GECO1"]["improved"], res["R-GECO1"]["single"]]
for m, e in zip(measured, ex):
print(f"{e['quantity']}: measured {m}, expected {e['value']} +/- {e['tolerance']}, within {within(m, e)}")
RCaMP1h: rows 1072, mutation-count distribution {1: 935, 2: 73, 3: 50, 4: 11, 5: 2, 151: 1}
single-mutation variants 934; improved (ratio > 1, p < 0.01) 230
variants: {'ratio > 1 alone': 637, 'ratio > 1, p < 0.05': 334, 'p < 0.01 either direction': 298, 'ratio > 1, p < 0.01 at any of 1, 3, 10, 160 AP': 307, 'missing 1 AP values': 0}
over all 1071 variant rows: improved 334
R-GECO1: rows 857, mutation-count distribution {1: 693, 2: 40, 3: 65, 4: 32, 5: 13, 6: 6, 7: 7, 29: 1}
single-mutation variants 692; improved (ratio > 1, p < 0.01) 58
variants: {'ratio > 1 alone': 207, 'ratio > 1, p < 0.05': 91, 'p < 0.01 either direction': 302, 'ratio > 1, p < 0.01 at any of 1, 3, 10, 160 AP': 66, 'missing 1 AP values': 0}
over all 856 variant rows: improved 122
improved single-mutation RCaMP1h variants: measured 230, expected 353 +/- 35.3, within False
single-mutation RCaMP1h variants tested: measured 934, expected 934 +/- 93.4, within True
improved single-mutation R-GECO1 variants: measured 58, expected 187 +/- 18.7, within False
single-mutation R-GECO1 variants tested: measured 692, expected 689 +/- 68.9, within True
Result: not reproduced. The tables hold 934 single-mutation RCaMP1h variants and 692 R-GECO1 variants, both within tolerance of the paper's 934 and 689, but by the paper's rule (1 AP ratio above 1, p < 0.01) only 230 RCaMP1h and 58 R-GECO1 variants are improved, against 353 and 187. No variant rule printed above gives both counts: for RCaMP1h, a ratio above 1 with p < 0.05 and the paper's rule over all variant rows both give 334, within 353 +/- 35.3, but for R-GECO1 no rule is within 187 +/- 18.7 (a ratio above 1 alone gives 207, just above 205.7).
culture-jrgeco1a-sensitivity¶
In cultured neurons jRGECO1a has an 8.5-fold larger 1 AP dF/F0 amplitude than R-GECO1 and a faster rise time, with decay time and maximal dF/F0 similar to R-GECO1.
cid = "culture-jrgeco1a-sensitivity"
row = supp[2].set_index("variant").loc["jRGECO1a"]
print(row.drop("mutations").to_string())
e = expected(cid)[0]
print(f"\n1 AP ratio {row['1 AP ∆F/F0']:.3f}, expected {e['value']} +/- {e['tolerance']}, within {within(row['1 AP ∆F/F0'], e)}")
for k, p in (("Decay half time (10 AP)", "Decay half time (10 AP) p-value"), ("160 AP ∆F/F0", "160 AP p-value")):
print(f"{k}: ratio {row[k]:.3f} (in 0.8 to 1.25: {0.8 <= row[k] <= 1.25}), p {row[p]:.3g} (>= 0.01: {row[p] >= 0.01})")
Number of wells 13 1 AP ∆F/F0 8.570565 3 AP ∆F/F0 6.067599 10 AP ∆F/F0 3.410433 160 AP ∆F/F0 1.098143 Decay half time (10 AP) 1.053159 F0 normalized to GFP fluorescence 0.769591 1 AP p-value 0.0 3 AP p-value 0.0 10 AP p-value 0.0 160 AP p-value 0.474745 Decay half time (10 AP) p-value 0.317499 F0 normalized to GFP fluorescence p-value 0.022958 1 AP ratio 8.571, expected 8.5 +/- 0.85, within True Decay half time (10 AP): ratio 1.053 (in 0.8 to 1.25: True), p 0.317 (>= 0.01: True) 160 AP ∆F/F0: ratio 1.098 (in 0.8 to 1.25: True), p 0.475 (>= 0.01: True)
Result: reproduced. The jRGECO1a row gives a 1 AP ratio of 8.57 against R-GECO1; its 10 AP half decay time (1.05) and 160 AP dF/F0 (1.10) ratios are within 0.8 to 1.25, with p-values 0.32 and 0.47. The rise time is not in the table and is not tested.
culture-jrcamp1-sensitivity¶
jRCaMP1a and jRCaMP1b have 24-fold and 13-fold higher sensitivity than RCaMP1h for 1 AP stimuli in cultured neurons; jRCaMP1a is more sensitive and decays more slowly than jRCaMP1b.
cid = "culture-jrcamp1-sensitivity"
t1 = supp[1].set_index("variant").loc[["jRCaMP1a", "jRCaMP1b"]]
print(t1.drop(columns="mutations").T.to_string())
for v, e in zip(["jRCaMP1a", "jRCaMP1b"], expected(cid)):
print(f"{v} 1 AP ratio {t1.loc[v, '1 AP ∆F/F0']:.2f}, expected {e['value']} +/- {e['tolerance']}, within {within(t1.loc[v, '1 AP ∆F/F0'], e)}")
print("jRCaMP1a larger 1 AP ratio:", t1.loc["jRCaMP1a", "1 AP ∆F/F0"] > t1.loc["jRCaMP1b", "1 AP ∆F/F0"],
"; larger 10 AP half decay ratio:", t1.loc["jRCaMP1a", "Decay half time (10 AP)"] > t1.loc["jRCaMP1b", "Decay half time (10 AP)"])
variant jRCaMP1a jRCaMP1b Number of wells 2.300000e+01 1.500000e+01 1 AP ∆F/F0 2.402214e+01 1.296138e+01 3 AP ∆F/F0 2.023781e+01 1.581518e+01 10 AP ∆F/F0 1.162845e+01 1.427132e+01 160 AP ∆F/F0 1.223831e+00 2.313433e+00 Decay half time (10 AP) 3.133386e+00 1.151055e+00 F0 normalized to GFP fluorescence 1.070756e+00 1.476052e+00 1 AP p-value 4.301091e-16 4.542935e-11 3 AP p-value 4.749133e-16 4.407504e-11 10 AP p-value 6.140693e-16 4.874969e-11 160 AP p-value 2.096844e-03 6.522158e-11 Decay half time (10 AP) p-value 3.912339e-16 6.388941e-03 F0 normalized to GFP fluorescence p-value 6.178713e-01 1.035189e-04 jRCaMP1a 1 AP ratio 24.02, expected 24 +/- 2.4, within True jRCaMP1b 1 AP ratio 12.96, expected 13 +/- 1.3, within True jRCaMP1a larger 1 AP ratio: True ; larger 10 AP half decay ratio: True
Result: reproduced. The 1 AP ratios are 24.02 (jRCaMP1a) and 12.96 (jRCaMP1b), and jRCaMP1a has the larger 1 AP ratio and the longer 10 AP half decay (3.13 against 1.15 times RCaMP1h).
Figure 4: simultaneous imaging and cell-attached recording¶
fig4-recorded-cells¶
Simultaneous imaging and cell-attached recording were made from 11 jRGECO1a cells in 6 mice and 10 jRCaMP1a cells in 5 mice.
Cells are the cell number and date in the file names; the data set does not name animals, so a mouse is a recording date (criterion).
cid = "fig4-recorded-cells"
measured_cells = []
for ind, rs in recs.items():
cells = sorted({r["cell"] for r in rs}); dates = sorted({r["date"] for r in rs})
measured_cells += [len(cells), len(dates)]
print(f"{ind}: {len(cells)} cells on {len(dates)} dates")
for d in dates:
print(f" {d}: cells {[c.split('_')[1] for c in cells if c.startswith(d)]}, recordings {sum(r['date'] == d for r in rs)}")
for m, e in zip(measured_cells, expected(cid)):
print(f"{e['quantity']}: measured {m}, expected {e['value']}, match {within(m, e)}")
jRGECO1a: 11 cells on 6 dates 20150529: cells ['cell2', 'cell9'], recordings 3 20150601: cells ['cell2', 'cell6', 'cell8'], recordings 9 20150708: cells ['cell1'], recordings 1 20150714: cells ['cell1'], recordings 1 20150728: cells ['cell1'], recordings 1 20150804: cells ['cell2', 'cell3', 'cell5'], recordings 12 jRCaMP1a: 10 cells on 5 dates 20150526: cells ['cell2'], recordings 1 20150527: cells ['cell1'], recordings 1 20150605: cells ['cell1', 'cell3', 'cell6', 'cell7'], recordings 10 20150701: cells ['cell2'], recordings 2 20150707: cells ['cell1', 'cell3', 'cell8'], recordings 5 jRGECO1a cells: measured 11, expected 11, match True jRGECO1a mice: measured 6, expected 6, match True jRCaMP1a cells: measured 10, expected 10, match True jRCaMP1a mice: measured 5, expected 5, match True
Result: reproduced. The file names give 11 jRGECO1a cells on 6 dates and 10 jRCaMP1a cells on 5 dates, as the paper reports. A mouse is identified by its recording date, which the data set does not confirm; the criterion takes dates as mice unless animals are named, and they are not.
The data set's analysis scripts¶
The three MATLAB files in cai-2/live/scripts/, printed in full, so that the "script" rules of
cai2.py can be checked line by line: interval_pre and interval_post (1 s and 0.8 s; the
comment in find_nspike_event.m says 1000 ms), the exclusion past sample 3.15e6, the 70-frame
window of which samples 1 to 300 are used, the 0.3 limit on noise traces, the 99th percentile
threshold and the d-prime formula. rawf2df_f and fit_dynamic_fitting are called but not
deposited.
for name, text in cai2.script_sources().items():
print(f"======== {name} ({len(text)} characters)")
print(text)
======== data_analysis_for_CRCNS_jRGECO1a.m (7789 characters)
function [s,summary]=data_analysis_for_CRCNS_jRGECO1a(file,disp_flag)
%example code for analysis of jRGECO1a data, as provided to CRCNS
disp_flag=0;
summary.nspike(1:8)=0;
summary.amp(1:8)=0;
summary.tpeak(1:8)=0;
summary.decay_half(1:8)=0;
summary.efficiency(1:8)=0;
summary.dprime(1:8)=0;
if ~exist('disp_flag')
disp_flag=1;
end
if ~exist('file')
file=uigetfile('data*.mat','MultiSelect','on'); %pick all fluorescence+ephys data files to be included in analysis
if ~iscell(file)
file={file};
end
end
cont_ratio=0.7; %Neuropil contamination ratio
fs=10000; %Ephys sampling rate (10KHz)
interval_pre=1000*fs/1000; %required time without spikes before analysis window - 1s
interval_post=800*fs/1000; %required time without spikes after analysis window - 800ms
% bin=250*fs/1000; %fixed bin size - 250ms
bin=[100 100 125 150 175 200 225 250]*fs/1000; %variable bin size
s=struct('nAP',{0,1,2,3,4,5,6,7,8},'spike_waveform',[],'ca_waveform',[],'t_ca',[],'burst_freq',[],'ROC_TPR',[],'ROC_FPR',[]);
nAP=[0,1,2,3,4,5,6,7,8];
count=0;
spike=[];
for i=1:length(file)
load(file{i});
peak=obj.timeSeriesArrayHash.value{1,5}.valueMatrix; %detected spikes
fmean=obj.timeSeriesArrayHash.value{1,1}.valueMatrix; %F signal from cell
fneuropil=obj.timeSeriesArrayHash.value{1,2}.valueMatrix; %Neuropil signal from cell's surroundings
filt=obj.timeSeriesArrayHash.value{1,4}.valueMatrix; %high-pass ephys signal
fmean_comp=fmean-fneuropil*cont_ratio; %neuropil corrected F signal
%% pile spike waveforms
idx=find(peak);
for k=1:length(idx)
if (idx(k)>60) && (idx(k)<(length(peak)-60))
temp=obj.timeSeriesArrayHash.value{1,3}.valueMatrix(idx(k)+(-30:30));
temp=temp-mean(temp(1:10));
spike=[spike,temp];
end
end
%% find event
for k=1:length(nAP)
if nAP(k)==0
isolate=find_no_event(peak,(interval_pre)*4); %find times w/o spikes to analyze noise
freq=zeros(size(peak));
else
[isolate, last_spike, freq]=find_nspike_event(peak,nAP(k),bin(k-1),interval_pre,interval_post);
end
ind_isolate=find(isolate);
ind_isolate(ind_isolate>3.15e6)=[]; %exclude end of recording data
spike_waveform=zeros(8801,length(ind_isolate));
ca_waveform=zeros(70,length(ind_isolate));
ca_waveform_int=zeros(691,length(ind_isolate)); %interpolated Ca waveform
t_ca=zeros(70,length(ind_isolate));
t_ca_int=zeros(691,length(ind_isolate));
burst_freq=zeros(1,length(ind_isolate));
for n=1:length(ind_isolate)
spike_waveform(:,n)=filt(ind_isolate(n)+(-4000:4800));
[m,idx]=min(abs(obj.timeSeriesArrayHash.value{1,1}.time-(ind_isolate(n)/fs+obj.timeSeriesArrayHash.value{1,1}.time(1))));
if idx>10
ca_waveform(:,n)=fmean_comp(idx+(-10:59));
else
for jj=1:11-idx
ca_waveform(jj,n)=fmean_comp(idx);
end
end
if idx>10
t_ca(:,n)=obj.timeSeriesArrayHash.value{1,1}.time(idx+(-10:59))-(ind_isolate(n)/fs+obj.timeSeriesArrayHash.value{1,1}.time(1));
else
dt=obj.timeSeriesArrayHash.value{1,1}.time(idx+1)-obj.timeSeriesArrayHash.value{1,1}.time(idx);
t_ca(:,n)=obj.timeSeriesArrayHash.value{1,1}.time(idx)-10*dt:dt:obj.timeSeriesArrayHash.value{1,1}.time(idx)+59*dt-obj.timeSeriesArrayHash.value{1,1}.time;
end
tspace=mean(diff(t_ca(:,n)));
tt=(-100:590)*tspace/10; %interpolated time vector
ca_int=interp1(t_ca(:,n),ca_waveform(:,n),tt,'linear','extrap'); %interpolating Ca data to improve alignment of different traces to spike time
ca_waveform_int(:,n)=ca_int;
t_ca_int(:,n)=tt;
burst_freq(n)=freq(ind_isolate(n));
end
s(k).t_ca=[s(k).t_ca,t_ca_int];
s(k).spike_waveform=[s(k).spike_waveform,spike_waveform];
s(k).ca_waveform=[s(k).ca_waveform,ca_waveform_int];
if k>2
s(k).burst_freq=[s(k).burst_freq, burst_freq];
end
clear burst_freq t_ca t_ca_int ca_waveform ca_waveform_int spike_waveform
end
end
%% amplitude
if disp_flag
figure('unit','inches','position',[3,3,3.2,2.4]);hold on;
end
for k=2:length(nAP)
ca_waveform=s(k).ca_waveform;
ind=find(std(ca_waveform)>0);
ca_waveform=ca_waveform(1:300,ind);
df_f=rawf2df_f(ca_waveform,1:100);
t_ca=s(k).t_ca;
t_ca=t_ca(1:300,ind);
if disp_flag
if k==1
plot([0,0],[-0.05,0.2],'k');
end
hold on;
plot(t_ca,df_f,'color',[1,1,1]*0.5);
plot(mean(t_ca,2),median(df_f,2),'r','linewidth',2)
end
if size(t_ca,2)>0
[rise_half,decay_half,time_to_peak,peak_value error]=fit_dynamic_fitting(median(df_f,2),mean(t_ca,2),0,0);
end
[amplitude(k),idx]=max(median(df_f(1:250,:),2)); %only time between spke and post interval should be used
sem(k-1)=std(df_f(idx,:))/sqrt(size(df_f,2));
if disp_flag
title(['dff=',num2str(max(median(df_f,2))*100,'%0.3f'),' n=',num2str(size(df_f,2)),' tpeak=',num2str(time_to_peak*1000,'%0.2f'),' decay=',num2str(decay_half*1000,'%0.2f')]);
ylim([-0.1,0.6]);
set(gca,'linewidth',2);
set(gca,'fontsize',16);
xlim([-0.2,1]);
end
summary.nspike(k-1)=size(df_f,2);
summary.amp(k-1)=max(median(df_f,2));
summary.ampsem(k-1)=sem(k-1);
summary.tpeak(k-1)=time_to_peak;
summary.decay_half(k-1)=decay_half;
end
%% spike detection
if disp_flag
figure('unit','inches','position',[3,3,6.4,2.4]);hold on;
end
for k=2:length(nAP)
ca_waveform=s(k).ca_waveform;
ind=find(std(ca_waveform)>0);
ca_waveform=ca_waveform(1:300,ind);
df_f=rawf2df_f(ca_waveform,1:100);
template=mean(df_f,2);
tnorm=template-mean(template);
tnorm=tnorm/norm(tnorm);
ca_noise=s(1).ca_waveform;
ind=find(std(ca_noise)>0);
ca_noise=ca_noise(1:300,ind);
df_fnoise=rawf2df_f(ca_noise,1:100);
ind=find(max(df_fnoise)<0.3);
df_fnoise=df_fnoise(:,ind);
ind=find(min(df_fnoise)>-0.3);
df_fnoise=df_fnoise(:,ind);
proj_sig=df_f'*tnorm;
proj_noise=df_fnoise'*tnorm;
th=prctile(proj_noise,99); % 1% false positive
efficiency=sum(proj_sig>th)/length(proj_sig);
dprime(k-1)=(mean(proj_sig)-mean(proj_noise))/sqrt(0.5*(var(proj_noise)+var(proj_sig))); %corrected formula, HD 20160107
%%ROC calculation
th=min(min(proj_sig),min(proj_noise)):0.001:max(max(proj_sig), max(proj_noise));
for m=1:length(th)
tmp=th(m);
TP(m)=sum(proj_sig>tmp);
FN(m)=sum(proj_sig<tmp);
FP(m)=sum(proj_noise>tmp);
TN(m)=sum(proj_noise<tmp);
FPR(m)=FP(m)/(FP(m)+TN(m));
TPR(m)=TP(m)/(TP(m)+FN(m));
end
s(k).ROC_TPR=TPR;
s(k).ROC_FPR=FPR;
clear TPR FPR TP FP TN FN
if disp_flag
subplot(1,2,1)
hold on;
[n1,xout]=hist(proj_noise,-0.4:0.05:2);
bar(xout,n1,1,'FaceColor',[1,1,1]*0.5,'EdgeColor','none');
[n2,xout]=hist(proj_sig,-0.4:0.05:2);
bar(xout,n2,1,'FaceColor',[1,1,1]*0.2,'EdgeColor','none');
plot([th,th],[0,max(n1)],'k','linewidth',2);
xlim([-0.5,1.5]);
title(['efficiency=',num2str(efficiency,'%0.2f'),' dprime=',num2str(dprime(k-1),'%0.2f')]);
set(gca,'linewidth',2);
set(gca,'fontsize',16);
xlim([-0.5,1]);
end
summary.efficiency(k-1)=efficiency;
summary.dprime(k-1)=dprime(k-1);
end
======== find_nspike_event.m (826 characters)
function [event,last_spike,freq]=find_nspike_event(peak,n,bin,interval_pre,interval_post)
fs=10000;
%Freq measure the mean frequency of a burst - last minus first spikes divided by time
ind=find(peak);
event=zeros(size(peak));
freq=zeros(size(peak));
last_spike=zeros(size(peak));
for i=2:(length(ind)-n)
if (ind(i+n-1)-ind(i))<bin % if first spike and last spike occur within bin
if (ind(i)-ind(i-1))>interval_pre % if the previous spike occur > 1000ms earlier than first spike
if (ind(i+n)-ind(i+n-1))>interval_post % if the next train start >1000ms after the last spike
event(ind(i))=1;
last_spike(ind(i+n-1))=1;
if n>=2
freq(ind(i))=1/((ind(i+n-1)-ind(i))/n/fs);
end
end
end
end
end
======== find_no_event.m (314 characters)
function [event,next_spike]=find_no_event(peak,interval)
fs=10000;
ind=find(peak);
event=zeros(size(peak));
next_spike=zeros(size(peak));
for i=1:(length(ind)-1)
if (ind(i+1)-ind(i))>interval
position=round((ind(i)+ind(i+1))/2);
event(position)=1;
next_spike(ind(i+1))=1;
end
end
fig4d-event-counts¶
The Figure 4 analysis rests on 199, 70, 29, 34, 35, 22, 14 and 21 jRGECO1a events and 135, 65, 71, 52, 33, 20, 14 and 11 jRCaMP1a events of 1 to 8 APs in their time bins, and on 320 (jRGECO1a, 4 s) and 274 (jRCaMP1a, 5 s) no-AP noise events.
Isolation readings of the claim: (a) more than 1 s before and after, (b) before only. The data
set's script isolates by 1 s before and 0.8 s after (interval_post=800*fs/1000), which
disagrees with the Methods ("isolated from other APs by >1 s") and with the script's own comment
(">1000ms after the last spike"); the claims file makes the Methods the main reading where they
and the script disagree, so the script's isolation is run as a variant, not a reading of the
claim, and reading (a) is the main one. Noise readings (i), (ii) and the script's
(find_no_event.m, one trace per spike-free gap longer than the bin, at its midpoint), which
settles a detail the Methods leave open and is the main noise reading. A combined reading pairs
one isolation reading with one noise reading; the claim counts how many of the 18 counts are
within tolerance. The duplicate jRCaMP1a recording is counted once.
cid = "fig4d-event-counts"
ex = expected(cid)
ISO = ["a", "b", "script"]; NOISE = ["i", "ii", "script"]
MAIN_ISO = "a" # Methods: isolated from other APs by >1 s; "script" (0.8 s after) is a variant
events = {(ind, iso, n): [cai2.nspike_events(r, n, cai2.BIN_S[ind][n], iso) for r in rs]
for ind, rs in recs.items() for iso in ISO for n in range(1, 9)}
noise = {(ind, nr): [cai2.noise_events(r, cai2.NOISE_S[ind], nr) for r in rs] for ind, rs in recs.items() for nr in NOISE}
count = lambda lst: int(sum(len(x) for x in lst))
exp_ev = {"jRGECO1a": ex[0:8], "jRCaMP1a": ex[8:16]}; exp_nz = {"jRGECO1a": ex[16], "jRCaMP1a": ex[17]}
tab = []
for ind in recs:
for iso in ISO:
c = [count(events[(ind, iso, n)]) for n in range(1, 9)]
tab.append(dict(indicator=ind, reading=f"isolation {iso}", **{f"{n}AP": v for n, v in zip(range(1, 9), c)},
within=sum(within(v, e) for v, e in zip(c, exp_ev[ind]))))
for nr in NOISE:
v = count(noise[(ind, nr)])
tab.append(dict(indicator=ind, reading=f"noise {nr}", noise=v, within=int(within(v, exp_nz[ind]))))
tab.append(dict(indicator=ind, reading="paper", **{f"{n}AP": e["value"] for n, e in zip(range(1, 9), exp_ev[ind])}, noise=exp_nz[ind]["value"]))
print(pd.DataFrame(tab).to_string(index=False))
combo = []
for iso, nr in itertools.product(ISO, NOISE):
k = 0
for ind in recs:
k += sum(within(count(events[(ind, iso, n)]), e) for n, e in zip(range(1, 9), exp_ev[ind]))
k += within(count(noise[(ind, nr)]), exp_nz[ind])
combo.append(dict(isolation=iso, noise=nr, within_of_18=int(k),
kind="variant (script isolation, against the Methods)" if iso == "script" else "reading of the claim"))
combo = pd.DataFrame(combo).sort_values("within_of_18", ascending=False)
print("\ncounts within tolerance, of 18, per combined reading:\n" + combo.to_string(index=False))
best = combo[combo.kind == "reading of the claim"].within_of_18.max()
print(f"\nbest reading of the claim: {best} of 18; script-isolation variant: "
f"{combo[combo.kind != 'reading of the claim'].within_of_18.max()} of 18")
def counts18(iso, nr):
return ([count(events[("jRGECO1a", iso, n)]) for n in range(1, 9)] + [count(events[("jRCaMP1a", iso, n)]) for n in range(1, 9)]
+ [count(noise[("jRGECO1a", nr)]), count(noise[("jRCaMP1a", nr)])])
measured_counts = counts18(MAIN_ISO, "script")
for label, iso in (("main reading (isolation a, script noise)", MAIN_ISO), ("variant (script isolation and noise)", "script")):
mc = counts18(iso, "script")
print(f"\n{label}, as measured: {mc}")
for m, e in zip(mc, ex):
print(f" {e['quantity']}: {m} (expected {e['value']} +/- {e['tolerance']}) {'within' if within(m, e) else 'outside'}")
indicator reading 1AP 2AP 3AP 4AP 5AP 6AP 7AP 8AP within noise
jRGECO1a isolation a 191.0 62.0 28.0 30.0 36.0 20.0 12.0 17.0 4.0 NaN
jRGECO1a isolation b 348.0 162.0 104.0 88.0 81.0 65.0 43.0 37.0 0.0 NaN
jRGECO1a isolation script 199.0 70.0 29.0 34.0 35.0 22.0 14.0 21.0 8.0 NaN
jRGECO1a noise i NaN NaN NaN NaN NaN NaN NaN NaN 0.0 1145.0
jRGECO1a noise ii NaN NaN NaN NaN NaN NaN NaN NaN 0.0 931.0
jRGECO1a noise script NaN NaN NaN NaN NaN NaN NaN NaN 1.0 320.0
jRGECO1a paper 199.0 70.0 29.0 34.0 35.0 22.0 14.0 21.0 NaN 320.0
jRCaMP1a isolation a 158.0 83.0 79.0 58.0 38.0 24.0 16.0 11.0 1.0 NaN
jRCaMP1a isolation b 231.0 147.0 128.0 88.0 61.0 43.0 22.0 17.0 0.0 NaN
jRCaMP1a isolation script 162.0 89.0 86.0 62.0 44.0 26.0 15.0 11.0 2.0 NaN
jRCaMP1a noise i NaN NaN NaN NaN NaN NaN NaN NaN 0.0 741.0
jRCaMP1a noise ii NaN NaN NaN NaN NaN NaN NaN NaN 0.0 585.0
jRCaMP1a noise script NaN NaN NaN NaN NaN NaN NaN NaN 0.0 246.0
jRCaMP1a paper 135.0 65.0 71.0 52.0 33.0 20.0 14.0 11.0 NaN 274.0
counts within tolerance, of 18, per combined reading:
isolation noise within_of_18 kind
script script 11 variant (script isolation, against the Methods)
script ii 10 variant (script isolation, against the Methods)
script i 10 variant (script isolation, against the Methods)
a script 6 reading of the claim
a i 5 reading of the claim
a ii 5 reading of the claim
b script 1 reading of the claim
b ii 0 reading of the claim
b i 0 reading of the claim
best reading of the claim: 6 of 18; script-isolation variant: 11 of 18
main reading (isolation a, script noise), as measured: [191, 62, 28, 30, 36, 20, 12, 17, 158, 83, 79, 58, 38, 24, 16, 11, 320, 246]
jRGECO1a 1 AP events: 191 (expected 199 +/- 19.9) within
jRGECO1a 2 AP events (100 ms): 62 (expected 70 +/- 7) outside
jRGECO1a 3 AP events (125 ms): 28 (expected 29 +/- 2.9) within
jRGECO1a 4 AP events (150 ms): 30 (expected 34 +/- 3.4) outside
jRGECO1a 5 AP events (175 ms): 36 (expected 35 +/- 3.5) within
jRGECO1a 6 AP events (200 ms): 20 (expected 22 +/- 2.2) within
jRGECO1a 7 AP events (225 ms): 12 (expected 14 +/- 1.4) outside
jRGECO1a 8 AP events (250 ms): 17 (expected 21 +/- 2.1) outside
jRCaMP1a 1 AP events: 158 (expected 135 +/- 13.5) outside
jRCaMP1a 2 AP events (150 ms): 83 (expected 65 +/- 6.5) outside
jRCaMP1a 3 AP events (200 ms): 79 (expected 71 +/- 7.1) outside
jRCaMP1a 4 AP events (250 ms): 58 (expected 52 +/- 5.2) outside
jRCaMP1a 5 AP events (300 ms): 38 (expected 33 +/- 3.3) outside
jRCaMP1a 6 AP events (350 ms): 24 (expected 20 +/- 2) outside
jRCaMP1a 7 AP events (350 ms): 16 (expected 14 +/- 1.4) outside
jRCaMP1a 8 AP events (350 ms): 11 (expected 11 +/- 1.1) within
jRGECO1a noise events (4 s): 320 (expected 320 +/- 32) within
jRCaMP1a noise events (5 s): 246 (expected 274 +/- 27.4) outside
variant (script isolation and noise), as measured: [199, 70, 29, 34, 35, 22, 14, 21, 162, 89, 86, 62, 44, 26, 15, 11, 320, 246]
jRGECO1a 1 AP events: 199 (expected 199 +/- 19.9) within
jRGECO1a 2 AP events (100 ms): 70 (expected 70 +/- 7) within
jRGECO1a 3 AP events (125 ms): 29 (expected 29 +/- 2.9) within
jRGECO1a 4 AP events (150 ms): 34 (expected 34 +/- 3.4) within
jRGECO1a 5 AP events (175 ms): 35 (expected 35 +/- 3.5) within
jRGECO1a 6 AP events (200 ms): 22 (expected 22 +/- 2.2) within
jRGECO1a 7 AP events (225 ms): 14 (expected 14 +/- 1.4) within
jRGECO1a 8 AP events (250 ms): 21 (expected 21 +/- 2.1) within
jRCaMP1a 1 AP events: 162 (expected 135 +/- 13.5) outside
jRCaMP1a 2 AP events (150 ms): 89 (expected 65 +/- 6.5) outside
jRCaMP1a 3 AP events (200 ms): 86 (expected 71 +/- 7.1) outside
jRCaMP1a 4 AP events (250 ms): 62 (expected 52 +/- 5.2) outside
jRCaMP1a 5 AP events (300 ms): 44 (expected 33 +/- 3.3) outside
jRCaMP1a 6 AP events (350 ms): 26 (expected 20 +/- 2) outside
jRCaMP1a 7 AP events (350 ms): 15 (expected 14 +/- 1.4) within
jRCaMP1a 8 AP events (350 ms): 11 (expected 11 +/- 1.1) within
jRGECO1a noise events (4 s): 320 (expected 320 +/- 32) within
jRCaMP1a noise events (5 s): 246 (expected 274 +/- 27.4) outside
Breakdown by cell and recording date under the script reading, and two variants: the counts with the duplicate jRCaMP1a file included, and, for jRCaMP1a, isolation intervals other than the script's, to show how far the counts move with them (not a reading of the claim).
by = []
for ind, rs in recs.items():
for j, r in enumerate(rs):
by.append(dict(indicator=ind, date=r["date"], cell=r["cell"], **{f"{n}AP": len(events[(ind, MAIN_ISO, n)][j]) for n in range(1, 9)},
noise=len(noise[(ind, "script")][j])))
by = pd.DataFrame(by)
print(by.groupby(["indicator", "date", "cell"]).sum(numeric_only=True).to_string())
print("\nper date:\n" + by.groupby(["indicator", "date"]).sum(numeric_only=True).to_string())
dup_recs = streamed["jRCaMP1a"][0]
print("(by cell and date: main reading, isolation a, script noise)")
for iso in (MAIN_ISO, "script"):
print(f"\njRCaMP1a with the duplicate file included (isolation {iso}, script noise):",
[sum(len(cai2.nspike_events(r, n, cai2.BIN_S["jRCaMP1a"][n], iso)) for r in dup_recs) for n in range(1, 9)],
"noise", sum(len(cai2.noise_events(r, 5.0, "script")) for r in dup_recs))
sweep = []
for pre, post in itertools.product([1.0, 1.25, 1.5, 2.0], [0.8, 1.0, 1.5, 2.0]):
cai2.ISOLATION["sweep"] = (pre, post)
c = [sum(len(cai2.nspike_events(r, n, cai2.BIN_S["jRCaMP1a"][n], "sweep")) for r in recs["jRCaMP1a"]) for n in range(1, 9)]
sweep.append(dict(pre_s=pre, post_s=post, counts=c, within_of_8=sum(within(v, e) for v, e in zip(c, exp_ev["jRCaMP1a"]))))
del cai2.ISOLATION["sweep"]
print("\njRCaMP1a event counts against isolation intervals (variant; spike on each side not required):")
print(pd.DataFrame(sweep).to_string(index=False))
print("noise counts for jRCaMP1a with script noise rule and bins of 4, 5, 6 s:",
{L: sum(len(cai2.noise_events(r, L, "script")) for r in recs["jRCaMP1a"]) for L in (4.0, 5.0, 6.0)})
1AP 2AP 3AP 4AP 5AP 6AP 7AP 8AP noise
indicator date cell
jRCaMP1a 20150526 20150526_cell2 7 2 3 0 1 0 0 0 12
20150527 20150527_cell1 2 0 1 0 0 0 0 0 2
20150605 20150605_cell1 6 0 1 0 2 0 0 1 11
20150605_cell3 14 6 4 0 0 0 0 0 18
20150605_cell6 51 20 8 6 2 1 0 0 73
20150605_cell7 11 5 3 6 3 1 1 1 24
20150701 20150701_cell2 12 16 30 20 12 9 2 2 22
20150707 20150707_cell1 28 12 5 3 0 0 0 0 18
20150707_cell3 26 20 16 15 8 6 8 4 51
20150707_cell8 1 2 8 8 10 7 5 3 15
jRGECO1a 20150529 20150529_cell2 20 7 1 0 0 0 0 0 30
20150529_cell9 8 1 1 1 0 0 1 0 18
20150601 20150601_cell2 22 5 0 1 0 0 0 1 44
20150601_cell6 22 12 9 10 7 5 3 6 78
20150601_cell8 2 1 2 1 1 0 2 2 21
20150708 20150708_cell1 1 2 2 1 0 2 0 1 0
20150714 20150714_cell1 37 1 2 0 0 0 0 0 13
20150728 20150728_cell1 23 1 0 0 0 0 0 0 28
20150804 20150804_cell2 38 25 5 6 10 2 3 5 19
20150804_cell3 1 0 2 5 13 7 2 0 23
20150804_cell5 17 7 4 5 5 4 1 2 46
per date:
1AP 2AP 3AP 4AP 5AP 6AP 7AP 8AP noise
indicator date
jRCaMP1a 20150526 7 2 3 0 1 0 0 0 12
20150527 2 0 1 0 0 0 0 0 2
20150605 82 31 16 12 7 2 1 2 126
20150701 12 16 30 20 12 9 2 2 22
20150707 55 34 29 26 18 13 13 7 84
jRGECO1a 20150529 28 8 2 1 0 0 1 0 48
20150601 46 18 11 12 8 5 5 9 143
20150708 1 2 2 1 0 2 0 1 0
20150714 37 1 2 0 0 0 0 0 13
20150728 23 1 0 0 0 0 0 0 28
20150804 56 32 11 16 28 13 6 7 88
(by cell and date: main reading, isolation a, script noise)
jRCaMP1a with the duplicate file included (isolation a, script noise): [165, 85, 82, 58, 39, 24, 16, 11] noise 258
jRCaMP1a with the duplicate file included (isolation script, script noise): [169, 89, 89, 62, 45, 26, 15, 11] noise 258
jRCaMP1a event counts against isolation intervals (variant; spike on each side not required):
pre_s post_s counts within_of_8
1.00 0.8 [174, 98, 89, 63, 47, 27, 16, 11] 1
1.00 1.0 [158, 83, 79, 58, 38, 24, 16, 11] 1
1.00 1.5 [125, 69, 65, 47, 36, 20, 14, 9] 7
1.00 2.0 [113, 60, 56, 35, 30, 13, 13, 8] 3
1.25 0.8 [152, 86, 75, 56, 40, 24, 15, 11] 4
1.25 1.0 [139, 73, 69, 52, 34, 21, 15, 11] 7
1.25 1.5 [109, 60, 57, 43, 32, 17, 13, 9] 3
1.25 2.0 [100, 52, 49, 34, 28, 11, 12, 8] 0
1.50 0.8 [147, 80, 69, 52, 36, 19, 14, 10] 7
1.50 1.0 [134, 68, 63, 48, 30, 17, 14, 10] 6
1.50 1.5 [105, 57, 52, 41, 28, 14, 12, 9] 0
1.50 2.0 [96, 50, 45, 32, 24, 8, 11, 8] 0
2.00 0.8 [135, 66, 60, 41, 33, 18, 13, 6] 5
2.00 1.0 [123, 55, 55, 37, 27, 16, 13, 6] 2
2.00 1.5 [94, 45, 45, 31, 25, 14, 11, 5] 0
2.00 2.0 [88, 41, 41, 24, 23, 8, 10, 5] 0
noise counts for jRCaMP1a with script noise rule and bins of 4, 5, 6 s: {4.0: 296, 5.0: 246, 6.0: 197}
Result: not reproduced. Under the main reading (isolation (a), more than 1 s on each side as the Methods say, with the script's noise traces) 6 of the 18 counts are within tolerance, the best of the six combined readings of the claim (0 to 6), below the 10 of a partial reproduction. The jRGECO1a counts are 191, 62, 28, 30, 36, 20, 12 and 17 against 199, 70, 29, 34, 35, 22, 14 and 21 (1, 3, 5 and 6 AP within), its noise count 320 is the paper's, and of the jRCaMP1a counts only 8 AP (11) is within; 1 to 7 AP are higher (158, 83, 79, 58, 38, 24, 16) and the noise count lower (246 against 274). The data set's script, with 0.8 s after the event, reproduces all nine jRGECO1a counts exactly (199, 70, 29, 34, 35, 22, 14, 21 and 320), which puts its combined variant at 11 of 18, but that isolation disagrees with the Methods and is not a reading of the claim. Under no rule tried do the jRCaMP1a counts match: the isolation sweep reaches at most 7 of the 8 event counts.
Detection: traces, templates and projections (claims fig4e-* and fig4df)¶
The traces of every event set are cut once per segment reading. Segment readings (a), (b), (c) are those of the claim; "script" is the data set's script (10 frames before to 20 after the frame nearest the event, interpolated ten-fold, F0 from the 10 frames before, noise traces with |dF/F0| >= 0.3 dropped). Templates (i) all events and (ii) leave-one-out. The detection rate is the fraction of event projections above the 95th percentile of the noise projections (5% false positives, Methods and criterion); the script's 99th percentile is shown as a variant. The main reading is isolation (a), the script's noise traces and segment, and the template from all events.
Some combinations of the named readings cut noise traces that hold a spike's transient: noise reading (i) starts its first bin at a spike, and the script's noise traces (centred in gaps of more than 4 or 5 s) run past the next spike under the 4 or 5 s segments (a) and (b). Tallies are given over all combinations and over the others ("clean" combinations).
The script is written for jRGECO1a at 30 Hz. Its frame window applied to jRCaMP1a at 15 Hz covers 0.67 s before to 1.33 s after the event, twice the time; that it was the jRCaMP1a analysis is an assumption.
The script segment places each event at its ephys time stamp, which the clock check above supports
(peak at lag 0 in 41 of 46 recordings). The script itself places it at the sample index divided by
the sampling rate plus the first frame time (ind_isolate(n)/fs+...time(1)), about 16 ms later at
30 Hz, 33 ms later at 15 Hz and 0.286 s later in data_20150804_cell5_002.mat. The script's event
times are shown as a variant of the main reading in each detection section.
SEGS = ["a", "b", "c", "script"]
t = time.time()
sig_tr, noise_tr, dropped = {}, {}, {}
for ind, rs in recs.items():
for seg in SEGS:
for nr in NOISE:
parts = [cai2.segment_traces(r, ts, seg, ind, noise=True) for r, ts in zip(rs, noise[(ind, nr)])]
noise_tr[(ind, nr, seg)] = np.concatenate([p[0] for p in parts if len(p[0])])
dropped[(ind, "noise " + nr, seg)] = sum(p[1] for p in parts)
for iso in ISO:
for n in range(1, 9):
parts = [cai2.segment_traces(r, ts, seg, ind) for r, ts in zip(rs, events[(ind, iso, n)])]
sig_tr[(ind, iso, n, seg)] = np.concatenate([p[0] for p in parts if len(p[0])])
dropped[(ind, f"{n}AP {iso}", seg)] = sum(p[1] for p in parts)
def after_spike(tr, seg):
# the part of each trace after the first spike: frames for a, c; frames 10 on for b; samples 100 to 300 for script
return tr[:, 10:] if seg == "b" else tr[:, 100:] if seg == "script" else tr
rows = []
for (ind, iso, n, seg), S in sig_tr.items():
for nr in NOISE:
N = noise_tr[(ind, nr, seg)]
for tpl in ["all", "loo"]:
ps, pn = cai2.projections(S, N, tpl)
rows.append(dict(indicator=ind, nAP=n, isolation=iso, noise=nr, segment=seg, template=tpl, n_events=len(S), n_noise=len(N),
rate95=100 * cai2.detection_rate(ps, pn, 95), rate99=100 * cai2.detection_rate(ps, pn, 99),
balanced95=100 * cai2.balanced_accuracy(ps, pn, 95),
dprime_i=cai2.dprime(ps, pn, "i"), dprime_ii=cai2.dprime(ps, pn, "ii"),
median_peak_seg=float(np.median(after_spike(S, seg).max(1)))))
grid = pd.DataFrame(rows)
# combinations whose noise traces cannot hold a spike transient (see above)
CLEAN = {("ii", "a"), ("ii", "b"), ("ii", "c"), ("ii", "script"), ("script", "c"), ("script", "script")}
grid["clean"] = [(r.noise, r.segment) in CLEAN for r in grid.itertuples()]
peak1s = {(ind, iso, n): np.concatenate([cai2.peak_dff(r, ts, ind, "1s") for r, ts in zip(rs, events[(ind, iso, n)])])
for ind, rs in recs.items() for iso in ISO for n in range(1, 9)}
grid["median_peak_1s"] = [float(np.median(peak1s[(r.indicator, r.isolation, r.nAP)])) for r in grid.itertuples()]
print(f"{len(grid)} combinations in {time.time() - t:.0f} s")
dr = pd.Series(dropped)
print("traces dropped at recording edges (or, for script noise, by the 0.3 limit), nonzero only:")
print(dr[dr > 0].to_string())
MAIN = dict(isolation=MAIN_ISO, noise="script", segment="script", template="all")
def script_rates(ind, iso, n, align="ephys", drop=()):
# script segment and noise traces, template from all events, for one isolation reading; align "script"
# places events at the script's times (cai2.script_time); recordings in `drop` are left out
keep = [j for j, r in enumerate(recs[ind]) if r["file"] not in drop]
N = [cai2.segment_traces(recs[ind][j], noise[(ind, "script")][j], "script", ind, noise=True, align=align)[0] for j in keep]
S = [cai2.segment_traces(recs[ind][j], events[(ind, iso, n)][j], "script", ind, align=align)[0] for j in keep]
N = np.concatenate([x for x in N if len(x)]); S = np.concatenate([x for x in S if len(x)])
ps, pn = cai2.projections(S, N, "all")
return dict(events=len(S), noise=len(N), rate95=100 * cai2.detection_rate(ps, pn, 95), rate99=100 * cai2.detection_rate(ps, pn, 99))
def pick(df, **kw):
m = np.ones(len(df), bool)
for k, v in kw.items():
m &= df[k] == v
return df[m]
1152 combinations in 1 s
traces dropped at recording edges (or, for script noise, by the 0.3 limit), nonzero only:
jRGECO1a noise i a 11
noise script a 1
1AP a a 1
5AP a a 1
1AP b a 3
2AP b a 2
3AP b a 1
5AP b a 2
8AP b a 1
noise i b 11
noise script b 1
1AP a b 1
5AP a b 1
1AP b b 3
2AP b b 2
3AP b b 1
5AP b b 2
8AP b b 1
noise i c 11
script 171
noise ii script 12
noise script script 1
5AP a script 1
3AP b script 1
5AP b script 1
jRCaMP1a noise i a 15
noise script a 1
1AP a a 1
3AP a a 1
4AP a a 1
6AP a a 1
1AP b a 5
2AP b a 1
3AP b a 2
4AP b a 1
6AP b a 1
2AP script a 1
noise i b 15
noise script b 1
1AP a b 1
3AP a b 1
4AP a b 1
6AP a b 1
1AP b b 5
2AP b b 1
3AP b b 2
4AP b b 1
6AP b b 1
2AP script b 1
noise i c 15
script 74
noise ii script 3
noise script script 4
1AP b script 3
3AP b script 1
fig4e-jrgeco1a-1ap-detection¶
With jRGECO1a, single spikes are detected with 82% accuracy at a 5% false-positive rate (11 cells, 6 mice, 199 spikes).
cid = "fig4e-jrgeco1a-1ap-detection"
ex = expected(cid)
for n, e in zip([1], ex):
g = pick(grid, indicator="jRGECO1a", nAP=n)
main = pick(g, **MAIN).iloc[0]
print(f"== jRGECO1a {n} AP: main reading (isolation a, script noise and segment, template from all events):"
f" rate {main.rate95:.1f}% ({main.n_events} events, {main.n_noise} noise traces); expected {e['value']} +/- {e['tolerance']}:"
f" within {within(main.rate95, e)}")
print(f" variants on the main reading: 99th percentile (script) {main.rate99:.1f}%, balanced accuracy {main.balanced95:.1f}%,"
f" leave-one-out {pick(g, isolation=MAIN_ISO, noise='script', segment='script', template='loo').iloc[0].rate95:.1f}%")
sv = pick(g, isolation="script", noise="script", segment="script", template="all").iloc[0]
print(f" variant, script isolation (0.8 s after): rate {sv.rate95:.1f}% ({sv.n_events} events), within {within(sv.rate95, e)};"
f" with the script's 99th percentile {sv.rate99:.1f}%")
for iso in (MAIN_ISO, "script"):
v = script_rates("jRGECO1a", iso, n, align="script")
print(f" variant, the script's event times (sample / fs + first frame time), isolation {iso}: rate {v['rate95']:.1f}%"
f" ({v['events']} events, {v['noise']} noise traces), within {within(v['rate95'], e)}; 99th percentile {v['rate99']:.1f}%")
named = g[g.segment != "script"]
ok = named[[within(v, e) for v in named.rate95]]
print(f" claim's named segment readings (a, b, c): rate {named.rate95.min():.1f} to {named.rate95.max():.1f}%;"
f" {len(ok)} of {len(named)} combinations within tolerance")
for lab, sub in (("readings of the claim (isolation a, b)", named[named.isolation != "script"]),
("clean readings of the claim", named[(named.isolation != "script") & named.clean])):
k = sum(within(v, e) for v in sub.rate95)
print(f" {lab}: {k} of {len(sub)} within tolerance, rate {sub.rate95.min():.1f} to {sub.rate95.max():.1f}%")
print(named.pivot_table(index=["isolation", "noise"], columns=["segment", "template"], values="rate95").round(1).to_string())
print(" script segment, all combinations of isolation and noise readings:")
print(pick(g, segment="script").pivot_table(index=["isolation", "noise"], columns="template", values="rate95").round(1).to_string())
== jRGECO1a 1 AP: main reading (isolation a, script noise and segment, template from all events): rate 84.3% (191 events, 319 noise traces); expected 82 +/- 8.2: within True
variants on the main reading: 99th percentile (script) 60.7%, balanced accuracy 89.6%, leave-one-out 84.3%
variant, script isolation (0.8 s after): rate 82.4% (199 events), within True; with the script's 99th percentile 60.8%
variant, the script's event times (sample / fs + first frame time), isolation a: rate 84.8% (191 events, 319 noise traces), within True; 99th percentile 60.7%
variant, the script's event times (sample / fs + first frame time), isolation script: rate 82.9% (199 events, 319 noise traces), within True; 99th percentile 58.8%
claim's named segment readings (a, b, c): rate 0.0 to 76.3%; 1 of 54 combinations within tolerance
readings of the claim (isolation a, b): 1 of 36 within tolerance, rate 0.0 to 76.3%
clean readings of the claim: 1 of 16 within tolerance, rate 21.4 to 76.3%
segment a b c
template all loo all loo all loo
isolation noise
a i 1.1 0.0 5.3 2.1 0.0 0.0
ii 63.2 60.5 76.3 73.7 49.7 49.7
script 3.2 0.0 3.7 1.1 69.1 68.1
b i 3.5 0.6 24.1 21.2 0.0 0.0
ii 25.5 21.4 60.3 56.8 38.8 35.9
script 61.7 55.7 57.7 53.3 46.8 45.4
script i 9.5 4.5 13.6 11.1 0.0 0.0
ii 61.3 59.8 58.8 57.3 48.2 47.7
script 4.5 0.5 6.0 3.5 68.3 67.3
script segment, all combinations of isolation and noise readings:
template all loo
isolation noise
a i 35.6 35.1
ii 84.3 84.3
script 84.3 84.3
b i 49.1 48.9
ii 74.7 74.7
script 74.1 74.1
script i 33.2 33.2
ii 82.4 82.4
script 82.4 82.4
# Main reading broken down by recording date (mouse): events of each date scored on the pooled template and noise threshold.
rs = recs["jRGECO1a"]
N = noise_tr[("jRGECO1a", "script", "script")]
for n in [1]:
per = [(r["date"], cai2.segment_traces(r, ts, "script", "jRGECO1a")[0]) for r, ts in zip(rs, events[("jRGECO1a", MAIN_ISO, n)])]
S = np.concatenate([tr for _, tr in per if len(tr)])
dates = np.concatenate([[d] * len(tr) for d, tr in per if len(tr)])
ps, pn = cai2.projections(S, N, "all")
th = np.percentile(pn, 95)
out = pd.DataFrame(dict(date=dates, hit=ps > th)).groupby("date").hit.agg(["size", "mean"])
out["mean"] = (100 * out["mean"]).round(1)
print(f"jRGECO1a {n} AP, detection rate by date (n events, % detected):", out.to_dict("index"))
jRGECO1a 1 AP, detection rate by date (n events, % detected): {'20150529': {'size': 28, 'mean': 78.6}, '20150601': {'size': 46, 'mean': 82.6}, '20150708': {'size': 1, 'mean': 0.0}, '20150714': {'size': 37, 'mean': 86.5}, '20150728': {'size': 23, 'mean': 78.3}, '20150804': {'size': 56, 'mean': 91.1}}
Result: reproduced. Under the main reading (isolation (a), the script's noise traces and segment, the template from all events, the Methods' 5% false-positive threshold) 84.3% of 191 single spikes are detected, within 82 +/- 8.2%; the script's isolation gives 82.4% of 199 spikes. Leave-one-out templates give 84.3%. Among the claim's named segment readings (a), (b), (c) with isolation (a) or (b), 1 of 36 combinations is within tolerance (isolation (a), noise (ii), segment (b): 76.3%), and it is among the 16 clean ones. The script's own 1% threshold gives 60.7%, and 60.8% under the script's isolation. With the script's event times (sample index / fs plus the first frame time) the rate is 84.8% under isolation (a) and 82.9% under the script's isolation, both within tolerance. By recording date the main-reading rate is 78.3 to 91.1% on the five dates with 23 or more events.
fig4e-jrgeco1a-2ap-detection¶
With jRGECO1a, two APs within 100 ms are detected with 96% accuracy at a 5% false-positive rate (70 events).
cid = "fig4e-jrgeco1a-2ap-detection"
ex = expected(cid)
for n, e in zip([2], ex):
g = pick(grid, indicator="jRGECO1a", nAP=n)
main = pick(g, **MAIN).iloc[0]
print(f"== jRGECO1a {n} AP: main reading (isolation a, script noise and segment, template from all events):"
f" rate {main.rate95:.1f}% ({main.n_events} events, {main.n_noise} noise traces); expected {e['value']} +/- {e['tolerance']}:"
f" within {within(main.rate95, e)}")
print(f" variants on the main reading: 99th percentile (script) {main.rate99:.1f}%, balanced accuracy {main.balanced95:.1f}%,"
f" leave-one-out {pick(g, isolation=MAIN_ISO, noise='script', segment='script', template='loo').iloc[0].rate95:.1f}%")
sv = pick(g, isolation="script", noise="script", segment="script", template="all").iloc[0]
print(f" variant, script isolation (0.8 s after): rate {sv.rate95:.1f}% ({sv.n_events} events), within {within(sv.rate95, e)};"
f" with the script's 99th percentile {sv.rate99:.1f}%")
for iso in (MAIN_ISO, "script"):
v = script_rates("jRGECO1a", iso, n, align="script")
print(f" variant, the script's event times (sample / fs + first frame time), isolation {iso}: rate {v['rate95']:.1f}%"
f" ({v['events']} events, {v['noise']} noise traces), within {within(v['rate95'], e)}; 99th percentile {v['rate99']:.1f}%")
named = g[g.segment != "script"]
ok = named[[within(v, e) for v in named.rate95]]
print(f" claim's named segment readings (a, b, c): rate {named.rate95.min():.1f} to {named.rate95.max():.1f}%;"
f" {len(ok)} of {len(named)} combinations within tolerance")
for lab, sub in (("readings of the claim (isolation a, b)", named[named.isolation != "script"]),
("clean readings of the claim", named[(named.isolation != "script") & named.clean])):
k = sum(within(v, e) for v in sub.rate95)
print(f" {lab}: {k} of {len(sub)} within tolerance, rate {sub.rate95.min():.1f} to {sub.rate95.max():.1f}%")
print(named.pivot_table(index=["isolation", "noise"], columns=["segment", "template"], values="rate95").round(1).to_string())
print(" script segment, all combinations of isolation and noise readings:")
print(pick(g, segment="script").pivot_table(index=["isolation", "noise"], columns="template", values="rate95").round(1).to_string())
== jRGECO1a 2 AP: main reading (isolation a, script noise and segment, template from all events): rate 100.0% (62 events, 319 noise traces); expected 96 +/- 4: within True
variants on the main reading: 99th percentile (script) 96.8%, balanced accuracy 97.5%, leave-one-out 100.0%
variant, script isolation (0.8 s after): rate 100.0% (70 events), within True; with the script's 99th percentile 98.6%
variant, the script's event times (sample / fs + first frame time), isolation a: rate 95.2% (62 events, 319 noise traces), within True; 99th percentile 93.5%
variant, the script's event times (sample / fs + first frame time), isolation script: rate 95.7% (70 events, 319 noise traces), within True; 99th percentile 94.3%
claim's named segment readings (a, b, c): rate 0.0 to 100.0%; 15 of 54 combinations within tolerance
readings of the claim (isolation a, b): 10 of 36 within tolerance, rate 0.0 to 100.0%
clean readings of the claim: 6 of 16 within tolerance, rate 51.2 to 100.0%
segment a b c
template all loo all loo all loo
isolation noise
a i 0.0 0.0 0.0 0.0 0.0 0.0
ii 85.5 71.0 100.0 96.8 96.8 96.8
script 98.4 93.5 100.0 95.2 98.4 98.4
b i 8.8 5.0 53.8 51.9 5.6 5.6
ii 58.1 51.2 89.4 88.1 64.2 62.3
script 65.6 58.8 51.2 48.1 71.0 70.4
script i 30.0 14.3 48.6 40.0 0.0 0.0
ii 90.0 82.9 92.9 84.3 98.6 95.7
script 65.7 45.7 37.1 30.0 100.0 97.1
script segment, all combinations of isolation and noise readings:
template all loo
isolation noise
a i 90.3 90.3
ii 100.0 100.0
script 100.0 100.0
b i 91.4 90.1
ii 95.7 95.1
script 95.7 95.1
script i 88.6 88.6
ii 100.0 100.0
script 100.0 100.0
# Main reading broken down by recording date (mouse): events of each date scored on the pooled template and noise threshold.
rs = recs["jRGECO1a"]
N = noise_tr[("jRGECO1a", "script", "script")]
for n in [2]:
per = [(r["date"], cai2.segment_traces(r, ts, "script", "jRGECO1a")[0]) for r, ts in zip(rs, events[("jRGECO1a", MAIN_ISO, n)])]
S = np.concatenate([tr for _, tr in per if len(tr)])
dates = np.concatenate([[d] * len(tr) for d, tr in per if len(tr)])
ps, pn = cai2.projections(S, N, "all")
th = np.percentile(pn, 95)
out = pd.DataFrame(dict(date=dates, hit=ps > th)).groupby("date").hit.agg(["size", "mean"])
out["mean"] = (100 * out["mean"]).round(1)
print(f"jRGECO1a {n} AP, detection rate by date (n events, % detected):", out.to_dict("index"))
jRGECO1a 2 AP, detection rate by date (n events, % detected): {'20150529': {'size': 8, 'mean': 100.0}, '20150601': {'size': 18, 'mean': 100.0}, '20150708': {'size': 2, 'mean': 100.0}, '20150714': {'size': 1, 'mean': 100.0}, '20150728': {'size': 1, 'mean': 100.0}, '20150804': {'size': 32, 'mean': 100.0}}
Result: reproduced. Under the main reading all 62 two-spike events are detected (100%, inside the 92 to 100% the criterion allows), and 100% of 70 under the script's isolation; 10 of the 36 combinations of the claim's named readings with isolation (a) or (b) are also within it (6 of the 16 clean ones), and the script's 1% threshold gives 96.8%. With the script's event times the rate is 95.2% (isolation (a)) and 95.7% (the script's isolation), both within tolerance. Every recording date detects all of its events.
fig4e-jrcamp1a-detection¶
jRCaMP1a fluorescence changes are smaller, with 1 AP and 2 AP detection rates of 65% and 80% at a 5% false-positive rate (10 cells, 5 mice, 135 and 65 events).
cid = "fig4e-jrcamp1a-detection"
ex = expected(cid)
for n, e in zip([1, 2], ex):
g = pick(grid, indicator="jRCaMP1a", nAP=n)
main = pick(g, **MAIN).iloc[0]
print(f"== jRCaMP1a {n} AP: main reading (isolation a, script noise and segment, template from all events):"
f" rate {main.rate95:.1f}% ({main.n_events} events, {main.n_noise} noise traces); expected {e['value']} +/- {e['tolerance']}:"
f" within {within(main.rate95, e)}")
print(f" variants on the main reading: 99th percentile (script) {main.rate99:.1f}%, balanced accuracy {main.balanced95:.1f}%,"
f" leave-one-out {pick(g, isolation=MAIN_ISO, noise='script', segment='script', template='loo').iloc[0].rate95:.1f}%")
sv = pick(g, isolation="script", noise="script", segment="script", template="all").iloc[0]
print(f" variant, script isolation (0.8 s after): rate {sv.rate95:.1f}% ({sv.n_events} events), within {within(sv.rate95, e)};"
f" with the script's 99th percentile {sv.rate99:.1f}%")
for iso in (MAIN_ISO, "script"):
v = script_rates("jRCaMP1a", iso, n, align="script")
print(f" variant, the script's event times (sample / fs + first frame time), isolation {iso}: rate {v['rate95']:.1f}%"
f" ({v['events']} events, {v['noise']} noise traces), within {within(v['rate95'], e)}; 99th percentile {v['rate99']:.1f}%")
named = g[g.segment != "script"]
ok = named[[within(v, e) for v in named.rate95]]
print(f" claim's named segment readings (a, b, c): rate {named.rate95.min():.1f} to {named.rate95.max():.1f}%;"
f" {len(ok)} of {len(named)} combinations within tolerance")
for lab, sub in (("readings of the claim (isolation a, b)", named[named.isolation != "script"]),
("clean readings of the claim", named[(named.isolation != "script") & named.clean])):
k = sum(within(v, e) for v in sub.rate95)
print(f" {lab}: {k} of {len(sub)} within tolerance, rate {sub.rate95.min():.1f} to {sub.rate95.max():.1f}%")
print(named.pivot_table(index=["isolation", "noise"], columns=["segment", "template"], values="rate95").round(1).to_string())
print(" script segment, all combinations of isolation and noise readings:")
print(pick(g, segment="script").pivot_table(index=["isolation", "noise"], columns="template", values="rate95").round(1).to_string())
== jRCaMP1a 1 AP: main reading (isolation a, script noise and segment, template from all events): rate 63.3% (158 events, 242 noise traces); expected 65 +/- 6.5: within True
variants on the main reading: 99th percentile (script) 41.1%, balanced accuracy 79.0%, leave-one-out 62.0%
variant, script isolation (0.8 s after): rate 63.0% (162 events), within True; with the script's 99th percentile 25.3%
variant, the script's event times (sample / fs + first frame time), isolation a: rate 63.3% (158 events, 243 noise traces), within True; 99th percentile 22.8%
variant, the script's event times (sample / fs + first frame time), isolation script: rate 59.9% (162 events, 243 noise traces), within True; 99th percentile 7.4%
claim's named segment readings (a, b, c): rate 0.6 to 41.6%; 0 of 54 combinations within tolerance
readings of the claim (isolation a, b): 0 of 36 within tolerance, rate 1.9 to 41.6%
clean readings of the claim: 0 of 16 within tolerance, rate 16.0 to 41.6%
segment a b c
template all loo all loo all loo
isolation noise
a i 28.0 24.2 22.9 21.7 1.9 1.9
ii 29.3 25.5 29.9 29.3 18.4 17.7
script 8.9 7.0 17.2 15.3 22.8 22.2
b i 23.5 17.7 18.6 17.3 3.0 2.6
ii 31.9 26.5 41.6 39.4 18.6 16.0
script 29.2 24.3 32.3 30.5 24.2 20.3
script i 25.9 18.5 28.4 25.3 1.2 0.6
ii 27.2 22.2 35.2 34.0 16.7 16.0
script 14.8 13.0 20.4 17.9 22.2 20.4
script segment, all combinations of isolation and noise readings:
template all loo
isolation noise
a i 2.5 1.9
ii 58.2 55.1
script 63.3 62.0
b i 12.7 12.7
ii 54.4 54.4
script 57.0 56.6
script i 2.5 1.9
ii 54.9 54.9
script 63.0 61.7
== jRCaMP1a 2 AP: main reading (isolation a, script noise and segment, template from all events): rate 80.7% (83 events, 242 noise traces); expected 80 +/- 8: within True
variants on the main reading: 99th percentile (script) 67.5%, balanced accuracy 87.7%, leave-one-out 79.5%
variant, script isolation (0.8 s after): rate 75.3% (89 events), within True; with the script's 99th percentile 56.2%
variant, the script's event times (sample / fs + first frame time), isolation a: rate 80.7% (83 events, 243 noise traces), within True; 99th percentile 53.0%
variant, the script's event times (sample / fs + first frame time), isolation script: rate 75.3% (89 events, 243 noise traces), within True; 99th percentile 42.7%
claim's named segment readings (a, b, c): rate 0.0 to 76.7%; 9 of 54 combinations within tolerance
readings of the claim (isolation a, b): 7 of 36 within tolerance, rate 0.0 to 76.7%
clean readings of the claim: 3 of 16 within tolerance, rate 19.7 to 76.7%
segment a b c
template all loo all loo all loo
isolation noise
a i 0.0 0.0 0.0 0.0 1.2 1.2
ii 20.5 20.5 72.3 68.7 39.8 38.6
script 59.0 56.6 73.5 72.3 43.4 43.4
b i 1.4 1.4 7.5 5.5 12.2 9.5
ii 30.8 30.1 76.7 76.0 26.5 21.1
script 48.6 45.9 76.7 76.7 24.5 19.7
script i 1.1 0.0 0.0 0.0 1.1 1.1
ii 23.9 23.9 73.9 70.5 33.7 31.5
script 45.5 44.3 73.9 70.5 41.6 39.3
script segment, all combinations of isolation and noise readings:
template all loo
isolation noise
a i 30.1 28.9
ii 78.3 78.3
script 80.7 79.5
b i 36.7 36.1
ii 72.1 72.1
script 75.5 74.1
script i 29.2 29.2
ii 74.2 73.0
script 75.3 75.3
# Main reading broken down by recording date (mouse): events of each date scored on the pooled template and noise threshold.
rs = recs["jRCaMP1a"]
N = noise_tr[("jRCaMP1a", "script", "script")]
for n in [1, 2]:
per = [(r["date"], cai2.segment_traces(r, ts, "script", "jRCaMP1a")[0]) for r, ts in zip(rs, events[("jRCaMP1a", MAIN_ISO, n)])]
S = np.concatenate([tr for _, tr in per if len(tr)])
dates = np.concatenate([[d] * len(tr) for d, tr in per if len(tr)])
ps, pn = cai2.projections(S, N, "all")
th = np.percentile(pn, 95)
out = pd.DataFrame(dict(date=dates, hit=ps > th)).groupby("date").hit.agg(["size", "mean"])
out["mean"] = (100 * out["mean"]).round(1)
print(f"jRCaMP1a {n} AP, detection rate by date (n events, % detected):", out.to_dict("index"))
jRCaMP1a 1 AP, detection rate by date (n events, % detected): {'20150526': {'size': 7, 'mean': 100.0}, '20150527': {'size': 2, 'mean': 100.0}, '20150605': {'size': 82, 'mean': 80.5}, '20150701': {'size': 12, 'mean': 25.0}, '20150707': {'size': 55, 'mean': 40.0}}
jRCaMP1a 2 AP, detection rate by date (n events, % detected): {'20150526': {'size': 2, 'mean': 100.0}, '20150605': {'size': 31, 'mean': 96.8}, '20150701': {'size': 16, 'mean': 75.0}, '20150707': {'size': 34, 'mean': 67.6}}
# jRCaMP1a counts and rates under each isolation reading (script noise and segment, template from all
# events): with all recordings, without data_20150707_cell1_001.mat (no relation of fluorescence to
# spikes in the clock check), and without both recordings that failed the clock check.
ex = expected("fig4e-jrcamp1a-detection")
bad = sorted(clock.loc[~clock.above_null, "file"])
ind = "jRCaMP1a"
sets = {"all": set(), "without 20150707_cell1_001": {"data_20150707_cell1_001.mat"}, "without both": set(bad)}
rows41 = []
for iso in ISO:
for label, out_files in sets.items():
keep = [j for j, r in enumerate(recs[ind]) if r["file"] not in out_files]
N = np.concatenate([cai2.segment_traces(recs[ind][j], noise[(ind, "script")][j], "script", ind, noise=True)[0] for j in keep])
row = dict(isolation=iso, recordings=label, cells=len({recs[ind][j]["cell"] for j in keep}), noise=len(N))
for n in (1, 2):
S = np.concatenate([x for x in (cai2.segment_traces(recs[ind][j], events[(ind, iso, n)][j], "script", ind)[0] for j in keep) if len(x)])
ps, pn = cai2.projections(S, N, "all")
row[f"{n}AP_events"] = len(S)
row[f"{n}AP_rate"] = round(100 * cai2.detection_rate(ps, pn), 1)
row["1AP_within"] = within(row["1AP_rate"], ex[0]); row["2AP_within"] = within(row["2AP_rate"], ex[1])
rows41.append(row)
print(f"recordings that failed the clock check: {bad}")
print(f"expected 1 AP {ex[0]['value']} +/- {ex[0]['tolerance']}%, 2 AP {ex[1]['value']} +/- {ex[1]['tolerance']}%; paper's events 135 and 65")
print(pd.DataFrame(rows41).to_string(index=False))
recordings that failed the clock check: ['data_20150605_cell7_003.mat', 'data_20150707_cell1_001.mat']
expected 1 AP 65 +/- 6.5%, 2 AP 80 +/- 8%; paper's events 135 and 65
isolation recordings cells noise 1AP_events 1AP_rate 2AP_events 2AP_rate 1AP_within 2AP_within
a all 10 242 158 63.3 83 80.7 True True
a without 20150707_cell1_001 9 227 130 74.6 71 87.3 False True
a without both 9 223 128 75.0 71 87.3 False True
b all 10 242 228 57.0 147 75.5 False True
b without 20150707_cell1_001 9 227 180 71.7 122 84.4 False True
b without both 9 223 178 71.9 122 84.4 False True
script all 10 242 162 63.0 89 75.3 True True
script without 20150707_cell1_001 9 227 131 74.0 76 82.9 False True
script without both 9 223 130 75.4 76 82.9 False True
# The recording data_20150707_cell1_001.mat against the other choices: the claim's named readings
# (isolation a or b) without it, and the script's event times with and without it.
ex = expected("fig4e-jrcamp1a-detection")
ind = "jRCaMP1a"
out_files = {"data_20150707_cell1_001.mat"}
keep = [j for j, r in enumerate(recs[ind]) if r["file"] not in out_files]
rows_nr = []
for iso, nr, seg, tpl in itertools.product(["a", "b"], NOISE, ["a", "b", "c"], ["all", "loo"]):
N = np.concatenate([x for x in (cai2.segment_traces(recs[ind][j], noise[(ind, nr)][j], seg, ind, noise=True)[0] for j in keep) if len(x)])
row = dict(isolation=iso, noise=nr, segment=seg, template=tpl, clean=(nr, seg) in CLEAN)
for n in (1, 2):
S = np.concatenate([x for x in (cai2.segment_traces(recs[ind][j], events[(ind, iso, n)][j], seg, ind)[0] for j in keep) if len(x)])
ps, pn = cai2.projections(S, N, tpl)
row[f"{n}AP_rate"] = 100 * cai2.detection_rate(ps, pn)
rows_nr.append(row)
nr_df = pd.DataFrame(rows_nr)
nr_df["1AP_within"] = [within(v, ex[0]) for v in nr_df["1AP_rate"]]
nr_df["2AP_within"] = [within(v, ex[1]) for v in nr_df["2AP_rate"]]
print("claim's named readings without data_20150707_cell1_001.mat (1 AP rate / 2 AP rate, %):")
print(nr_df.pivot_table(index=["isolation", "noise"], columns=["segment", "template"], values=["1AP_rate", "2AP_rate"]).round(1).to_string())
for lab, sub in (("all 36", nr_df), ("16 clean", nr_df[nr_df.clean])):
print(f" {lab}: 1 AP within {int(sub['1AP_within'].sum())}, 2 AP within {int(sub['2AP_within'].sum())},"
f" both within {int((sub['1AP_within'] & sub['2AP_within']).sum())}; 1 AP rate {sub['1AP_rate'].min():.1f} to {sub['1AP_rate'].max():.1f}%")
print(" combinations with both within:")
print(nr_df[nr_df["1AP_within"] & nr_df["2AP_within"]].round(1).to_string(index=False))
print("\nscript segment and noise, template from all events, by event times and recordings:")
rows_al = []
for label, drop in (("all", set()), ("without 20150707_cell1_001", out_files)):
for iso in ISO:
for align in ("ephys", "script"):
v1, v2 = script_rates(ind, iso, 1, align, drop), script_rates(ind, iso, 2, align, drop)
rows_al.append(dict(recordings=label, isolation=iso, event_times=align, noise=v1["noise"],
**{"1AP_events": v1["events"], "1AP_rate": round(v1["rate95"], 1), "2AP_events": v2["events"],
"2AP_rate": round(v2["rate95"], 1), "1AP_within": within(v1["rate95"], ex[0]),
"2AP_within": within(v2["rate95"], ex[1])}))
print(pd.DataFrame(rows_al).to_string(index=False))
claim's named readings without data_20150707_cell1_001.mat (1 AP rate / 2 AP rate, %):
1AP_rate 2AP_rate
segment a b c a b c
template all loo all loo all loo all loo all loo all loo
isolation noise
a i 1.5 0.8 4.6 2.3 1.5 1.5 0.0 0.0 0.0 0.0 2.8 1.4
ii 14.6 10.8 56.9 45.4 19.2 17.7 21.1 21.1 74.6 71.8 43.7 43.7
script 19.2 13.8 28.5 23.1 26.2 25.4 77.5 76.1 80.3 77.5 53.5 52.1
b i 4.5 3.4 12.3 11.2 1.6 1.6 1.7 0.8 6.6 5.8 11.5 9.8
ii 24.0 20.1 57.0 54.2 20.8 17.5 33.1 32.2 83.5 82.6 36.1 30.3
script 53.6 50.3 70.9 65.9 23.5 19.7 72.7 70.2 83.5 83.5 37.7 35.2
all 36: 1 AP within 2, 2 AP within 10, both within 2; 1 AP rate 0.8 to 70.9%
16 clean: 1 AP within 0, 2 AP within 3, both within 0; 1 AP rate 10.8 to 57.0%
combinations with both within:
isolation noise segment template clean 1AP_rate 2AP_rate 1AP_within 2AP_within
b script b all False 70.9 83.5 True True
b script b loo False 65.9 83.5 True True
script segment and noise, template from all events, by event times and recordings:
recordings isolation event_times noise 1AP_events 1AP_rate 2AP_events 2AP_rate 1AP_within 2AP_within
all a ephys 242 158 63.3 83 80.7 True True
all a script 243 158 63.3 83 80.7 True True
all b ephys 242 228 57.0 147 75.5 False True
all b script 243 228 57.0 147 74.8 False True
all script ephys 242 162 63.0 89 75.3 True True
all script script 243 162 59.9 89 75.3 True True
without 20150707_cell1_001 a ephys 227 130 74.6 71 87.3 False True
without 20150707_cell1_001 a script 227 130 73.1 71 87.3 False True
without 20150707_cell1_001 b ephys 227 180 71.7 122 84.4 False True
without 20150707_cell1_001 b script 227 180 69.4 122 82.8 True True
without 20150707_cell1_001 script ephys 227 131 74.0 76 82.9 False True
without 20150707_cell1_001 script script 227 131 74.8 76 82.9 False True
Result: reproduced, resting on two assumptions. Under the main reading the jRCaMP1a 1 AP and
2 AP detection rates are 63.3% and 80.7%, both within tolerance, on 158 and 83 events, not the
paper's 135 and 65 (see fig4d-event-counts); the script's isolation gives 63.0% and 75.3%. With the
script's event times the main reading gives the same 63.3% and 80.7%, and the script's isolation
59.9% and 75.3%, all within tolerance. The outcome rests on two choices, and under the main reading
each one is needed for it. First, the jRGECO1a script's frame window is applied to jRCaMP1a, which
is assumed: under the claim's named segment readings (a), (b), (c) with isolation (a) or (b) no
combination puts the 1 AP rate within tolerance (at most 41.6%), while 7 of 36 put the 2 AP rate
within it. Second, data_20150707_cell1_001.mat is kept, which is also assumed: its fluorescence
showed no relation to its spikes in the clock check, and without it the main reading gives 74.6%
(130 events) and 87.3% (71), the 1 AP rate outside tolerance. Without it the 1 AP rate is within
tolerance only under isolation (b) with the script's event times (69.4%, with 82.8% for 2 AP), and
in 2 of the 36 combinations of the claim's named readings, isolation (b) with the script's noise
traces and segment (b) (70.9% and 65.9%, with 83.5%), neither of them clean; the 16 clean
combinations give at most 57.0%. The printed counts point both ways on the recording: without it 9
cells remain where the paper reports 10, and the 1 AP and 2 AP event counts become 130 and 71,
nearer the paper's 135 and 65 than 158 and 83. Which recordings the paper used is asked of its
authors. The 1 AP rate also differs between dates (80.5% of 82 events on 20150605, 40.0% of 55 on
20150707).
fig4df-jrgeco1a-better-than-jrcamp1a¶
jRGECO1a shows higher dF/F0 amplitudes and better spike detection (d-prime) than jRCaMP1a over the whole range of AP bursts from 1 to 8 APs.
Per n, the median peak dF/F0 (window (a) 1 s after the first spike, or (b) the projected segment) and d-prime (readings (i) and (ii)), jRGECO1a against jRCaMP1a, under each combination of readings; the paper reports no test.
cid = "fig4df-jrgeco1a-better-than-jrcamp1a"
keys = ["isolation", "noise", "segment", "template", "nAP"]
G = grid[grid.indicator == "jRGECO1a"].set_index(keys); C = grid[grid.indicator == "jRCaMP1a"].set_index(keys)
cmp = pd.DataFrame(index=G.index)
for pk in ["median_peak_1s", "median_peak_seg"]:
cmp[pk] = G[pk] > C[pk]
for dk in ["dprime_i", "dprime_ii"]:
cmp[dk] = G[dk] > C[dk]
res = []
for (iso, nr, seg, tpl), sub in cmp.groupby(level=[0, 1, 2, 3]):
for pk, dk in itertools.product(["median_peak_1s", "median_peak_seg"], ["dprime_i", "dprime_ii"]):
both = (sub[pk] & sub[dk])
res.append(dict(isolation=iso, noise=nr, segment=seg, template=tpl, peak=pk, dprime=dk, n_of_8=int(both.sum()),
peak_n=int(sub[pk].sum()), dprime_n=int(sub[dk].sum())))
res = pd.DataFrame(res)
print("values of n (of 8) where jRGECO1a exceeds jRCaMP1a in both, over", len(res), "combined readings:",
res.n_of_8.value_counts().sort_index().to_dict())
cl = res.merge(grid[["isolation", "noise", "segment", "clean"]].drop_duplicates(), on=["isolation", "noise", "segment"])
for lab, sub in (("readings of the claim (isolation a, b)", cl[cl.isolation != "script"]),
("clean readings of the claim", cl[(cl.isolation != "script") & cl.clean])):
print(f"{lab}: {len(sub)} combinations; all 8 in {int((sub.n_of_8 == 8).sum())}, 6 or 7 in {int(sub.n_of_8.isin([6, 7]).sum())}")
m = pick(res, **MAIN)
print("\nmain reading:\n" + m.to_string(index=False))
show = ["nAP", "n_events", "median_peak_1s", "median_peak_seg", "dprime_i", "dprime_ii"]
print("\nmain reading, per n:")
print(pd.concat({"jRGECO1a": pick(grid, indicator="jRGECO1a", **MAIN)[show].set_index("nAP"),
"jRCaMP1a": pick(grid, indicator="jRCaMP1a", **MAIN)[show].set_index("nAP")}, axis=1).round(3).to_string())
print("\nreadings with all 8:", len(res[res.n_of_8 == 8]), "; with 6 or 7:", len(res[res.n_of_8.isin([6, 7])]))
print(res[res.n_of_8 == 8].groupby(["isolation", "noise", "segment"]).size().to_string())
values of n (of 8) where jRGECO1a exceeds jRCaMP1a in both, over 288 combined readings: {0: 2, 1: 8, 2: 6, 3: 10, 4: 10, 5: 16, 6: 26, 7: 58, 8: 152}
readings of the claim (isolation a, b): 192 combinations; all 8 in 94, 6 or 7 in 56
clean readings of the claim: 96 combinations; all 8 in 66, 6 or 7 in 18
main reading:
isolation noise segment template peak dprime n_of_8 peak_n dprime_n
a script script all median_peak_1s dprime_i 8 8 8
a script script all median_peak_1s dprime_ii 8 8 8
a script script all median_peak_seg dprime_i 8 8 8
a script script all median_peak_seg dprime_ii 8 8 8
main reading, per n:
jRGECO1a jRCaMP1a
n_events median_peak_1s median_peak_seg dprime_i dprime_ii n_events median_peak_1s median_peak_seg dprime_i dprime_ii
nAP
1 191 0.211 0.204 2.374 3.482 158 0.107 0.116 1.255 1.922
2 62 0.373 0.369 3.950 8.152 83 0.169 0.167 1.861 3.510
3 28 0.539 0.534 2.772 11.111 79 0.266 0.280 1.803 6.193
4 30 0.691 0.684 3.657 16.445 58 0.230 0.226 2.323 6.149
5 35 0.657 0.641 4.238 16.387 38 0.361 0.359 2.539 8.794
6 20 0.821 0.813 2.840 20.661 24 0.321 0.325 2.171 7.787
7 12 0.828 0.819 2.994 22.320 16 0.361 0.359 2.434 9.557
8 17 1.168 1.162 3.755 27.128 11 0.375 0.376 2.228 10.627
readings with all 8: 152 ; with 6 or 7: 84
isolation noise segment
a i script 8
ii a 4
b 4
c 8
script 8
script c 8
script 8
b i b 8
script 8
ii b 2
c 4
script 8
script b 4
c 4
script 8
script i b 4
c 4
script 8
ii a 8
b 2
c 8
script 8
script c 8
script 8
# Peak dF/F0 (1 s window) per n under the main isolation (a), by indicator, with quartiles, and the
# script's own amplitude (maximum of the median trace over samples 1 to 250).
q = []
for ind in recs:
for n in range(1, 9):
p = peak1s[(ind, MAIN_ISO, n)]
S = sig_tr[(ind, MAIN_ISO, n, "script")]
q.append(dict(indicator=ind, nAP=n, n=len(p), q1=np.percentile(p, 25), median=np.median(p), q3=np.percentile(p, 75),
min=p.min(), max=p.max(), script_amplitude=np.median(S, 0)[:250].max()))
q = pd.DataFrame(q).round(3)
print(q.to_string(index=False))
fig, ax = plt.subplots(figsize=(6, 3))
for ind, col in (("jRGECO1a", "tab:blue"), ("jRCaMP1a", "black")):
d = q[q.indicator == ind]
ax.plot(d.nAP, d["median"], "o-", color=col, label=ind)
ax.fill_between(d.nAP, d.q1, d.q3, color=col, alpha=0.15)
ax.set_xlabel("APs in time bin"); ax.set_ylabel("peak dF/F0 (1 s window)"); ax.legend(); plt.tight_layout(); plt.show()
print("plotted: medians and quartiles; all values within the axes (range", q["q1"].min(), "to", q["q3"].max(), ")")
indicator nAP n q1 median q3 min max script_amplitude jRGECO1a 1 191 0.173 0.211 0.252 -0.031 0.433 0.136 jRGECO1a 2 62 0.305 0.373 0.468 0.094 0.742 0.310 jRGECO1a 3 28 0.378 0.539 0.613 0.140 1.012 0.408 jRGECO1a 4 30 0.539 0.691 0.925 0.099 1.271 0.582 jRGECO1a 5 36 0.535 0.657 0.822 0.288 1.300 0.593 jRGECO1a 6 20 0.658 0.821 1.149 0.369 2.347 0.722 jRGECO1a 7 12 0.764 0.828 1.112 0.230 1.805 0.757 jRGECO1a 8 17 0.998 1.168 1.363 0.640 1.875 0.963 jRCaMP1a 1 158 0.080 0.107 0.140 -0.056 0.327 0.056 jRCaMP1a 2 83 0.122 0.169 0.212 -0.016 0.450 0.121 jRCaMP1a 3 79 0.156 0.266 0.338 -0.025 1.097 0.212 jRCaMP1a 4 58 0.157 0.230 0.350 0.079 0.616 0.198 jRCaMP1a 5 38 0.247 0.361 0.514 0.045 0.656 0.333 jRCaMP1a 6 24 0.185 0.321 0.475 0.103 0.640 0.267 jRCaMP1a 7 16 0.294 0.361 0.488 0.135 0.846 0.338 jRCaMP1a 8 11 0.261 0.375 0.596 0.058 0.825 0.376
plotted: medians and quartiles; all values within the axes (range 0.08 to 1.363 )
Result: reproduced. Under the main reading jRGECO1a has the higher median peak dF/F0 (both windows) and the higher d-prime (both formulas) for all 8 values of n, for example 0.211 against 0.107 peak dF/F0 and d-prime 2.37 against 1.26 at 1 AP. Of the 192 combinations that use the claim's isolation readings, 94 give all 8 and 56 give 6 or 7; of the 96 clean ones, 66 give all 8 and 18 give 6 or 7 (the distributions are printed above).
fig4g-jrgeco1a-faster¶
jRGECO1a has faster rise and decay kinetics than jRCaMP1a for 2 AP responses.
2 AP events (100 ms and 150 ms bins) with no spike in the 2 s before, under each post-event isolation reading; an exponential fitted from the peak; the 16 traces with the smallest RMS residual kept. Half decay (a) tau ln 2, (b) peak to half peak on the trace; half rise from the first spike to half peak.
cid = "fig4g-jrgeco1a-faster"
kin_rows, kin = [], {}
for iso in ISO:
post = cai2.ISOLATION[iso][1] or 1.0
for ind, rs in recs.items():
ks = []
for r in rs:
ts = cai2.nspike_events(r, 2, cai2.BIN_S[ind][2], iso, pre_override=2.0)
for d in cai2.kinetics(r, ts, ind, post):
d.update(date=r["date"]); ks.append(d)
ks = pd.DataFrame(ks).sort_values("rms")
kin[(iso, ind)] = ks
for sel, sub in (("best 16", ks.head(16)), ("all fitted", ks)):
row = dict(isolation=iso, indicator=ind, traces=sel, n=len(sub), available=len(ks))
for k in ["rise", "decay_fit", "decay_trace", "t_peak"]:
v = sub[k].dropna()
row[k] = f"{1000 * v.mean():.0f} +/- {1000 * v.std(ddof=1) / np.sqrt(len(v)):.0f} ms (n={len(v)})"
row["tau_at_bound"] = int((sub.tau >= 19.9).sum())
kin_rows.append(row)
print(pd.DataFrame(kin_rows).to_string(index=False))
print("\njRGECO1a faster (mean of the best 16) by reading:")
for iso in ISO:
g, c = kin[(iso, "jRGECO1a")].head(16), kin[(iso, "jRCaMP1a")].head(16)
print(f" isolation {iso}: rise {g.rise.mean() < c.rise.mean()}, decay (a) fit {g.decay_fit.mean() < c.decay_fit.mean()},"
f" decay (b) trace {g.decay_trace.mean() < c.decay_trace.mean()}")
print("\nbest 16 by recording date:", {f"{iso} {ind}": kin[(iso, ind)].head(16).date.value_counts().to_dict()
for iso in ISO for ind in recs})
isolation indicator traces n available rise decay_fit decay_trace t_peak tau_at_bound
a jRGECO1a best 16 16 32 15 +/- 4 ms (n=16) 225 +/- 29 ms (n=16) 155 +/- 19 ms (n=16) 77 +/- 9 ms (n=16) 0
a jRGECO1a all fitted 32 32 18 +/- 3 ms (n=32) 286 +/- 34 ms (n=32) 148 +/- 14 ms (n=32) 86 +/- 11 ms (n=32) 0
a jRCaMP1a best 16 16 54 47 +/- 9 ms (n=16) 2300 +/- 1115 ms (n=16) 312 +/- 71 ms (n=15) 285 +/- 47 ms (n=16) 1
a jRCaMP1a all fitted 54 54 91 +/- 19 ms (n=54) 2097 +/- 571 ms (n=54) 195 +/- 26 ms (n=53) 286 +/- 26 ms (n=54) 5
b jRGECO1a best 16 16 84 262 +/- 90 ms (n=16) 537 +/- 160 ms (n=16) 185 +/- 37 ms (n=11) 498 +/- 104 ms (n=16) 0
b jRGECO1a all fitted 84 84 147 +/- 25 ms (n=84) 1831 +/- 459 ms (n=84) 164 +/- 12 ms (n=74) 335 +/- 35 ms (n=84) 9
b jRCaMP1a best 16 16 86 129 +/- 36 ms (n=16) 1545 +/- 803 ms (n=16) 318 +/- 84 ms (n=12) 423 +/- 77 ms (n=16) 0
b jRCaMP1a all fitted 86 86 162 +/- 24 ms (n=86) 2407 +/- 492 ms (n=86) 175 +/- 20 ms (n=75) 375 +/- 27 ms (n=86) 10
script jRGECO1a best 16 16 36 19 +/- 4 ms (n=16) 172 +/- 18 ms (n=16) 135 +/- 18 ms (n=16) 112 +/- 25 ms (n=16) 0
script jRGECO1a all fitted 36 36 20 +/- 3 ms (n=36) 222 +/- 17 ms (n=36) 134 +/- 14 ms (n=36) 97 +/- 12 ms (n=36) 0
script jRCaMP1a best 16 16 55 50 +/- 8 ms (n=16) 969 +/- 357 ms (n=16) 176 +/- 39 ms (n=13) 348 +/- 54 ms (n=16) 0
script jRCaMP1a all fitted 55 55 90 +/- 17 ms (n=55) 792 +/- 209 ms (n=55) 151 +/- 18 ms (n=52) 284 +/- 25 ms (n=55) 0
jRGECO1a faster (mean of the best 16) by reading:
isolation a: rise True, decay (a) fit True, decay (b) trace True
isolation b: rise False, decay (a) fit True, decay (b) trace True
isolation script: rise True, decay (a) fit True, decay (b) trace True
best 16 by recording date: {'a jRGECO1a': {'20150601': 6, '20150804': 5, '20150529': 4, '20150708': 1}, 'a jRCaMP1a': {'20150605': 12, '20150707': 2, '20150526': 1, '20150701': 1}, 'b jRGECO1a': {'20150529': 6, '20150601': 6, '20150804': 4}, 'b jRCaMP1a': {'20150605': 10, '20150707': 3, '20150526': 2, '20150701': 1}, 'script jRGECO1a': {'20150601': 5, '20150804': 5, '20150529': 4, '20150714': 1, '20150708': 1}, 'script jRCaMP1a': {'20150605': 13, '20150707': 2, '20150701': 1}}
# Variant: a longer fit window, to 2 s after the first spike (past the isolation interval), with the same 16-trace rule.
for iso in ISO:
out = {}
for ind, rs in recs.items():
ks = []
for r in rs:
ts = cai2.nspike_events(r, 2, cai2.BIN_S[ind][2], iso, pre_override=2.0)
ks += cai2.kinetics(r, ts, ind, 2.0 - cai2.BIN_S[ind][2])
out[ind] = pd.DataFrame(ks).sort_values("rms").head(16)
g, c = out["jRGECO1a"], out["jRCaMP1a"]
print(f"2 s window, isolation {iso}: rise {1000 * g.rise.mean():.0f} vs {1000 * c.rise.mean():.0f} ms, decay fit {1000 * g.decay_fit.mean():.0f} vs"
f" {1000 * c.decay_fit.mean():.0f} ms, decay trace {1000 * g.decay_trace.mean():.0f} vs {1000 * c.decay_trace.mean():.0f} ms (jRGECO1a vs jRCaMP1a)")
# Variant: the 16 traces with the smallest RMS residual relative to their peak.
for iso in ISO:
for ind in recs:
ks = kin[(iso, ind)]
b = ks.assign(rel=ks.rms / ks.peak).sort_values("rel").head(16)
print(f"isolation {iso} {ind}: rise {1000 * b.rise.mean():.0f} ms, decay fit {1000 * b.decay_fit.mean():.0f} ms,"
f" decay trace {1000 * b.decay_trace.mean():.0f} ms (n={b.decay_trace.notna().sum()})")
2 s window, isolation a: rise 17 vs 53 ms, decay fit 277 vs 844 ms, decay trace 145 vs 282 ms (jRGECO1a vs jRCaMP1a)
2 s window, isolation b: rise 71 vs 74 ms, decay fit 429 vs 880 ms, decay trace 188 vs 370 ms (jRGECO1a vs jRCaMP1a)
2 s window, isolation script: rise 17 vs 68 ms, decay fit 277 vs 1673 ms, decay trace 145 vs 259 ms (jRGECO1a vs jRCaMP1a) isolation a jRGECO1a: rise 14 ms, decay fit 258 ms, decay trace 150 ms (n=16) isolation a jRCaMP1a: rise 54 ms, decay fit 802 ms, decay trace 366 ms (n=15) isolation b jRGECO1a: rise 479 ms, decay fit 528 ms, decay trace 231 ms (n=9) isolation b jRCaMP1a: rise 175 ms, decay fit 1478 ms, decay trace 399 ms (n=7) isolation script jRGECO1a: rise 16 ms, decay fit 249 ms, decay trace 157 ms (n=16) isolation script jRCaMP1a: rise 51 ms, decay fit 609 ms, decay trace 232 ms (n=13)
Result: reproduced. Under isolation (a), the main reading, the 16 best-fitted jRGECO1a 2 AP traces have a shorter mean half rise (15 against 47 ms) and a shorter mean half decay, by the fit (225 against 2300 ms) and on the trace (155 against 312 ms), than jRCaMP1a; the script's isolation gives the same (19 against 50, 172 against 969, 135 against 176 ms). Under reading (b), without isolation after the event, the half rise is longer for jRGECO1a (262 against 129 ms) while both decays are shorter. The fitted jRCaMP1a decay is unstable (s.e.m. 357 to 1115 ms, and one fit at the 20 s bound under reading (a)), as the fit window ends 1 s after the event; on the trace the decay of the slowest jRCaMP1a traces is not measured (15 of 16 under reading (a)), which works against the claim. The half rise times of 15 to 50 ms under readings (a) and script are shorter than one frame for both indicators (33 and 67 ms), so they rest on the interpolation with the frame before the spike. With the fit window extended to 2 s after the first spike, jRGECO1a is faster on all three measures under every isolation reading (reading (a): half rise 17 against 53 ms, trace half decay 145 against 282 ms). Ranking the traces by RMS residual relative to their peak gives the same order under readings (a) and script (reading (a): 14 against 54 ms, 258 against 802 ms, 150 against 366 ms).
fig4g-kinetics-like-gcamp6¶
Rise and decay times of jRGECO1a and jRCaMP1a are similar to those of GCaMP6f and GCaMP6s, respectively.
The jRGECO1a and jRCaMP1a mean 2 AP half rise and half decay times of the 16 best-fitted traces (fig4g-jrgeco1a-faster) against the GCaMP6f and GCaMP6s values of Chen et al. (2013b). The values used are those of Supplementary Table 3 of that paper, its V1 in vivo cell-attached recordings, the preparation of Figure 4 (the passage cites Chen et al. without a table; this is the table of the same experiment): 1 AP half decay and 1 AP rise time to peak. Chen et al. give no half rise, so the claim's half rise is compared with their time to peak, their only rise measure. This is a choice: the criterion says only to compare with the values Chen et al. report, and the measure is asked of a reader; the time to peak of the same traces is shown as a variant, and so are the culture values of Supplementary Table 1 (10 AP). Each time must be within 25% of the matching GCaMP6 value and closer to it than to the other variant (criterion).
cid = "fig4g-kinetics-like-gcamp6"
chen, chen_file, chen_md5 = cai2.chen2013_tables()
print(f"Chen et al. (2013b) supplementary file read: {chen_file}, MD5 {chen_md5}")
print("Supplementary Table 3 (V1 in vivo), (mean, s.e.m.): dF/F0 1 AP %, half decay 1 AP ms, rise time to peak 1 AP ms, detection %:")
for k, v in chen[3].items():
print(f" {k}: {v}")
print("Supplementary Table 1 (culture), (mean, s.e.m.): F0 %, dynamic range %, half decay 10 AP ms, rise time to peak 10 AP ms, SNR 1 AP, SNR 10 AP:")
for k, v in chen[1].items():
print(f" {k}: {v}")
REF = {"Table 3 (V1, 1 AP)": {s: dict(rise=chen[3][s][2][0], decay=chen[3][s][1][0]) for s in ("GCaMP6f", "GCaMP6s")},
"Table 1 (culture, 10 AP)": {s: dict(rise=chen[1][s][3][0], decay=chen[1][s][2][0]) for s in ("GCaMP6f", "GCaMP6s")}}
MATCH = {"jRGECO1a": ("GCaMP6f", "GCaMP6s"), "jRCaMP1a": ("GCaMP6s", "GCaMP6f")}
rows_g = []
for table, ref in REF.items():
for iso in ISO:
for rise_k in ("rise", "t_peak"):
for decay_k in ("decay_fit", "decay_trace"):
row = dict(reference=table, isolation=iso, rise=rise_k, decay=decay_k)
ok = 0
for ind, (same, other) in MATCH.items():
b = kin[(iso, ind)].head(16)
for q, k in (("rise", rise_k), ("decay", decay_k)):
v = 1000 * b[k].mean()
m, o = ref[same][q], ref[other][q]
good = abs(v - m) <= 0.25 * m and abs(v - m) < abs(v - o)
ok += good
row[f"{ind} {q}"] = f"{v:.0f} vs {m:.0f} ({100 * (v - m) / m:+.0f}%){' ok' if good else ''}"
row["of_4"] = ok
rows_g.append(row)
tab_g = pd.DataFrame(rows_g)
pd.set_option("display.width", 250)
print("\nmean of the 16 best-fitted 2 AP traces against the matching GCaMP6 value (ms; ok = within 25% and closer than to the other variant):")
print(tab_g.to_string(index=False))
main_g = pick(tab_g, reference="Table 3 (V1, 1 AP)", isolation=MAIN_ISO, rise="rise", decay="decay_fit").iloc[0]
print(f"\nmain reading (Table 3, isolation a, half rise, fitted half decay): {main_g.of_4} of 4 times pass")
print("readings of the claim (half rise; isolation a or b) with all 4 passing:",
int(((tab_g.rise == "rise") & (tab_g.isolation != "script") & (tab_g.of_4 == 4)).sum()), "of",
int(((tab_g.rise == "rise") & (tab_g.isolation != "script")).sum()),
"; any combination with all 4:", int((tab_g.of_4 == 4).sum()), "of", len(tab_g), "; most passing:", int(tab_g.of_4.max()))
Chen et al. (2013b) supplementary file read: NIHMS489004-supplement-supp_info_2_revised_20130705.pdf, MD5 910abc8b19fb27ef2584cb59f2e04a19
Supplementary Table 3 (V1 in vivo), (mean, s.e.m.): dF/F0 1 AP %, half decay 1 AP ms, rise time to peak 1 AP ms, detection %:
GCaMP6s: [(23.0, 3.2), (550.0, 52.0), (179.0, 23.0), (99.0, 0.2)]
GCaMP6f: [(19.0, 2.8), (142.0, 11.0), (45.0, 4.0), (84.0, 6.0)]
Supplementary Table 1 (culture), (mean, s.e.m.): F0 %, dynamic range %, half decay 10 AP ms, rise time to peak 10 AP ms, SNR 1 AP, SNR 10 AP:
GCaMP6s: [(74.0, 5.0), (1680.0, 48.0), (1796.0, 73.0), (480.0, 24.0), (11.2, 2.0), (4.6, 0.8)]
GCaMP6f: [(67.0, 5.0), (1314.0, 56.0), (400.0, 41.0), (80.0, 35.0), (6.2, 2.0), (4.1, 0.3)]
mean of the 16 best-fitted 2 AP traces against the matching GCaMP6 value (ms; ok = within 25% and closer than to the other variant):
reference isolation rise decay jRGECO1a rise jRGECO1a decay jRCaMP1a rise jRCaMP1a decay of_4
Table 3 (V1, 1 AP) a rise decay_fit 15 vs 45 (-66%) 225 vs 142 (+58%) 47 vs 179 (-74%) 2300 vs 550 (+318%) 0
Table 3 (V1, 1 AP) a rise decay_trace 15 vs 45 (-66%) 155 vs 142 (+9%) ok 47 vs 179 (-74%) 312 vs 550 (-43%) 1
Table 3 (V1, 1 AP) a t_peak decay_fit 77 vs 45 (+72%) 225 vs 142 (+58%) 285 vs 179 (+59%) 2300 vs 550 (+318%) 0
Table 3 (V1, 1 AP) a t_peak decay_trace 77 vs 45 (+72%) 155 vs 142 (+9%) ok 285 vs 179 (+59%) 312 vs 550 (-43%) 1
Table 3 (V1, 1 AP) b rise decay_fit 262 vs 45 (+481%) 537 vs 142 (+278%) 129 vs 179 (-28%) 1545 vs 550 (+181%) 0
Table 3 (V1, 1 AP) b rise decay_trace 262 vs 45 (+481%) 185 vs 142 (+30%) 129 vs 179 (-28%) 318 vs 550 (-42%) 0
Table 3 (V1, 1 AP) b t_peak decay_fit 498 vs 45 (+1006%) 537 vs 142 (+278%) 423 vs 179 (+136%) 1545 vs 550 (+181%) 0
Table 3 (V1, 1 AP) b t_peak decay_trace 498 vs 45 (+1006%) 185 vs 142 (+30%) 423 vs 179 (+136%) 318 vs 550 (-42%) 0
Table 3 (V1, 1 AP) script rise decay_fit 19 vs 45 (-58%) 172 vs 142 (+21%) ok 50 vs 179 (-72%) 969 vs 550 (+76%) 1
Table 3 (V1, 1 AP) script rise decay_trace 19 vs 45 (-58%) 135 vs 142 (-5%) ok 50 vs 179 (-72%) 176 vs 550 (-68%) 1
Table 3 (V1, 1 AP) script t_peak decay_fit 112 vs 45 (+149%) 172 vs 142 (+21%) ok 348 vs 179 (+94%) 969 vs 550 (+76%) 1
Table 3 (V1, 1 AP) script t_peak decay_trace 112 vs 45 (+149%) 135 vs 142 (-5%) ok 348 vs 179 (+94%) 176 vs 550 (-68%) 1
Table 1 (culture, 10 AP) a rise decay_fit 15 vs 80 (-81%) 225 vs 400 (-44%) 47 vs 480 (-90%) 2300 vs 1796 (+28%) 0
Table 1 (culture, 10 AP) a rise decay_trace 15 vs 80 (-81%) 155 vs 400 (-61%) 47 vs 480 (-90%) 312 vs 1796 (-83%) 0
Table 1 (culture, 10 AP) a t_peak decay_fit 77 vs 80 (-3%) ok 225 vs 400 (-44%) 285 vs 480 (-41%) 2300 vs 1796 (+28%) 1
Table 1 (culture, 10 AP) a t_peak decay_trace 77 vs 80 (-3%) ok 155 vs 400 (-61%) 285 vs 480 (-41%) 312 vs 1796 (-83%) 1
Table 1 (culture, 10 AP) b rise decay_fit 262 vs 80 (+227%) 537 vs 400 (+34%) 129 vs 480 (-73%) 1545 vs 1796 (-14%) ok 1
Table 1 (culture, 10 AP) b rise decay_trace 262 vs 80 (+227%) 185 vs 400 (-54%) 129 vs 480 (-73%) 318 vs 1796 (-82%) 0
Table 1 (culture, 10 AP) b t_peak decay_fit 498 vs 80 (+522%) 537 vs 400 (+34%) 423 vs 480 (-12%) ok 1545 vs 1796 (-14%) ok 2
Table 1 (culture, 10 AP) b t_peak decay_trace 498 vs 80 (+522%) 185 vs 400 (-54%) 423 vs 480 (-12%) ok 318 vs 1796 (-82%) 1
Table 1 (culture, 10 AP) script rise decay_fit 19 vs 80 (-76%) 172 vs 400 (-57%) 50 vs 480 (-90%) 969 vs 1796 (-46%) 0
Table 1 (culture, 10 AP) script rise decay_trace 19 vs 80 (-76%) 135 vs 400 (-66%) 50 vs 480 (-90%) 176 vs 1796 (-90%) 0
Table 1 (culture, 10 AP) script t_peak decay_fit 112 vs 80 (+40%) 172 vs 400 (-57%) 348 vs 480 (-28%) 969 vs 1796 (-46%) 0
Table 1 (culture, 10 AP) script t_peak decay_trace 112 vs 80 (+40%) 135 vs 400 (-66%) 348 vs 480 (-28%) 176 vs 1796 (-90%) 0
main reading (Table 3, isolation a, half rise, fitted half decay): 0 of 4 times pass
readings of the claim (half rise; isolation a or b) with all 4 passing: 0 of 8 ; any combination with all 4: 0 of 24 ; most passing: 2
Result: not reproduced. Against Chen et al. (2013b) Supplementary Table 3 (V1 in vivo, 1 AP), under the main reading none of the four times is within 25% of the matching GCaMP6 value: jRGECO1a half rise 15 ms against GCaMP6f's 45 ms time to peak, fitted half decay 225 against 142 ms; jRCaMP1a half rise 47 against GCaMP6s's 179 ms, fitted half decay 2300 against 550 ms. With the trace half decay, jRGECO1a's 155 ms is within 9% of GCaMP6f, but jRCaMP1a's 312 ms is 43% short of GCaMP6s. None of the 8 readings of the claim, and none of the 24 combinations shown (with the time to peak of the same traces or the culture values of Supplementary Table 1), has all four times pass; at most 2 do. The comparison mixes measures: Chen et al. give 1 AP time to peak and 1 AP half decay, the claim uses 2 AP half rise and half decay, and that is asked of a reader.
Summary¶
| Claim | Outcome |
|---|---|
| screen-single-mutations-improved | not reproduced (230 and 58 improved single mutants, against 353 and 187) |
| culture-jrgeco1a-sensitivity | reproduced (data elsewhere) |
| culture-jrcamp1-sensitivity | reproduced (data elsewhere) |
| fig4-recorded-cells | reproduced |
| fig4d-event-counts | not reproduced (6 of 18 counts under the Methods' isolation; the script's 0.8 s isolation gives the jRGECO1a counts exactly, 11 of 18) |
| fig4e-jrgeco1a-1ap-detection | reproduced |
| fig4e-jrgeco1a-2ap-detection | reproduced |
| fig4e-jrcamp1a-detection | reproduced, resting on two assumptions |
| fig4df-jrgeco1a-better-than-jrcamp1a | reproduced |
| fig4g-jrgeco1a-faster | reproduced |
| fig4g-kinetics-like-gcamp6 | not reproduced (data elsewhere; 0 of 4 times within 25% of the GCaMP6 values) |
| the other 24 claims | blocked (data missing) |
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.
How the analysis differs from the paper's: events are isolated by more than 1 s on each side, as
the Methods say, where the data set's script uses 0.8 s after the event; the detection claims use
the frame window and the noise traces of the script, which the Methods do not give, with the
Methods' 5% false-positive threshold in place of the script's 1%; the script is written for
jRGECO1a and its frame window is assumed for jRCaMP1a. Events are placed at their ephys time
stamps, where the script adds the first frame time; the script's times are shown as a variant and
leave every detection outcome unchanged. The jRCaMP1a recording data_20150707_cell1_001.mat,
whose fluorescence does not follow its spikes, is kept, which is assumed; the jRCaMP1a detection
outcome depends on it. The claim's named segment readings give a
wide range of rates. The kinetics fit window and the fit-error rule are choices the paper leaves
open. The GCaMP6 comparison uses Chen et al.'s 1 AP time to peak and half decay, the values that
paper gives.
What was found about the dataset: two jRCaMP1a files (data_20150526_cell2_001.mat and
_002.mat) are the same recording deposited twice; the data set names no animals, so mice are
counted by recording date; the visual stimulus is not included, as the description says. In two
jRCaMP1a recordings (data_20150707_cell1_001.mat, 304 spikes, and data_20150605_cell7_003.mat,
15 spikes) the fluorescence shows no relation to the spikes above a shifted-spike null, so their
shared clock could not be established. The script's event isolation (0.8 s after the event)
differs from the Methods and from its own comment (1000 ms). The streamed archives match the
published MD5 sums.
print(f"notebook ran in {(time.time() - T0) / 60:.1f} min; peak memory {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024:.0f} MB")
notebook ran in 2.3 min; peak memory 490 MB