Reproducing Plitt, Kaganovsky et al. (2023) from dandiset 001710¶

Paper: Plitt, Kaganovsky, Südhof & Giocomo, "Hippocampal place code plasticity in CA1 requires postsynaptic membrane fusion", bioRxiv doi:10.1101/2023.11.20.567978, version 1 (21 November 2023). The claims file (claims/001710/10.1101-2023.11.20.567978.yaml) was written from that preprint's full text: main text, Figure 1 to 7 and S1 to S9 legends, Methods.

Dataset: DANDI:001710, version 0.260213.0329. The paper (a preprint) cites no dataset version. Two versions are published, 0.260212.2225 and 0.260213.0329; their asset lists (paths and sizes) are identical (checked below), so the most recent published version is pinned, as the protocol asks.

Outside inputs (the claims file says the paper tracked cells across sessions with custom code): the authors' across-session ROI matches, Figshare doi:10.6084/m9.figshare.31286365 version 5 (roi_aligners.zip), and the session-to-aligner index in the authors' code, github.com/GiocomoLab/Plitt_Kaganovsky_Stx3_CA1 at commit f2ab24d (mouse_metadata.py). Both are named in the dandiset's description. They map ROI indices the dataset holds; they bring no measurements (with_labels). Link claim: link-roi-alignment.

Activity signal (an assumption): The files hold dF/F, raw fluorescence and neuropil, but not the deconvolved "activity rates" the preprint's Methods describe. The authors' code for these files uses the deposited dF/F as the activity signal in every analysis; this notebook does the same. Every imaging outcome rests on this assumption.

Claims tested and blocked (outcomes are in the summary at the end):

claim status here
fig1c-novelty-preference, figs1c-, figs1e-, figs1f- (x2) blocked: freely moving behaviour not in the dataset
fig5h-, fig5i- (extinction) blocked: days 7 and 8 not in the dataset
figs4-morph-task, figs5-ca3-dg-place-fields blocked: sessions not in the dataset
fig3bc-, fig3d-, fig3e- (model) blocked: simulation, not specified by the paper
fig2ab-example-cell-counts tested
fig1f-, fig1g-, vr-reward-location-learning, figs2f-, figs2g-, figs2i- tested (behaviour)
fig2cd- (x2), figs3a-, figs3b-, figs3c- tested
fig2gh-, figs3eg- (across days) tested, depend on the link claim
fig3f-, fig3g-, fig3h-, fig3i- (single fields) tested
fig4e- (x3), fig4-block6-, fig4e-novel-increase-, fig4d-, figs6b-, figs6e- tested
figs7b-, fig5d- (x3) tested
fig6c- (x2), figs8h-, figs8d-, fig6d-, fig6e- tested
figs9a-, figs9b-, fig7e- (x3), fig7h- (x3) tested, then blocked: methods_underspecified (checks of the HSE detector)
In [1]:
import warnings, json, re
import numpy as np
import pandas as pd
from concurrent.futures import ThreadPoolExecutor
import stx3
from stx3 import mixed, fmt_mixed, ttest2, holm, virus_of, CTRL, CRE
warnings.filterwarnings("ignore")
pd.set_option("display.width", 200, "display.max_columns", 40)
print("dandiset", stx3.DANDISET, "version", stx3.VERSION)
dandiset 001710 version 0.260213.0329
In [2]:
A = stx3.list_assets()
A_old = stx3.list_assets("0.260212.2225")
same = {(a["path"], a["size"]) for a in A} == {(a["path"], a["size"]) for a in A_old}
print(len(A), "assets; identical paths and sizes in 0.260212.2225:", same)
assets = pd.DataFrame(A)
print(assets.groupby("group")["mouse"].nunique().to_string())
print(assets.pivot_table(index="mouse", columns="file_day", values="scan", aggfunc="count").fillna(0).astype(int).to_string())
139 assets; identical paths and sizes in 0.260212.2225: True
group
Cre         7
Ctrl        9
SparseKO    7
file_day    0  1  2  3  4  5
mouse                       
Cre-1       1  1  1  1  1  1
Cre-2       1  1  1  1  1  1
Cre-3       1  1  1  1  1  1
Cre-4       1  1  1  1  1  1
Cre-5       1  1  1  1  1  1
Cre-6       1  1  1  1  1  1
Cre-7       1  1  1  1  1  1
Ctrl-1      1  1  1  1  1  1
Ctrl-2      1  1  1  2  1  1
Ctrl-3      1  1  1  1  1  1
Ctrl-4      1  2  1  1  1  1
Ctrl-5      1  1  1  1  1  1
Ctrl-6      1  1  1  1  1  1
Ctrl-7      1  1  1  1  1  1
Ctrl-8      1  1  1  1  1  1
Ctrl-9      1  1  1  1  1  1
SparseKO-1  1  1  1  1  1  1
SparseKO-2  1  1  1  1  1  1
SparseKO-3  1  1  1  1  1  1
SparseKO-4  1  1  0  1  1  1
SparseKO-5  1  1  1  1  1  1
SparseKO-6  1  1  1  1  1  1
SparseKO-7  1  1  1  1  1  1

Survey of every file's metadata (no data read)¶

In [3]:
M = stx3.read_all_metadata([a["asset_id"] for a in A])
meta = pd.concat([assets, pd.DataFrame(M)], axis=1)
meta["n_frames"] = meta["dff_shape"].map(lambda s: s[0])
meta["n_cells"] = meta["dff_shape"].map(lambda s: s[1])
print("imaging rate (Hz) files by group:", meta.groupby(["group", meta["imaging_rate"].round(4)]).size().to_dict())
print("dF/F rate equals the imaging-plane rate in every file:", bool((meta["dff_rate"].round(4) == meta["imaging_rate"].round(4)).all()))
print("files at 15.5078 Hz:", meta[meta["imaging_rate"].round(4) == 15.5078]["path"].str.split("/").str[0].value_counts().to_dict())
print("locations:", meta["location"].unique(), "mux:", meta.groupby("group")["mux"].unique().to_dict())
print("multiplexed files: n_rois=-1 where the file has no single segmentation;", int((meta.n_rois < 0).sum()))
print("file day == metadata day:", (meta["file_day"] == meta["meta_day"]).all())
dense = ~meta.mux
print("frames of dF/F == frames of 2P-aligned behaviour (control and Cre files):", (meta.loc[dense, "n_frames"] == meta.loc[dense, "n_aligned"]).all(),
      "; ROI count == dF/F columns:", (meta.loc[~meta.mux, "n_rois"] == meta.loc[~meta.mux, "n_cells"]).all())
print("novel arm constant per mouse:", (meta.groupby("mouse")["novel_arm"].nunique() == 1).all())
print(meta.groupby("group")["subject_description"].unique().map(lambda x: x[0][:120]).to_string())
dup = meta[meta.group.isin(["Ctrl", "Cre"])].groupby(["n_frames", "n_cells"]).size()
print("files sharing frame and cell counts (possible duplicates):", int((dup > 1).sum()))
print(meta[meta.group.isin(["Ctrl", "Cre"])].pivot_table(index="mouse", columns="file_day", values="n_cells", aggfunc="sum").to_string())
imaging rate (Hz) files by group: {('Cre', 15.4609): 30, ('Cre', 15.5078): 12, ('Ctrl', 15.4609): 32, ('Ctrl', 15.5078): 24, ('SparseKO', 15.625): 41}
dF/F rate equals the imaging-plane rate in every file: True
files at 15.5078 Hz: {'sub-Cre-6': 6, 'sub-Cre-7': 6, 'sub-Ctrl-6': 6, 'sub-Ctrl-7': 6, 'sub-Ctrl-8': 6, 'sub-Ctrl-9': 6}
locations: <StringArray>
['CA1', nan]
Length: 2, dtype: str mux: {'Cre': array([False]), 'Ctrl': array([False]), 'SparseKO': array([ True])}
multiplexed files: n_rois=-1 where the file has no single segmentation; 41
file day == metadata day: True
frames of dF/F == frames of 2P-aligned behaviour (control and Cre files): True ; ROI count == dF/F columns: True
novel arm constant per mouse: True
group
Cre         Cre mouse. Viruses: AAV1-hSyn-jGCaMP7f        ...
Ctrl        Control mouse. Viruses: AAV1-hSyn-jGCaMP7f    ...
SparseKO    Sparse mouse. Viruses: AAV8-CreON/FlpOFF-2.0-G...
files sharing frame and cell counts (possible duplicates): 0
file_day     0     1     2     3     4     5
mouse                                       
Cre-1      904   520   797   689   664   771
Cre-2      288   441   388   353   250   333
Cre-3      936  1258  1444  1233  1087  1115
Cre-4     1148  1505  1346  1389  1154  1223
Cre-5     1578  1554  1535  1649  1436  1840
Cre-6      973  1051  1181   935   908   894
Cre-7     1050  1088  1044   942   995   996
Ctrl-1    1381  1093   972  1068   962  1370
Ctrl-2    1283  1170  1093  2096  1033   982
Ctrl-3    1568  1422  1155  1046  1208  1242
Ctrl-4    1694  2940  1537  1684  1509  1586
Ctrl-5    1554  1450  1447  1467  1354  1428
Ctrl-6    1030   799   961   985   965  1079
Ctrl-7     909   873   781   858   820   861
Ctrl-8     639   740  1030   736   808   730
Ctrl-9     977  1038   996   958   896   942

Reduce every control and Cre day to what the claims use¶

Each day's file (two files for the days split in two, Ctrl-2 file day 3 and Ctrl-4 file day 1, merged on the ROIs the authors matched between them) is streamed once and reduced in stx3.session_summary: trial x bin x cell mean dF/F, behaviour per trial and bin at full resolution, 1000 within-trial shuffles per trial type (place fields and recomputed spatial information) and HSEs. This takes about 20 minutes with four processes.

In [4]:
G = stx3.day_groups(A)
S = stx3.summarize_all(G, workers=4)
print(len(S), "mouse-days reduced")
96 mouse-days reduced

Data check¶

In [5]:
keys = sorted(S)
mice = sorted({k[0] for k in keys}, key=lambda m: (m[:3], int(m.split("-")[1])))
print("mice:", mice)
rows = []
for (m, fd), s in sorted(S.items()):
    LR = s["LR"]; nov = s["novel_arm"]
    rows.append(dict(mouse=m, virus=virus_of(m), day=fd + stx3.DAY_OFFSET, cells=s["n_cells"], scans=s["n_scans"],
                     trials=len(LR), fam=int((LR == -nov).sum()), nov=int((LR == nov).sum()),
                     blocks=int(s["block"].max()) + 1, nov_first_block=int(s["block"][LR == nov].min()) + 1 if (LR == nov).any() else -1,
                     full_res_trials=len(s["full"]["LR"]), lr_match=bool(np.all(s["full"]["LR"] == LR)) if len(s["full"]["LR"]) == len(LR) else False))
days = pd.DataFrame(rows)
print(days.pivot_table(index="mouse", columns="day", values="cells").to_string())
print(days.pivot_table(index="mouse", columns="day", values="nov").to_string())
print("days with fewer than 6 blocks:", days[days.blocks < 6][["mouse", "day", "blocks", "nov_first_block", "nov"]].to_string(index=False))
print("days per mouse:", days.groupby("mouse").size().to_dict())
print("first block with novel trials, days 1-5:", days[days.day <= 5]["nov_first_block"].value_counts().to_dict(),
      "; day 6:", days[days.day == 6]["nov_first_block"].value_counts().to_dict())
print("full-resolution trials agree with the trial table (count and arm):", days["lr_match"].all())
print(days[~days["lr_match"]][["mouse", "day", "trials", "full_res_trials"]].to_string())
print("blocks per day:", days["blocks"].value_counts().to_dict())
pos_all = np.concatenate([s["full"]["reward_pos"] for s in S.values()])
R_all = np.concatenate([s["R"].reshape(-1) for s in list(S.values())[:5]])
print("dF/F (5 days sample): range %.2f to %.2f, median %.3f" % (np.nanmin(R_all), np.nanmax(R_all), np.nanmedian(R_all)))
spd = np.concatenate([s["full"]["speed"].ravel() for s in S.values()])
print("binned speed (cm/s): 1st, 50th, 99th percentile", np.nanpercentile(spd, [1, 50, 99]).round(1))
dur = np.concatenate([s["full"]["dur"] for s in S.values()]); dist = np.concatenate([s["full"]["dist"] for s in S.values()])
print("trial duration on the track (s): median %.1f; integral of the speed series over a trial: median %.0f (track 300 cm), so the speed is in cm/s, not the 10 cm/s its unit says" % (np.median(dur), np.median(dist)))
# reward zone fronts from where rewards were given (the paper gives no coordinates)
rew = {arm: np.concatenate([s["full"]["reward_pos"][s["full"]["LR"] == arm] for s in S.values()]) for arm in (-1, 1)}
FRONT = {arm: float(np.nanpercentile(rew[arm], 1)) for arm in (-1, 1)}
FB = {arm: int(round(FRONT[arm] - stx3.POS_MIN)) for arm in (-1, 1)}
ANT = {arm: np.arange(FB[arm] - 3, FB[arm]) for arm in (-1, 1)}
for arm, name in ((-1, "left"), (1, "right")):
    print(f"{name} arm: reward positions 1st/50th/99th pct {np.nanpercentile(rew[arm], [1, 50, 99]).round(2)} (spline units, 10 cm); "
          f"zone front {FRONT[arm]:.2f} -> anticipatory bins {ANT[arm].tolist()} (cm {ANT[arm][0]*10}-{(ANT[arm][-1]+1)*10})")
# days split over two files: block numbers per scan after joining (block numbers restart at 0 in the
# second file and are continued from the first file's last block, as in the authors' code; helper _concat_scans)
for (m, fd) in [k for k, s in sorted(S.items()) if s["n_scans"] > 1]:
    nt = meta[(meta.mouse == m) & (meta.file_day == fd)].sort_values("scan")["n_trials"].tolist()
    s = S[(m, fd)]; o = 0
    for j, n in enumerate(nt):
        b = s["block"][o:o + n].astype(int); lr = s["LR"][o:o + n]
        print(f"{m} day {fd + 1} file {j}: {n} trials; block (trials, novel trials):",
              {int(x) + 1: (int((b == x).sum()), int(((b == x) & (lr == s['novel_arm'])).sum())) for x in np.unique(b)})
        o += n
s = S[("Cre-3", 4)]; b = s["block"].astype(int)
print("Cre-3 day 5, block (all, familiar, novel trials):", {int(x) + 1: (int((b == x).sum()), int(((b == x) & (s['LR'] == -s['novel_arm'])).sum()),
      int(((b == x) & (s['LR'] == s['novel_arm'])).sum())) for x in np.unique(b)})
# position of the first reward of each trial, per mouse and arm (spline units; the zone fronts above are the pooled 1st percentile)
rp = pd.DataFrame([dict(mouse=m, arm="left" if a < 0 else "right", pos=p) for (m, fd), s in S.items()
                   for a, p in zip(s["full"]["LR"], s["full"]["reward_pos"])]).dropna()
print(rp.groupby(["mouse", "arm"]).pos.quantile([0.01, 0.5]).unstack([1, 2]).round(2).to_string())
mice: ['Cre-1', 'Cre-2', 'Cre-3', 'Cre-4', 'Cre-5', 'Cre-6', 'Cre-7', 'Ctrl-1', 'Ctrl-2', 'Ctrl-3', 'Ctrl-4', 'Ctrl-5', 'Ctrl-6', 'Ctrl-7', 'Ctrl-8', 'Ctrl-9']
day          1       2       3       4       5       6
mouse                                                 
Cre-1    904.0   520.0   797.0   689.0   664.0   771.0
Cre-2    288.0   441.0   388.0   353.0   250.0   333.0
Cre-3    936.0  1258.0  1444.0  1233.0  1087.0  1115.0
Cre-4   1148.0  1505.0  1346.0  1389.0  1154.0  1223.0
Cre-5   1578.0  1554.0  1535.0  1649.0  1436.0  1840.0
Cre-6    973.0  1051.0  1181.0   935.0   908.0   894.0
Cre-7   1050.0  1088.0  1044.0   942.0   995.0   996.0
Ctrl-1  1381.0  1093.0   972.0  1068.0   962.0  1370.0
Ctrl-2  1283.0  1170.0  1093.0  1048.0  1033.0   982.0
Ctrl-3  1568.0  1422.0  1155.0  1046.0  1208.0  1242.0
Ctrl-4  1694.0  1036.0  1537.0  1684.0  1509.0  1586.0
Ctrl-5  1554.0  1450.0  1447.0  1467.0  1354.0  1428.0
Ctrl-6  1030.0   799.0   961.0   985.0   965.0  1079.0
Ctrl-7   909.0   873.0   781.0   858.0   820.0   861.0
Ctrl-8   639.0   740.0  1030.0   736.0   808.0   730.0
Ctrl-9   977.0  1038.0   996.0   958.0   896.0   942.0
day        1     2     3     4     5     6
mouse                                     
Cre-1   22.0  16.0  20.0  20.0  21.0  68.0
Cre-2   18.0  15.0   9.0   7.0  15.0  62.0
Cre-3   17.0  15.0   7.0  14.0  11.0  38.0
Cre-4   17.0  18.0  19.0  17.0  18.0  55.0
Cre-5    7.0   6.0   7.0  10.0   6.0  38.0
Cre-6   19.0  19.0  21.0  21.0   7.0  58.0
Cre-7   18.0  16.0  10.0  13.0   6.0  53.0
Ctrl-1  19.0  21.0  21.0  19.0  21.0  76.0
Ctrl-2  19.0  19.0  20.0  19.0  19.0  70.0
Ctrl-3  20.0  16.0  20.0  20.0  20.0  77.0
Ctrl-4  19.0  18.0  20.0  19.0  19.0  64.0
Ctrl-5  19.0  19.0  21.0  19.0  21.0  70.0
Ctrl-6  20.0  20.0  18.0  19.0  18.0  57.0
Ctrl-7  20.0  20.0  20.0  20.0  19.0  65.0
Ctrl-8  18.0  19.0  19.0  18.0  18.0  64.0
Ctrl-9  21.0  19.0  20.0  20.0  20.0  81.0
days with fewer than 6 blocks: Empty DataFrame
Columns: [mouse, day, blocks, nov_first_block, nov]
Index: []
days per mouse: {'Cre-1': 6, 'Cre-2': 6, 'Cre-3': 6, 'Cre-4': 6, 'Cre-5': 6, 'Cre-6': 6, 'Cre-7': 6, 'Ctrl-1': 6, 'Ctrl-2': 6, 'Ctrl-3': 6, 'Ctrl-4': 6, 'Ctrl-5': 6, 'Ctrl-6': 6, 'Ctrl-7': 6, 'Ctrl-8': 6, 'Ctrl-9': 6}
first block with novel trials, days 1-5: {6: 80} ; day 6: {1: 16}
full-resolution trials agree with the trial table (count and arm): True
Empty DataFrame
Columns: [mouse, day, trials, full_res_trials]
Index: []
blocks per day: {6: 96}
dF/F (5 days sample): range -0.29 to 2.84, median 0.037
binned speed (cm/s): 1st, 50th, 99th percentile [  2.6  48.8 100.3]
trial duration on the track (s): median 10.0; integral of the speed series over a trial: median 288 (track 300 cm), so the speed is in cm/s, not the 10 cm/s its unit says
left arm: reward positions 1st/50th/99th pct [31.92 32.1  33.85] (spline units, 10 cm); zone front 31.92 -> anticipatory bins [16, 17, 18] (cm 160-190)
right arm: reward positions 1st/50th/99th pct [39.38 39.53 40.78] (spline units, 10 cm); zone front 39.38 -> anticipatory bins [23, 24, 25] (cm 230-260)
Ctrl-2 day 4 file 0: 20 trials; block (trials, novel trials): {1: (20, 0)}
Ctrl-2 day 4 file 1: 120 trials; block (trials, novel trials): {2: (20, 0), 3: (20, 0), 4: (20, 0), 5: (20, 0), 6: (40, 19)}
Ctrl-4 day 2 file 0: 36 trials; block (trials, novel trials): {1: (19, 0), 2: (17, 0)}
Ctrl-4 day 2 file 1: 100 trials; block (trials, novel trials): {3: (20, 0), 4: (20, 0), 5: (20, 0), 6: (40, 18)}
Cre-3 day 5, block (all, familiar, novel trials): {1: (14, 14, 0), 2: (13, 13, 0), 3: (18, 18, 0), 4: (17, 17, 0), 5: (13, 13, 0), 6: (18, 7, 11)}
arm      left         right       
         0.01   0.50   0.01   0.50
mouse                             
Cre-1   31.91  32.06  39.37  39.50
Cre-2   31.91  32.03  39.37  39.56
Cre-3   31.92  32.15  39.38  39.62
Cre-4   31.92  32.06  39.40  39.60
Cre-5   31.94  32.19  39.38  39.66
Cre-6   31.92  32.11  39.38  39.63
Cre-7   31.91  32.06  39.39  39.53
Ctrl-1  31.94  32.15  39.38  39.54
Ctrl-2  31.93  32.15  39.42  39.69
Ctrl-3  31.94  32.11  39.39  39.52
Ctrl-4  31.91  32.24  39.40  39.66
Ctrl-5  31.92  32.04  39.39  39.48
Ctrl-6  31.91  32.10  39.39  39.56
Ctrl-7  31.91  32.10  39.38  39.55
Ctrl-8  31.93  32.16  39.39  39.59
Ctrl-9  31.92  32.05  39.38  39.47

Checks of the description against the data. Control and Cre files are imaged at 15.46 Hz, as the Methods say, or 15.51 Hz (counts above); the helper's frame-based windows (8 frames for 500 ms, 12 for 750 ms, 15 for 1 s) use 15.46 Hz, a 0.3% difference. File dayN is the paper's day N+1: Ctrl-3 file day 4 holds 1208 cells and Cre-3 file day 0 holds 936, the paper's Ctrl-3 day 5 and Cre-3 day 1 (Fig 2A-B legends; see claim fig2ab below). Novel trials appear in block 6 of days 1 to 5 and from block 1 on day 6, as in the Methods. On the two days split over two files, the block numbers restart at 0 in the second file; they are continued from the first file's last block, as the authors' code does (printed below), which gives 6 blocks on every day. Position runs over the 30 bins of the 300 cm track. The speed series is labelled 10 cm/s, but its integral over a trial is about 290, the track's 300 cm, so it is in cm/s: the data are trusted and this is recorded as a finding. The lick series at imaging resolution says it must not be used for comparisons between groups, so licks are taken from the full-resolution non-consummatory lick series. The paper gives no coordinates for the reward zones; the zone front on each arm is taken as the 1st percentile of the positions where rewards were given.

Clock check¶

Split-half reliability of the familiar-trial maps with dF/F shifted against the position trace, for one control and one Cre day. A shared clock gives a peak at zero shift.

In [6]:
for m, fd in (("Ctrl-1", 2), ("Cre-1", 2)):
    aid = [a["asset_id"] for a in A if a.get("mouse") == m and a.get("file_day") == fd][0]
    print(m, "day", fd + 1); print(stx3.clock_check(aid).round(3).to_string(index=False))
Ctrl-1 day 3
 shift_frames  shift_s  median_split_half_r
          -60   -3.881                0.934
          -30   -1.940                0.950
          -15   -0.970                0.957
           -8   -0.517                0.960
           -4   -0.259                0.961
            0    0.000                0.962
            4    0.259                0.959
            8    0.517                0.957
           15    0.970                0.950
           30    1.940                0.926
           60    3.881                0.887
Cre-1 day 3
 shift_frames  shift_s  median_split_half_r
          -60   -3.881                0.901
          -30   -1.940                0.942
          -15   -0.970                0.951
           -8   -0.517                0.956
           -4   -0.259                0.955
            0    0.000                0.953
            4    0.259                0.951
            8    0.517                0.946
           15    0.970                0.939
           30    1.940                0.920
           60    3.881                0.807

The reliability is highest at zero shift for Ctrl-1 (0.962). For Cre-1 it is highest at -8 frames (-0.52 s, 0.956 against 0.953 at zero). In both it falls at larger shifts either way. This is consistent with a shared clock, within the slow calcium response; it was checked on these two days only.

The zone fronts per mouse (1st percentile of the first-reward positions, printed in the data check) are 31.91 to 31.94 on the left arm and 39.37 to 39.42 on the right arm, so one front per arm serves every mouse.

Statements about the authors' code¶

The assumptions below cite the authors' code at the pinned commit. The lines are printed here from that commit: the activity signal (F_dff, the deposited dF/F), the decoder input, the per-bin PV correlation (calc_pv_corr) and the block numbering of joined files.

In [7]:
import requests
CODE_BASE = f"https://raw.githubusercontent.com/{stx3.CODE_REPO}/{stx3.CODE_COMMIT}/src/stx3_2p_analyses/"
for f, pat, n in (("session.py", "'F_dff': ophys_module", 1), ("novel_activity_rate.py", "ts_key='F_dff'", 1),
                  ("naive_bayes.py", "trial_mat = sess.trial_matrices['F_dff']", 7), ("spatial_analyses.py", "def calc_pv_corr", 12),
                  ("session.py", "elif k == 'block_number' and day_inds", 4)):
    lines = requests.get(CODE_BASE + f, timeout=60).text.splitlines()
    k = next(j for j, l in enumerate(lines) if pat in l)
    print(f"--- {f}, line {k + 1}:"); print("\n".join(lines[k:k + n]))
--- session.py, line 474:
            'F_dff': ophys_module['dF']['dF'].data[:].T,
--- novel_activity_rate.py, line 28:
                 days=np.arange(6), ts_key='F_dff', block = 5):
--- naive_bayes.py, line 26:
        trial_mat = sess.trial_matrices['F_dff'][trial_mask,:,:]*10
    else:
        trial_mat = sess.trial_matrices[f'{chan}_F_dff'][trial_mask,:,:]*10
    
    trial_mat -= np.nanmin(trial_mat,axis=-1,keepdims=True)
    trial_mat[np.isnan(trial_mat)]=0
    trial_mat += 1E-3
--- spatial_analyses.py, line 23:
def calc_pv_corr(trial_mat, nanzero=True):
    """
    trial_mat: trials x positions x cells
    """
    if nanzero:
        trial_mat[np.isnan(trial_mat)]=0

    corr_mat = np.zeros((trial_mat.shape[0], trial_mat.shape[0], trial_mat.shape[1]))
    for pos in range(trial_mat.shape[1]):
        corr_mat[:, :, pos] = np.corrcoef(trial_mat[:,pos,:])

    return np.nanmean(corr_mat, axis=-1)
--- session.py, line 785:
                elif k == 'block_number' and day_inds is not None and ind > 0:
                    if _sess.trial_info[k][0] == 0 and day_inds[ind - 1] == day_inds[ind]:
                        trial_info[k].append(_sess.trial_info[k] + _sess_list[ind - 1].trial_info[k][-1] + 1)
                    else:

Link claim: link-roi-alignment¶

The across-day claims use the authors' ROI matches (Figshare v5). Check that every matched index exists in the dataset's files, how many cells are tracked over all six days, and that matched ROIs sit at the same place in the field of view: after removing each pair of sessions' median displacement, matched centroids should lie within a few pixels, unlike random pairs.

In [8]:
RI = stx3.ravel_index()
TRACK = {}
link_rows = []
for m in CTRL + CRE:
    al = stx3.load_aligner(m)
    inds = [RI[(m, fd, 0)] for fd in range(6)]
    cm = stx3.common_rois(al, inds)               # (6, n tracked), ROI index in each day's first scan
    cols = np.zeros_like(cm)
    ok_idx = True
    resid, rand = [], []
    rng = np.random.default_rng(0)
    for d in range(6):
        s = S[(m, d)]
        n0 = int(meta[(meta.mouse == m) & (meta.file_day == d) & (meta.scan == 0)]["n_cells"].iloc[0])
        ok_idx &= bool(cm[d].max() < n0)
        if s["n_scans"] == 1:
            cols[d] = cm[d]
        else:   # split day: position of the ROI in the merged session (ROIs present in both scans)
            mp = stx3.split_mapping(m, G[(m, d)])[0]
            lut = {r: j for j, r in enumerate(mp)}
            cols[d] = [lut.get(r, -1) for r in cm[d]]
    keep = (cols >= 0).all(0)
    cols = cols[:, keep]
    TRACK[m] = cols
    c0 = S[(m, 0)]["centroid"][cols[0]]
    for d in range(1, 6):
        cd = S[(m, d)]["centroid"][cols[d]]
        shift = np.median(cd - c0, axis=0)
        resid.append(np.linalg.norm(cd - c0 - shift, axis=1))
        rp = S[(m, d)]["centroid"][rng.integers(0, S[(m, d)]["n_cells"], len(c0))]
        rand.append(np.linalg.norm(rp - c0 - shift, axis=1))
    resid = np.concatenate(resid); rand = np.concatenate(rand)
    link_rows.append(dict(mouse=m, tracked_6_days=int(keep.sum()), dropped_split=int((~keep).sum()),
                          cells_day1=S[(m, 0)]["n_cells"], indices_valid=ok_idx,
                          median_resid_px=float(np.median(resid)), frac_within_10px=float(np.mean(resid < 10)),
                          random_median_px=float(np.median(rand))))
link = pd.DataFrame(link_rows)
print(link.round(2).to_string(index=False))
print("all indices valid:", link.indices_valid.all(), "; tracked cells per mouse: median", link.tracked_6_days.median(),
      "range", link.tracked_6_days.min(), "-", link.tracked_6_days.max())
print("matched pairs within 10 px after the median shift: %.3f (over mice, mean); random pairs median distance %.0f px"
      % (link.frac_within_10px.mean(), link.random_median_px.median()))
 mouse  tracked_6_days  dropped_split  cells_day1  indices_valid  median_resid_px  frac_within_10px  random_median_px
Ctrl-1             376              0        1381           True             1.59               1.0            266.56
Ctrl-2             314              0        1283           True             1.19               1.0            225.54
Ctrl-3             342              0        1568           True             0.93               1.0            257.77
Ctrl-4             562             32        1694           True             0.75               1.0            251.33
Ctrl-5             543              0        1554           True             1.22               1.0            240.12
Ctrl-6             360              0        1030           True             1.46               1.0            250.96
Ctrl-7             379              0         909           True             1.17               1.0            245.64
Ctrl-8             267              0         639           True             0.92               1.0            234.73
Ctrl-9             433              0         977           True             1.16               1.0            281.93
 Cre-1             163              0         904           True             0.77               1.0            167.14
 Cre-2              70              0         288           True             0.79               1.0            202.55
 Cre-3             274              0         936           True             1.17               1.0            248.59
 Cre-4             326              0        1148           True             0.58               1.0            222.62
 Cre-5             522              0        1578           True             0.52               1.0            204.89
 Cre-6             188              0         973           True             0.94               1.0            280.85
 Cre-7             305              0        1050           True             0.83               1.0            262.31
all indices valid: True ; tracked cells per mouse: median 334.0 range 70 - 562
matched pairs within 10 px after the median shift: 1.000 (over mice, mean); random pairs median distance 247 px

Result: the link holds. Every matched ROI index exists in the dataset's files. After removing each day pair's median displacement, all matched centroids lie within 10 px (median residual 0.5 to 1.6 px per mouse), against a median of 247 px for random pairs. Between 70 and 562 cells per mouse are tracked over all six days. Ctrl-4 loses 32 tracked cells because they are not among the ROIs matched between the two files of its split day 2.

Behaviour (Fig 1F-G, S2)¶

Per trial, from the full-resolution series: time, non-consummatory licks and time-weighted mean speed in each 10 cm bin. Anticipatory lick rate (Methods, VR behavioral analyses) is the lick rate in the 30 cm before the zone front of the trial's arm: reading (i) licks over time in those 30 cm, (ii) the mean of the three bins' rates. All trials of the type are used. The Cre group is Cre-1 to Cre-7: reading (b) of the claims file, Cre-1 to Cre-8, cannot be run, as Cre-8 is not in the dataset.

In [9]:
def trial_table():
    rows = []
    for (m, fd), s in sorted(S.items()):
        f = s["full"]; nov = s["novel_arm"]
        n = min(len(f["LR"]), len(s["LR"]))
        for i in range(n):
            arm = int(f["LR"][i]); ab = ANT[arm]
            T = f["time"][i]; L = f["licks"][i]; V = f["speed"][i]
            with np.errstate(invalid="ignore", divide="ignore"):
                rates = L[ab] / T[ab]
            rows.append(dict(mouse=m, virus=virus_of(m), day=fd + 1, trial=i, block=int(f["block"][i]) + 1, arm=arm,
                             ttype="nov" if arm == nov else "fam",
                             lick_i=L[ab].sum() / T[ab].sum() if T[ab].sum() > 0 else np.nan,
                             lick_ii=np.nanmean(rates),
                             spd_binned=np.nanmean(V), spd_time=f["dist"][i] / f["dur"][i] if f["dur"][i] > 0 else np.nan))
    return pd.DataFrame(rows)
TT = trial_table()
# "block 6" = the block in which novel trials first appear (block 6 on every day 1 to 5; see the data check)
nb = TT[TT.ttype == "nov"].groupby(["mouse", "day"]).block.min().rename("test_block")
TT = TT.join(nb, on=["mouse", "day"])
TT["b6"] = TT.block == TT.test_block
print(TT.groupby(["virus", "ttype"]).size().to_string())
print(TT[["lick_i", "lick_ii", "spd_binned", "spd_time"]].describe().round(2).to_string())
virus  ttype
cre    fam      3612
       nov       874
ctrl   fam      5998
       nov      1497
         lick_i   lick_ii  spd_binned  spd_time
count  11981.00  11981.00    11981.00  11981.00
mean       3.03      2.79       48.11     28.59
std        1.64      1.68       12.94      9.68
min        0.00      0.00        7.31      1.77
25%        1.89      1.48       40.25     22.14
50%        2.97      2.66       47.89     28.70
75%        4.27      4.04       56.00     35.07
max       10.10     10.17       93.49     64.04

fig1f-anticipatory-licking-familiar¶

On familiar arm trials, control mice licked at a higher rate than Cre mice as they approached the reward zone, across the six days.

In [10]:
def lick_anova(ttype):
    out = {}
    for rd in ("lick_i", "lick_ii"):
        d = TT[TT.ttype == ttype].groupby(["mouse", "virus", "day"], as_index=False)[rd].mean()
        mm = mixed(d, rd)
        means = d.groupby(["virus", "day"])[rd].mean().unstack().round(2)
        print(f"reading ({rd[-2:].strip('_')}): {fmt_mixed(mm)}")
        print(means.to_string())
        print("  per mouse, mean over days:", d.groupby("mouse")[rd].mean().round(2).to_dict())
        out[rd] = (mm, means)
    return out
LF = lick_anova("fam")
reading (i): N=9 ctrl, 7 cre; virus F(1,14)=21 p=0.000425; day F(5,70)=3.47 p=0.00731; interaction F(5,70)=2.26 p=0.0579
day       1     2     3     4     5     6
virus                                    
cre    2.73  2.09  2.23  1.77  1.52  1.80
ctrl   3.71  3.75  3.23  3.64  3.33  3.55
  per mouse, mean over days: {'Cre-1': 2.62, 'Cre-2': 2.1, 'Cre-3': 1.34, 'Cre-4': 2.15, 'Cre-5': 1.48, 'Cre-6': 2.11, 'Cre-7': 2.36, 'Ctrl-1': 3.52, 'Ctrl-2': 3.74, 'Ctrl-3': 4.57, 'Ctrl-4': 2.2, 'Ctrl-5': 4.29, 'Ctrl-6': 3.57, 'Ctrl-7': 2.88, 'Ctrl-8': 2.88, 'Ctrl-9': 4.16}
reading (ii): N=9 ctrl, 7 cre; virus F(1,14)=21.2 p=0.000406; day F(5,70)=4.97 p=0.000593; interaction F(5,70)=1.67 p=0.152
day       1     2     3     4     5     6
virus                                    
cre    2.73  1.85  1.89  1.43  1.24  1.51
ctrl   3.62  3.56  2.97  3.41  2.89  3.24
  per mouse, mean over days: {'Cre-1': 2.27, 'Cre-2': 1.68, 'Cre-3': 1.23, 'Cre-4': 1.35, 'Cre-5': 1.39, 'Cre-6': 2.05, 'Cre-7': 2.44, 'Ctrl-1': 3.27, 'Ctrl-2': 3.78, 'Ctrl-3': 4.33, 'Ctrl-4': 1.93, 'Ctrl-5': 4.02, 'Ctrl-6': 3.2, 'Ctrl-7': 2.62, 'Ctrl-8': 2.78, 'Ctrl-9': 3.61}

Result: reproduced. On familiar trials, control mice lick more in the 30 cm before the zone than Cre mice under both rate readings: virus F(1,14)=21.0, p=0.0004 for (i) and F(1,14)=21.2, p=0.0004 for (ii). Control means are 2.9 to 3.8 licks/s on each day, Cre means 1.2 to 2.7. Only Cre-1 to Cre-7 are in the dataset, so the paper's 8-Cre reading (df 15) cannot be run.

fig1g-anticipatory-licking-novel¶

On novel arm trials, control mice licked at a higher rate than Cre mice as they approached the reward zone.

In [11]:
LN = lick_anova("nov")
reading (i): N=9 ctrl, 7 cre; virus F(1,14)=25 p=0.000195; day F(5,70)=0.173 p=0.972; interaction F(5,70)=2.83 p=0.0218
day       1     2     3     4     5     6
virus                                    
cre    2.40  2.25  2.11  2.07  1.64  1.81
ctrl   3.43  3.56  3.41  3.49  3.94  3.85
  per mouse, mean over days: {'Cre-1': 2.71, 'Cre-2': 2.37, 'Cre-3': 1.26, 'Cre-4': 1.97, 'Cre-5': 1.16, 'Cre-6': 2.02, 'Cre-7': 2.84, 'Ctrl-1': 3.0, 'Ctrl-2': 4.07, 'Ctrl-3': 4.5, 'Ctrl-4': 3.03, 'Ctrl-5': 3.91, 'Ctrl-6': 3.67, 'Ctrl-7': 2.68, 'Ctrl-8': 3.69, 'Ctrl-9': 3.98}
reading (ii): N=9 ctrl, 7 cre; virus F(1,14)=25.6 p=0.000173; day F(5,70)=0.608 p=0.694; interaction F(5,70)=2.53 p=0.0367
day       1     2     3     4     5     6
virus                                    
cre    2.40  2.11  1.98  1.85  1.34  1.56
ctrl   3.37  3.55  3.25  3.32  3.70  3.64
  per mouse, mean over days: {'Cre-1': 2.28, 'Cre-2': 2.28, 'Cre-3': 1.09, 'Cre-4': 1.64, 'Cre-5': 1.12, 'Cre-6': 1.92, 'Cre-7': 2.76, 'Ctrl-1': 3.02, 'Ctrl-2': 4.06, 'Ctrl-3': 4.35, 'Ctrl-4': 2.84, 'Ctrl-5': 3.87, 'Ctrl-6': 3.47, 'Ctrl-7': 2.37, 'Ctrl-8': 3.64, 'Ctrl-9': 3.64}

Result: reproduced. On novel trials control mice lick more: virus F(1,14)=25.0, p=0.0002 for (i) and F(1,14)=25.6, p=0.0002 for (ii).

vr-reward-location-learning¶

Both control and Cre mice learned the context-dependent reward locations, licking more and running slower only in the bins just before the reward zones, and anticipatory licking on familiar trials changed over days.

Day 6, per mouse: binned lick rate and speed for each arm, divided by the mouse's overall mean over all bins and trials of the day; across-animal means per group and arm. The Methods do not say how the "average running speed" is taken. Reading (ii), the mean of the binned speeds, is the main one: it is normalised the same way as the binned values it divides. Reading (i), the time-weighted mean speed of the session, is shown as a variant: it weights the reward stops, where speed is near 0, by their long duration, so it falls below the bin mean and pushes the normalised binned speeds above 1. It is not a reading the claims file names.

In [12]:
res_vr = {}
for v in ("ctrl", "cre"):
    for arm, name in ((-1, "left"), (1, "right")):
        L_m, V_m, V2_m = [], [], []
        for m in (CTRL if v == "ctrl" else CRE):
            f = S[(m, 5)]["full"]
            tot_rate = f["licks"].sum() / f["time"].sum()
            tot_spd = np.nansum(f["speed"] * f["time"]) / f["time"].sum()      # (i) time-weighted mean speed
            tot_spd2 = np.nanmean(f["speed"])                                     # (ii) mean of the binned speeds
            sel = f["LR"] == arm
            with np.errstate(invalid="ignore", divide="ignore"):
                lr = f["licks"][sel].sum(0) / f["time"][sel].sum(0)
            L_m.append(lr / tot_rate); V_m.append(np.nanmean(f["speed"][sel], 0) / tot_spd)
            V2_m.append(np.nanmean(f["speed"][sel], 0) / tot_spd2)
        Lm, Vm, V2m = np.nanmean(L_m, 0), np.nanmean(V_m, 0), np.nanmean(V2_m, 0)
        ab = ANT[arm]; zone = np.arange(FB[arm], FB[arm] + 3)
        outside = np.setdiff1d(np.arange(30), np.r_[ab, zone])
        ant_l = Lm[ab].mean(); ant_v = Vm[ab].mean(); ant_v2 = V2m[ab].mean()
        holds = bool(ant_l > Lm[outside].max() and ant_v < 1)
        holds2 = bool(ant_l > Lm[outside].max() and ant_v2 < 1)
        res_vr[(v, name)] = (holds, holds2)
        print(f"{v} {name}: norm lick in 30 cm before zone {ant_l:.2f}, max outside {Lm[outside].max():.2f} (bin {outside[np.argmax(Lm[outside])]}); "
              f"norm speed there (i) time-weighted mean {ant_v:.2f}, (ii) bin mean {ant_v2:.2f}; pattern holds: (i) {holds}, (ii) {holds2}")
        print("   norm lick by bin:", np.round(Lm, 2).tolist())
        print("   norm speed by bin:", np.round(Vm, 2).tolist())
for rd in ("lick_i", "lick_ii"):
    mm, means = LF[rd]
    dmean = means.mean(0)
    print(f"fig1f ANOVA, reading {rd}: day F={mm['day']['F']:.3g} p={mm['day']['p']:.3g}; mean day 1 {dmean[1]:.2f}, day 6 {dmean[6]:.2f}")
ctrl left: norm lick in 30 cm before zone 2.95, max outside 0.84 (bin 22); norm speed there (i) time-weighted mean 0.93, (ii) bin mean 0.57; pattern holds: (i) True, (ii) True
   norm lick by bin: [0.02, 0.06, 0.13, 0.23, 0.17, 0.05, 0.09, 0.06, 0.02, 0.26, 0.1, 0.21, 0.15, 0.18, 0.53, 0.74, 1.8, 3.34, 3.7, 0.72, 0.85, 1.03, 0.84, 0.63, 0.46, 0.3, 0.18, 0.13, 0.08, 0.04]
   norm speed by bin: [1.64, 1.72, 1.97, 2.11, 2.18, 2.19, 2.15, 2.11, 2.05, 1.98, 1.88, 1.79, 1.67, 1.57, 1.45, 1.32, 1.17, 0.96, 0.68, 0.26, 0.92, 1.37, 1.58, 1.72, 1.8, 1.83, 1.89, 1.96, 1.99, 1.97]
ctrl right: norm lick in 30 cm before zone 3.50, max outside 1.65 (bin 22); norm speed there (i) time-weighted mean 0.95, (ii) bin mean 0.57; pattern holds: (i) True, (ii) True
   norm lick by bin: [0.02, 0.04, 0.09, 0.11, 0.08, 0.1, 0.1, 0.24, 0.05, 0.08, 0.1, 0.1, 0.09, 0.15, 0.16, 0.23, 0.16, 0.34, 0.39, 0.38, 0.59, 0.95, 1.65, 2.44, 3.62, 4.45, 1.33, 0.81, 0.76, 0.64]
   norm speed by bin: [1.65, 1.74, 1.92, 2.04, 2.06, 2.09, 2.1, 2.11, 2.09, 2.09, 2.05, 2.01, 2.0, 2.03, 2.02, 1.98, 1.9, 1.82, 1.73, 1.64, 1.54, 1.44, 1.31, 1.15, 0.96, 0.73, 0.27, 0.6, 1.17, 1.4]
cre left: norm lick in 30 cm before zone 1.69, max outside 0.98 (bin 27); norm speed there (i) time-weighted mean 1.10, (ii) bin mean 0.47; pattern holds: (i) False, (ii) True
   norm lick by bin: [0.06, 0.07, 0.08, 0.13, 0.13, 0.31, 0.13, 0.1, 0.08, 0.28, 0.17, 0.32, 0.29, 0.66, 0.32, 0.8, 1.04, 1.85, 2.17, 0.95, 0.65, 0.62, 0.55, 0.86, 0.72, 0.3, 0.36, 0.98, 0.11, 0.03]
   norm speed by bin: [2.3, 2.47, 2.85, 3.02, 3.01, 2.98, 2.93, 2.87, 2.84, 2.79, 2.7, 2.63, 2.49, 2.29, 2.08, 1.9, 1.61, 1.12, 0.55, 0.31, 1.48, 2.21, 2.55, 2.61, 2.56, 2.57, 2.49, 2.34, 2.32, 2.41]
cre right: norm lick in 30 cm before zone 2.26, max outside 1.04 (bin 22); norm speed there (i) time-weighted mean 1.10, (ii) bin mean 0.48; pattern holds: (i) False, (ii) True
   norm lick by bin: [0.23, 0.16, 0.17, 0.18, 0.11, 0.29, 0.23, 0.1, 0.1, 0.17, 0.21, 0.18, 0.23, 0.15, 0.16, 0.15, 0.21, 0.6, 0.4, 0.39, 0.6, 0.68, 1.04, 1.6, 2.42, 2.77, 1.17, 1.01, 0.62, 0.71]
   norm speed by bin: [2.27, 2.47, 2.81, 2.96, 2.98, 2.93, 2.9, 2.86, 2.83, 2.87, 2.79, 2.71, 2.6, 2.65, 2.75, 2.76, 2.72, 2.54, 2.31, 2.15, 2.0, 1.85, 1.67, 1.44, 1.09, 0.78, 0.22, 1.0, 1.74, 2.08]
fig1f ANOVA, reading lick_i: day F=3.47 p=0.00731; mean day 1 3.22, day 6 2.67
fig1f ANOVA, reading lick_ii: day F=4.97 p=0.000593; mean day 1 3.17, day 6 2.38

Result: partially reproduced. Under speed reading (ii), the main one, the day-6 spatial pattern holds in both groups on both arms. Normalized lick rate in the 30 cm before the zone is 1.69 to 3.50, above every bin outside the zone, where the maximum is 0.84 to 1.65. Normalized speed there is 0.47 to 0.57. Under the variant (i), which divides by the time-weighted session mean speed, the Cre speed ratio is 1.10. The day effect of the familiar-trial licking ANOVA is significant (p=0.007 and p=0.0006). But the day-6 mean (2.67 and 2.38 licks/s) is below the day-1 mean (3.22 and 3.17), and the criterion asks for day 6 above day 1. So the day part fails. The paper says only that licking changed over days; whether the criterion should ask for an increase is asked of a reader (questions file).

figs2f-novelty-slowing-familiar¶

When the novel arm block began, control mice slowed down more than Cre mice on familiar arm trials, most clearly on day 1.

Normalized speed = log10 of the mean speed on the block 6 trials over the mean speed on the 10 trials before block 6. Readings: trials (a) first two familiar trials of block 6, (b) all familiar trials of block 6; speed (i) mean of the binned speeds, (ii) distance over time.

In [13]:
def slowing(ttype):
    out = {}
    for tr in ("a", "b"):
        for sp in ("spd_binned", "spd_time"):
            rows = []
            for (m, day), d in TT[TT.day <= 5].groupby(["mouse", "day"]):
                d = d.sort_values("trial").reset_index(drop=True)
                first6 = np.flatnonzero(d.b6.values)
                if len(first6) == 0:
                    continue
                pos6 = first6[0]
                base = d.iloc[max(0, pos6 - 10):pos6][sp].mean()
                b6 = d[d.b6 & (d.ttype == ttype)]
                b6 = b6.iloc[:2] if tr == "a" else b6
                rows.append(dict(mouse=m, virus=virus_of(m), day=day, ns=np.log10(b6[sp].mean() / base)))
            df = pd.DataFrame(rows)
            mm = mixed(df, "ns")
            ph = []
            for day in range(1, 6):
                t = ttest2(df[(df.day == day) & (df.virus == "ctrl")].ns, df[(df.day == day) & (df.virus == "cre")].ns)
                ph.append(t)
            adj = holm([t["p"] for t in ph]); adjw = holm([t["p_welch"] for t in ph])
            print(f"reading ({tr},{'i' if sp == 'spd_binned' else 'ii'}): {fmt_mixed(mm)}")
            print("   group means by day:", df.groupby(["virus", "day"]).ns.mean().unstack().round(3).to_dict("index"))
            print("   posthoc ctrl vs cre per day: t=", [round(t["t"], 2) for t in ph], "Holm p=", adj.round(3).tolist(), "Welch Holm p=", adjw.round(3).tolist())
            out[(tr, sp)] = (mm, df, ph, adj, adjw)
    return out
SF = slowing("fam")
reading (a,i): N=9 ctrl, 7 cre; virus F(1,14)=4.89 p=0.0442; day F(4,56)=1.16 p=0.34; interaction F(4,56)=0.71 p=0.589
   group means by day: {'cre': {1: -0.051, 2: -0.065, 3: -0.081, 4: -0.048, 5: -0.028}, 'ctrl': {1: -0.136, 2: -0.126, 3: -0.087, 4: -0.094, 5: -0.078}}
   posthoc ctrl vs cre per day: t= [-3.98, -1.56, -0.12, -1.31, -1.7] Holm p= [0.007, 0.448, 0.909, 0.448, 0.448] Welch Holm p= [0.006, 0.411, 0.918, 0.411, 0.411]
reading (a,ii): N=9 ctrl, 7 cre; virus F(1,14)=10.4 p=0.00606; day F(4,56)=2.87 p=0.031; interaction F(4,56)=0.412 p=0.799
   group means by day: {'cre': {1: -0.035, 2: -0.025, 3: 0.004, 4: 0.016, 5: 0.041}, 'ctrl': {1: -0.095, 2: -0.102, 3: -0.036, 4: -0.082, 5: -0.042}}
   posthoc ctrl vs cre per day: t= [-2.59, -2.13, -0.97, -2.19, -2.09] Holm p= [0.108, 0.185, 0.348, 0.185, 0.185] Welch Holm p= [0.089, 0.212, 0.392, 0.212, 0.212]
reading (b,i): N=9 ctrl, 7 cre; virus F(1,14)=0.354 p=0.561; day F(4,56)=0.384 p=0.819; interaction F(4,56)=1.31 p=0.276
   group means by day: {'cre': {1: -0.024, 2: -0.022, 3: -0.061, 4: -0.019, 5: -0.029}, 'ctrl': {1: -0.046, 2: -0.03, 3: -0.006, 4: -0.013, 5: -0.023}}
   posthoc ctrl vs cre per day: t= [-1.33, -0.45, 1.2, 0.31, 0.33] Holm p= [1.0, 1.0, 1.0, 1.0, 1.0] Welch Holm p= [0.917, 1.0, 1.0, 1.0, 1.0]
reading (b,ii): N=9 ctrl, 7 cre; virus F(1,14)=1.3 p=0.273; day F(4,56)=1.09 p=0.371; interaction F(4,56)=0.774 p=0.547
   group means by day: {'cre': {1: -0.014, 2: 0.003, 3: 0.009, 4: -0.005, 5: 0.018}, 'ctrl': {1: -0.015, 2: -0.036, 3: 0.021, 4: -0.012, 5: -0.019}}
   posthoc ctrl vs cre per day: t= [-0.02, -1.57, 0.45, -0.24, -1.66] Holm p= [1.0, 0.593, 1.0, 1.0, 0.593] Welch Holm p= [1.0, 0.722, 1.0, 1.0, 0.722]

Result: reproduced (reading a,i). With the first two familiar trials of block 6 and the binned speed, control mice slow more than Cre mice: virus F(1,14)=4.89, p=0.044 (paper F(1,14)=4.82, p=0.045). Control means are -0.08 to -0.14 log units, Cre means -0.03 to -0.08. On day 1, Holm p=0.007 (Student) and 0.006 (Welch), t=-3.98 (paper t=4.43, p=0.007). Reading (a,ii) has a virus effect (p=0.006) but no day-1 effect (Holm p=0.108). Readings (b,i) and (b,ii), all block-6 familiar trials, show no effect (p=0.56, 0.27).

figs2g-novel-arm-slowing-no-difference¶

Control and Cre mice slowed similarly on novel arm trajectories.

Main: first two novel trials of block 6, speed reading (i); the others are variants.

In [14]:
SN = slowing("nov")
reading (a,i): N=9 ctrl, 7 cre; virus F(1,14)=1.11 p=0.309; day F(4,56)=0.828 p=0.513; interaction F(4,56)=0.572 p=0.684
   group means by day: {'cre': {1: -0.086, 2: -0.059, 3: -0.086, 4: -0.101, 5: -0.06}, 'ctrl': {1: -0.113, 2: -0.089, 3: -0.081, 4: -0.106, 5: -0.105}}
   posthoc ctrl vs cre per day: t= [-0.9, -0.77, 0.14, -0.16, -2.02] Holm p= [1.0, 1.0, 1.0, 1.0, 0.313] Welch Holm p= [1.0, 1.0, 1.0, 1.0, 0.271]
reading (a,ii): N=9 ctrl, 7 cre; virus F(1,14)=4.7 p=0.0479; day F(4,56)=3.1 p=0.0223; interaction F(4,56)=1.6 p=0.188
   group means by day: {'cre': {1: -0.032, 2: 0.016, 3: 0.044, 4: -0.054, 5: 0.015}, 'ctrl': {1: -0.024, 2: -0.05, 3: -0.024, 4: -0.118, 5: -0.136}}
   posthoc ctrl vs cre per day: t= [0.15, -1.49, -1.35, -1.14, -2.78] Holm p= [0.88, 0.636, 0.636, 0.636, 0.074] Welch Holm p= [0.888, 0.741, 0.741, 0.741, 0.186]
reading (b,i): N=9 ctrl, 7 cre; virus F(1,14)=0.35 p=0.563; day F(4,56)=1.02 p=0.404; interaction F(4,56)=1.16 p=0.34
   group means by day: {'cre': {1: -0.025, 2: -0.039, 3: -0.097, 4: -0.036, 5: -0.051}, 'ctrl': {1: -0.042, 2: -0.026, 3: -0.037, 4: -0.036, 5: -0.057}}
   posthoc ctrl vs cre per day: t= [-0.68, 0.36, 1.37, 0.03, -0.29] Holm p= [1.0, 1.0, 0.968, 1.0, 1.0] Welch Holm p= [1.0, 1.0, 1.0, 1.0, 1.0]
reading (b,ii): N=9 ctrl, 7 cre; virus F(1,14)=0.229 p=0.64; day F(4,56)=1.44 p=0.234; interaction F(4,56)=1.28 p=0.288
   group means by day: {'cre': {1: 0.01, 2: -0.007, 3: -0.011, 4: -0.034, 5: 0.025}, 'ctrl': {1: 0.021, 2: -0.015, 3: -0.003, 4: -0.035, 5: -0.049}}
   posthoc ctrl vs cre per day: t= [0.28, -0.2, 0.18, -0.02, -1.71] Holm p= [1.0, 1.0, 1.0, 1.0, 0.545] Welch Holm p= [1.0, 1.0, 1.0, 1.0, 0.838]

Result: reproduced. On the first two novel trials of block 6 (binned speed), the virus main effect is F(1,14)=1.11, p=0.309 (paper F(1,14)=1.12, p=0.308). The variant (a,ii) gives p=0.048.

figs2i-reward-approach-speed-cv¶

Cre mice have more variable running speed during reward approach (higher coefficient of variation) than control mice, on familiar and novel trials.

In [15]:
CVR = {}
for ttype in ("fam", "nov"):
    rows = []
    for (m, fd), s in S.items():
        f = s["full"]; nov = s["novel_arm"]
        arm = nov if ttype == "nov" else -nov
        V = f["speed"][f["LR"] == arm]
        if len(V) < 2:
            continue
        cv = np.nanstd(V, 0, ddof=1) / np.nanmean(V, 0)
        rows.append(dict(mouse=m, virus=virus_of(m), day=fd + 1, cv=np.nanmean(cv[ANT[arm]])))
    df = pd.DataFrame(rows); mm = mixed(df, "cv"); CVR[ttype] = mm
    print(ttype, fmt_mixed(mm)); print(df.groupby(["virus", "day"]).cv.mean().unstack().round(3).to_string())
fam N=9 ctrl, 7 cre; virus F(1,14)=8.33 p=0.012; day F(5,70)=1.61 p=0.169; interaction F(5,70)=2.31 p=0.0531
day        1      2      3      4      5      6
virus                                          
cre    0.376  0.437  0.465  0.432  0.602  0.569
ctrl   0.383  0.364  0.331  0.375  0.412  0.294
nov N=9 ctrl, 7 cre; virus F(1,14)=6.32 p=0.0248; day F(5,70)=4.91 p=0.000662; interaction F(5,70)=2.12 p=0.073
day        1      2      3      4      5      6
virus                                          
cre    0.333  0.426  0.463  0.450  0.572  0.602
ctrl   0.330  0.363  0.362  0.405  0.430  0.380

Result: reproduced. The speed CV in the 30 cm before the zone is higher in Cre mice on familiar trials (virus F(1,14)=8.33, p=0.012) and on novel trials (F(1,14)=6.32, p=0.025). On day 6 the Cre mean is 0.57 and the control mean 0.29 (familiar).

Imaging: common definitions¶

Familiar trials are those on the arm that is not the novel arm; novel trials those on the novel arm. Place cells are the deposited per-arm place-cell masks of each file (place_cell_info; they equal shuffle p < 0.05 of the deposited spatial information, checked below); the place cells recomputed here from the same 1000 shuffles are a variant. Per-mouse values are on the paper's days 1 to 6.

In [16]:
def tidx(s, tt):
    return np.flatnonzero(s["LR"] == (s["novel_arm"] if tt == "nov" else -s["novel_arm"]))

def pcmask(s, tt, src="dep"):
    return s["dep_pc"][tt]["masks"].astype(bool) if src == "dep" else (s["si_p"][tt] < 0.05)

chk = []
for (m, fd), s in S.items():
    for tt in ("fam", "nov"):
        d = s["dep_pc"][tt]
        chk.append(dict(mouse=m, day=fd + 1, tt=tt, dep_eq_p=np.mean(d["masks"].astype(bool) == (d["p"] < 0.05)),
                        frac_dep=d["masks"].mean(), frac_re=(s["si_p"][tt] < 0.05).mean(),
                        agree=np.mean(d["masks"].astype(bool) == (s["si_p"][tt] < 0.05))))
chk = pd.DataFrame(chk)
print("deposited mask == deposited p < 0.05: mean agreement %.4f, min %.4f" % (chk.dep_eq_p.mean(), chk.dep_eq_p.min()))
print("place-cell fraction, deposited vs recomputed (mean over mouse-days):")
print(chk.groupby("tt")[["frac_dep", "frac_re", "agree"]].mean().round(3).to_string())

def block_test(s):
    """Index of the first trial of the block with the first novel trial, and that block's trials."""
    nidx = tidx(s, "nov")
    b = s["block"][nidx[0]]
    tr = np.flatnonzero(s["block"] == b)
    return tr[0], tr

# deposited against recomputed spatial information (SI) and shuffle p, per cell
from scipy import stats
pcc = []
for (m, fd), s in S.items():
    for tt in ("fam", "nov"):
        d = s["dep_pc"][tt]; re_p = s["si_p"][tt]
        pcc.append(dict(mouse=m, day=fd + 1, tt=tt, rho_SI=stats.spearmanr(d["SI"], s["si_obs"][tt]).statistic,
                        SI_ratio=np.median(s["si_obs"][tt] / d["SI"]), rho_p=stats.spearmanr(d["p"], re_p).statistic,
                        dep_only=np.mean(d["masks"].astype(bool) & (re_p >= 0.05)), re_only=np.mean(~d["masks"].astype(bool) & (re_p < 0.05))))
pcc = pd.DataFrame(pcc)
print("per mouse-day, deposited vs recomputed: Spearman rho of SI, median SI ratio (recomputed / deposited), rho of p, "
      "fraction place cell only in the deposited / only in the recomputed masks:")
print(pcc.groupby("tt")[["rho_SI", "SI_ratio", "rho_p", "dep_only", "re_only"]].describe().loc[:, (slice(None), ["min", "50%", "max"])].round(3).T.to_string())
s = S[("Ctrl-1", 2)]; d = s["dep_pc"]["fam"]
ex = pd.DataFrame(dict(SI_dep=d["SI"], SI_re=s["si_obs"]["fam"], p_dep=d["p"], p_re=s["si_p"]["fam"]))
print("Ctrl-1 day 3, familiar trials, first 10 cells:"); print(ex.head(10).round(3).to_string())
print("Ctrl-1 day 3 familiar: cells with p_dep < 0.05 and p_re >= 0.05:", int(((ex.p_dep < 0.05) & (ex.p_re >= 0.05)).sum()),
      "; p_re < 0.05 and p_dep >= 0.05:", int(((ex.p_re < 0.05) & (ex.p_dep >= 0.05)).sum()), "of", len(ex))
deposited mask == deposited p < 0.05: mean agreement 1.0000, min 0.9961
place-cell fraction, deposited vs recomputed (mean over mouse-days):
     frac_dep  frac_re  agree
tt                           
fam     0.886    0.974  0.911
nov     0.667    0.816  0.846
per mouse-day, deposited vs recomputed: Spearman rho of SI, median SI ratio (recomputed / deposited), rho of p, fraction place cell only in the deposited / only in the recomputed masks:
tt               fam     nov
rho_SI   min   0.898   0.841
         50%   0.952   0.927
         max   0.981   0.965
SI_ratio min   1.331   2.595
         50%  24.808  30.986
         max  75.698  87.462
rho_p    min   0.282   0.451
         50%   0.586   0.879
         max   0.862   0.972
dep_only min   0.000   0.000
         50%   0.000   0.000
         max   0.040   0.035
re_only  min   0.001   0.041
         50%   0.074   0.139
         max   0.450   0.488
Ctrl-1 day 3, familiar trials, first 10 cells:
   SI_dep  SI_re  p_dep  p_re
0   0.248  0.856    0.0   0.0
1   0.093  0.664    0.0   0.0
2   0.275  1.010    0.0   0.0
3   0.106  0.915    0.0   0.0
4   0.038  0.261    0.0   0.0
5   0.053  0.719    0.0   0.0
6   0.045  0.643    0.0   0.0
7   0.035  0.476    0.0   0.0
8   0.107  0.771    0.0   0.0
9   0.075  0.638    0.0   0.0
Ctrl-1 day 3 familiar: cells with p_dep < 0.05 and p_re >= 0.05: 0 ; p_re < 0.05 and p_dep >= 0.05: 77 of 972

fig2ab-example-cell-counts¶

The example sessions of Fig 2A-B hold 1208 cells and 120 familiar trials (Ctrl-3, day 5), 1568 cells and 20 novel trials (Ctrl-3, day 1), 1087 cells and 17 familiar trials (Cre-3, day 5) and 936 cells and 17 novel trials (Cre-3, day 1).

In [17]:
ex = [("Ctrl-3", 5, "fam", 1208, 120), ("Ctrl-3", 1, "nov", 1568, 20), ("Cre-3", 5, "fam", 1087, 17), ("Cre-3", 1, "nov", 936, 17)]
FIG2AB = []
for m, day, tt, nc, ntr in ex:
    s = S[(m, day - 1)]
    got_c, got_t = s["n_cells"], len(tidx(s, tt))
    FIG2AB += [got_c, got_t]
    print(f"{m} day {day} {tt}: cells {got_c} (paper {nc}, within 10%: {abs(got_c - nc) <= 0.1 * nc}); "
          f"trials {got_t} (paper {ntr}, within 10%: {abs(got_t - ntr) <= 0.1 * ntr})")
s = S[("Cre-3", 4)]
print("Cre-3 day 5 trials by type:", {tt: len(tidx(s, tt)) for tt in ("fam", "nov")}, "; block-6 familiar trials:", int(np.sum(s["block"][tidx(s, "fam")] == 5)))
Ctrl-3 day 5 fam: cells 1208 (paper 1208, within 10%: True); trials 120 (paper 120, within 10%: True)
Ctrl-3 day 1 nov: cells 1568 (paper 1568, within 10%: True); trials 20 (paper 20, within 10%: True)
Cre-3 day 5 fam: cells 1087 (paper 1087, within 10%: True); trials 82 (paper 17, within 10%: False)
Cre-3 day 1 nov: cells 936 (paper 936, within 10%: True); trials 17 (paper 17, within 10%: True)
Cre-3 day 5 trials by type: {'fam': 82, 'nov': 11} ; block-6 familiar trials: 7

Result: partially reproduced. Seven of the eight counts match exactly: the four cell counts (1208, 1568, 1087, 936) and the trial counts for Ctrl-3 (120 familiar, 20 novel) and Cre-3 day 1 (17 novel). Cre-3 day 5 has 82 familiar trials, not 17; that day also has 11 novel trials and 7 familiar trials in block 6.

fig2cd-decoding-no-group-difference¶

Controlling for the number of cells, position decoding error did not differ between control and Cre mice on familiar or novel trials.

Decoder input as in the authors' code (dF/F x 10, shifted to be positive); Poisson log likelihood with continuous rates, uniform prior, leave-one-trial-out; 50 draws of 128 cells with replacement per mouse, day and trial type; error in cm over the visited bins.

In [18]:
rng_dec = np.random.default_rng(2)
dec_rows = []
for (m, fd), s in sorted(S.items()):
    for tt in ("fam", "nov"):
        idx = tidx(s, tt)
        dec_rows.append(dict(mouse=m, virus=virus_of(m), day=fd + 1, tt=tt,
                             err=stx3.decode_loo(s["R"][idx], s["occ"][idx], rng_dec)))
DEC = pd.DataFrame(dec_rows)
DECM = {}
for tt in ("fam", "nov"):
    d = DEC[DEC.tt == tt]; DECM[tt] = mixed(d, "err")
    print(tt, fmt_mixed(DECM[tt]))
    print(d.groupby(["virus", "day"]).err.mean().unstack().round(1).to_string())
print("decoding error range (cm):", DEC.err.min().round(1), "-", DEC.err.max().round(1), "; chance for a uniform guess is about 100 cm")
fam N=9 ctrl, 7 cre; virus F(1,14)=0.995 p=0.335; day F(5,70)=6.97 p=2.48e-05; interaction F(5,70)=0.861 p=0.512
day       1     2     3     4     5     6
virus                                    
cre    23.4  14.9  14.7   9.7  13.2  10.8
ctrl   35.3  17.2  12.8  13.5  12.1  14.5
nov N=9 ctrl, 7 cre; virus F(1,14)=0.257 p=0.62; day F(5,70)=8.93 p=1.34e-06; interaction F(5,70)=1.66 p=0.155
day       1     2     3     4     5     6
virus                                    
cre    19.8  14.1  14.2  10.2  16.1  11.7
ctrl   23.8  16.1  14.3  13.5  11.7  14.7
decoding error range (cm): 6.3 - 121.4 ; chance for a uniform guess is about 100 cm

Result: reproduced. Decoding error does not differ between groups: virus F(1,14)=0.995, p=0.335 on familiar trials and F(1,14)=0.257, p=0.62 on novel trials. Errors range from 6 to 121 cm per mouse and day.

fig2cd-decoding-improves-over-days¶

Decoding error fell as the mice gained experience over days, on familiar and novel trials, with day 1 worse than every later day.

In [19]:
from scipy import stats
DAYS_PH = {}
for tt in ("fam", "nov"):
    w = DEC[DEC.tt == tt].pivot(index="mouse", columns="day", values="err")
    pairs = [(i, j) for i in range(1, 7) for j in range(i + 1, 7)]
    res = [stats.ttest_rel(w[i], w[j]) for i, j in pairs]
    adj = holm([r.pvalue for r in res])
    d1 = {j: (round(float(res[k].statistic), 2), float(adj[k])) for k, (i, j) in enumerate(pairs) if i == 1}
    DAYS_PH[tt] = d1
    print(tt, "day effect F=%.3g p=%.3g" % (DECM[tt]["day"]["F"], DECM[tt]["day"]["p"]))
    print("   day 1 vs day j (paired t, Holm over 15 pairs):", {j: (t, f"{p:.3g}") for j, (t, p) in d1.items()})
    wc = w.loc[[m for m in w.index if m.startswith("Ctrl")]]
    print("   control only, day 1 vs day 2: t=%.2f p=%.3g (uncorrected)" % tuple(stats.ttest_rel(wc[1], wc[2])))
fam day effect F=6.97 p=2.48e-05
   day 1 vs day j (paired t, Holm over 15 pairs): {2: (2.42, '0.289'), 3: (2.69, '0.196'), 4: (3.02, '0.12'), 5: (2.83, '0.165'), 6: (2.7, '0.196')}
   control only, day 1 vs day 2: t=1.78 p=0.112 (uncorrected)
nov day effect F=8.93 p=1.34e-06
   day 1 vs day j (paired t, Holm over 15 pairs): {2: (5.1, '0.00183'), 3: (4.55, '0.00485'), 4: (7.76, '1.86e-05'), 5: (3.15, '0.0655'), 6: (4.56, '0.00485')}
   control only, day 1 vs day 2: t=4.73 p=0.00148 (uncorrected)

Result: partially reproduced. The day effect is significant on familiar trials (F(5,70)=6.97, p=2.5e-5) and on novel trials (F(5,70)=8.93, p=1.3e-6). On novel trials, day 1 error is above days 2, 3, 4 and 6 (Holm p 2e-5 to 0.005) but not day 5 (Holm p=0.066). On familiar trials, none of the five day-1 contrasts survives Holm correction (p 0.12 to 0.29), though all have t > 2.4.

figs3a-spatial-information-fraction-no-difference¶

The fraction of cells with significant spatial information did not differ between control and Cre mice, on familiar or novel trials.

In [20]:
S3A = {}
for src in ("dep", "re"):
    rows = [dict(mouse=m, virus=virus_of(m), day=fd + 1, tt=tt, frac=pcmask(s, tt, src).mean())
            for (m, fd), s in S.items() for tt in ("fam", "nov")]
    d = pd.DataFrame(rows)
    for tt in ("fam", "nov"):
        mm = mixed(d[d.tt == tt], "frac"); S3A[(src, tt)] = mm
        print(f"place cells {src}, {tt}: {fmt_mixed(mm)}; means ctrl {d[(d.tt == tt) & (d.virus == 'ctrl')].frac.mean():.3f}, cre {d[(d.tt == tt) & (d.virus == 'cre')].frac.mean():.3f}")
place cells dep, fam: N=9 ctrl, 7 cre; virus F(1,14)=0.182 p=0.676; day F(5,70)=1.76 p=0.133; interaction F(5,70)=2.27 p=0.057; means ctrl 0.881, cre 0.893
place cells dep, nov: N=9 ctrl, 7 cre; virus F(1,14)=0.118 p=0.736; day F(5,70)=19.8 p=3.08e-12; interaction F(5,70)=5.32 p=0.000338; means ctrl 0.675, cre 0.657
place cells re, fam: N=9 ctrl, 7 cre; virus F(1,14)=2.26 p=0.155; day F(5,70)=5.79 p=0.000158; interaction F(5,70)=3.34 p=0.00925; means ctrl 0.979, cre 0.968
place cells re, nov: N=9 ctrl, 7 cre; virus F(1,14)=5.39 p=0.0358; day F(5,70)=17.2 p=4.59e-11; interaction F(5,70)=5.39 p=0.0003; means ctrl 0.846, cre 0.777

Result: reproduced. With the deposited place-cell masks there is no virus effect on the place-cell fraction: F(1,14)=0.182, p=0.676 (familiar) and F(1,14)=0.118, p=0.736 (novel). With the recomputed masks (variant), the novel fraction differs (p=0.036). The fractions are high: 0.88 to 0.89 familiar and 0.66 to 0.68 novel.

Why the masks differ: the recomputed place cells contain almost every deposited one (cells only in the deposited masks: 0 to 4% per mouse-day), and add others (0.1 to 49%, median 7% familiar and 14% novel). Spatial information ranks agree (Spearman rho 0.84 to 0.98 per mouse-day), but its scale does not (recomputed over deposited, median 25 and 31, range 1.3 to 87), and the shuffle p-values agree less (rho 0.28 to 0.97). So the deposited masks come from a different spatial information measure and a stricter null. The authors' place-cell function is in a package (two_photon_utils) that the linked repository does not hold, so the cause could not be traced further. The deposited masks are used for the outcome.

figs3b-within-day-stability-no-difference¶

Within-day stability of spatial representations, the mean trial by trial population vector correlation, was similar between control and Cre mice.

Readings: correlation (a) flattened cells x bins, (b) mean over bins of the per-bin correlation (the authors' calc_pv_corr); cells (i) all, (ii) place cells of that trial type and day.

In [21]:
rows = []
for (m, fd), s in S.items():
    for tt in ("fam", "nov"):
        idx = tidx(s, tt)
        for cells in ("i", "ii"):
            cm = np.ones(s["n_cells"], bool) if cells == "i" else pcmask(s, tt)
            for rd in ("a", "b"):
                rows.append(dict(mouse=m, virus=virus_of(m), day=fd + 1, tt=tt, reading=rd + "," + cells,
                                 pv=stx3.pairwise_pv(s["R"][idx][:, :, cm], rd)))
PVW = pd.DataFrame(rows)
S3B = {}
for (rdg, tt), d in PVW.groupby(["reading", "tt"]):
    mm = mixed(d, "pv"); S3B[(rdg, tt)] = mm
    print(f"reading ({rdg}) {tt}: {fmt_mixed(mm)}; ctrl {d[d.virus == 'ctrl'].pv.mean():.3f}, cre {d[d.virus == 'cre'].pv.mean():.3f}")
reading (a,i) fam: N=9 ctrl, 7 cre; virus F(1,14)=0.00212 p=0.964; day F(5,70)=40.8 p=1.98e-19; interaction F(5,70)=1.76 p=0.133; ctrl 0.387, cre 0.388
reading (a,i) nov: N=9 ctrl, 7 cre; virus F(1,14)=0.0169 p=0.898; day F(5,70)=31.1 p=1.61e-16; interaction F(5,70)=1.65 p=0.159; ctrl 0.422, cre 0.416
reading (a,ii) fam: N=9 ctrl, 7 cre; virus F(1,14)=0.000327 p=0.986; day F(5,70)=38.4 p=8.92e-19; interaction F(5,70)=1.58 p=0.178; ctrl 0.392, cre 0.392
reading (a,ii) nov: N=9 ctrl, 7 cre; virus F(1,14)=0.00156 p=0.969; day F(5,70)=33.9 p=1.95e-17; interaction F(5,70)=1.9 p=0.104; ctrl 0.446, cre 0.445
reading (b,i) fam: N=9 ctrl, 7 cre; virus F(1,14)=0.0174 p=0.897; day F(5,70)=37.8 p=1.33e-18; interaction F(5,70)=1.58 p=0.178; ctrl 0.386, cre 0.391
reading (b,i) nov: N=9 ctrl, 7 cre; virus F(1,14)=0.00702 p=0.934; day F(5,70)=30.9 p=1.84e-16; interaction F(5,70)=1.68 p=0.151; ctrl 0.417, cre 0.413
reading (b,ii) fam: N=9 ctrl, 7 cre; virus F(1,14)=0.0138 p=0.908; day F(5,70)=36.1 p=4.17e-18; interaction F(5,70)=1.44 p=0.219; ctrl 0.390, cre 0.394
reading (b,ii) nov: N=9 ctrl, 7 cre; virus F(1,14)=0.00144 p=0.97; day F(5,70)=33.2 p=3.27e-17; interaction F(5,70)=1.68 p=0.152; ctrl 0.437, cre 0.439

Result: reproduced. Under all four readings and both trial types, the virus main effect has p >= 0.897. Group means are 0.39 to 0.45 in both groups.

figs3c-familiar-novel-remapping¶

Place codes were largely uncorrelated between the familiar and novel arms (global remapping) in both groups, and the familiar to novel population vector correlation did not differ between control and Cre mice.

In [22]:
rows = []
for (m, fd), s in S.items():
    fa = np.nanmean(s["R"][tidx(s, "fam")], 0); no = np.nanmean(s["R"][tidx(s, "nov")], 0)
    for cells in ("i", "ii"):
        cm = np.ones(s["n_cells"], bool) if cells == "i" else (pcmask(s, "fam") | pcmask(s, "nov"))
        for rd in ("a", "b"):
            rows.append(dict(mouse=m, virus=virus_of(m), day=fd + 1, reading=rd + "," + cells,
                             fn=stx3.pv_corr(fa[:, cm], no[:, cm], rd)))
FN = pd.DataFrame(rows)
S3C = {}
for rdg, d in FN.groupby("reading"):
    mm = mixed(d, "fn"); S3C[rdg] = mm
    within = PVW[PVW.reading == rdg].groupby("virus").pv.mean()
    print(f"reading ({rdg}): {fmt_mixed(mm)}; familiar-novel PV corr ctrl {d[d.virus == 'ctrl'].fn.mean():.3f}, cre {d[d.virus == 'cre'].fn.mean():.3f}; "
          f"within-type trial x trial ctrl {within['ctrl']:.3f}, cre {within['cre']:.3f}")
print("(for reading ii the cells are the union of familiar and novel place cells, as the paper does for sequences across trial types)")
# like for like (variant): the familiar to novel correlation of single trials (mean over all familiar x novel trial pairs)
# beside the single-trial within-type value of figs3b, all cells
lfl = []
for (m, fd), s in S.items():
    Rf, Rn = s["R"][tidx(s, "fam")], s["R"][tidx(s, "nov")]
    for rd in ("a", "b"):
        lfl.append(dict(mouse=m, virus=virus_of(m), day=fd + 1, reading=rd + ",i", fn_trials=stx3.cross_pv(Rf, Rn, rd)))
LFL = pd.DataFrame(lfl)
for rdg, d in LFL.groupby("reading"):
    mm = mixed(d, "fn_trials"); within = PVW[PVW.reading == rdg].groupby("virus").pv.mean()
    print(f"single trials, reading ({rdg}): {fmt_mixed(mm)}; familiar x novel ctrl {d[d.virus == 'ctrl'].fn_trials.mean():.3f}, cre {d[d.virus == 'cre'].fn_trials.mean():.3f}; "
          f"within-type ctrl {within['ctrl']:.3f}, cre {within['cre']:.3f}")
reading (a,i): N=9 ctrl, 7 cre; virus F(1,14)=7.19 p=0.0179; day F(5,70)=4.49 p=0.00133; interaction F(5,70)=0.409 p=0.841; familiar-novel PV corr ctrl 0.246, cre 0.321; within-type trial x trial ctrl 0.404, cre 0.402
reading (a,ii): N=9 ctrl, 7 cre; virus F(1,14)=6.91 p=0.0199; day F(5,70)=4.43 p=0.00145; interaction F(5,70)=0.451 p=0.811; familiar-novel PV corr ctrl 0.240, cre 0.316; within-type trial x trial ctrl 0.419, cre 0.419
reading (b,i): N=9 ctrl, 7 cre; virus F(1,14)=1.09 p=0.314; day F(5,70)=8.93 p=1.36e-06; interaction F(5,70)=2.06 p=0.081; familiar-novel PV corr ctrl 0.301, cre 0.328; within-type trial x trial ctrl 0.401, cre 0.402
reading (b,ii): N=9 ctrl, 7 cre; virus F(1,14)=1.08 p=0.316; day F(5,70)=8.83 p=1.56e-06; interaction F(5,70)=2.16 p=0.0684; familiar-novel PV corr ctrl 0.296, cre 0.323; within-type trial x trial ctrl 0.413, cre 0.416
(for reading ii the cells are the union of familiar and novel place cells, as the paper does for sequences across trial types)
single trials, reading (a,i): N=9 ctrl, 7 cre; virus F(1,14)=2.05 p=0.174; day F(5,70)=15.8 p=2.28e-10; interaction F(5,70)=1.37 p=0.247; familiar x novel ctrl 0.108, cre 0.140; within-type ctrl 0.404, cre 0.402
single trials, reading (b,i): N=9 ctrl, 7 cre; virus F(1,14)=1.14 p=0.303; day F(5,70)=18.8 p=8.05e-12; interaction F(5,70)=2.18 p=0.0662; familiar x novel ctrl 0.116, cre 0.140; within-type ctrl 0.401, cre 0.402

Result: reproduced, resting on an assumption. The readings disagree, and reading (b), the per-bin correlation of the authors' code (calc_pv_corr), is adopted. Under (b) the virus effect has p=0.314 (cells i) and p=0.316 (ii). Under the flattened reading (a), Cre mice have a higher familiar-to-novel correlation (p=0.018 and 0.020; 0.32 against 0.25). The familiar-to-novel correlation, 0.30 (control) and 0.33 (Cre) under (b,i), is lower than the within-type trial-by-trial correlation, 0.40 in both groups. It is not near zero, as the stem is shared. Compared like for like, single familiar trials against single novel trials, the familiar-to-novel correlation is 0.108 (control) and 0.140 (Cre) under (a,i), and 0.116 and 0.140 under (b,i), against 0.40 within type; there the virus effect is p=0.174 (a,i) and p=0.303 (b,i).

fig2gh-across-day-pv-correlation-no-difference¶

The across-day population vector correlation of place cells tracked over all six days did not differ between control and Cre mice, for familiar or novel trials.

Cells tracked over the six days (link claim). Readings: cells (a) all tracked, (b) tracked cells that are place cells of the trial type on at least one day; PV correlation readings a, b as in figs3b.

In [23]:
def day_maps(m, tt):
    cols = TRACK[m]
    return np.stack([np.nanmean(S[(m, d)]["R"][tidx(S[(m, d)], tt)][:, :, cols[d]], 0) for d in range(6)])

def tracked_pc(m, tt):
    cols = TRACK[m]
    return np.any([pcmask(S[(m, d)], tt)[cols[d]] for d in range(6)], axis=0)

rows = []
for m in CTRL + CRE:
    for tt in ("fam", "nov"):
        DM = day_maps(m, tt)
        for cells in ("a", "b"):
            cm = np.ones(DM.shape[2], bool) if cells == "a" else tracked_pc(m, tt)
            for rd in ("a", "b"):
                C = np.array([[stx3.pv_corr(DM[i][:, cm], DM[j][:, cm], rd) for j in range(6)] for i in range(6)])
                rows.append(dict(mouse=m, virus=virus_of(m), tt=tt, reading=cells + "," + rd,
                                 pv=C[~np.eye(6, dtype=bool)].mean(), n=int(cm.sum())))
AD = pd.DataFrame(rows)
G2GH = {}
for (rdg, tt), d in AD.groupby(["reading", "tt"]):
    t = ttest2(d[d.virus == "ctrl"].pv, d[d.virus == "cre"].pv); G2GH[(rdg, tt)] = t
    print(f"cells,pv ({rdg}) {tt}: ctrl {d[d.virus == 'ctrl'].pv.mean():.3f}, cre {d[d.virus == 'cre'].pv.mean():.3f}; "
          f"t={t['t']:.3f} p={t['p']:.3g} (Welch p={t['p_welch']:.3g}); cells median {int(d.n.median())}")
cells,pv (a,a) fam: ctrl 0.577, cre 0.549; t=0.932 p=0.367 (Welch p=0.382); cells median 334
cells,pv (a,a) nov: ctrl 0.530, cre 0.506; t=0.708 p=0.491 (Welch p=0.486); cells median 334
cells,pv (a,b) fam: ctrl 0.563, cre 0.545; t=0.597 p=0.56 (Welch p=0.575); cells median 334
cells,pv (a,b) nov: ctrl 0.520, cre 0.487; t=1.069 p=0.303 (Welch p=0.289); cells median 334
cells,pv (b,a) fam: ctrl 0.577, cre 0.548; t=0.937 p=0.365 (Welch p=0.379); cells median 333
cells,pv (b,a) nov: ctrl 0.529, cre 0.505; t=0.694 p=0.499 (Welch p=0.493); cells median 333
cells,pv (b,b) fam: ctrl 0.563, cre 0.545; t=0.602 p=0.557 (Welch p=0.571); cells median 333
cells,pv (b,b) nov: ctrl 0.519, cre 0.485; t=1.053 p=0.31 (Welch p=0.295); cells median 333

Result: reproduced. Under every reading and both trial types, the across-day PV correlation does not differ between groups: p=0.30 to 0.56 (Welch 0.29 to 0.58). Means are 0.52 to 0.58 (control) and 0.49 to 0.55 (Cre).

figs3eg-across-day-decoding-no-difference¶

Position decoders trained on one day and tested on other days did not differ in accuracy between control and Cre mice.

All tracked cells; the decoder is fit on the mean map of all trials of one day and tested on each trial of every other day. Readings: per-mouse value (a) mean of the off-diagonal entries, (b) with the diagonal filled by the within-day leave-one-trial-out error (all tracked cells, no subsampling).

In [24]:
rows = []
rng_x = np.random.default_rng(3)
for m in CTRL + CRE:
    cols = TRACK[m]
    for tt in ("fam", "nov"):
        Rs = [S[(m, d)]["R"][tidx(S[(m, d)], tt)][:, :, cols[d]] for d in range(6)]
        Os = [S[(m, d)]["occ"][tidx(S[(m, d)], tt)] for d in range(6)]
        E = np.array([[stx3.decode_cross(Rs[i], Rs[j], Os[j]) if i != j else np.nan for j in range(6)] for i in range(6)])
        off = np.nanmean(E)
        for d in range(6):
            E[d, d] = stx3.decode_loo(Rs[d], Os[d], rng_x, n_cells=None, n_iter=1) if Rs[d].shape[2] else np.nan
        rows.append(dict(mouse=m, virus=virus_of(m), tt=tt, a=off, b=np.nanmean(E)))
XD = pd.DataFrame(rows)
S3EG = {}
for tt in ("fam", "nov"):
    d = XD[XD.tt == tt]
    for rd in ("a", "b"):
        t = ttest2(d[d.virus == "ctrl"][rd], d[d.virus == "cre"][rd]); S3EG[(rd, tt)] = t
        print(f"{tt} reading {rd}: ctrl {d[d.virus == 'ctrl'][rd].mean():.1f} cm, cre {d[d.virus == 'cre'][rd].mean():.1f} cm; t={t['t']:.3f} p={t['p']:.3g} (Welch p={t['p_welch']:.3g})")
fam reading a: ctrl 24.9 cm, cre 26.8 cm; t=-0.495 p=0.628 (Welch p=0.633)
fam reading b: ctrl 22.2 cm, cre 23.9 cm; t=-0.491 p=0.631 (Welch p=0.636)
nov reading a: ctrl 27.0 cm, cre 29.0 cm; t=-0.454 p=0.657 (Welch p=0.631)
nov reading b: ctrl 24.1 cm, cre 25.9 cm; t=-0.459 p=0.653 (Welch p=0.629)

Result: reproduced. The across-day decoding error does not differ between groups under either reading: p=0.63 to 0.66. Control is 22 to 27 cm, Cre 24 to 29 cm.

Single place fields (Fig 3F-I)¶

Fields from 1000 within-trial shuffles of each trial type's trial-averaged map (helper find_fields): contiguous bins above the 95th percentile of the null, at least 20 cm. Readings: fields (a) all candidates, (b) only those with a formation lap; width averaged (x) over fields, (y) over cells (each cell's mean width); cells for fields per cell (a) cells with at least one field, (b) place cells of that type and day (cells with no field count 0).

In [25]:
FLD = []
for (m, fd), s in S.items():
    for tt, flds in s["fields"].items():
        for (c, lo, hi, form) in flds:
            FLD.append(dict(mouse=m, virus=virus_of(m), day=fd + 1, tt=tt, cell=c, width=(hi - lo) * 10.0, form=form >= 0))
FLD = pd.DataFrame(FLD)
print(FLD.groupby(["virus", "tt"]).agg(fields=("width", "size"), with_formation=("form", "mean"), width_mean=("width", "mean")).round(3).to_string())
print("width range (cm):", FLD.width.min(), "-", FLD.width.max())

def width_table(tt, fsel, avg):
    d = FLD[(FLD.tt == tt) & (FLD.form | (fsel == "a"))]
    if avg == "x":
        return d.groupby(["mouse", "virus", "day"], as_index=False).width.mean()
    return d.groupby(["mouse", "virus", "day", "cell"], as_index=False).width.mean().groupby(["mouse", "virus", "day"], as_index=False).width.mean()

def nfield_table(tt, fsel, csel):
    rows = []
    for (m, fd), s in S.items():
        d = FLD[(FLD.mouse == m) & (FLD.day == fd + 1) & (FLD.tt == tt) & (FLD.form | (fsel == "a"))]
        cnt = np.bincount(d.cell.values.astype(int), minlength=s["n_cells"])
        sel = cnt > 0 if csel == "a" else pcmask(s, tt)
        rows.append(dict(mouse=m, virus=virus_of(m), day=fd + 1, nf=cnt[sel].mean() if sel.any() else np.nan))
    return pd.DataFrame(rows)

def field_claim(tt, kind):
    out = {}
    for r1 in ("a", "b"):
        for r2 in (("x", "y") if kind == "width" else ("a", "b")):
            d = width_table(tt, r1, r2) if kind == "width" else nfield_table(tt, r1, r2)
            v = "width" if kind == "width" else "nf"
            mm = mixed(d[d.day <= 5], v)
            t6 = ttest2(d[(d.day == 6) & (d.virus == "ctrl")][v], d[(d.day == 6) & (d.virus == "cre")][v])
            out[(r1, r2)] = (mm, t6, d.groupby("virus")[v].mean())
            print(f"fields {r1}, {'average' if kind == 'width' else 'cells'} {r2}: days 1-5 {fmt_mixed(mm)}")
            print(f"     day 6 ctrl vs cre t={t6['t']:.2f} p={t6['p']:.3g} (Welch p={t6['p_welch']:.3g}); means ctrl {d[d.virus == 'ctrl'][v].mean():.3f}, cre {d[d.virus == 'cre'][v].mean():.3f}")
    return out
           fields  with_formation  width_mean
virus tt                                     
cre   fam   63716           0.525      60.985
      nov   50500           0.687      50.104
ctrl  fam   80352           0.429      67.884
      nov   67863           0.642      57.858
width range (cm): 20.0 - 260.0

fig3f-narrower-fields-cre-familiar¶

On familiar trials, place fields of Cre mice are narrower than those of control mice.

In [26]:
F3F = field_claim("fam", "width")
fields a, average x: days 1-5 N=9 ctrl, 7 cre; virus F(1,14)=2.12 p=0.167; day F(4,56)=22.3 p=4.74e-11; interaction F(4,56)=1.21 p=0.317
     day 6 ctrl vs cre t=1.53 p=0.147 (Welch p=0.177); means ctrl 68.361, cre 63.394
fields a, average y: days 1-5 N=9 ctrl, 7 cre; virus F(1,14)=3.34 p=0.0888; day F(4,56)=19.8 p=3.21e-10; interaction F(4,56)=1.31 p=0.278
     day 6 ctrl vs cre t=2.05 p=0.0596 (Welch p=0.0649); means ctrl 72.523, cre 66.644
fields b, average x: days 1-5 N=9 ctrl, 7 cre; virus F(1,14)=1.69 p=0.214; day F(4,56)=12 p=3.98e-07; interaction F(4,56)=1.45 p=0.23
     day 6 ctrl vs cre t=1.32 p=0.209 (Welch p=0.255); means ctrl 73.256, cre 68.494
fields b, average y: days 1-5 N=9 ctrl, 7 cre; virus F(1,14)=2.13 p=0.166; day F(4,56)=12.9 p=1.63e-07; interaction F(4,56)=1.68 p=0.166
     day 6 ctrl vs cre t=1.72 p=0.108 (Welch p=0.135); means ctrl 74.860, cre 69.956

Result: not reproduced. Familiar-trial fields of Cre mice are narrower on average (all days, all candidate fields: 61 against 68 cm; on day 6, 63.4 against 68.4 cm). But no reading has a significant virus effect over days 1 to 5 (p=0.089 to 0.214) or on day 6 (p=0.060 to 0.209).

fig3g-narrower-fields-cre-novel¶

On novel trials, place fields of Cre mice are narrower than those of control mice.

In [27]:
F3G = field_claim("nov", "width")
fields a, average x: days 1-5 N=9 ctrl, 7 cre; virus F(1,14)=4.56 p=0.0509; day F(4,56)=15.4 p=1.53e-08; interaction F(4,56)=1.3 p=0.28
     day 6 ctrl vs cre t=2.49 p=0.0259 (Welch p=0.0496); means ctrl 57.859, cre 51.058
fields a, average y: days 1-5 N=9 ctrl, 7 cre; virus F(1,14)=3.96 p=0.0664; day F(4,56)=14.7 p=2.9e-08; interaction F(4,56)=1.15 p=0.34
     day 6 ctrl vs cre t=2.54 p=0.0236 (Welch p=0.0423); means ctrl 60.956, cre 53.814
fields b, average x: days 1-5 N=9 ctrl, 7 cre; virus F(1,14)=4.29 p=0.0574; day F(4,56)=13 p=1.5e-07; interaction F(4,56)=0.889 p=0.477
     day 6 ctrl vs cre t=1.48 p=0.162 (Welch p=0.19); means ctrl 60.557, cre 53.998
fields b, average y: days 1-5 N=9 ctrl, 7 cre; virus F(1,14)=3.5 p=0.0822; day F(4,56)=12.3 p=3.15e-07; interaction F(4,56)=0.724 p=0.579
     day 6 ctrl vs cre t=1.27 p=0.226 (Welch p=0.258); means ctrl 62.970, cre 56.477

Result: partially reproduced. On novel trials Cre fields are narrower. With all candidate fields, day 6 differs: t=2.49, p=0.026 (Welch 0.050) for the field average, and t=2.54, p=0.024 for the cell average. The days 1 to 5 virus effect is not significant under any reading (p=0.051 to 0.082). With formation-lap fields only, neither test is significant.

fig3h-more-fields-per-cell-cre-familiar¶

On familiar trials, place cells of Cre mice have more place fields per cell than those of control mice.

In [28]:
F3H = field_claim("fam", "nf")
fields a, cells a: days 1-5 N=9 ctrl, 7 cre; virus F(1,14)=17.5 p=0.000921; day F(4,56)=3.25 p=0.0181; interaction F(4,56)=2.54 p=0.0499
     day 6 ctrl vs cre t=-4.64 p=0.000379 (Welch p=0.000896); means ctrl 1.392, cre 1.572
fields a, cells b: days 1-5 N=9 ctrl, 7 cre; virus F(1,14)=12.9 p=0.00298; day F(4,56)=1.22 p=0.315; interaction F(4,56)=1.68 p=0.167
     day 6 ctrl vs cre t=-4.48 p=0.000521 (Welch p=0.00155); means ctrl 1.358, cre 1.532
fields b, cells a: days 1-5 N=9 ctrl, 7 cre; virus F(1,14)=15.9 p=0.00136; day F(4,56)=8.1 p=3.15e-05; interaction F(4,56)=1.62 p=0.182
     day 6 ctrl vs cre t=-5.41 p=9.15e-05 (Welch p=0.000971); means ctrl 1.187, cre 1.365
fields b, cells b: days 1-5 N=9 ctrl, 7 cre; virus F(1,14)=4.96 p=0.0429; day F(4,56)=24.3 p=1.11e-11; interaction F(4,56)=1.1 p=0.368
     day 6 ctrl vs cre t=-2.25 p=0.041 (Welch p=0.0509); means ctrl 0.592, cre 0.820

Result: reproduced. On familiar trials Cre cells have more fields per cell under all four readings. Over days 1 to 5 the virus p is 0.0009 to 0.043. On day 6, p is 9e-5 to 0.041 (Welch up to 0.051). With all fields and cells with a field, the means are 1.57 (Cre) and 1.39 (control).

fig3i-more-fields-per-cell-cre-novel¶

On novel trials, place cells of Cre mice have more place fields per cell than those of control mice.

In [29]:
F3I = field_claim("nov", "nf")
fields a, cells a: days 1-5 N=9 ctrl, 7 cre; virus F(1,14)=13 p=0.00284; day F(4,56)=8.04 p=3.41e-05; interaction F(4,56)=3.51 p=0.0126
     day 6 ctrl vs cre t=-6.22 p=2.24e-05 (Welch p=0.000182); means ctrl 1.275, cre 1.398
fields a, cells b: days 1-5 N=9 ctrl, 7 cre; virus F(1,14)=14.8 p=0.00179; day F(4,56)=2.31 p=0.0694; interaction F(4,56)=3.68 p=0.00993
     day 6 ctrl vs cre t=-4.93 p=0.000221 (Welch p=0.000844); means ctrl 1.240, cre 1.364
fields b, cells a: days 1-5 N=9 ctrl, 7 cre; virus F(1,14)=9.53 p=0.00804; day F(4,56)=5.71 p=0.000634; interaction F(4,56)=3.96 p=0.00667
     day 6 ctrl vs cre t=-5.03 p=0.000186 (Welch p=0.00109); means ctrl 1.229, cre 1.341
fields b, cells b: days 1-5 N=9 ctrl, 7 cre; virus F(1,14)=3.83 p=0.0705; day F(4,56)=21.1 p=1.21e-10; interaction F(4,56)=2.17 p=0.0838
     day 6 ctrl vs cre t=-2.08 p=0.0564 (Welch p=0.0709); means ctrl 0.826, cre 0.985

Result: reproduced. On novel trials Cre cells have more fields per cell under three of four readings, with days 1 to 5 virus p=0.002 to 0.008 and day 6 p=2e-5 to 0.0002. The fourth reading (formation-lap fields, place cells) gives p=0.071 and 0.056. The criterion lists these readings, and a claim is reproduced when it holds under any of them; the failing reading counts place cells, as the paper's words "place cells ... had more place fields" do, so the outcome is weaker than the count of readings suggests.

Block 6 population activity (Fig 4, S6)¶

Each cell's binned dF/F on a block trial is divided by the cell's mean over the bins of the 10 trials before the block (as baseline_avg_act in the authors' code); the population value is log10 of the mean over cells; the mouse-day value is its mean over bins and block trials of the type (Methods, Novel arm population activity rate). With dF/F, a cell whose baseline mean is at or below 0 has no ratio; such cells are dropped and counted. Variants: (v1) the code's population normalisation (mean over cells of the block activity over the mean over cells of the baseline); (v2) Fig 4A legend, log per cell before averaging, over cells and bins where the ratio is positive.

In [30]:
def block_values(s, block=None):
    """Per trial and bin, normalized population activity for the block (default: first block
    with novel trials). Returns dict with trials, values (main, v1, v2) and dropped cells."""
    if block is None:
        first, tr = block_test(s)
    else:
        tr = np.flatnonzero(s["block"] == block)
        if len(tr) == 0:
            return None
        first = tr[0]
    if first < 10:
        return None
    base_tr = np.arange(first - 10, first)
    base = np.nanmean(s["R"][base_tr], axis=(0, 1))
    ok = base > 0
    X = s["R"][tr][:, :, ok] / base[ok]
    with np.errstate(invalid="ignore", divide="ignore"):
        main = np.log10(np.nanmean(X, axis=2))
        v1 = np.log10(np.nanmean(s["R"][tr], axis=2) / np.nanmean(base))
        lx = np.where(X > 0, np.log10(X), np.nan)
        v2 = np.nanmean(lx, axis=2)
    return dict(trials=tr, main=main, v1=v1, v2=v2, dropped=int((~ok).sum()), n=len(ok), percell=np.nanmean(X, axis=1))

BV = {}
for (m, fd), s in S.items():
    BV[(m, fd)] = block_values(s)
rows = []
for (m, fd), b in BV.items():
    s = S[(m, fd)]
    if b is None:
        continue
    for tt in ("fam", "nov"):
        sel = np.isin(b["trials"], tidx(s, tt))
        for k in ("main", "v1", "v2"):
            rows.append(dict(mouse=m, virus=virus_of(m), day=fd + 1, tt=tt, var=k, val=np.nanmean(b[k][sel]),
                             stem_a=np.nanmean(b[k][sel][:, :15]), arm_a=np.nanmean(b[k][sel][:, 15:]),
                             stem_b=np.nanmean(b[k][sel][:, :10]), arm_b=np.nanmean(b[k][sel][:, 10:])))
BLK = pd.DataFrame(rows)
drop = pd.DataFrame([dict(mouse=m, day=fd + 1, dropped=b["dropped"], n=b["n"]) for (m, fd), b in BV.items() if b is not None])
print("cells dropped for baseline <= 0: %d of %d (%.2f%%), per mouse-day max %.1f%%" % (drop.dropped.sum(), drop.n.sum(), 100 * drop.dropped.sum() / drop.n.sum(), 100 * (drop.dropped / drop.n).max()))
print("mouse-days without a block value:", [k for k, b in BV.items() if b is None])
print("value range (main):", BLK[BLK["var"] == "main"].val.min().round(3), BLK[BLK["var"] == "main"].val.max().round(3))

def blk_anova(tt, var="main", days=5):
    d = BLK[(BLK.tt == tt) & (BLK["var"] == var) & (BLK.day <= days)]
    mm = mixed(d, "val")
    ph = [ttest2(d[(d.day == k) & (d.virus == "ctrl")].val, d[(d.day == k) & (d.virus == "cre")].val) for k in range(1, 6)]
    adj = holm([t["p"] for t in ph])
    return mm, ph, adj, d
cells dropped for baseline <= 0: 0 of 85746 (0.00%), per mouse-day max 0.0%
mouse-days without a block value: [('Cre-1', 5), ('Cre-2', 5), ('Cre-3', 5), ('Cre-4', 5), ('Cre-5', 5), ('Cre-6', 5), ('Cre-7', 5), ('Ctrl-1', 5), ('Ctrl-2', 5), ('Ctrl-3', 5), ('Ctrl-4', 5), ('Ctrl-5', 5), ('Ctrl-6', 5), ('Ctrl-7', 5), ('Ctrl-8', 5), ('Ctrl-9', 5)]
value range (main): -0.114 0.246

fig4e-block6-familiar-activity-lower-cre¶

During block 6, population activity on familiar trials, relative to the preceding baseline, is lower in Cre mice than in control mice.

In [31]:
F4 = {}
for tt in ("fam", "nov"):
    for var in ("main", "v1", "v2"):
        mm, ph, adj, d = blk_anova(tt, var); F4[(tt, var)] = (mm, ph, adj)
        if tt == "fam":
            print(f"{var}: {fmt_mixed(mm)}")
            print("   means by day:", d.groupby(["virus", "day"]).val.mean().unstack().round(3).to_dict("index"))
            print("   posthoc ctrl vs cre (Student t, Holm over 5 days): t=", [round(t["t"], 2) for t in ph], "p=", adj.round(3).tolist())
main: N=9 ctrl, 7 cre; virus F(1,14)=22.4 p=0.000322; day F(4,56)=1.44 p=0.232; interaction F(4,56)=1.07 p=0.378
   means by day: {'cre': {1: 0.035999998450279236, 2: 0.01600000075995922, 3: 0.004000000189989805, 4: 0.035999998450279236, 5: 0.024000000208616257}, 'ctrl': {1: 0.06800000369548798, 2: 0.07999999821186066, 3: 0.07000000029802322, 4: 0.08399999886751175, 5: 0.08500000089406967}}
   posthoc ctrl vs cre (Student t, Holm over 5 days): t= [3.55, 4.08, 3.13, 3.24, 2.97] p= [0.013, 0.006, 0.018, 0.018, 0.018]
v1: N=9 ctrl, 7 cre; virus F(1,14)=12.5 p=0.00334; day F(4,56)=2.19 p=0.0819; interaction F(4,56)=2.38 p=0.0622
   means by day: {'cre': {1: 0.004000000189989805, 2: -0.028999999165534973, 3: -0.04800000041723251, 4: 0.006000000052154064, 5: -0.007000000216066837}, 'ctrl': {1: 0.008999999612569809, 2: 0.027000000700354576, 3: 0.01899999938905239, 4: 0.029999999329447746, 5: 0.03099999949336052}}
   posthoc ctrl vs cre (Student t, Holm over 5 days): t= [0.61, 2.39, 2.46, 2.55, 3.35] p= [0.552, 0.092, 0.092, 0.092, 0.024]
v2: N=9 ctrl, 7 cre; virus F(1,14)=7.65 p=0.0152; day F(4,56)=3.29 p=0.0171; interaction F(4,56)=2.21 p=0.0796
   means by day: {'cre': {1: -0.10400000214576721, 2: -0.13099999725818634, 3: -0.15800000727176666, 4: -0.09799999743700027, 5: -0.11999999731779099}, 'ctrl': {1: -0.09000000357627869, 2: -0.08100000023841858, 3: -0.09300000220537186, 4: -0.07900000363588333, 5: -0.07800000160932541}}
   posthoc ctrl vs cre (Student t, Holm over 5 days): t= [0.91, 2.14, 2.64, 1.78, 2.81] p= [0.381, 0.15, 0.078, 0.192, 0.07]

Result: reproduced, resting on an assumption (dF/F as activity). Block-6 familiar-trial activity relative to baseline is lower in Cre mice: virus F(1,14)=22.4, p=0.0003. Daily means are 0.068 to 0.085 (control) and 0.004 to 0.036 (Cre). Posthoc Holm p is 0.013 on day 1 and 0.018 on day 5. The variants agree (v1 p=0.003, v2 p=0.015). No cell had a baseline at or below zero.

fig4e-block6-novel-activity-lower-cre¶

During block 6, population activity on novel trials, relative to the preceding baseline, is lower in Cre mice than in control mice.

In [32]:
for var in ("main", "v1", "v2"):
    mm, ph, adj = F4[("nov", var)]
    d = BLK[(BLK.tt == "nov") & (BLK["var"] == var) & (BLK.day <= 5)]
    print(f"{var}: {fmt_mixed(mm)}")
    print("   means by day:", d.groupby(["virus", "day"]).val.mean().unstack().round(3).to_dict("index"))
    print("   posthoc ctrl vs cre (Student t, Holm over 5 days): t=", [round(t["t"], 2) for t in ph], "p=", adj.round(3).tolist())
main: N=9 ctrl, 7 cre; virus F(1,14)=39.9 p=1.9e-05; day F(4,56)=4.47 p=0.00332; interaction F(4,56)=1.85 p=0.132
   means by day: {'cre': {1: 0.05700000002980232, 2: 0.03799999877810478, 3: 0.03200000151991844, 4: 0.06700000166893005, 5: 0.05999999865889549}, 'ctrl': {1: 0.0949999988079071, 2: 0.11500000208616257, 3: 0.11699999868869781, 4: 0.13699999451637268, 5: 0.14499999582767487}}
   posthoc ctrl vs cre (Student t, Holm over 5 days): t= [3.4, 4.77, 4.02, 4.02, 4.76] p= [0.004, 0.001, 0.004, 0.004, 0.001]
v1: N=9 ctrl, 7 cre; virus F(1,14)=14.1 p=0.00212; day F(4,56)=2.33 p=0.0667; interaction F(4,56)=2.55 p=0.0493
   means by day: {'cre': {1: 0.0020000000949949026, 2: -0.04100000113248825, 3: -0.061000000685453415, 4: -0.014999999664723873, 5: -0.00800000037997961}, 'ctrl': {1: 0.00800000037997961, 2: 0.023000000044703484, 3: 0.01899999938905239, 4: 0.03700000047683716, 5: 0.032999999821186066}}
   posthoc ctrl vs cre (Student t, Holm over 5 days): t= [0.45, 2.61, 2.82, 2.94, 3.08] p= [0.657, 0.043, 0.043, 0.043, 0.041]
v2: N=9 ctrl, 7 cre; virus F(1,14)=13.9 p=0.00223; day F(4,56)=3.23 p=0.0187; interaction F(4,56)=2.1 p=0.0928
   means by day: {'cre': {1: -0.10899999737739563, 2: -0.1469999998807907, 3: -0.17399999499320984, 4: -0.12099999934434891, 5: -0.12999999523162842}, 'ctrl': {1: -0.09099999815225601, 2: -0.08500000089406967, 3: -0.09700000286102295, 4: -0.08100000023841858, 5: -0.07999999821186066}}
   posthoc ctrl vs cre (Student t, Holm over 5 days): t= [1.08, 2.85, 3.23, 2.73, 3.14] p= [0.3, 0.039, 0.03, 0.039, 0.03]

Result: reproduced, resting on an assumption. Novel-trial activity is lower in Cre mice: virus F(1,14)=39.9, p=1.9e-5. Posthoc Holm p is 0.004 on day 1 and 0.001 on day 5. The variants agree (v1 p=0.002, v2 p=0.002).

fig4e-novel-minus-familiar-larger-control¶

The difference between novel and familiar trial population activity in block 6 is larger in control mice than in Cre mice.

In [33]:
F4D = {}
for var in ("main", "v1", "v2"):
    d = BLK[(BLK["var"] == var) & (BLK.day <= 5)].pivot_table(index=["mouse", "virus", "day"], columns="tt", values="val").reset_index()
    d["diff"] = d["nov"] - d["fam"]
    mm = mixed(d, "diff"); F4D[var] = (mm, d.groupby("virus")["diff"].mean())
    print(f"{var}: {fmt_mixed(mm)}; mean novel minus familiar ctrl {d[d.virus == 'ctrl']['diff'].mean():.3f}, cre {d[d.virus == 'cre']['diff'].mean():.3f}")
main: N=9 ctrl, 7 cre; virus F(1,14)=5.16 p=0.0395; day F(4,56)=5.88 p=0.000503; interaction F(4,56)=0.712 p=0.587; mean novel minus familiar ctrl 0.044, cre 0.028
v1: N=9 ctrl, 7 cre; virus F(1,14)=1.26 p=0.28; day F(4,56)=0.685 p=0.605; interaction F(4,56)=1.87 p=0.128; mean novel minus familiar ctrl 0.001, cre -0.010
v2: N=9 ctrl, 7 cre; virus F(1,14)=2.72 p=0.121; day F(4,56)=1.16 p=0.338; interaction F(4,56)=0.98 p=0.426; mean novel minus familiar ctrl -0.003, cre -0.014

Result: reproduced, resting on an assumption. Novel minus familiar activity is larger in control mice (0.044 against 0.028): virus F(1,14)=5.16, p=0.040. The variants v1 and v2 do not show it (p=0.28, 0.12).

fig4-block6-activity-increase-pattern¶

In block 6 population activity increased above baseline on familiar and novel trials in both groups, more on the arms than on the stem, and more on novel than on familiar trials in both groups.

Per mouse, mean over days 1 to 5 of the main measure; group means. Stem readings: (a) first 150 cm, (b) first 100 cm.

In [34]:
d = BLK[(BLK["var"] == "main") & (BLK.day <= 5)].groupby(["mouse", "virus", "tt"], as_index=False)[["val", "stem_a", "arm_a", "stem_b", "arm_b"]].mean()
gm = d.groupby(["virus", "tt"])[["val", "stem_a", "arm_a", "stem_b", "arm_b"]].mean()
print(gm.round(3).to_string())
PAT = {}
for v in ("ctrl", "cre"):
    i_ = bool(gm.loc[(v, "fam"), "val"] > 0 and gm.loc[(v, "nov"), "val"] > 0)
    ii_a = bool(all(gm.loc[(v, t), "arm_a"] > gm.loc[(v, t), "stem_a"] for t in ("fam", "nov")))
    ii_b = bool(all(gm.loc[(v, t), "arm_b"] > gm.loc[(v, t), "stem_b"] for t in ("fam", "nov")))
    iii = bool(gm.loc[(v, "nov"), "val"] > gm.loc[(v, "fam"), "val"])
    PAT[v] = (i_, ii_a, ii_b, iii)
    print(f"{v}: (i) both above 0: {i_}; (ii) arm > stem, stem 150 cm: {ii_a}, stem 100 cm: {ii_b}; (iii) novel > familiar: {iii}")
print("per mouse familiar and novel values:", d.pivot(index="mouse", columns="tt", values="val").round(3).to_dict("index"))
             val  stem_a  arm_a  stem_b  arm_b
virus tt                                      
cre   fam  0.023   0.023  0.024   0.029  0.020
      nov  0.051   0.037  0.065   0.032  0.060
ctrl  fam  0.077   0.067  0.088   0.073  0.080
      nov  0.122   0.080  0.164   0.072  0.147
ctrl: (i) both above 0: True; (ii) arm > stem, stem 150 cm: True, stem 100 cm: True; (iii) novel > familiar: True
cre: (i) both above 0: True; (ii) arm > stem, stem 150 cm: True, stem 100 cm: False; (iii) novel > familiar: True
per mouse familiar and novel values: {'Cre-1': {'fam': 0.03700000047683716, 'nov': 0.054999999701976776}, 'Cre-2': {'fam': 0.020999999716877937, 'nov': 0.02199999988079071}, 'Cre-3': {'fam': 0.03099999949336052, 'nov': 0.057999998331069946}, 'Cre-4': {'fam': 0.032999999821186066, 'nov': 0.08100000023841858}, 'Cre-5': {'fam': 0.01899999938905239, 'nov': 0.05299999937415123}, 'Cre-6': {'fam': -0.009999999776482582, 'nov': 0.01600000075995922}, 'Cre-7': {'fam': 0.03200000151991844, 'nov': 0.07100000232458115}, 'Ctrl-1': {'fam': 0.07800000160932541, 'nov': 0.13199999928474426}, 'Ctrl-2': {'fam': 0.10199999809265137, 'nov': 0.15000000596046448}, 'Ctrl-3': {'fam': 0.05700000002980232, 'nov': 0.11299999803304672}, 'Ctrl-4': {'fam': 0.05299999937415123, 'nov': 0.09000000357627869}, 'Ctrl-5': {'fam': 0.07699999958276749, 'nov': 0.12800000607967377}, 'Ctrl-6': {'fam': 0.06300000101327896, 'nov': 0.11100000143051147}, 'Ctrl-7': {'fam': 0.09700000286102295, 'nov': 0.11500000208616257}, 'Ctrl-8': {'fam': 0.04399999976158142, 'nov': 0.10499999672174454}, 'Ctrl-9': {'fam': 0.12600000202655792, 'nov': 0.15299999713897705}}

Result: reproduced, resting on assumptions (dF/F as activity; stem as the first 150 cm). In both groups, familiar and novel values are above 0 (control 0.077 and 0.122, Cre 0.023 and 0.051), and novel exceeds familiar. With the stem as the first 150 cm, arm exceeds stem for both types in both groups. With a 100 cm stem, Cre familiar trials do not show it (arm 0.020, stem 0.029), so the readings give different outcomes; the 150 cm stem is adopted because the Methods say the stem and the arms are of equal length.

fig4e-novel-increase-grows-over-days¶

The increase in activity on novel trials did not dissipate over days and grew stronger over the five days.

In [35]:
for var in ("main", "v1", "v2"):
    mm = F4[("nov", var)][0]
    d = BLK[(BLK.tt == "nov") & (BLK["var"] == var) & (BLK.day <= 5)]
    dm = d.groupby("day").val.mean()
    print(f"{var}: day F({mm['day']['df1']},{mm['day']['df2']})={mm['day']['F']:.3g} p={mm['day']['p']:.3g}; pooled mean day 1 {dm[1]:.3f}, day 5 {dm[5]:.3f}")
main: day F(4,56)=4.47 p=0.00332; pooled mean day 1 0.078, day 5 0.108
v1: day F(4,56)=2.33 p=0.0667; pooled mean day 1 0.005, day 5 0.015
v2: day F(4,56)=3.23 p=0.0187; pooled mean day 1 -0.099, day 5 -0.102

Result: reproduced, resting on an assumption. The day main effect on novel-trial activity is F(4,56)=4.47, p=0.003 (paper F(4,56)=4.13, p=0.005). The pooled mean rises from 0.078 on day 1 to 0.108 on day 5. Variant v1 gives p=0.067.

fig4d-activity-increase-spread-across-cells¶

On day 5 the larger activity increase of control mice is spread over a large part of the population, roughly half of the cells on novel trials, and is not due to a small population of highly active cells.

Per cell, day 5 block 6 trials of the type: binned ratio to baseline, averaged over bins and trials; per mouse, quantiles of that distribution over cells; across-animal mean per group.

In [36]:
qs = np.round(np.arange(0.1, 1.0, 0.1), 1)
Q4D = {}
for tt in ("nov", "fam"):
    rows = []
    for m in CTRL + CRE:
        s = S[(m, 4)]; b = BV[(m, 4)]
        sel = np.isin(b["trials"], tidx(s, tt))
        pc = np.nanmean(b["percell"][sel], axis=0)
        rows.append(dict(mouse=m, virus=virus_of(m), **{f"q{q}": np.nanquantile(pc, q) for q in qs}))
    d = pd.DataFrame(rows); g = d.groupby("virus")[[f"q{q}" for q in qs]].mean()
    above = {q: bool(g.loc["ctrl", f"q{q}"] > g.loc["cre", f"q{q}"]) for q in qs}
    Q4D[tt] = (g, above)
    print(tt, "across-animal mean quantile of per-cell ratio to baseline:"); print(g.round(3).to_string())
    print("   control above Cre at deciles:", above)
nov across-animal mean quantile of per-cell ratio to baseline:
        q0.1   q0.2   q0.3   q0.4   q0.5   q0.6   q0.7   q0.8   q0.9
virus                                                               
cre    0.518  0.660  0.769  0.865  0.968  1.084  1.234  1.463  1.944
ctrl   0.498  0.686  0.828  0.957  1.084  1.245  1.465  1.832  2.624
   control above Cre at deciles: {np.float64(0.1): False, np.float64(0.2): True, np.float64(0.3): True, np.float64(0.4): True, np.float64(0.5): True, np.float64(0.6): True, np.float64(0.7): True, np.float64(0.8): True, np.float64(0.9): True}
fam across-animal mean quantile of per-cell ratio to baseline:
        q0.1   q0.2   q0.3   q0.4   q0.5   q0.6   q0.7   q0.8   q0.9
virus                                                               
cre    0.710  0.792  0.864  0.929  0.994  1.067  1.146  1.271  1.477
ctrl   0.711  0.825  0.917  1.001  1.090  1.189  1.307  1.492  1.879
   control above Cre at deciles: {np.float64(0.1): True, np.float64(0.2): True, np.float64(0.3): True, np.float64(0.4): True, np.float64(0.5): True, np.float64(0.6): True, np.float64(0.7): True, np.float64(0.8): True, np.float64(0.9): True}

Result: reproduced, resting on an assumption. On day 5 novel trials, the across-animal mean quantile of the per-cell ratio is higher in control than in Cre mice at every decile from 0.2 to 0.9: 1.08 against 0.97 at the median and 2.62 against 1.94 at 0.9. So the shift is not confined to the top tail. Familiar trials show the same at every decile.

figs6b-block4-activity-no-difference¶

In the fourth (familiar) block, normalized population activity did not differ between control and Cre mice.

In [37]:
rows = []
for (m, fd), s in S.items():
    if fd > 4:
        continue
    b = block_values(s, block=3)
    if b is None:
        continue
    for k in ("main", "v1", "v2"):
        rows.append(dict(mouse=m, virus=virus_of(m), day=fd + 1, var=k, val=np.nanmean(b[k])))
B4 = pd.DataFrame(rows)
S6B = {}
for var, d in B4.groupby("var"):
    mm = mixed(d, "val"); S6B[var] = mm
    print(f"{var}: {fmt_mixed(mm)}; means ctrl {d[d.virus == 'ctrl'].val.mean():.3f}, cre {d[d.virus == 'cre'].val.mean():.3f}")
# before round 1 the block numbers of a split day's second file restarted at 0 (helper _concat_scans);
# the same test with that numbering, to show what the continued numbering changed
rows = []
for (m, fd), s in S.items():
    if fd > 4:
        continue
    if s["n_scans"] > 1:
        n0 = s["scan_trials"][0]
        blk = s["block"].copy(); blk[n0:] -= blk[n0]
        b = block_values(dict(s, block=blk), block=3)
        print(f"{m} day {fd + 1}: trials per file {s['scan_trials']}; block 4 trials, continued {np.flatnonzero(s['block'] == 3).tolist()}, restarted {np.flatnonzero(blk == 3).tolist()}")
    else:
        b = block_values(s, block=3)
    if b is not None:
        rows.append(dict(mouse=m, virus=virus_of(m), day=fd + 1, val=np.nanmean(b["main"])))
d = pd.DataFrame(rows)
print(f"restarted numbering, main: {fmt_mixed(mixed(d, 'val'))}; means ctrl {d[d.virus == 'ctrl'].val.mean():.3f}, cre {d[d.virus == 'cre'].val.mean():.3f}")
main: N=9 ctrl, 7 cre; virus F(1,14)=0.118 p=0.736; day F(4,56)=1.53 p=0.207; interaction F(4,56)=0.552 p=0.698; means ctrl 0.032, cre 0.024
v1: N=9 ctrl, 7 cre; virus F(1,14)=0.00216 p=0.964; day F(4,56)=1.34 p=0.265; interaction F(4,56)=0.49 p=0.743; means ctrl 0.000, cre 0.001
v2: N=9 ctrl, 7 cre; virus F(1,14)=0.403 p=0.536; day F(4,56)=1.38 p=0.251; interaction F(4,56)=0.481 p=0.749; means ctrl -0.098, cre -0.111
Ctrl-2 day 4: trials per file [20, 120]; block 4 trials, continued [60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79], restarted [80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]
Ctrl-4 day 2: trials per file [36, 100]; block 4 trials, continued [56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75], restarted [96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135]
restarted numbering, main: N=9 ctrl, 7 cre; virus F(1,14)=0.118 p=0.736; day F(4,56)=1.51 p=0.212; interaction F(4,56)=0.671 p=0.615; means ctrl 0.032, cre 0.024

Result: reproduced. Block-4 normalized activity does not differ between groups: virus F(1,14)=0.118, p=0.736 (paper F(1,14)=0.139, p=0.715). The variants give p=0.964 (v1) and p=0.536 (v2). With the block numbers of the two split days restarting in their second file, as before round 1, block 4 of Ctrl-2 day 4 and Ctrl-4 day 2 moves to later trials (for Ctrl-4 day 2, to its novel block), but the group means (0.032 and 0.024) and the virus test (F(1,14)=0.118, p=0.736) are the same; only the interaction changes (p=0.615 against 0.698).

figs6e-familiar-activity-trials-since-novel¶

Familiar trial activity in block 6 depends on the number of trials since the last novel trial, in control and in Cre mice.

Per familiar trial of block 6 after the first novel trial, the main population value (mean over bins), grouped by trials since the last novel trial; two-way repeated measures ANOVA (day and level within) per group, complete cases.

In [38]:
import pingouin as pg
rows = []
for (m, fd), s in S.items():
    b = BV[(m, fd)] if fd < 5 else block_values(s, block=5)
    if b is None:
        continue
    lr = s["LR"][b["trials"]]; nov = s["novel_arm"]
    last = -1
    for k, t in enumerate(b["trials"]):
        if lr[k] == nov:
            last = k; continue
        if last < 0:
            continue
        rows.append(dict(mouse=m, virus=virus_of(m), day=fd + 1, since=k - last, val=np.nanmean(b["main"][k])))
TS = pd.DataFrame(rows)
S6E = {}
for lv in ("a", "b"):
    for dy in ("i", "ii"):
        d = TS[TS.day <= (5 if dy == "i" else 6)].copy()
        if lv == "a":
            d = d[d.since <= 3]
        else:
            d["since"] = d.since.clip(upper=3)
        g = d.groupby(["mouse", "virus", "day", "since"], as_index=False).val.mean()
        for v in ("ctrl", "cre"):
            gv = g[g.virus == v]
            cnt = gv.groupby("mouse").size()
            full = cnt[cnt == gv.day.nunique() * gv.since.nunique()].index
            gv = gv[gv.mouse.isin(full)]
            try:
                a = pg.rm_anova(data=gv, dv="val", within=["day", "since"], subject="mouse")
                pcol = "p_unc" if "p_unc" in a.columns else "p-unc"
                r = a[a.Source == "since"].iloc[0]
                S6E[(lv, dy, v)] = dict(F=float(r["F"]), p=float(r[pcol]), df=(int(r["ddof1"]), int(r["ddof2"])), n=len(full),
                                        means=gv.groupby("since").val.mean().round(3).to_dict())
            except Exception as e:
                S6E[(lv, dy, v)] = dict(F=np.nan, p=np.nan, df=None, n=len(full), means=gv.groupby("since").val.mean().round(3).to_dict(), err=str(e)[:80])
            print(f"levels ({lv}) days ({dy}) {v}: {S6E[(lv, dy, v)]}")
levels (a) days (i) ctrl: {'F': 4.750615697312792, 'p': 0.02401433945041513, 'df': (2, 16), 'n': 9, 'means': {1: 0.09200000017881393, 2: 0.05999999865889549, 3: 0.0560000017285347}}
levels (a) days (i) cre: {'F': 22.390002172005797, 'p': 0.0016495882333115509, 'df': (2, 6), 'n': 4, 'means': {1: 0.028999999165534973, 2: 0.009999999776482582, 3: -0.0010000000474974513}}
levels (a) days (ii) ctrl: {'F': 6.190685285588479, 'p': 0.010202179193674233, 'df': (2, 16), 'n': 9, 'means': {1: 0.07999999821186066, 2: 0.05400000140070915, 3: 0.050999999046325684}}
levels (a) days (ii) cre: {'F': 10.734194709218501, 'p': 0.010422074274762941, 'df': (2, 6), 'n': 4, 'means': {1: 0.023000000044703484, 2: 0.007000000216066837, 3: -0.004000000189989805}}
levels (b) days (i) ctrl: {'F': 5.476154315972753, 'p': 0.0154238251137963, 'df': (2, 16), 'n': 9, 'means': {1: 0.09200000017881393, 2: 0.05999999865889549, 3: 0.050999999046325684}}
levels (b) days (i) cre: {'F': 16.48919259650431, 'p': 0.003647390158078272, 'df': (2, 6), 'n': 4, 'means': {1: 0.028999999165534973, 2: 0.009999999776482582, 3: 0.0010000000474974513}}
levels (b) days (ii) ctrl: {'F': 6.86355490126987, 'p': 0.007042686605123948, 'df': (2, 16), 'n': 9, 'means': {1: 0.07999999821186066, 2: 0.05400000140070915, 3: 0.04600000008940697}}
levels (b) days (ii) cre: {'F': 9.692347265936698, 'p': 0.013204985423906024, 'df': (2, 6), 'n': 4, 'means': {1: 0.023000000044703484, 2: 0.007000000216066837, 3: -0.0020000000949949026}}

Result: reproduced, resting on an assumption. Under every reading, the trials-since-novel effect is significant in control mice (9 mice, F(2,16)=4.75 to 6.86, p=0.024 to 0.007; paper F(2,16)=6.46, p=0.009). It is also significant in Cre mice (4 mice with complete data, as the paper's df imply; F(2,6)=9.7 to 22.4, p=0.013 to 0.002; paper F(2,6)=15.2, p=0.004). Activity is highest on the trial just after a novel trial and falls with the trials since.

Reward representation (Fig 5, S7)¶

Zone fronts as in the data check. A cell's peak is the bin of the maximum of its trial-averaged map on all trials of the type.

In [39]:
def peaks(s, tt):
    M = np.nanmean(s["R"][tidx(s, tt)], 0)
    return np.nanargmax(np.nan_to_num(M, nan=-np.inf), axis=0)

def arm_of(s, tt):
    return s["novel_arm"] if tt == "nov" else -s["novel_arm"]

figs7b-reward-overrepresentation¶

Control mice allocate a greater proportion of place cells to the locations just before the reward zone than Cre mice, on familiar and novel trials.

In [40]:
S7B = {}
for src in ("dep", "re"):
    rows = []
    for (m, fd), s in S.items():
        for tt in ("fam", "nov"):
            pcm = pcmask(s, tt, src); fb = FB[arm_of(s, tt)]
            pk = peaks(s, tt)[pcm]
            k = int(((pk >= fb - 5) & (pk < fb)).sum()); n = int(pcm.sum())
            rows.append(dict(mouse=m, virus=virus_of(m), day=fd + 1, tt=tt, prop=k / n, lg=stx3.logit_prop(k, n)))
    d = pd.DataFrame(rows)
    for tt in ("fam", "nov"):
        mm = mixed(d[d.tt == tt], "lg"); S7B[(src, tt)] = (mm, d[d.tt == tt].groupby("virus").prop.mean())
        print(f"place cells {src}, {tt}: {fmt_mixed(mm)}; mean proportion ctrl {d[(d.tt == tt) & (d.virus == 'ctrl')].prop.mean():.3f}, cre {d[(d.tt == tt) & (d.virus == 'cre')].prop.mean():.3f}")
place cells dep, fam: N=9 ctrl, 7 cre; virus F(1,14)=5.57 p=0.0333; day F(5,70)=0.241 p=0.943; interaction F(5,70)=0.82 p=0.539; mean proportion ctrl 0.219, cre 0.192
place cells dep, nov: N=9 ctrl, 7 cre; virus F(1,14)=9.27 p=0.00875; day F(5,70)=0.453 p=0.809; interaction F(5,70)=0.951 p=0.454; mean proportion ctrl 0.217, cre 0.174
place cells re, fam: N=9 ctrl, 7 cre; virus F(1,14)=4.51 p=0.052; day F(5,70)=0.335 p=0.89; interaction F(5,70)=0.782 p=0.566; mean proportion ctrl 0.214, cre 0.190
place cells re, nov: N=9 ctrl, 7 cre; virus F(1,14)=8.13 p=0.0128; day F(5,70)=0.848 p=0.521; interaction F(5,70)=1.08 p=0.381; mean proportion ctrl 0.209, cre 0.174

Result: reproduced. Among deposited place cells, control mice have a larger proportion with peaks in the 50 cm before the zone. On familiar trials this is 0.219 against 0.192 (virus F(1,14)=5.57, p=0.033). On novel trials it is 0.217 against 0.174 (F(1,14)=9.27, p=0.009). With recomputed place cells, the familiar effect is p=0.052.

fig5d-reward-cells-fewer-in-cre¶

Control mice have a larger proportion of reward cells, active before the reward zone on both arms, than Cre mice, and the proportion changes over days.

Readings: window (a) the 50 cm before the front, (b) within 50 cm of the front on either side; denominator (i) all cells, (ii) cells significant on both trial types.

In [41]:
def in_win(pk, fb, w):
    return (pk >= fb - 5) & (pk < fb) if w == "a" else (pk >= fb - 5) & (pk < fb + 5)

rows = []
for (m, fd), s in S.items():
    both = pcmask(s, "fam") & pcmask(s, "nov")
    pf, pn = peaks(s, "fam"), peaks(s, "nov")
    for w in ("a", "b"):
        rc = both & in_win(pf, FB[arm_of(s, "fam")], w) & in_win(pn, FB[arm_of(s, "nov")], w)
        for den in ("i", "ii"):
            n = s["n_cells"] if den == "i" else int(both.sum())
            rows.append(dict(mouse=m, virus=virus_of(m), day=fd + 1, reading=w + "," + den, k=int(rc.sum()), n=n,
                             prop=rc.sum() / n, lg=stx3.logit_prop(int(rc.sum()), n)))
RC = pd.DataFrame(rows)
F5D = {}
for rdg, d in RC.groupby("reading"):
    mm = mixed(d, "lg"); F5D[rdg] = mm
    print(f"reading ({rdg}): {fmt_mixed(mm)}")
    print("   mean proportion by day:", d.groupby(["virus", "day"]).prop.mean().unstack().round(4).to_dict("index"))
reading (a,i): N=9 ctrl, 7 cre; virus F(1,14)=7.97 p=0.0136; day F(5,70)=3.01 p=0.0163; interaction F(5,70)=2.25 p=0.0588
   mean proportion by day: {'cre': {1: 0.0265, 2: 0.0275, 3: 0.0255, 4: 0.0274, 5: 0.0272, 6: 0.0411}, 'ctrl': {1: 0.0341, 2: 0.0402, 3: 0.0447, 4: 0.0461, 5: 0.0537, 6: 0.0544}}
reading (a,ii): N=9 ctrl, 7 cre; virus F(1,14)=20.9 p=0.000434; day F(5,70)=0.791 p=0.56; interaction F(5,70)=0.375 p=0.864
   mean proportion by day: {'cre': {1: 0.0461, 2: 0.0438, 3: 0.0444, 4: 0.0425, 5: 0.0463, 6: 0.0529}, 'ctrl': {1: 0.0712, 2: 0.0709, 3: 0.071, 4: 0.0704, 5: 0.0779, 6: 0.0782}}
reading (b,i): N=9 ctrl, 7 cre; virus F(1,14)=5.24 p=0.0381; day F(5,70)=6.41 p=5.9e-05; interaction F(5,70)=2.97 p=0.0173
   mean proportion by day: {'cre': {1: 0.0899, 2: 0.0922, 3: 0.0858, 4: 0.1111, 5: 0.0913, 6: 0.1357}, 'ctrl': {1: 0.0971, 2: 0.116, 3: 0.1388, 4: 0.1392, 5: 0.1506, 6: 0.1689}}
reading (b,ii): N=9 ctrl, 7 cre; virus F(1,14)=14.5 p=0.00193; day F(5,70)=2.22 p=0.0616; interaction F(5,70)=0.712 p=0.617
   mean proportion by day: {'cre': {1: 0.1561, 2: 0.1458, 3: 0.149, 4: 0.1723, 5: 0.1648, 6: 0.1746}, 'ctrl': {1: 0.1978, 2: 0.2081, 3: 0.2237, 4: 0.223, 5: 0.2224, 6: 0.2367}}

Result: reproduced. Control mice have more reward cells under all four readings (virus p=0.0004 to 0.038). The proportion changes over days under readings (a,i) and (b,i) (day p=0.016 and 6e-5) but not (a,ii) and (b,ii) (p=0.56 and 0.062).

fig5d-reward-cells-increase-over-days-control¶

The proportion of reward cells increased over days in control mice.

In [42]:
for rdg, d in RC.groupby("reading"):
    mm = F5D[rdg]; c = d[d.virus == "ctrl"].groupby("day").prop.mean()
    print(f"reading ({rdg}): day F={mm['day']['F']:.3g} p={mm['day']['p']:.3g}; control mean day 1 {c[1]:.4f}, day 6 {c[6]:.4f}, increase {c[6] > c[1]}")
reading (a,i): day F=3.01 p=0.0163; control mean day 1 0.0341, day 6 0.0544, increase True
reading (a,ii): day F=0.791 p=0.56; control mean day 1 0.0712, day 6 0.0782, increase True
reading (b,i): day F=6.41 p=5.9e-05; control mean day 1 0.0971, day 6 0.1689, increase True
reading (b,ii): day F=2.22 p=0.0616; control mean day 1 0.1978, day 6 0.2367, increase True

Result: reproduced (reading a,i). The day main effect is F(5,70)=3.01, p=0.016. The control mean rises from 0.034 on day 1 to 0.054 on day 6. Reading (b,i) agrees (p=6e-5, 0.097 to 0.169). The day effect is not significant under the denominators of significant cells (p=0.56, 0.062), though the control means still rise.

fig5d-reward-cells-above-chance-control-only¶

Averaged across days, the fraction of reward cells exceeds the level expected from random remapping in control mice but not in Cre mice.

Chance readings: (a) per mouse and day, permute the novel-trial peaks across the cells (significant on both types) whose novel peak is on the arm (bin 15 on, stem and arms of equal length), stem peaks kept, 1000 permutations; (b) analytic: arm peaks uniform over the 15 arm bins, independent between types; stem peaks equal. One-sample t-test of the per-mouse mean over days of observed minus chance.

In [43]:
rng_ch = np.random.default_rng(5)
rows = []
for (m, fd), s in S.items():
    both = pcmask(s, "fam") & pcmask(s, "nov")
    pf, pn = peaks(s, "fam")[both], peaks(s, "nov")[both]
    fbf, fbn = FB[arm_of(s, "fam")], FB[arm_of(s, "nov")]
    for w in ("a", "b"):
        obs = int((in_win(pf, fbf, w) & in_win(pn, fbn, w)).sum())
        arm = pn >= 15
        perm = []
        for _ in range(1000):
            q = pn.copy(); q[arm] = rng_ch.permutation(pn[arm])
            perm.append((in_win(pf, fbf, w) & in_win(q, fbn, w)).sum())
        ca = float(np.mean(perm))
        winn = np.flatnonzero(in_win(np.arange(30), fbn, w))
        p_arm = np.isin(np.arange(15, 30), winn).mean()
        fw = in_win(pf, fbf, w)
        cb = float(np.sum(np.where(pf[fw] < 15, in_win(pf[fw], fbn, w).astype(float), p_arm)))
        for den in ("i", "ii"):
            n = s["n_cells"] if den == "i" else int(both.sum())
            rows.append(dict(mouse=m, virus=virus_of(m), day=fd + 1, reading=w + "," + den, obs=obs / n, chance_a=ca / n, chance_b=cb / n))
CH = pd.DataFrame(rows)
F5C = {}
for rdg, d in CH.groupby("reading"):
    g = d.groupby(["mouse", "virus"], as_index=False)[["obs", "chance_a", "chance_b"]].mean()
    for ch in ("chance_a", "chance_b"):
        for v in ("ctrl", "cre"):
            x = g[g.virus == v]
            t = stats.ttest_1samp(x.obs - x[ch], 0)
            F5C[(rdg, ch, v)] = (float(t.statistic), float(t.pvalue), float((x.obs - x[ch]).mean()))
        print(f"fraction ({rdg}), {ch}: ctrl obs {g[g.virus == 'ctrl'].obs.mean():.4f} vs chance {g[g.virus == 'ctrl'][ch].mean():.4f}: t={F5C[(rdg, ch, 'ctrl')][0]:.2f} p={F5C[(rdg, ch, 'ctrl')][1]:.3g}; "
              f"cre obs {g[g.virus == 'cre'].obs.mean():.4f} vs chance {g[g.virus == 'cre'][ch].mean():.4f}: t={F5C[(rdg, ch, 'cre')][0]:.2f} p={F5C[(rdg, ch, 'cre')][1]:.3g}")

# variant: stem ending at 100 cm (bin 10), as the stem readings of fig4-block6-activity-increase-pattern
rng_ch10 = np.random.default_rng(6)
rows = []
for (m, fd), s in S.items():
    both = pcmask(s, "fam") & pcmask(s, "nov")
    pf, pn = peaks(s, "fam")[both], peaks(s, "nov")[both]
    fbf, fbn = FB[arm_of(s, "fam")], FB[arm_of(s, "nov")]
    for w in ("a", "b"):
        obs = int((in_win(pf, fbf, w) & in_win(pn, fbn, w)).sum())
        arm = pn >= 10
        perm = []
        for _ in range(1000):
            q = pn.copy(); q[arm] = rng_ch10.permutation(pn[arm])
            perm.append((in_win(pf, fbf, w) & in_win(q, fbn, w)).sum())
        winn = np.flatnonzero(in_win(np.arange(30), fbn, w))
        p_arm = np.isin(np.arange(10, 30), winn).mean()
        fw = in_win(pf, fbf, w)
        cb = float(np.sum(np.where(pf[fw] < 10, in_win(pf[fw], fbn, w).astype(float), p_arm)))
        for den in ("i", "ii"):
            n = s["n_cells"] if den == "i" else int(both.sum())
            rows.append(dict(mouse=m, virus=virus_of(m), day=fd + 1, reading=w + "," + den, obs=obs / n, chance_a=float(np.mean(perm)) / n, chance_b=cb / n))
CH10 = pd.DataFrame(rows)
for rdg, d in CH10.groupby("reading"):
    g = d.groupby(["mouse", "virus"], as_index=False)[["obs", "chance_a", "chance_b"]].mean()
    for ch in ("chance_a", "chance_b"):
        out = []
        for v in ("ctrl", "cre"):
            x = g[g.virus == v]; t = stats.ttest_1samp(x.obs - x[ch], 0)
            out.append(f"{v} obs {x.obs.mean():.4f} vs chance {x[ch].mean():.4f}: t={t.statistic:.2f} p={t.pvalue:.3g}")
        print(f"stem 100 cm, fraction ({rdg}), {ch}: " + "; ".join(out))
fraction (a,i), chance_a: ctrl obs 0.0455 vs chance 0.0342: t=7.20 p=9.28e-05; cre obs 0.0292 vs chance 0.0233: t=4.99 p=0.00248
fraction (a,i), chance_b: ctrl obs 0.0455 vs chance 0.0345: t=5.32 p=0.00071; cre obs 0.0292 vs chance 0.0290: t=0.10 p=0.925
fraction (a,ii), chance_a: ctrl obs 0.0733 vs chance 0.0551: t=9.51 p=1.23e-05; cre obs 0.0460 vs chance 0.0367: t=5.13 p=0.00216
fraction (a,ii), chance_b: ctrl obs 0.0733 vs chance 0.0552: t=5.92 p=0.000352; cre obs 0.0460 vs chance 0.0461: t=-0.03 p=0.976
fraction (b,i), chance_a: ctrl obs 0.1351 vs chance 0.1269: t=6.69 p=0.000154; cre obs 0.1010 vs chance 0.0974: t=2.73 p=0.0341
fraction (b,i), chance_b: ctrl obs 0.1351 vs chance 0.1456: t=-2.97 p=0.0178; cre obs 0.1010 vs chance 0.1258: t=-6.44 p=0.000665
fraction (b,ii), chance_a: ctrl obs 0.2186 vs chance 0.2055: t=7.75 p=5.47e-05; cre obs 0.1604 vs chance 0.1547: t=2.65 p=0.0378
fraction (b,ii), chance_b: ctrl obs 0.2186 vs chance 0.2346: t=-3.36 p=0.00995; cre obs 0.1604 vs chance 0.2015: t=-7.06 p=0.000404
stem 100 cm, fraction (a,i), chance_a: ctrl obs 0.0455 vs chance 0.0325: t=7.51 p=6.88e-05; cre obs 0.0292 vs chance 0.0224: t=7.32 p=0.000332
stem 100 cm, fraction (a,i), chance_b: ctrl obs 0.0455 vs chance 0.0313: t=6.67 p=0.000157; cre obs 0.0292 vs chance 0.0260: t=2.15 p=0.0755
stem 100 cm, fraction (a,ii), chance_a: ctrl obs 0.0733 vs chance 0.0524: t=10.44 p=6.15e-06; cre obs 0.0460 vs chance 0.0352: t=7.91 p=0.000217
stem 100 cm, fraction (a,ii), chance_b: ctrl obs 0.0733 vs chance 0.0503: t=8.21 p=3.63e-05; cre obs 0.0460 vs chance 0.0415: t=1.99 p=0.0935
stem 100 cm, fraction (b,i), chance_a: ctrl obs 0.1351 vs chance 0.1193: t=9.64 p=1.11e-05; cre obs 0.1010 vs chance 0.0933: t=3.74 p=0.00967
stem 100 cm, fraction (b,i), chance_b: ctrl obs 0.1351 vs chance 0.1203: t=5.16 p=0.000861; cre obs 0.1010 vs chance 0.1030: t=-0.49 p=0.638
stem 100 cm, fraction (b,ii), chance_a: ctrl obs 0.2186 vs chance 0.1932: t=13.15 p=1.06e-06; cre obs 0.1604 vs chance 0.1480: t=3.63 p=0.011
stem 100 cm, fraction (b,ii), chance_b: ctrl obs 0.2186 vs chance 0.1938: t=5.92 p=0.000354; cre obs 0.1604 vs chance 0.1653: t=-0.73 p=0.495

Result: reproduced (chance reading b). With the analytic chance (b) and window (a): control mice exceed chance (0.046 against 0.035, t=5.32, p=0.0007); Cre mice do not (0.029 against 0.029, p=0.925). The same holds with denominator (ii). With the permutation chance (a), Cre mice also exceed chance (p=0.002 and 0.002), which the criterion counts as partial. With the wider window (b), the analytic chance exceeds the observed fraction in both groups. With the stem ending at 100 cm (variant), the analytic chance gives the same result: control above chance (p=0.0002 for (a,i)), Cre not (p=0.076; (a,ii) p=0.094); the permutation chance again puts Cre above chance (p=0.0003).

Place field shifts (Fig 6, S8)¶

Initial PV shift: spatial cross-correlation of population vectors (lags -290 to 290 cm, PV correlation over the overlapping bins), shift = centre of mass in cm, mean of the upper triangle of the first five novel trials (helper initial_shift). Readings: cells (a) all, (b) novel place cells of the day; COM (i) raw cross-correlation, (ii) negative values set to zero.

The raw COM (i) is ill-conditioned: negative correlations at large lags enter its weights, so its value can fall outside the lag range, and on synthetic maps with a known shift it misses the shift (printed below). It is shown, but the clipped COM (ii) is the reading the conclusions rest on.

In [44]:
rows = []
for (m, fd), s in S.items():
    if fd > 4:
        continue
    Rn = s["R"][tidx(s, "nov")]
    for cells in ("a", "b"):
        cm = np.ones(s["n_cells"], bool) if cells == "a" else pcmask(s, "nov")
        for com in ("i", "ii"):
            rows.append(dict(mouse=m, virus=virus_of(m), day=fd + 1, reading=cells + "," + com,
                             shift=stx3.initial_shift(Rn[:, :, cm], clip_negative=(com == "ii"))))
PVS = pd.DataFrame(rows)
print("initial shift range (cm):", PVS["shift"].min().round(1), PVS["shift"].max().round(1))

def pvs_tests(d):
    mm = mixed(d, "shift")
    ph = [ttest2(d[(d.day == k) & (d.virus == "ctrl")]["shift"], d[(d.day == k) & (d.virus == "cre")]["shift"]) for k in range(1, 6)]
    adj = holm([t["p"] for t in ph])
    one = [(v, k, stats.ttest_1samp(d[(d.day == k) & (d.virus == v)]["shift"], 0)) for v in ("ctrl", "cre") for k in range(1, 6)]
    adj1 = holm([o[2].pvalue for o in one])
    return mm, ph, adj, one, adj1

# the centre of mass of the raw cross-correlation (reading i) on synthetic maps with a known shift of -30 cm
for nz in (0.1, 0.5, 1.0):
    r = stx3.synthetic_shift_check(np.random.default_rng(8), true_shift_bins=-3, noise=nz)
    print(f"synthetic, true shift -30 cm, noise sd {nz}: " + "; ".join(f"{k} COM mean {v.mean():.1f} cm, range {v.min():.1f} to {v.max():.1f}" for k, v in r.items()))
print("real data, values outside the +-290 cm lag range:", PVS.groupby("reading")["shift"].apply(lambda x: int((x.abs() > 290).sum())).to_dict())
initial shift range (cm): -622.4 138.9
synthetic, true shift -30 cm, noise sd 0.1: raw COM mean -9.6 cm, range -25.8 to 5.7; clipped COM mean -29.4 cm, range -29.9 to -27.2
synthetic, true shift -30 cm, noise sd 0.5: raw COM mean -26.8 cm, range -132.5 to 63.4; clipped COM mean -20.9 cm, range -49.9 to 5.5
synthetic, true shift -30 cm, noise sd 1.0: raw COM mean 1416.0 cm, range -360.3 to 29179.3; clipped COM mean -6.8 cm, range -61.7 to 79.5
real data, values outside the +-290 cm lag range: {'a,i': 0, 'a,ii': 0, 'b,i': 2, 'b,ii': 0}

fig6c-pv-backward-shift-day1-control¶

Control mice show a population-level backward shift of place fields over the first novel arm trials of day 1, larger than in Cre mice; it is not detectable on later days.

In [45]:
F6C = {}
for rdg, d in PVS.groupby("reading"):
    F6C[rdg] = pvs_tests(d)
    mm, ph, adj, one, adj1 = F6C[rdg]
    print(f"reading ({rdg}): {fmt_mixed(mm)}")
    print("   means by day:", d.groupby(["virus", "day"])["shift"].mean().unstack().round(2).to_dict("index"))
    print("   ctrl vs cre per day: t=", [round(t["t"], 2) for t in ph], "Holm p=", adj.round(3).tolist())
    print("   one-sample vs 0 (Holm over 10):", [(v, k, round(float(o.statistic), 2), round(float(p), 3)) for (v, k, o), p in zip(one, adj1)])
reading (a,i): N=9 ctrl, 7 cre; virus F(1,14)=15.9 p=0.00135; day F(4,56)=0.883 p=0.48; interaction F(4,56)=0.664 p=0.619
   means by day: {'cre': {1: 6.07, 2: 9.09, 3: -2.03, 4: 7.01, 5: 14.6}, 'ctrl': {1: -17.56, 2: -12.33, 3: -10.28, 4: 1.82, 5: -8.15}}
   ctrl vs cre per day: t= [-2.54, -1.61, -0.75, -0.97, -1.95] Holm p= [0.118, 0.388, 0.698, 0.698, 0.287]
   one-sample vs 0 (Holm over 10): [('ctrl', 1, -2.43, 0.412), ('ctrl', 2, -1.34, 1.0), ('ctrl', 3, -1.22, 1.0), ('ctrl', 4, 0.52, 1.0), ('ctrl', 5, -0.99, 1.0), ('cre', 1, 1.23, 1.0), ('cre', 2, 0.98, 1.0), ('cre', 3, -0.33, 1.0), ('cre', 4, 1.73, 1.0), ('cre', 5, 1.83, 1.0)]
reading (a,ii): N=9 ctrl, 7 cre; virus F(1,14)=16.2 p=0.00126; day F(4,56)=1.04 p=0.396; interaction F(4,56)=0.908 p=0.466
   means by day: {'cre': {1: 2.9, 2: 2.22, 3: -2.43, 4: 3.19, 5: 11.93}, 'ctrl': {1: -16.46, 2: -12.92, 3: -11.18, 4: -2.06, 5: -10.82}}
   ctrl vs cre per day: t= [-3.46, -1.52, -0.99, -1.66, -2.59] Holm p= [0.019, 0.358, 0.358, 0.358, 0.085]
   one-sample vs 0 (Holm over 10): [('ctrl', 1, -4.5, 0.02), ('ctrl', 2, -1.89, 0.809), ('ctrl', 3, -1.71, 0.878), ('ctrl', 4, -1.21, 1.0), ('ctrl', 5, -1.93, 0.809), ('cre', 1, 0.68, 1.0), ('cre', 2, 0.32, 1.0), ('cre', 3, -0.45, 1.0), ('cre', 4, 1.12, 1.0), ('cre', 5, 1.74, 0.878)]
reading (b,i): N=9 ctrl, 7 cre; virus F(1,14)=2.3 p=0.152; day F(4,56)=2.72 p=0.0385; interaction F(4,56)=1.18 p=0.328
   means by day: {'cre': {1: -4.63, 2: 15.19, 3: -4.11, 4: 10.49, 5: 19.99}, 'ctrl': {1: -111.09, 2: -21.79, 3: -19.59, 4: -5.76, 5: 2.94}}
   ctrl vs cre per day: t= [-1.39, -1.94, -0.35, -1.89, -1.42] Holm p= [0.535, 0.365, 0.731, 0.365, 0.535]
   one-sample vs 0 (Holm over 10): [('ctrl', 1, -1.68, 1.0), ('ctrl', 2, -1.57, 1.0), ('ctrl', 3, -0.52, 1.0), ('ctrl', 4, -1.02, 1.0), ('ctrl', 5, 0.4, 1.0), ('cre', 1, -0.38, 1.0), ('cre', 2, 1.25, 1.0), ('cre', 3, -0.36, 1.0), ('cre', 4, 1.61, 1.0), ('cre', 5, 2.01, 0.916)]
reading (b,ii): N=9 ctrl, 7 cre; virus F(1,14)=12.1 p=0.00371; day F(4,56)=0.854 p=0.497; interaction F(4,56)=0.97 p=0.431
   means by day: {'cre': {1: -0.59, 2: 1.65, 3: -3.43, 4: 0.55, 5: 8.41}, 'ctrl': {1: -16.33, 2: -15.3, 3: -10.92, 4: -3.05, 5: -12.71}}
   ctrl vs cre per day: t= [-3.37, -1.6, -0.89, -1.2, -2.52] Holm p= [0.023, 0.393, 0.501, 0.501, 0.098]
   one-sample vs 0 (Holm over 10): [('ctrl', 1, -5.13, 0.009), ('ctrl', 2, -2.04, 0.603), ('ctrl', 3, -1.65, 0.823), ('ctrl', 4, -1.86, 0.695), ('ctrl', 5, -2.23, 0.508), ('cre', 1, -0.18, 1.0), ('cre', 2, 0.23, 1.0), ('cre', 3, -0.8, 1.0), ('cre', 4, 0.2, 1.0), ('cre', 5, 1.4, 1.0)]

Result: reproduced (COM reading ii). With negative cross-correlation set to zero, all cells, the virus main effect is F(1,14)=16.2, p=0.001. On day 1, control is more negative than Cre (-16.5 against 2.9 cm, Holm p=0.019). The control day-1 shift is below 0 (t=-4.50, Holm p=0.020), and control days 2 to 5 are not (Holm p >= 0.81). Place cells only (b,ii) gives the same (day 1 Holm p=0.023, control vs 0 p=0.009). With the raw COM (i), the virus effect holds (p=0.001 for all cells) but the day-1 tests do not (Holm p=0.118 and 0.41). The raw COM is ill-conditioned: on synthetic maps with a true shift of -30 cm it gives means of -9.6, -26.8 and 1416 cm as noise grows (ranges up to -360 to 29179 cm), where the clipped COM gives -29.4, -20.9 and -6.8 cm. The raw-COM results are therefore not evidence either way, and the outcome rests on the clipped COM.

fig6c-no-pv-shift-cre¶

In Cre mice there is no significant population-wide backward shift within a day.

In [46]:
for rdg in F6C:
    one, adj1 = F6C[rdg][3], F6C[rdg][4]
    cre = [(k, round(float(o.statistic), 2), round(float(p), 3)) for (v, k, o), p in zip(one, adj1) if v == "cre"]
    print(f"reading ({rdg}) Cre one-sample tests (day, t, Holm p):", cre, "; all p >= 0.05:", all(c[2] >= 0.05 for c in cre))
reading (a,i) Cre one-sample tests (day, t, Holm p): [(1, 1.23, 1.0), (2, 0.98, 1.0), (3, -0.33, 1.0), (4, 1.73, 1.0), (5, 1.83, 1.0)] ; all p >= 0.05: True
reading (a,ii) Cre one-sample tests (day, t, Holm p): [(1, 0.68, 1.0), (2, 0.32, 1.0), (3, -0.45, 1.0), (4, 1.12, 1.0), (5, 1.74, 0.878)] ; all p >= 0.05: True
reading (b,i) Cre one-sample tests (day, t, Holm p): [(1, -0.38, 1.0), (2, 1.25, 1.0), (3, -0.36, 1.0), (4, 1.61, 1.0), (5, 2.01, 0.916)] ; all p >= 0.05: True
reading (b,ii) Cre one-sample tests (day, t, Holm p): [(1, -0.18, 1.0), (2, 0.23, 1.0), (3, -0.8, 1.0), (4, 0.2, 1.0), (5, 1.4, 1.0)] ; all p >= 0.05: True

Result: reproduced. No Cre one-sample test against 0 is significant on any day under any reading: Holm p >= 0.88.

figs8h-across-day-pv-shift¶

Across days, novel arm place codes shift backward gradually in control mice but not in Cre mice.

Tracked cells; the PV shift between the day-averaged novel maps of each pair of days; per mouse the mean of the upper triangle. Readings: days (a) 1 to 6, (b) 1 to 5; COM (i), (ii).

In [47]:
rows = []
for m in CTRL + CRE:
    DM = day_maps(m, "nov")
    for dy, nd in (("a", 6), ("b", 5)):
        for com in ("i", "ii"):
            v = [stx3.xcorr_shift(DM[i], DM[j], com == "ii") for i in range(nd) for j in range(i + 1, nd)]
            rows.append(dict(mouse=m, virus=virus_of(m), reading=dy + "," + com, shift=np.nanmean(v)))
XS = pd.DataFrame(rows)
S8H = {}
for rdg, d in XS.groupby("reading"):
    c, k = d[d.virus == "ctrl"]["shift"], d[d.virus == "cre"]["shift"]
    t = ttest2(c, k); oc = stats.ttest_1samp(c, 0); ok_ = stats.ttest_1samp(k, 0)
    S8H[rdg] = (t, oc, ok_)
    print(f"reading ({rdg}): ctrl {c.mean():.2f} cm (vs 0 t={oc.statistic:.2f} p={oc.pvalue:.3g}), cre {k.mean():.2f} cm (vs 0 t={ok_.statistic:.2f} p={ok_.pvalue:.3g}); "
          f"ctrl vs cre t={t['t']:.2f} p={t['p']:.3g} (Welch p={t['p_welch']:.3g})")
reading (a,i): ctrl 2.39 cm (vs 0 t=0.23 p=0.826), cre 17.35 cm (vs 0 t=1.97 p=0.0959); ctrl vs cre t=-1.05 p=0.311 (Welch p=0.293)
reading (a,ii): ctrl -1.77 cm (vs 0 t=-0.31 p=0.762), cre 11.64 cm (vs 0 t=1.92 p=0.104); ctrl vs cre t=-1.60 p=0.131 (Welch p=0.13)
reading (b,i): ctrl -9.31 cm (vs 0 t=-1.18 p=0.272), cre 15.02 cm (vs 0 t=1.55 p=0.173); ctrl vs cre t=-1.97 p=0.0695 (Welch p=0.0747)
reading (b,ii): ctrl -7.70 cm (vs 0 t=-1.61 p=0.145), cre 8.74 cm (vs 0 t=1.25 p=0.259); ctrl vs cre t=-2.01 p=0.0645 (Welch p=0.0783)

Result: not reproduced. Across days, the control novel-arm shift is not below 0 under any reading. With the clipped COM, the reading the conclusions rest on, the control means are -1.77 cm (days 1 to 6, p=0.76) and -7.70 cm (days 1 to 5, p=0.145), and control and Cre do not differ (p=0.131 and 0.065). With the raw COM, which is ill-conditioned (fig6c), the control means are 2.4 and -9.3 cm (p=0.83, 0.27). Cre means are positive under every reading, 8.7 to 17.4 cm, with p=0.10 to 0.26 against 0.

figs8d-pv-shift-not-explained-by-speed¶

The day 1 PV shift is not correlated with running speed on the first five novel trials.

In [48]:
d1 = PVS[(PVS.day == 1) & (PVS.reading == "a,ii")].set_index("mouse")["shift"]
sp5 = TT[(TT.day == 1) & (TT.ttype == "nov")].sort_values("trial").groupby("mouse").head(5).groupby("mouse").spd_binned.mean()
j = pd.concat([d1, sp5], axis=1).dropna()
r8d = stats.pearsonr(j["shift"], j["spd_binned"])
print(f"main reading (a,ii), clipped COM: N={len(j)} mice; Pearson r={r8d.statistic:.3f} p={r8d.pvalue:.3g}; speed range {j.spd_binned.min():.1f}-{j.spd_binned.max():.1f} cm/s; shift range {j['shift'].min():.1f} to {j['shift'].max():.1f} cm")
for rdg in ("a,i", "b,i", "b,ii"):
    dd = pd.concat([PVS[(PVS.day == 1) & (PVS.reading == rdg)].set_index("mouse")["shift"], sp5], axis=1).dropna()
    rr = stats.pearsonr(dd["shift"], dd["spd_binned"]); print(f"   variant PV reading ({rdg}): r={rr.statistic:.3f} p={rr.pvalue:.3g}")
main reading (a,ii), clipped COM: N=16 mice; Pearson r=-0.148 p=0.585; speed range 12.7-51.6 cm/s; shift range -31.7 to 15.6 cm
   variant PV reading (a,i): r=-0.109 p=0.689
   variant PV reading (b,i): r=-0.375 p=0.152
   variant PV reading (b,ii): r=-0.390 p=0.135

Result: reproduced. With the clipped COM, all cells (a,ii), the day-1 initial PV shift is not correlated with running speed over the first five novel trials: r=-0.148, p=0.585, 16 mice (paper r=-0.317, p=0.231). The other readings give r=-0.109 to -0.390, p >= 0.135; the raw-COM ones (a,i and b,i) are ill-conditioned (fig6c).

fig6d-field-com-shift-larger-control¶

Single place fields shift backward abruptly after their formation lap on novel trials, more in control than in Cre mice, after controlling for running speed on the formation lap; the difference holds on days 1, 2 and 3.

Novel-trial fields with a formation lap. COM (from frames, unbinned) on each lap, relative to the field's mean COM over laps from the formation lap on, in cm; speed = mean speed through the field on the formation lap. statsmodels MixedLM, shift ~ speed + virus (Cre = 1), random intercept per mouse; Wald test of the virus term. Readings: "trial 1" is (a) the formation lap, (b) the lap after it. Under this measure a field that moves backward after forming has a positive value on the formation lap. Variant (c): the COM on the lap after the formation lap minus the COM on the formation lap (negative = backward), shown because the claims file's sign convention and the paper's "backward shift" point opposite ways under reading (a).

In [49]:
import statsmodels.formula.api as smf
import warnings as _w
from statsmodels.tools.sm_exceptions import ConvergenceWarning
_w.simplefilter("ignore", ConvergenceWarning)
rows = []
for (m, fd), s in S.items():
    for L in s["field_laps"].get("nov", []):
        c, lo, hi, form = L["field"]
        com = L["com"]; ref = np.nanmean(com[form:])
        rows.append(dict(mouse=m, virus=virus_of(m), cre=int(virus_of(m) == "cre"), day=fd + 1, cell=c,
                         width=(hi - lo) * 10.0, speed=L["speed"][form],
                         sh_a=(com[form] - ref) * 10.0, sh_b=(com[form + 1] - ref) * 10.0 if form + 1 < len(com) else np.nan,
                         sh_c=(com[form + 1] - com[form]) * 10.0 if form + 1 < len(com) else np.nan))
FL = pd.DataFrame(rows)
print("novel fields with a formation lap:", FL.groupby("virus").size().to_dict(), "; by day:", FL.groupby("day").size().to_dict())
F6D = {}
for rd in ("sh_a", "sh_b", "sh_c"):
    for day in range(1, 7):
        d = FL[(FL.day == day)].dropna(subset=[rd, "speed"])
        try:
            fit = smf.mixedlm(f"{rd} ~ speed + cre", d, groups=d["mouse"]).fit()
            b, se = fit.params["cre"], fit.bse["cre"]
            chi2 = (b / se) ** 2; p = float(stats.chi2.sf(chi2, 1))
        except Exception as e:
            b = se = chi2 = p = np.nan
        F6D[(rd, day)] = dict(b=b, chi2=chi2, p=p, ctrl=d[d.cre == 0][rd].mean(), cre=d[d.cre == 1][rd].mean(), n=len(d))
        print(f"reading {rd[-1]}, day {day}: n={len(d)}; mean shift ctrl {F6D[(rd, day)]['ctrl']:.2f} cm, cre {F6D[(rd, day)]['cre']:.2f} cm; "
              f"virus coef (Cre - ctrl) {b:.2f} cm, Wald chi2={chi2:.2f} p={p:.3g}")
novel fields with a formation lap: {'cre': 34674, 'ctrl': 43581} ; by day: {1: 10871, 2: 13073, 3: 13931, 4: 14408, 5: 12761, 6: 13211}
reading a, day 1: n=10871; mean shift ctrl 1.09 cm, cre 0.95 cm; virus coef (Cre - ctrl) 0.09 cm, Wald chi2=0.05 p=0.815
reading a, day 2: n=13073; mean shift ctrl 0.96 cm, cre 0.94 cm; virus coef (Cre - ctrl) 0.28 cm, Wald chi2=0.34 p=0.559
reading a, day 3: n=13931; mean shift ctrl 0.74 cm, cre 0.93 cm; virus coef (Cre - ctrl) 0.19 cm, Wald chi2=0.18 p=0.673
reading a, day 4: n=14408; mean shift ctrl 0.33 cm, cre 1.08 cm; virus coef (Cre - ctrl) 0.96 cm, Wald chi2=4.41 p=0.0357
reading a, day 5: n=12761; mean shift ctrl 0.43 cm, cre 1.03 cm; virus coef (Cre - ctrl) 0.72 cm, Wald chi2=3.58 p=0.0587
reading a, day 6: n=13211; mean shift ctrl 1.14 cm, cre 1.04 cm; virus coef (Cre - ctrl) 0.27 cm, Wald chi2=0.28 p=0.594
reading b, day 1: n=10789; mean shift ctrl 0.35 cm, cre 0.28 cm; virus coef (Cre - ctrl) 0.01 cm, Wald chi2=0.00 p=0.984
reading b, day 2: n=13010; mean shift ctrl 0.31 cm, cre 0.19 cm; virus coef (Cre - ctrl) -0.06 cm, Wald chi2=0.03 p=0.855
reading b, day 3: n=13875; mean shift ctrl 0.54 cm, cre 0.61 cm; virus coef (Cre - ctrl) 0.11 cm, Wald chi2=0.26 p=0.607
reading b, day 4: n=14344; mean shift ctrl 0.24 cm, cre 0.29 cm; virus coef (Cre - ctrl) -0.03 cm, Wald chi2=0.00 p=0.947
reading b, day 5: n=12710; mean shift ctrl 0.22 cm, cre 0.22 cm; virus coef (Cre - ctrl) -0.03 cm, Wald chi2=0.01 p=0.942
reading b, day 6: n=13130; mean shift ctrl 0.63 cm, cre 0.13 cm; virus coef (Cre - ctrl) -0.35 cm, Wald chi2=0.86 p=0.355
reading c, day 1: n=10789; mean shift ctrl -0.74 cm, cre -0.68 cm; virus coef (Cre - ctrl) -0.08 cm, Wald chi2=0.00 p=0.956
reading c, day 2: n=13010; mean shift ctrl -0.65 cm, cre -0.74 cm; virus coef (Cre - ctrl) -0.33 cm, Wald chi2=0.42 p=0.516
reading c, day 3: n=13875; mean shift ctrl -0.19 cm, cre -0.33 cm; virus coef (Cre - ctrl) -0.08 cm, Wald chi2=0.03 p=0.854
reading c, day 4: n=14344; mean shift ctrl -0.09 cm, cre -0.80 cm; virus coef (Cre - ctrl) -0.97 cm, Wald chi2=4.60 p=0.0319
reading c, day 5: n=12710; mean shift ctrl -0.21 cm, cre -0.82 cm; virus coef (Cre - ctrl) -0.76 cm, Wald chi2=1.71 p=0.191
reading c, day 6: n=13130; mean shift ctrl -0.52 cm, cre -0.92 cm; virus coef (Cre - ctrl) -0.60 cm, Wald chi2=1.32 p=0.251

Result: not reproduced. Under no reading is there a virus effect on day 1. With the formation lap relative to the field mean, Wald chi2=0.05, p=0.815. With the next lap, p=0.984. In variant (c), next lap minus formation lap, p=0.956. Both groups show a small backward step after the formation lap in variant (c): -0.74 cm (control) and -0.68 cm (Cre) on day 1. The only significant virus terms are on day 4 (p=0.036 and 0.032), where Cre fields shift more. Which sign the paper's greater shift takes under the criterion's measure is asked of a reader (questions file).

fig6e-width-speed-correlation¶

Place field width correlates with running speed through the field on the formation lap in both groups, and neither the intercept nor the slope differs between control and Cre.

In [50]:
F6E = {}
for rdg, d in (("a", FL[FL.day == 1]), ("b", FL)):
    d = d.dropna(subset=["speed", "width"])
    fit = smf.mixedlm("width ~ speed * cre", d, groups=d["mouse"]).fit()
    pv = fit.pvalues
    per = {}
    for v in (0, 1):
        dv = d[d.cre == v]
        fv = smf.mixedlm("width ~ speed", dv, groups=dv["mouse"]).fit()
        per[v] = (float(fv.params["speed"]), float(fv.pvalues["speed"]))
    F6E[rdg] = dict(p_cre=float(pv["cre"]), p_int=float(pv["speed:cre"]), per=per, n=len(d))
    print(f"reading {rdg}: n={len(d)}; slope ctrl {per[0][0]:.3f} cm per cm/s (p={per[0][1]:.3g}), cre {per[1][0]:.3f} (p={per[1][1]:.3g}); "
          f"virus term p={pv['cre']:.3g}, speed x virus p={pv['speed:cre']:.3g}")
# variants for the pooled reading (b), where 78k fields share a random intercept per mouse: (1) random slope of speed per mouse,
# (2) a variance component per mouse-day, (3) two-stage: OLS slope and intercept per mouse, then control against Cre (t-test)
d = FL.dropna(subset=["speed", "width"]).copy()
d["md"] = d.mouse + "_d" + d.day.astype(str)
for name, kw in (("random slope per mouse", dict(re_formula="~speed")), ("intercept per mouse-day", dict(vc_formula={"md": "0 + md"}))):
    try:
        f = smf.mixedlm("width ~ speed * cre", d, groups=d["mouse"], **kw).fit()
        print(f"pooled, {name}: virus term p={f.pvalues['cre']:.3g}, speed x virus p={f.pvalues['speed:cre']:.3g}, speed slope p={f.pvalues['speed']:.3g}")
    except Exception as e:
        print(f"pooled, {name}: fit failed ({str(e)[:60]})")
for rdg, dd in (("a", d[d.day == 1]), ("b", d)):
    ps = pd.DataFrame([dict(mouse=m, virus=virus_of(m), slope=np.polyfit(g.speed, g.width, 1)[0], icpt=np.polyfit(g.speed, g.width, 1)[1])
                       for m, g in dd.groupby("mouse")])
    ts, ti = ttest2(ps[ps.virus == "ctrl"].slope, ps[ps.virus == "cre"].slope), ttest2(ps[ps.virus == "ctrl"].icpt, ps[ps.virus == "cre"].icpt)
    print(f"two-stage, reading {rdg}: slope ctrl {ps[ps.virus == 'ctrl'].slope.mean():.3f}, cre {ps[ps.virus == 'cre'].slope.mean():.3f}, p={ts['p']:.3g}; "
          f"intercept ctrl {ps[ps.virus == 'ctrl'].icpt.mean():.1f}, cre {ps[ps.virus == 'cre'].icpt.mean():.1f} cm, p={ti['p']:.3g}; slopes > 0 in {int((ps.slope > 0).sum())} of {len(ps)} mice")
reading a: n=10871; slope ctrl 0.428 cm per cm/s (p=8.9e-78), cre 0.462 (p=7.2e-45); virus term p=0.688, speed x virus p=0.409
reading b: n=78255; slope ctrl 0.597 cm per cm/s (p=0), cre 0.649 (p=0); virus term p=0.501, speed x virus p=0.000991
pooled, random slope per mouse: virus term p=0.702, speed x virus p=0.585, speed slope p=1.98e-13
pooled, intercept per mouse-day: virus term p=0.347, speed x virus p=0.002, speed slope p=0
two-stage, reading a: slope ctrl 0.423, cre 0.457, p=0.789; intercept ctrl 34.1, cre 33.3 cm, p=0.835; slopes > 0 in 16 of 16 mice
two-stage, reading b: slope ctrl 0.606, cre 0.677, p=0.586; intercept ctrl 36.4, cre 34.9 cm, p=0.707; slopes > 0 in 16 of 16 mice

Result: reproduced, resting on an assumption (day 1 novel trials, reading a). On day 1 novel trials, field width rises with formation-lap speed in both groups: 0.43 cm per cm/s in control (p=9e-78) and 0.46 in Cre (p=7e-45). Neither the virus term (p=0.688) nor the speed by virus term (p=0.409) is significant. Pooling days 1 to 6 (reading b) with a random intercept per mouse, the speed by virus term is significant (p=0.001), so the readings differ; day 1 is adopted because Fig 6E plots the fields of Fig 6D and S8F, which are day 1. The pooled interaction rests on 78,255 fields sharing one intercept per mouse: with a random slope per mouse it is p=0.585 (virus p=0.702), and from per-mouse slopes it is p=0.586 (intercepts p=0.707, slopes positive in 16 of 16 mice). With a variance component per mouse-day it stays p=0.002.

HSEs and reactivation (Fig 7, S9)¶

HSEs per the Methods (helper hse): post-reward stopping periods, transients above 20% of the session maximum beginning in the period, coactivity within 8 frames, threshold the 95th percentile of 1000 per-cell circular shuffles. The Methods shuffle "each cell's timeseries" within each period but count only transients that "began after the animal stopped"; whether the null also counts transients that began before the stop and were moved into the period by the shift is open. Readings: S (shift the activity series and recompute onsets, the Methods' words) and O (shift only the onsets that began in the period). Every HSE claim is shown under both; reading labels in the reactivation claims are prefixed S: or O:.

In [51]:
rows = []
for hk in ("hse", "hse_on"):
    for (m, fd), s in S.items():
        h = s[hk]
        rows.append(dict(mode=hk, mouse=m, virus=virus_of(m), day=fd + 1, periods=h["n_periods"], thr=h["thr"], n_hse=len(h["events"]),
                         frac_trials=h["trial_hse"].mean(),
                         size=np.mean([len(e["cells"]) / s["n_cells"] for e in h["events"]]) if h["events"] else np.nan))
HSALL = pd.DataFrame(rows)
for hk, HS in HSALL.groupby("mode"):
    print("reading", "series (shift activity)" if hk == "hse" else "onsets (shift onsets)")
    print(HS.groupby("virus")[["periods", "thr", "n_hse", "frac_trials", "size"]].mean().round(3).to_string())
    print("   mouse-days without any HSE:", HS[HS.n_hse == 0][["mouse", "day"]].values.tolist())
reading series (shift activity)
       periods     thr   n_hse  frac_trials   size
virus                                             
cre     93.381  15.857  54.548        0.257  0.026
ctrl    80.444  24.370   3.185        0.021  0.027
   mouse-days without any HSE: [['Cre-6', 1], ['Cre-6', 2], ['Ctrl-1', 2], ['Ctrl-1', 3], ['Ctrl-1', 4], ['Ctrl-2', 6], ['Ctrl-4', 1], ['Ctrl-5', 1], ['Ctrl-5', 5], ['Ctrl-6', 3], ['Ctrl-6', 5], ['Ctrl-7', 1], ['Ctrl-7', 4], ['Ctrl-7', 6], ['Ctrl-8', 5], ['Ctrl-9', 1], ['Ctrl-9', 2], ['Ctrl-9', 3], ['Ctrl-9', 4], ['Ctrl-9', 5], ['Ctrl-9', 6]]
reading onsets (shift onsets)
       periods     thr    n_hse  frac_trials   size
virus                                              
cre     93.381  12.167  115.881        0.459  0.022
ctrl    80.444  14.815   36.167        0.199  0.020
   mouse-days without any HSE: [['Ctrl-7', 1], ['Ctrl-9', 6]]

Checks of the HSE detector¶

The detector follows the Methods' words, but nothing in the paper shows what it gives when cells are not synchronous. Three checks:

  1. Synthetic sessions (helper synthetic_hse_check): independent cells with random transients and one post-reward stop per trial, without and with a planted synchronous event of 30 cells (10% of the population) in half of the stops.
  2. Real data with synchrony removed: in every session each cell's whole dF/F series is circularly shifted by its own random offset (helper time_shuffled), which keeps each cell's transients and the stopping periods and removes coactivity between cells; the detector is then run unchanged. Per mouse and day, the fraction of trials with an HSE in the real data is set beside that of the null, and the figs9a ANOVA is run on the null too.
  3. The fraction of stopping-period time points above the threshold, against the 5% that the 95th-percentile threshold implies for each time point.

The authors' Figshare record of pre-computed shuffles (shuffle_pkls.zip, same version as the ROI matches) is listed to see whether it holds HSE results to compare with.

How the checks bear on the HSE claims was fixed before the null was run on all sessions: if, under both null readings, the data with synchrony removed give at least half the real fraction of trials with an HSE in either group, the detector's output in these data is mostly chance coincidence of independent transients, so the procedure as read here does not pick out synchronous events, and the claims that rest on it (figs9a, figs9b, fig7e and fig7h) are blocked as methods_underspecified, with the result of every reading shown.

In [52]:
syn = []
for rate in (0.005, 0.02):
    for sync in (0, 30):
        r = stx3.synthetic_hse_check(np.random.default_rng(7), rate=rate, sync=sync)
        syn.append(dict(onset_prob_per_frame=rate, planted_cells=sync, **{f"{k}: trials flagged": v["frac_trials"] for k, v in r.items()},
                        **{f"{k}: HSEs": v["n_hse"] for k, v in r.items()}))
print("synthetic sessions, 300 cells, 60 trials (planted events in 30 of them when planted_cells > 0):")
print(pd.DataFrame(syn).round(3).to_string(index=False))

rows = []
for hk, nk in (("hse", "hse_null"), ("hse_on", "hse_on_null")):
    for (m, fd), s in S.items():
        h, z = s[hk], s[nk]
        rows.append(dict(mode="S" if hk == "hse" else "O", mouse=m, virus=virus_of(m), day=fd + 1, period_s=h["period_s"], periods=h["n_periods"],
                         real=h["trial_hse"].mean(), null=z["trial_hse"].mean(), n_real=len(h["events"]), n_null=len(z["events"]),
                         above_real=h["frac_above"], above_null=z["frac_above"],
                         size_real=np.mean([len(e["cells"]) / s["n_cells"] for e in h["events"]]) if h["events"] else np.nan,
                         size_null=np.mean([len(e["cells"]) / s["n_cells"] for e in z["events"]]) if z["events"] else np.nan))
HN = pd.DataFrame(rows)
HNULL = {}
for mode, d in HN.groupby("mode"):
    print(f"--- reading {mode}: group means over mouse-days")
    print(d.groupby("virus")[["periods", "period_s", "real", "null", "n_real", "n_null", "above_real", "above_null", "size_real", "size_null"]].mean().round(3).to_string())
    print("   per mouse (mean over days): trials with an HSE real / null, HSEs per day real / null")
    print(d.groupby("mouse")[["real", "null", "n_real", "n_null"]].mean().round(2).T.to_string())
    d = d.assign(excess=d.real - d.null)
    HNULL[mode] = dict(r=stats.pearsonr(d.real, d.null))
    for k, lab in (("null", "the null fraction"), ("excess", "real minus null")):
        try:
            HNULL[mode][k] = mixed(d, k); print(f"   figs9a ANOVA on {lab}: {fmt_mixed(HNULL[mode][k])}")
        except Exception as e:
            print(f"   figs9a ANOVA on {lab}: failed ({str(e)[:60]})")
    print(f"   real against null over mouse-days: Pearson r={HNULL[mode]['r'].statistic:.2f}; mouse-days with real > null: {int((d.real > d.null).sum())} of {len(d)}")
    print(f"   stopping-period time points above threshold: real {d.above_real.mean():.3f}, null {d.above_null.mean():.3f} (the threshold implies 0.05)")
print("mean stopping period length (s) and periods per day, by group:", HN[HN["mode"] == "S"].groupby("virus")[["period_s", "periods"]].mean().round(2).to_dict("index"))

import io, zipfile
fs = requests.get(f"https://api.figshare.com/v2/articles/{stx3.FIGSHARE_ARTICLE}/versions/{stx3.FIGSHARE_VERSION}", timeout=60).json()
url = [x["download_url"] for x in fs["files"] if x["name"] == "shuffle_pkls.zip"][0]
names = sorted(n.split("/")[-1] for n in zipfile.ZipFile(io.BytesIO(requests.get(url, timeout=300).content)).namelist() if n.endswith(".pkl"))
print(len(names), "files in shuffle_pkls.zip:", names)
print("files naming HSEs, reactivation or synchrony:", [n for n in names if re.search("hse|reactiv|sync", n, re.I)])
synthetic sessions, 300 cells, 60 trials (planted events in 30 of them when planted_cells > 0):
 onset_prob_per_frame  planted_cells  series: trials flagged  onsets: trials flagged  series: HSEs  onsets: HSEs
                0.005              0                   0.267                   0.400            23            39
                0.005             30                   0.400                   0.400            24            25
                0.020              0                   0.200                   0.383            16            41
                0.020             30                   0.433                   0.583            28            51
--- reading O: group means over mouse-days
       periods  period_s   real   null   n_real   n_null  above_real  above_null  size_real  size_null
virus                                                                                                 
cre     93.381     5.431  0.459  0.433  115.881  105.429       0.071       0.037      0.022      0.025
ctrl    80.444     1.495  0.199  0.157   36.167   30.056       0.062       0.042      0.020      0.025
   per mouse (mean over days): trials with an HSE real / null, HSEs per day real / null
mouse   Cre-1   Cre-2   Cre-3   Cre-4   Cre-5  Cre-6  Cre-7  Ctrl-1  Ctrl-2  Ctrl-3  Ctrl-4  Ctrl-5  Ctrl-6  Ctrl-7  Ctrl-8  Ctrl-9
real     0.32    0.41    0.49    0.57    0.81   0.18   0.44    0.32    0.23    0.41    0.38    0.10    0.06    0.09    0.18    0.02
null     0.26    0.43    0.44    0.50    0.76   0.19   0.46    0.23    0.16    0.24    0.27    0.09    0.08    0.11    0.21    0.02
n_real  54.67   82.33  120.67  149.33  271.33  33.33  99.50   58.83   40.17   69.17   67.50   19.50   10.50   14.83   41.33    3.67
n_null  48.00  110.33   96.50  128.83  227.33  34.83  92.17   41.50   29.33   49.83   52.33   22.50   14.50   17.33   40.17    3.00
   figs9a ANOVA on the null fraction: N=9 ctrl, 7 cre; virus F(1,14)=15.9 p=0.00136; day F(5,70)=9.54 p=5.69e-07; interaction F(5,70)=3.53 p=0.00671
   figs9a ANOVA on real minus null: N=9 ctrl, 7 cre; virus F(1,14)=0.271 p=0.611; day F(5,70)=0.617 p=0.687; interaction F(5,70)=0.262 p=0.932
   real against null over mouse-days: Pearson r=0.90; mouse-days with real > null: 61 of 96
   stopping-period time points above threshold: real 0.066, null 0.040 (the threshold implies 0.05)
--- reading S: group means over mouse-days
       periods  period_s   real   null  n_real  n_null  above_real  above_null  size_real  size_null
virus                                                                                               
cre     93.381     5.431  0.257  0.152  54.548  25.929       0.024       0.005      0.026      0.028
ctrl    80.444     1.495  0.021  0.003   3.185   0.426       0.003       0.000      0.027      0.027
   per mouse (mean over days): trials with an HSE real / null, HSEs per day real / null
mouse   Cre-1  Cre-2  Cre-3  Cre-4   Cre-5  Cre-6  Cre-7  Ctrl-1  Ctrl-2  Ctrl-3  Ctrl-4  Ctrl-5  Ctrl-6  Ctrl-7  Ctrl-8  Ctrl-9
real     0.13   0.31   0.17   0.28    0.65   0.06   0.20    0.01    0.02    0.10    0.02    0.01    0.01    0.00    0.02     0.0
null     0.01   0.17   0.10   0.06    0.56   0.04   0.12    0.00    0.01    0.00    0.00    0.00    0.00    0.00    0.01     0.0
n_real  20.33  51.50  28.00  53.50  182.83   8.67  37.00    2.17    2.50   15.50    2.33    0.83    0.83    0.67    3.83     0.0
n_null   2.00  28.67  12.33   8.50  110.17   4.83  15.00    0.17    1.00    0.33    0.50    0.00    0.00    0.00    1.83     0.0
   figs9a ANOVA on the null fraction: N=9 ctrl, 7 cre; virus F(1,14)=5.94 p=0.0287; day F(5,70)=2.94 p=0.0182; interaction F(5,70)=3.9 p=0.00353
   figs9a ANOVA on real minus null: N=9 ctrl, 7 cre; virus F(1,14)=12.5 p=0.00334; day F(5,70)=0.799 p=0.554; interaction F(5,70)=0.798 p=0.555
   real against null over mouse-days: Pearson r=0.90; mouse-days with real > null: 66 of 96
   stopping-period time points above threshold: real 0.012, null 0.002 (the threshold implies 0.05)
mean stopping period length (s) and periods per day, by group: {'cre': {'period_s': 5.43, 'periods': 93.38}, 'ctrl': {'period_s': 1.5, 'periods': 80.44}}
28 files in shuffle_pkls.zip: ['dense_all_blocks_norm_activity.pkl', 'dense_n_fields_mixedlm_shuffle.pkl', 'dense_naive_bayes_across_days_results.pkl', 'dense_naive_bayes_results.pkl', 'dense_novel_activity_mixedlm_shuffle.pkl', 'dense_pc_frac_mixedlm_shuffle.pkl', 'dense_place_field_spatial_shuffle_F_dff.pkl', 'dense_rewardcell_mixedlm_shuffle.pkl', 'dense_width_mixedlm_shuffle.pkl', 'reward_stability_df_dff.pkl', 'sparse_all_blocks_norm_activity.pkl', 'sparse_n_fields_mixedlm_shuffle.pkl', 'sparse_n_fields_mixedlm_shuffle_spks_tau1.5.pkl', 'sparse_naive_bayes_results.pkl', 'sparse_novel_activity_mixedlm_shuffle.pkl', 'sparse_novel_activity_mixedlm_shuffle_spks.pkl', 'sparse_pc_frac_mixedlm_shuffle.pkl', 'sparse_pc_fracs_mixedlm_shuffle.pkl', 'sparse_place_field_spatial_shuffle_F_dff.pkl', 'sparse_place_field_spatial_shuffle_spks.pkl', 'sparse_place_field_spatial_shuffle_spks_tau0.7.pkl', 'sparse_place_field_spatial_shuffle_spks_tau1.0.pkl', 'sparse_place_field_spatial_shuffle_spks_tau1.2.pkl', 'sparse_place_field_spatial_shuffle_spks_tau1.5.pkl', 'sparse_rewardcell_mixedlm_shuffle.pkl', 'sparse_width_mixedlm_shuffle.pkl', 'sparse_width_mixedlm_shuffle_F_dff.pkl', 'sparse_width_mixedlm_shuffle_spks_tau1.5.pkl']
files naming HSEs, reactivation or synchrony: []

figs9a-hse-trial-proportion-no-difference¶

The proportion of trials containing a highly synchronous event does not differ between control and Cre mice.

In [53]:
S9A = {}
for hk, HS in HSALL.groupby("mode"):
    S9A[hk] = mixed(HS, "frac_trials"); print(hk, fmt_mixed(S9A[hk]))
    print(HS.groupby(["virus", "day"]).frac_trials.mean().unstack().round(3).to_string())
hse N=9 ctrl, 7 cre; virus F(1,14)=13.1 p=0.00278; day F(5,70)=3.34 p=0.00923; interaction F(5,70)=3.7 p=0.00496
day        1      2      3      4      5      6
virus                                          
cre    0.091  0.208  0.276  0.351  0.327  0.287
ctrl   0.010  0.024  0.041  0.018  0.019  0.014
hse_on N=9 ctrl, 7 cre; virus F(1,14)=9.3 p=0.00867; day F(5,70)=5.18 p=0.000419; interaction F(5,70)=1.35 p=0.253
day        1      2      3      4      5      6
virus                                          
cre    0.269  0.422  0.480  0.495  0.578  0.511
ctrl   0.144  0.173  0.209  0.202  0.270  0.195

Result: blocked, methods_underspecified. As tested, Cre mice have more trials with HSEs under both shuffle readings: S, 0.26 against 0.02, virus F(1,14)=13.1, p=0.003; O, 0.46 against 0.20, F(1,14)=9.3, p=0.009. But the same ANOVA on the data with synchrony removed also finds Cre higher (O p=0.0014, S p=0.029), Cre stopping periods are longer (5.4 s against 1.5 s), and on real minus null the virus effect is p=0.61 (O) and p=0.003 (S). The HSE checks above decide the outcome: with each cell's series shifted in time, which removes synchrony, the detector still flags 0.43 (Cre) and 0.16 (control) of trials under reading O, against 0.46 and 0.20 in the real data, and 0.15 (Cre) against 0.26 under reading S. That is more than half the real fraction in the Cre group under both readings, the rule fixed before the null was run, so the detector as read here does not pick out synchronous events, and the claim is blocked as methods_underspecified. The two readings would give different outcomes if the null were settled: under S, the Methods' words, real minus null still has Cre higher (p=0.003), so the claim would be not reproduced; under O, real minus null gives p=0.61.

figs9b-hse-size-no-difference¶

The proportion of the population participating in HSEs does not differ between control and Cre mice.

In [54]:
S9B = {}
for hk, HS in HSALL.groupby("mode"):
    S9B[hk] = mixed(HS, "size"); print(hk, fmt_mixed(S9B[hk]), "(mouse-days without HSEs have no value; the ANOVA keeps mice with all six days)")
    print(HS.groupby(["virus", "day"])["size"].mean().unstack().round(4).to_string())
    g = HS.groupby(["mouse", "virus"], as_index=False)["size"].mean()
    t = ttest2(g[g.virus == "ctrl"]["size"], g[g.virus == "cre"]["size"])
    print(f"   variant, per-mouse mean over the days with HSEs: ctrl {g[g.virus == 'ctrl']['size'].mean():.4f} (n={g[g.virus == 'ctrl']['size'].notna().sum()}), cre {g[g.virus == 'cre']['size'].mean():.4f}; t={t['t']:.2f} p={t['p']:.3g}")
hse N=1 ctrl, 6 cre; virus F(1,5)=0.000401 p=0.985; day F(5,25)=1.06 p=0.406; interaction F(5,25)=0.941 p=0.472 (mouse-days without HSEs have no value; the ANOVA keeps mice with all six days)
day         1       2       3       4       5       6
virus                                                
cre    0.0272  0.0225  0.0308  0.0293  0.0237  0.0227
ctrl   0.0237  0.0249  0.0287  0.0249  0.0263  0.0347
   variant, per-mouse mean over the days with HSEs: ctrl 0.0279 (n=8), cre 0.0258; t=0.43 p=0.671
hse_on N=7 ctrl, 7 cre; virus F(1,12)=0.135 p=0.72; day F(5,60)=2.64 p=0.0319; interaction F(5,60)=2.41 p=0.047 (mouse-days without HSEs have no value; the ANOVA keeps mice with all six days)
day         1       2       3       4       5       6
virus                                                
cre    0.0205  0.0189  0.0248  0.0249  0.0210  0.0200
ctrl   0.0167  0.0190  0.0191  0.0195  0.0191  0.0262
   variant, per-mouse mean over the days with HSEs: ctrl 0.0198 (n=9), cre 0.0217; t=-0.47 p=0.646

Result: blocked, methods_underspecified. As tested, the fraction of cells per HSE does not differ between groups. Under reading O, 7 control and 7 Cre mice have HSEs on every day: virus F(1,12)=0.135, p=0.72, means 0.020 and 0.022. Under reading S, only 1 control mouse has HSEs every day (p=0.985). The per-mouse t-test variant gives p=0.67 (S) and 0.65 (O). The HSEs found in the data with synchrony removed have the same size, 0.025 to 0.028 of the cells. The HSE checks above decide the outcome: with each cell's series shifted in time, which removes synchrony, the detector still flags 0.43 (Cre) and 0.16 (control) of trials under reading O, against 0.46 and 0.20 in the real data, and 0.15 (Cre) against 0.26 under reading S. That is more than half the real fraction in the Cre group under both readings, the rule fixed before the null was run, so the detector as read here does not pick out synchronous events, and the claim is blocked as methods_underspecified.

fig7e-reactivated-cells-more-stable-across-days-control¶

In control mice, cells that participated in at least one HSE have higher across-day spatial rate map correlation than cells that did not, on familiar and novel trials.

Tracked cells. Per cell, Pearson correlation of its day-averaged maps; readings: (a) mean over all pairs of days, (b) over consecutive days; reactivated (i) in an HSE on any day, (ii) on the earlier day of the pair. Per mouse and type, mean of reactivated minus mean of non-reactivated; one-sample t-tests, Holm over the four tests (two groups, two types).

In [55]:
def part_tracked(m, hk):
    cols = TRACK[m]
    P = np.zeros((6, cols.shape[1]), bool)
    for d in range(6):
        ev = S[(m, d)][hk]["events"]
        cells = np.unique(np.concatenate([e["cells"] for e in ev])) if ev else np.array([], int)
        P[d] = np.isin(cols[d], cells)
    return P

def cellcorr(a, b):
    a = np.nan_to_num(a) - np.nan_to_num(a).mean(0); b = np.nan_to_num(b) - np.nan_to_num(b).mean(0)
    with np.errstate(invalid="ignore", divide="ignore"):
        return (a * b).sum(0) / np.sqrt((a * a).sum(0) * (b * b).sum(0))

rows = []
for hk in ("hse", "hse_on"):
  for m in CTRL + CRE:
    P = part_tracked(m, hk)
    for tt in ("fam", "nov"):
        DM = day_maps(m, tt)
        for pr in ("a", "b"):
            pairs = [(i, j) for i in range(6) for j in range(i + 1, 6)] if pr == "a" else [(i, i + 1) for i in range(5)]
            C = np.array([cellcorr(DM[i], DM[j]) for i, j in pairs])
            for re_ in ("i", "ii"):
                if re_ == "i":
                    r = P.any(0); diff = np.nanmean(C[:, r]) - np.nanmean(C[:, ~r])
                else:
                    diff = np.nanmean([np.nanmean(C[k, P[i]]) - np.nanmean(C[k, ~P[i]]) for k, (i, j) in enumerate(pairs) if P[i].any() and (~P[i]).any()])
                rows.append(dict(mouse=m, virus=virus_of(m), tt=tt, reading=("S" if hk == "hse" else "O") + ":" + pr + "," + re_, diff=diff, n_react=int(P.any(0).sum()), n=P.shape[1]))
RE = pd.DataFrame(rows)
for pre in ("S", "O"):
    print(pre, "tracked cells reactivated on any day:", RE[RE.reading.str.startswith(pre)].drop_duplicates("mouse").set_index("mouse")[["n_react", "n"]].to_dict("index"))
F7E = {}
for rdg, d in RE.groupby("reading"):
    tests = [(v, tt, stats.ttest_1samp(d[(d.virus == v) & (d.tt == tt)]["diff"].dropna(), 0)) for v in ("ctrl", "cre") for tt in ("fam", "nov")]
    adj = holm([t[2].pvalue for t in tests])
    F7E[rdg] = {(v, tt): (float(t.statistic), float(p), float(d[(d.virus == v) & (d.tt == tt)]["diff"].mean())) for (v, tt, t), p in zip(tests, adj)}
    print(f"reading ({rdg}):", {f"{v} {tt}": f"mean {x[2]:.3f}, t={x[0]:.2f}, Holm p={x[1]:.3g}" for (v, tt), x in F7E[rdg].items()})
# group sizes behind reading (i): tracked cells reactivated on any day and not, per mouse
NR = RE.drop_duplicates(["mouse", "reading"])
NR = NR[NR.reading.str.endswith("a,i")].assign(pre=lambda x: x.reading.str[0], n_non=lambda x: x.n - x.n_react)
print("tracked cells (reactivated / not reactivated), reading (i):")
print(NR.pivot(index="mouse", columns="pre", values=["n_react", "n_non"]).to_string())
# variant: reading (i) only in mice with at least 10 cells in each group
for rdg in sorted(r for r in RE.reading.unique() if r.endswith(",i")):
    d = RE[(RE.reading == rdg) & (RE.n_react >= 10) & (RE.n - RE.n_react >= 10)]
    out = []
    for v in ("ctrl", "cre"):
        for tt in ("fam", "nov"):
            x = d[(d.virus == v) & (d.tt == tt)]["diff"].dropna(); t = stats.ttest_1samp(x, 0)
            out.append(f"{v} {tt} n={len(x)} mean {x.mean():.3f} p={t.pvalue:.3g}")
    print(f"reading ({rdg}), mice with >= 10 cells in each group (uncorrected): " + "; ".join(out))
S tracked cells reactivated on any day: {'Ctrl-1': {'n_react': 69, 'n': 376}, 'Ctrl-2': {'n_react': 61, 'n': 314}, 'Ctrl-3': {'n_react': 197, 'n': 342}, 'Ctrl-4': {'n_react': 117, 'n': 562}, 'Ctrl-5': {'n_react': 59, 'n': 543}, 'Ctrl-6': {'n_react': 35, 'n': 360}, 'Ctrl-7': {'n_react': 35, 'n': 379}, 'Ctrl-8': {'n_react': 97, 'n': 267}, 'Ctrl-9': {'n_react': 0, 'n': 433}, 'Cre-1': {'n_react': 103, 'n': 163}, 'Cre-2': {'n_react': 63, 'n': 70}, 'Cre-3': {'n_react': 192, 'n': 274}, 'Cre-4': {'n_react': 279, 'n': 326}, 'Cre-5': {'n_react': 521, 'n': 522}, 'Cre-6': {'n_react': 72, 'n': 188}, 'Cre-7': {'n_react': 251, 'n': 305}}
O tracked cells reactivated on any day: {'Ctrl-1': {'n_react': 263, 'n': 376}, 'Ctrl-2': {'n_react': 216, 'n': 314}, 'Ctrl-3': {'n_react': 295, 'n': 342}, 'Ctrl-4': {'n_react': 493, 'n': 562}, 'Ctrl-5': {'n_react': 340, 'n': 543}, 'Ctrl-6': {'n_react': 149, 'n': 360}, 'Ctrl-7': {'n_react': 196, 'n': 379}, 'Ctrl-8': {'n_react': 207, 'n': 267}, 'Ctrl-9': {'n_react': 83, 'n': 433}, 'Cre-1': {'n_react': 131, 'n': 163}, 'Cre-2': {'n_react': 64, 'n': 70}, 'Cre-3': {'n_react': 245, 'n': 274}, 'Cre-4': {'n_react': 306, 'n': 326}, 'Cre-5': {'n_react': 521, 'n': 522}, 'Cre-6': {'n_react': 133, 'n': 188}, 'Cre-7': {'n_react': 274, 'n': 305}}
reading (O:a,i): {'ctrl fam': 'mean -0.067, t=-3.36, Holm p=0.0198', 'ctrl nov': 'mean -0.056, t=-3.86, Holm p=0.0145', 'cre fam': 'mean -0.156, t=-3.20, Holm p=0.0198', 'cre nov': 'mean -0.112, t=-6.49, Holm p=0.00255'}
reading (O:a,ii): {'ctrl fam': 'mean -0.010, t=-1.00, Holm p=0.691', 'ctrl nov': 'mean -0.013, t=-0.73, Holm p=0.691', 'cre fam': 'mean -0.043, t=-4.33, Holm p=0.0148', 'cre nov': 'mean -0.040, t=-6.09, Holm p=0.00356'}
reading (O:b,i): {'ctrl fam': 'mean -0.058, t=-4.44, Holm p=0.00759', 'ctrl nov': 'mean -0.046, t=-3.13, Holm p=0.0238', 'cre fam': 'mean -0.140, t=-3.56, Holm p=0.0238', 'cre nov': 'mean -0.116, t=-5.26, Holm p=0.00759'}
reading (O:b,ii): {'ctrl fam': 'mean -0.009, t=-1.18, Holm p=0.337', 'ctrl nov': 'mean -0.022, t=-1.51, Holm p=0.337', 'cre fam': 'mean -0.050, t=-6.41, Holm p=0.00273', 'cre nov': 'mean -0.051, t=-5.18, Holm p=0.00617'}
reading (S:a,i): {'ctrl fam': 'mean -0.012, t=-0.72, Holm p=0.993', 'ctrl nov': 'mean -0.000, t=-0.00, Holm p=1', 'cre fam': 'mean -0.138, t=-2.65, Holm p=0.114', 'cre nov': 'mean -0.074, t=-2.93, Holm p=0.105'}
reading (S:a,ii): {'ctrl fam': 'mean -0.019, t=-0.97, Holm p=1', 'ctrl nov': 'mean 0.005, t=0.15, Holm p=1', 'cre fam': 'mean -0.016, t=-1.03, Holm p=1', 'cre nov': 'mean -0.014, t=-0.90, Holm p=1'}
reading (S:b,i): {'ctrl fam': 'mean -0.012, t=-0.86, Holm p=0.836', 'ctrl nov': 'mean -0.005, t=-0.19, Holm p=0.856', 'cre fam': 'mean -0.125, t=-2.92, Holm p=0.107', 'cre nov': 'mean -0.080, t=-2.76, Holm p=0.107'}
reading (S:b,ii): {'ctrl fam': 'mean -0.002, t=-0.14, Holm p=1', 'ctrl nov': 'mean -0.015, t=-0.40, Holm p=1', 'cre fam': 'mean -0.034, t=-3.01, Holm p=0.0945', 'cre nov': 'mean -0.014, t=-0.60, Holm p=1'}
tracked cells (reactivated / not reactivated), reading (i):
       n_react      n_non     
pre          O    S     O    S
mouse                         
Cre-1      131  103    32   60
Cre-2       64   63     6    7
Cre-3      245  192    29   82
Cre-4      306  279    20   47
Cre-5      521  521     1    1
Cre-6      133   72    55  116
Cre-7      274  251    31   54
Ctrl-1     263   69   113  307
Ctrl-2     216   61    98  253
Ctrl-3     295  197    47  145
Ctrl-4     493  117    69  445
Ctrl-5     340   59   203  484
Ctrl-6     149   35   211  325
Ctrl-7     196   35   183  344
Ctrl-8     207   97    60  170
Ctrl-9      83    0   350  433
reading (O:a,i), mice with >= 10 cells in each group (uncorrected): ctrl fam n=9 mean -0.067 p=0.00991; ctrl nov n=9 mean -0.056 p=0.00483; cre fam n=5 mean -0.108 p=0.00559; cre nov n=5 mean -0.091 p=0.00266
reading (O:b,i), mice with >= 10 cells in each group (uncorrected): ctrl fam n=9 mean -0.058 p=0.00218; ctrl nov n=9 mean -0.046 p=0.0139; cre fam n=5 mean -0.102 p=0.00372; cre nov n=5 mean -0.095 p=0.00252
reading (S:a,i), mice with >= 10 cells in each group (uncorrected): ctrl fam n=8 mean -0.012 p=0.496; ctrl nov n=8 mean -0.000 p=1; cre fam n=5 mean -0.072 p=0.00361; cre nov n=5 mean -0.046 p=0.0965
reading (S:b,i), mice with >= 10 cells in each group (uncorrected): ctrl fam n=8 mean -0.012 p=0.418; ctrl nov n=8 mean -0.005 p=0.856; cre fam n=5 mean -0.072 p=0.00839; cre nov n=5 mean -0.049 p=0.0543

Result: blocked, methods_underspecified, as figs9a, on which it depends. As tested, in control mice reactivated tracked cells are not more stable across days under any reading. The differences are -0.067 to 0.005, and none is positive and significant. Under reading O with all day pairs, they are significantly lower (familiar -0.067, Holm p=0.020; novel -0.056, p=0.015). Reading (i) rests on few non-reactivated cells in some Cre mice (Cre-5: 1 of 522; Cre-2: 6 or 7 of 70); keeping mice with at least 10 cells in each group (9 control, 5 Cre under reading O) changes no control result.

fig7e-cre-reactivation-boost-novel-only¶

In Cre mice, reactivated cells have a weakly higher across-day correlation on novel trials but not on familiar trials.

In [56]:
for rdg, x in F7E.items():
    n_, f_ = x[("cre", "nov")], x[("cre", "fam")]
    print(f"reading ({rdg}): Cre novel mean {n_[2]:.3f} t={n_[0]:.2f} Holm p={n_[1]:.3g}; Cre familiar mean {f_[2]:.3f} t={f_[0]:.2f} Holm p={f_[1]:.3g}")
reading (O:a,i): Cre novel mean -0.112 t=-6.49 Holm p=0.00255; Cre familiar mean -0.156 t=-3.20 Holm p=0.0198
reading (O:a,ii): Cre novel mean -0.040 t=-6.09 Holm p=0.00356; Cre familiar mean -0.043 t=-4.33 Holm p=0.0148
reading (O:b,i): Cre novel mean -0.116 t=-5.26 Holm p=0.00759; Cre familiar mean -0.140 t=-3.56 Holm p=0.0238
reading (O:b,ii): Cre novel mean -0.051 t=-5.18 Holm p=0.00617; Cre familiar mean -0.050 t=-6.41 Holm p=0.00273
reading (S:a,i): Cre novel mean -0.074 t=-2.93 Holm p=0.105; Cre familiar mean -0.138 t=-2.65 Holm p=0.114
reading (S:a,ii): Cre novel mean -0.014 t=-0.90 Holm p=1; Cre familiar mean -0.016 t=-1.03 Holm p=1
reading (S:b,i): Cre novel mean -0.080 t=-2.76 Holm p=0.107; Cre familiar mean -0.125 t=-2.92 Holm p=0.107
reading (S:b,ii): Cre novel mean -0.014 t=-0.60 Holm p=1; Cre familiar mean -0.034 t=-3.01 Holm p=0.0945

Result: blocked, methods_underspecified, as figs9a. As tested, in Cre mice reactivated cells are less stable across days on novel trials (differences -0.014 to -0.116; significant and negative under the O readings, Holm p=0.003 to 0.008). On familiar trials they are also less stable (-0.016 to -0.156).

fig7e-reactivation-effect-virus-and-novelty¶

The across-day stability gain of reactivated cells is larger in control than in Cre mice and larger on novel than familiar trials, and the novelty effect is larger in control mice.

In [57]:
F7EV = {}
for rdg, d in RE.groupby("reading"):
    mm = mixed(d, "diff", within="tt")
    w = d.pivot(index=["mouse", "virus"], columns="tt", values="diff").reset_index(); w["nf"] = w["nov"] - w["fam"]
    t = ttest2(w[w.virus == "ctrl"].nf, w[w.virus == "cre"].nf)
    F7EV[rdg] = (mm, t, d.groupby(["virus", "tt"])["diff"].mean())
    print(f"reading ({rdg}): {fmt_mixed(mm, 'tt')}; novel minus familiar ctrl vs cre t={t['t']:.2f} p={t['p']:.3g} (Welch p={t['p_welch']:.3g})")
    print("   means:", d.groupby(["virus", "tt"])["diff"].mean().round(3).to_dict())
reading (O:a,i): N=9 ctrl, 7 cre; virus F(1,14)=4.83 p=0.0453; tt F(1,14)=2.02 p=0.177; interaction F(1,14)=0.867 p=0.367; novel minus familiar ctrl vs cre t=-0.93 p=0.367 (Welch p=0.428)
   means: {('cre', 'fam'): -0.156, ('cre', 'nov'): -0.112, ('ctrl', 'fam'): -0.067, ('ctrl', 'nov'): -0.056}
reading (O:a,ii): N=9 ctrl, 7 cre; virus F(1,14)=5.76 p=0.0309; tt F(1,14)=0.000886 p=0.977; interaction F(1,14)=0.0442 p=0.837; novel minus familiar ctrl vs cre t=-0.21 p=0.837 (Welch p=0.825)
   means: {('cre', 'fam'): -0.043, ('cre', 'nov'): -0.04, ('ctrl', 'fam'): -0.01, ('ctrl', 'nov'): -0.013}
reading (O:b,i): N=9 ctrl, 7 cre; virus F(1,14)=6.48 p=0.0233; tt F(1,14)=2.37 p=0.146; interaction F(1,14)=0.308 p=0.588; novel minus familiar ctrl vs cre t=-0.55 p=0.588 (Welch p=0.616)
   means: {('cre', 'fam'): -0.14, ('cre', 'nov'): -0.116, ('ctrl', 'fam'): -0.058, ('ctrl', 'nov'): -0.046}
reading (O:b,ii): N=9 ctrl, 7 cre; virus F(1,14)=11.6 p=0.00425; tt F(1,14)=0.406 p=0.534; interaction F(1,14)=0.261 p=0.617; novel minus familiar ctrl vs cre t=-0.51 p=0.617 (Welch p=0.597)
   means: {('cre', 'fam'): -0.05, ('cre', 'nov'): -0.051, ('ctrl', 'fam'): -0.009, ('ctrl', 'nov'): -0.022}
reading (S:a,i): N=8 ctrl, 7 cre; virus F(1,13)=5.81 p=0.0314; tt F(1,13)=3.6 p=0.08; interaction F(1,13)=1.81 p=0.202; novel minus familiar ctrl vs cre t=-1.34 p=0.202 (Welch p=0.226)
   means: {('cre', 'fam'): -0.138, ('cre', 'nov'): -0.074, ('ctrl', 'fam'): -0.012, ('ctrl', 'nov'): -0.0}
reading (S:a,ii): N=8 ctrl, 7 cre; virus F(1,13)=0.1 p=0.757; tt F(1,13)=0.521 p=0.483; interaction F(1,13)=0.341 p=0.569; novel minus familiar ctrl vs cre t=0.58 p=0.569 (Welch p=0.566)
   means: {('cre', 'fam'): -0.016, ('cre', 'nov'): -0.014, ('ctrl', 'fam'): -0.019, ('ctrl', 'nov'): 0.005}
reading (S:b,i): N=8 ctrl, 7 cre; virus F(1,13)=5.97 p=0.0296; tt F(1,13)=3.09 p=0.102; interaction F(1,13)=1.78 p=0.205; novel minus familiar ctrl vs cre t=-1.33 p=0.205 (Welch p=0.201)
   means: {('cre', 'fam'): -0.125, ('cre', 'nov'): -0.08, ('ctrl', 'fam'): -0.012, ('ctrl', 'nov'): -0.005}
reading (S:b,ii): N=8 ctrl, 7 cre; virus F(1,13)=0.315 p=0.584; tt F(1,13)=0.0151 p=0.904; interaction F(1,13)=0.507 p=0.489; novel minus familiar ctrl vs cre t=-0.71 p=0.489 (Welch p=0.484)
   means: {('cre', 'fam'): -0.034, ('cre', 'nov'): -0.014, ('ctrl', 'fam'): -0.002, ('ctrl', 'nov'): -0.015}

Result: blocked, methods_underspecified, as figs9a. As tested, the virus main effect is significant under six of eight readings (p=0.004 to 0.045), with control less negative than Cre. The trial-type main effect is not significant under any reading (p=0.08 to 0.98), and the novelty comparison is not either (p=0.20 to 0.84).

fig7h-reactivated-cells-higher-trial-correlation-control¶

In control mice, cells that participated in HSEs have higher trial by trial rate map correlation than cells that did not, on familiar and novel trials.

Per cell, day and type, mean Pearson correlation of its single-trial maps over trial pairs. Readings: reactivated (i) on that day, (ii) on any day; cells (a) all cells, (b) tracked cells. Reading (a, ii) needs a cell's HSEs on other days, which is defined only for tracked cells, so it equals (b, ii) and is not shown separately.

In [58]:
TC = {}
for (m, fd), s in S.items():
    for tt in ("fam", "nov"):
        TC[(m, fd, tt)] = stx3.cell_trial_corr(s["R"][tidx(s, tt)])
rows = []
for hk in ("hse", "hse_on"):
  for m in CTRL + CRE:
    P = part_tracked(m, hk); cols = TRACK[m]
    for tt in ("fam", "nov"):
        for rdg in ("a,i", "b,i", "b,ii"):
            diffs, nmin = [], []
            for fd in range(6):
                s = S[(m, fd)]; c = TC[(m, fd, tt)]
                ev = s[hk]["events"]
                part = np.zeros(s["n_cells"], bool)
                if ev:
                    part[np.unique(np.concatenate([e["cells"] for e in ev]))] = True
                if rdg == "a,i":
                    cc, pp = c, part
                elif rdg == "b,i":
                    cc, pp = c[cols[fd]], part[cols[fd]]
                else:
                    cc, pp = c[cols[fd]], P.any(0)
                if pp.any() and (~pp).any():
                    diffs.append(np.nanmean(cc[pp]) - np.nanmean(cc[~pp]))
                    nmin.append(min(int(pp.sum()), int((~pp).sum())))
            rows.append(dict(mouse=m, virus=virus_of(m), tt=tt, reading=("S" if hk == "hse" else "O") + ":" + rdg, diff=np.nanmean(diffs) if diffs else np.nan,
                             days=len(diffs), min_group=min(nmin) if nmin else 0))
TH = pd.DataFrame(rows)
F7H = {}
for rdg, d in TH.groupby("reading"):
    tests = [(v, tt, stats.ttest_1samp(d[(d.virus == v) & (d.tt == tt)]["diff"].dropna(), 0)) for v in ("ctrl", "cre") for tt in ("fam", "nov")]
    adj = holm([t[2].pvalue for t in tests])
    F7H[rdg] = {(v, tt): (float(t.statistic), float(p), float(d[(d.virus == v) & (d.tt == tt)]["diff"].mean())) for (v, tt, t), p in zip(tests, adj)}
    print(f"reading ({rdg}):", {f"{v} {tt}": f"mean {x[2]:.4f}, t={x[0]:.2f}, Holm p={x[1]:.3g}" for (v, tt), x in F7H[rdg].items()})
print("days entering each mouse's mean, and the smallest group (reactivated or not) on those days:")
print(TH[TH.tt == "nov"].pivot(index="mouse", columns="reading", values="min_group").to_string())
print(TH[TH.tt == "nov"].pivot(index="mouse", columns="reading", values="days").to_string())
reading (O:a,i): {'ctrl fam': 'mean -0.0054, t=-0.71, Holm p=0.997', 'ctrl nov': 'mean -0.0029, t=-0.50, Holm p=0.997', 'cre fam': 'mean -0.0304, t=-3.98, Holm p=0.0218', 'cre nov': 'mean -0.0274, t=-5.44, Holm p=0.00642'}
reading (O:b,i): {'ctrl fam': 'mean -0.0166, t=-1.82, Holm p=0.212', 'ctrl nov': 'mean -0.0077, t=-0.74, Holm p=0.48', 'cre fam': 'mean -0.0507, t=-4.99, Holm p=0.00742', 'cre nov': 'mean -0.0409, t=-7.25, Holm p=0.0014'}
reading (O:b,ii): {'ctrl fam': 'mean -0.0488, t=-3.73, Holm p=0.0173', 'ctrl nov': 'mean -0.0313, t=-2.36, Holm p=0.0459', 'cre fam': 'mean -0.1209, t=-3.07, Holm p=0.044', 'cre nov': 'mean -0.0734, t=-6.82, Holm p=0.00194'}
reading (S:a,i): {'ctrl fam': 'mean 0.0023, t=0.24, Holm p=1', 'ctrl nov': 'mean 0.0078, t=0.55, Holm p=1', 'cre fam': 'mean -0.0230, t=-3.81, Holm p=0.0265', 'cre nov': 'mean -0.0222, t=-8.45, Holm p=0.000599'}
reading (S:b,i): {'ctrl fam': 'mean -0.0039, t=-0.47, Holm p=1', 'ctrl nov': 'mean 0.0080, t=0.34, Holm p=1', 'cre fam': 'mean -0.0382, t=-3.91, Holm p=0.0236', 'cre nov': 'mean -0.0405, t=-5.63, Holm p=0.00539'}
reading (S:b,ii): {'ctrl fam': 'mean -0.0145, t=-1.49, Holm p=0.361', 'ctrl nov': 'mean 0.0034, t=0.20, Holm p=0.848', 'cre fam': 'mean -0.1154, t=-2.65, Holm p=0.115', 'cre nov': 'mean -0.0504, t=-3.88, Holm p=0.0328'}
days entering each mouse's mean, and the smallest group (reactivated or not) on those days:
reading  O:a,i  O:b,i  O:b,ii  S:a,i  S:b,i  S:b,ii
mouse                                              
Cre-1      164     24      32     43      7      60
Cre-2       99     21       6     87     14       7
Cre-3      351     99      29    162     45      82
Cre-4      350    110      20    328     83      47
Cre-5      169     53       1    190     61       1
Cre-6       67     13      55     23      2      72
Cre-7      422    133      31    204     61      54
Ctrl-1     300    104     113     84     23      69
Ctrl-2     190     49      98     25      7      61
Ctrl-3     364     79      47     52     14     145
Ctrl-4     437    162      69     30      7     117
Ctrl-5     237     65     203     40      9      59
Ctrl-6      60     14     149     22      6      35
Ctrl-7      72     23     183     20      6      35
Ctrl-8     145     59      60     44     16      97
Ctrl-9      23     12      83      0      0       0
reading  O:a,i  O:b,i  O:b,ii  S:a,i  S:b,i  S:b,ii
mouse                                              
Cre-1        6      6       6      6      6       6
Cre-2        6      6       6      6      6       6
Cre-3        6      6       6      6      6       6
Cre-4        6      6       6      6      6       6
Cre-5        6      6       6      6      6       6
Cre-6        6      6       6      4      4       6
Cre-7        6      6       6      6      6       6
Ctrl-1       6      6       6      3      3       6
Ctrl-2       6      6       6      5      5       6
Ctrl-3       6      6       6      6      6       6
Ctrl-4       6      6       6      5      5       6
Ctrl-5       6      6       6      4      4       6
Ctrl-6       6      6       6      4      4       6
Ctrl-7       5      5       6      3      3       6
Ctrl-8       6      6       6      5      5       6
Ctrl-9       5      5       6      0      0       0

Result: blocked, methods_underspecified, as figs9a. As tested, in control mice reactivated cells do not have a higher trial-by-trial correlation under any reading. The differences are -0.049 to 0.008. Under reading O:b,ii they are significantly lower (familiar -0.049, Holm p=0.017; novel -0.031, p=0.046). The smallest group per mouse is printed above; under reading S:b,i some mice have only 2 to 9 cells in it.

fig7h-no-trial-correlation-boost-cre¶

In Cre mice, reactivated cells do not have higher trial by trial correlation than non-reactivated cells, on either trial type.

In [59]:
for rdg, x in F7H.items():
    print(f"reading ({rdg}): Cre familiar mean {x[('cre', 'fam')][2]:.4f} Holm p={x[('cre', 'fam')][1]:.3g}; Cre novel mean {x[('cre', 'nov')][2]:.4f} Holm p={x[('cre', 'nov')][1]:.3g}")
reading (O:a,i): Cre familiar mean -0.0304 Holm p=0.0218; Cre novel mean -0.0274 Holm p=0.00642
reading (O:b,i): Cre familiar mean -0.0507 Holm p=0.00742; Cre novel mean -0.0409 Holm p=0.0014
reading (O:b,ii): Cre familiar mean -0.1209 Holm p=0.044; Cre novel mean -0.0734 Holm p=0.00194
reading (S:a,i): Cre familiar mean -0.0230 Holm p=0.0265; Cre novel mean -0.0222 Holm p=0.000599
reading (S:b,i): Cre familiar mean -0.0382 Holm p=0.0236; Cre novel mean -0.0405 Holm p=0.00539
reading (S:b,ii): Cre familiar mean -0.1154 Holm p=0.115; Cre novel mean -0.0504 Holm p=0.0328

Result: blocked, methods_underspecified, as figs9a. As tested, reactivated cells in Cre mice have a lower trial-by-trial correlation: differences -0.022 to -0.121, Holm p=0.0006 to 0.044 under five of six readings; under reading S:b,ii, familiar p=0.115 and novel p=0.033. They are higher in no reading, which is the paper's statement, but the two-sided test of the criterion finds a difference; whether the test should be one-sided is asked of a reader (questions file).

fig7h-reactivation-effect-virus-and-novelty¶

The trial by trial correlation gain of reactivated cells is larger in control than in Cre mice and larger on novel than familiar trials.

In [60]:
for rdg, d in TH.groupby("reading"):
    mm = mixed(d, "diff", within="tt")
    print(f"reading ({rdg}): {fmt_mixed(mm, 'tt')}; means {d.groupby(['virus', 'tt'])['diff'].mean().round(4).to_dict()}")
reading (O:a,i): N=9 ctrl, 7 cre; virus F(1,14)=8.15 p=0.0127; tt F(1,14)=0.44 p=0.518; interaction F(1,14)=0.00453 p=0.947; means {('cre', 'fam'): -0.0304, ('cre', 'nov'): -0.0274, ('ctrl', 'fam'): -0.0054, ('ctrl', 'nov'): -0.0029}
reading (O:b,i): N=9 ctrl, 7 cre; virus F(1,14)=8.05 p=0.0132; tt F(1,14)=2.53 p=0.134; interaction F(1,14)=0.00457 p=0.947; means {('cre', 'fam'): -0.0507, ('cre', 'nov'): -0.0409, ('ctrl', 'fam'): -0.0166, ('ctrl', 'nov'): -0.0077}
reading (O:b,ii): N=9 ctrl, 7 cre; virus F(1,14)=5.36 p=0.0362; tt F(1,14)=3.77 p=0.0727; interaction F(1,14)=0.886 p=0.363; means {('cre', 'fam'): -0.1209, ('cre', 'nov'): -0.0734, ('ctrl', 'fam'): -0.0488, ('ctrl', 'nov'): -0.0313}
reading (S:a,i): N=8 ctrl, 7 cre; virus F(1,13)=8.73 p=0.0112; tt F(1,13)=0.112 p=0.743; interaction F(1,13)=0.0559 p=0.817; means {('cre', 'fam'): -0.023, ('cre', 'nov'): -0.0222, ('ctrl', 'fam'): 0.0023, ('ctrl', 'nov'): 0.0078}
reading (S:b,i): N=8 ctrl, 7 cre; virus F(1,13)=7.08 p=0.0196; tt F(1,13)=0.16 p=0.696; interaction F(1,13)=0.29 p=0.6; means {('cre', 'fam'): -0.0382, ('cre', 'nov'): -0.0405, ('ctrl', 'fam'): -0.0039, ('ctrl', 'nov'): 0.008}
reading (S:b,ii): N=8 ctrl, 7 cre; virus F(1,13)=7.73 p=0.0156; tt F(1,13)=4.6 p=0.0515; interaction F(1,13)=1.59 p=0.229; means {('cre', 'fam'): -0.1154, ('cre', 'nov'): -0.0504, ('ctrl', 'fam'): -0.0145, ('ctrl', 'nov'): 0.0034}

Result: blocked, methods_underspecified, as figs9a. As tested, the virus main effect is significant under every reading (p=0.011 to 0.036), with control higher, that is, less negative, because the Cre differences are negative. The trial-type main effect is not significant under any reading (p=0.05 to 0.74).

Summary¶

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.

claim outcome
link-roi-alignment reproduced (the link holds)
fig1c-novelty-preference, figs1c-training-occupancy-no-difference, figs1e-open-field-distance-no-difference, figs1f-epm-closed-arm-no-difference, figs1f-epm-distance-no-difference blocked, data_missing (freely moving behaviour not deposited)
fig2ab-example-cell-counts partially reproduced (7 of 8 counts; Cre-3 day 5 has 82 familiar trials, not 17)
fig1f-anticipatory-licking-familiar, fig1g-anticipatory-licking-novel reproduced
vr-reward-location-learning partially reproduced (spatial pattern holds; familiar licking falls, not rises, from day 1 to day 6)
figs2f-novelty-slowing-familiar, figs2g-novel-arm-slowing-no-difference, figs2i-reward-approach-speed-cv reproduced
fig2cd-decoding-no-group-difference reproduced*
fig2cd-decoding-improves-over-days partially reproduced*
figs3a-, figs3b-, figs3c- (S3C on the adopted reading), fig2gh-, figs3eg- reproduced*
figs4-morph-task-context-discrimination, figs5-ca3-dg-place-fields blocked, data_missing
fig3bc-, fig3d-, fig3e- (model) blocked, methods_underspecified
fig3f-narrower-fields-cre-familiar not reproduced*
fig3g-narrower-fields-cre-novel partially reproduced*
fig3h-, fig3i- (more fields per cell) reproduced*
fig4e- (x3), fig4-block6-activity-increase-pattern (150 cm stem adopted), fig4e-novel-increase-grows-over-days, fig4d-, figs6b-, figs6e- reproduced*
figs7b-, fig5d- (x3) reproduced*
fig5h-extinction-group-difference, fig5i-extinction-intercept-not-slope blocked, data_missing (days 7 and 8 not deposited)
fig6c-pv-backward-shift-day1-control, fig6c-no-pv-shift-cre, figs8d- (clipped COM), fig6e- (day 1 adopted) reproduced*
figs8h-across-day-pv-shift, fig6d-field-com-shift-larger-control not reproduced*
figs9a-, figs9b- (HSEs), fig7e- (x3), fig7h- (x3) blocked, methods_underspecified (the HSE detector, as read from the Methods, still flags more than half as many trials in the Cre group when synchrony is removed)

* rests on the assumption that the deposited dF/F stands for the paper's deconvolved activity rates.

How the analysis differs from the paper's:

  • Activity is the deposited dF/F, as in the authors' code for these files, not the deconvolved activity rates of the preprint's Methods.
  • Cre-8 is not in the dataset, so the 8-Cre readings of the behaviour claims are not run.
  • The reward zone fronts are estimated from where rewards were given.
  • HSE stopping periods use a speed from the spline position smoothed over 1 s, because the speed series jitters while the mouse is still. The HSE null is run under two readings. With each cell's series shifted in time, which removes synchrony, the detector flags more than half as many trials as in the real data in the Cre group under both readings, so the HSE claims are blocked.
  • The raw-COM PV shift is ill-conditioned (synthetic check); the PV shift claims rest on the clipped COM.
  • The block numbers of the second file of a split day restart at 0; they are continued from the first file, as in the authors' code.
  • Several method details the paper leaves open are run under every reading named in the claims file; the results above say which readings match.
  • The two days split over two files are merged on the ROIs the authors matched between them.

What was found about the dataset:

  • The dataset holds the head-fixed imaging and VR behaviour of Ctrl-1 to Ctrl-9 and Cre-1 to Cre-7 on days 1 to 6, plus seven SparseKO mice that are not in this preprint.
  • The freely moving behaviour, the reversal days 7 and 8, the Cre-8 CA2/3 sessions, the dentate gyrus session and the morph task are not deposited.
  • The deconvolved activity rates are not deposited.
  • The speed series is labelled 10 cm/s but is in cm/s.
  • The across-day cell matches are not in the NWB files; they are on Figshare.
  • The two published versions have identical files.
  • On the two days split over two files, the block numbers restart at 0 in the second file.
  • The deposited place-cell masks are stricter than the 1000-shuffle test recomputed here, and their spatial information is on another scale; the function that made them is not in the linked repository.
  • Cre mice stop for longer after rewards than control mice (5.4 s against 1.5 s per stopping period).
  • The Figshare shuffles (shuffle_pkls.zip) hold no HSE results.