Conserved role of primary motor cortex in the control of prehension in mice and macaques.
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
Python · 335 lines · 12 KB · CC-BY-4.0
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- Matched-data plotting and trace-visualization script.
- This script:
- 1. Builds per-neuron trace data from trial traces.
- 2. Plots example mean traces with variance.
- 3. Plots session-level mean-trace heatmaps.
- 4. Plots FOV overlays with trajectories.
- 5. Builds session-by-neuron trace panels.
- 6. Plots coefficient of variation and MAD for selected traces.
- Expected workspace objects:
- - mice_traces
- - trial_type_traces
- - coordinates
- - pnrs
- - dates
- - xmins / xmaxs (or the script computes limits where needed)
- """
- import numpy as np
- import pandas as pd
- import seaborn as sb
- import matplotlib
- matplotlib.use("TkAgg")
- import matplotlib.pyplot as plt
- import matplotlib.ticker as mticker
- from matplotlib import gridspec
- from reach_analysis_funcs import edit_bounding_lines
- # ---------------------------------------------------------------------
- # plotting style
- # ---------------------------------------------------------------------
- sb.set(font="Arial", context="talk", font_scale=0.7, style="white")
- sb.set_style("ticks")
- # ---------------------------------------------------------------------
- # helpers
- # ---------------------------------------------------------------------
- def build_neuron_data_from_trial_traces(trial_traces_df):
- """
- Build a neuron -> DataFrame dictionary from a trial_traces dataframe.
- Each neuron gets a DataFrame whose columns are trials and whose rows
- are timepoints.
- """
- n_neurons = trial_traces_df.iloc[0].shape[0]
- neuron_data = {}
- for neuron_idx in range(n_neurons):
- traces = []
- for session in trial_traces_df.index:
- session_trials = trial_traces_df.loc[session]
- traces.append(np.asarray([session_trials.iloc[n][neuron_idx] for n in range(session_trials.shape[0])]))
- neuron_data[neuron_idx] = pd.DataFrame(np.asarray(traces).T)
- return neuron_data
- def build_session_neuron_data(trial_traces_df):
- """
- Build a session -> neuron -> DataFrame dictionary.
- This matches the nested structure used for the multi-panel variance plots.
- """
- session_neuron_data = {}
- for session_idx, session in enumerate(trial_traces_df.index):
- session_trials = trial_traces_df.loc[session]
- n_neurons = session_trials.iloc[0].shape[0]
- session_neuron_data[session_idx] = {}
- for neuron_idx in range(n_neurons):
- traces = []
- for trial_idx in range(session_trials.shape[0]):
- traces.append(np.asarray(session_trials.iloc[trial_idx][neuron_idx]))
- session_neuron_data[session_idx][neuron_idx] = pd.DataFrame(np.asarray(traces).T)
- return session_neuron_data
- def plot_example_mean_traces_with_variance(neuron_data, neuron_ids, time_xlim=(10, 90), time_label="time (s)"):
- """Plot selected neuron traces with variance-style line overlays."""
- lens = len(neuron_ids)
- fig = plt.figure(figsize=(8, 3 * lens), constrained_layout=False)
- spec = fig.add_gridspec(ncols=1, nrows=lens, wspace=0.01, hspace=0.02)
- for i, neuron_idx in enumerate(neuron_ids):
- ax = fig.add_subplot(spec[i])
- df_plot = pd.DataFrame(neuron_data[neuron_idx].stack()).droplevel([1], axis=0).reset_index().melt(
- id_vars="index", value_vars=0
- )
- sb.lineplot(data=df_plot, x="index", y="value", ax=ax)
- ax.axvline(x=neuron_data[neuron_idx].shape[0] / 2, color="k", alpha=0.4, linewidth=2)
- ax.spines["top"].set_visible(False)
- ax.spines["right"].set_visible(False)
- if i != lens - 1:
- ax.spines["bottom"].set_visible(False)
- ax.get_xaxis().set_ticks([])
- else:
- ax.xaxis.set_major_locator(mticker.MaxNLocator(11))
- ticks_loc = ax.get_xticks().tolist()
- ax.xaxis.set_major_locator(mticker.FixedLocator(ticks_loc))
- ax.set_xticklabels([int(x / 10) - 5 for x in ticks_loc], size=30)
- ax.set_xlabel(time_label, size=40)
- ticks_loc = ax.get_yticks().tolist()
- ax.yaxis.set_major_locator(mticker.FixedLocator(ticks_loc))
- ax.set_yticklabels([x for x in ticks_loc], size=20)
- ax.set_ylabel(f"neuron {neuron_idx + 1}", rotation=0, labelpad=60, size=20)
- ax.set_xlim(*time_xlim)
- if i != 0:
- ax.spines["left"].set_visible(False)
- plt.show()
- def plot_selected_session_heatmaps(trial_mean_traces_sorted, sessions, titles=None):
- """Plot heatmaps of selected session mean traces."""
- lens = len(sessions)
- fig, axes = plt.subplots(nrows=1, ncols=lens, figsize=(4 * lens, 4))
- axes = np.atleast_1d(axes)
- for i, sess in enumerate(sessions):
- t = trial_mean_traces_sorted.loc[sess].mean_traces
- axes[i].imshow(
- t,
- aspect="auto",
- vmin=np.percentile(t, 85),
- vmax=np.percentile(t, 100),
- interpolation="none",
- )
- axes[i].xaxis.set_major_locator(mticker.MaxNLocator(11))
- ticks_loc = axes[i].get_xticks().tolist()
- axes[i].xaxis.set_major_locator(mticker.FixedLocator(ticks_loc))
- axes[i].set_xticklabels([int((x / 10) - 5) for x in ticks_loc], size=20)
- axes[i].set_xlabel("time (s)", size=20)
- axes[i].set_title(titles[i] if titles is not None else sess, size=20)
- plt.show()
- def get_session_limits(session_coords, padding=50):
- """Compute a display range from a session's coordinate trajectories."""
- min_max_vals = [
- [np.nanmin(session_coords[j][:, 0]), np.nanmax(session_coords[j][:, 0])]
- for j in range(session_coords.shape[0])
- ]
- ymins = np.min(min_max_vals) - padding
- ymaxs = np.max(min_max_vals) + padding
- return ymins, ymaxs
- def plot_fov_overlays(coordinates, pnrs, sessions):
- """Plot FOV images with red trajectory overlays."""
- lens = len(sessions)
- fig, axes = plt.subplots(nrows=1, ncols=lens, figsize=(5 * lens, 4), sharey=True)
- axes = np.atleast_1d(axes)
- for i, sess in enumerate(sessions):
- session_coords = coordinates.loc[sess]
- ymins, ymaxs = get_session_limits(session_coords, padding=50)
- axes[i].imshow(
- pnrs.loc[sess].T,
- aspect="auto",
- vmin=np.percentile(pnrs.loc[sess], 85),
- vmax=np.percentile(pnrs.loc[sess][0], 100),
- cmap="gray",
- )
- for j in range(session_coords.shape[0]):
- axes[i].plot(session_coords[j][:, 1], session_coords[j][:, 0], linewidth=1, color="r")
- axes[i].set_ylim(ymaxs, ymins)
- axes[i].set_title(sess, size=20)
- axes[i].set_axis_off()
- plt.show()
- def plot_matched_session_group(coordinates, pnrs, session_groups, group_index, xmins, xmaxs, title):
- """Plot a matched session group with trajectories overlaid on FOV images."""
- sessions = session_groups[group_index]
- lens = len(sessions)
- fig, axes = plt.subplots(nrows=1, ncols=lens, figsize=(5 * lens, 4))
- axes = np.atleast_1d(axes)
- fig.subplots_adjust(left=0.1, right=0.8, top=0.995, bottom=0.02, wspace=0.01, hspace=0.1)
- stage_labels = [["early", "mid", "late"], ["early", "late"]]
- for i, sess in enumerate(sessions):
- axes[i].imshow(
- pnrs.loc[sess],
- aspect=2,
- vmin=np.percentile(pnrs.loc[sess], 80),
- vmax=np.percentile(pnrs.loc[sess][0], 100),
- cmap="gray",
- )
- for j in range(coordinates.loc[sess].shape[0]):
- axes[i].plot(coordinates.loc[sess][j][:, 0], coordinates.loc[sess][j][:, 1], linewidth=1, color="r")
- axes[i].set_xlim(xmins, xmaxs)
- axes[i].set_title(stage_labels[group_index][i], size=20)
- axes[i].set_axis_off()
- plt.suptitle(title, size=20)
- plt.show()
- def plot_session_neuron_panels(session_neuron_data):
- """Plot blocks of session-by-neuron trace panels."""
- num = 4
- for start_idx in np.arange(0, len(session_neuron_data), num):
- fig = plt.figure(figsize=(10, 8))
- outer = gridspec.GridSpec(1, 4, wspace=0.3, hspace=0.1)
- num_n = num
- if (len(session_neuron_data) - start_idx) < num:
- num_n = int(len(session_neuron_data) - start_idx)
- for j, k in enumerate(range(start_idx, start_idx + num_n)):
- inner = gridspec.GridSpecFromSubplotSpec(
- len(session_neuron_data[0]),
- 1,
- subplot_spec=outer[j],
- wspace=0.3,
- hspace=0.01,
- )
- for i in range(len(session_neuron_data[0])):
- ax = plt.Subplot(fig, inner[i])
- df_plot = pd.DataFrame(session_neuron_data[k][i].stack()).droplevel([1], axis=0).reset_index().melt(
- id_vars="index",
- value_vars=0,
- )
- sb.lineplot(data=df_plot, x="index", y="value", ax=ax)
- ax.axvline(x=session_neuron_data[k][i].shape[0] / 2, color="k", alpha=0.4, linewidth=2)
- ax.spines["top"].set_visible(False)
- ax.spines["right"].set_visible(False)
- ax.spines["left"].set_visible(False)
- fig.add_subplot(ax)
- if i != len(session_neuron_data[0]) - 1:
- ax.spines["bottom"].set_visible(False)
- ax.get_xaxis().set_ticks([])
- else:
- ax.xaxis.set_major_locator(mticker.MaxNLocator(11))
- ticks_loc = ax.get_xticks().tolist()
- ax.xaxis.set_major_locator(mticker.FixedLocator(ticks_loc))
- ax.set_xticklabels([int(x / 10) - 5 for x in ticks_loc], size=30)
- ax.set_xlabel("time (s)", size=40, weight="bold")
- ticks_loc = ax.get_yticks().tolist()
- ax.yaxis.set_major_locator(mticker.FixedLocator(ticks_loc))
- ax.set_yticklabels([x for x in ticks_loc], size=20)
- ax.set_ylabel("", rotation=0, labelpad=60, size=20)
- ax.set_xlim(10, 90)
- ax.get_yaxis().set_ticks([])
- ax.get_xaxis().set_ticks([])
- plt.show()
- def plot_trace_cv_and_mad(session_neuron_data, session_idx, neuron_idx):
- """Plot CV and MAD for each trace in a selected session/neuron."""
- dats = [n.values for _, n in session_neuron_data[session_idx].items()]
- fig = plt.figure(figsize=(8, 4))
- for da in dats:
- cv = np.std(da, axis=1) / np.mean(da, axis=1)
- mad = np.mean(np.abs(da - np.mean(da, axis=1, keepdims=True)), axis=1)
- plt.plot(cv, "--")
- plt.plot(mad)
- plt.show()
- # ---------------------------------------------------------------------
- # primary analysis objects
- # ---------------------------------------------------------------------
- mouse = "m63"
- m = mouse
- trial_traces_df = mice_traces[m]["trial_traces"]
- dates = trial_traces_df.index.values
- neuron_data = build_neuron_data_from_trial_traces(trial_traces_df)
- plot_example_mean_traces_with_variance(neuron_data)
- trial_mean_traces_sorted = mice_traces[m]["trial_mean_traces_sorted"]
- dates = trial_mean_traces_sorted.index.values
- datess = np.asarray(dates)[np.asarray([0, 8, 13])]
- plot_selected_session_heatmaps(trial_mean_traces_sorted, datess, titles=["early", "mid", "late"])
- plot_fov_overlays(coordinates, pnrs, datess)
- dates_fil = {
- "m63": ["2021-02-03", "2021-02-05", "2021-02-09", "2021-03-17", "2021-03-19", "2021-03-24", "2021-03-31", "2021-05-04", "2021-05-06"],
- "m72": ["2021-03-01", "2021-03-04", "2021-03-10", "2021-05-05", "2021-05-19", "2021-08-12", "2021-08-13", "2021-10-01", "2021-10-07"],
- "m105": ["2021-12-08", "2021-12-10", "2022-02-03", "2022-02-07", "2022-02-14", "2022-03-14", "2022-03-21", "2022-04-06", "2022-04-08"],
- "m106": ["2022-02-02", "2022-02-03", "2022-02-07", "2022-03-16", "2022-03-21", "2022-04-04"],
- }
- acc_sessions = [["2021-02-03", "2021-03-12", "2021-04-21"], ["2021-05-04", "2021-05-21"]]
- dates = [list(coordinates.loc[d].sort_index().index) for d in acc_sessions]
- d = 0
- xmins, xmaxs = 0, 100
- plot_matched_session_group(
- coordinates=coordinates,
- pnrs=pnrs,
- session_groups=dates,
- group_index=d,
- xmins=xmins,
- xmaxs=xmaxs,
- title="learning" if d == 0 else "post stroke",
- )
- # ---------------------------------------------------------------------
- # session-by-neuron plots
- # ---------------------------------------------------------------------
- session_neuron_data = build_session_neuron_data(mice_traces[m]["trial_traces"])
- plot_session_neuron_panels(session_neuron_data)
- k = max(session_neuron_data.keys())
- plot_trace_cv_and_mad(session_neuron_data, session_idx=k, neuron_idx=0)
activity_plotting.py, under CC-BY-4.0 · at the source
Overview
- Department of Neurology, University of California, San Francisco, San Francisco, CA 94158, USA
- San Francisco VA Medical Center, San Francisco, CA 94158, USA
- These authors contributed equally
- California National Primate Research Center, University of California, Davis, Davis, CA 95616, USA
- Laboratory of Neurological Sciences, Division of Biomedical and Translational Sciences, Sanford School of Medicine, The University of South Dakota, Vermillion, SD 57069, USA
- Department of Anatomy, University of California, San Francisco, San Francisco, CA 94158, USA
- Lead contact
Abstract
A central goal in neuroscience is to develop cross-species frameworks that reveal conserved principles of movement control. Recent work has suggested a potential species difference in the role of primary motor cortex (M1) during skilled forelimb tasks: in rodents, extensive practice appears to shift control to subcortical circuits, leading to “disengagement” of M1 from task execution. Importantly, there is no evidence of such disengagement in macaques. We hypothesized that these differences instead reflect task demands, particularly the need for fine (i.e., grasping) versus gross motor control. Strikingly, M1 lesions in macaques produced recovery patterns similar to rodents: gross motor control, including an exclusively gross motor task, recovered rapidly, whereas fine motor control exhibited persistent deficits. Detailed kinematic analyses in both macaques and mice performing a single-pellet reach-to-grasp task (RGT) revealed analogous disruptions in the temporal structure of sub-movements. These findings underscore the importance of task design and the translational value of rodent models for understanding motor control and recovery.
Reproduced under the paper's license (CC BY), from the paper cited above.
Repositories
Its files are read in the Code ↔ Paper reader above.
Zenodo 19615415
Availability: 1 check, the latest on 27 September 2026: the link answers (HTTP 200)
- 27 September 2026: the link answers (HTTP 200)
9 files
- mouse/
ca_imaging/ , Python, 335 linesactivity_plotting.py - mouse/
ca_imaging/ , Python, 545 linesmatched_data_analysis.py - mouse/
ca_imaging/ , Python, 409 linestrace_analysis.py - mouse/
kinematic_analysis/ , Python, 373 linesmouse_moseq_analysis.py - mouse/
kinematic_analysis/ , Python, 576 linesmouse_moseq_plotting.py - mouse/
kinematic_analysis/ , Python, 624 linesstroke_mice_kinematic_an alysis.py - nhp/
pellet_task/ , Python, 353 linesnhp_moseq_analysis.py - nhp/
pellet_task/ , Python, 645 linesnhp_pellet_reach_analysi s.py - nhp/
touch_task/ , Python, 704 linestouch_task_script.py
faparici0/2026_m1_lesion_manuscript
Availability: 1 check, the latest on 27 September 2026: the link is dead
- 27 September 2026: the link is dead
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 9 scripts, each with its path and the digest of its content;
- no match between paragraphs and code yet;
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
Datasets cited
- doi:10.48324/
dandi.001782/ , at DANDI; found in the resources table0.260421.2247
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 2, 28 September 2026
- Publisher: n/a → Cell Press
Version 1, 27 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 7 authors, 8 keywords, 9 MeSH terms, 8 funders, 75 references, 8 RRIDs.
Cite
This paper
Aparicio, F., Ghuman, H., Khanna, P., Barati, S., Morecraft, R., Kirst, C., & Ganguly, K. (2026). Conserved role of primary motor cortex in the control of prehension in mice and macaques. Cell reports, 45(6), 117419. https://
BibTeX
@article{aparicio2026con
author = {Aparicio, Francisco and Ghuman, Harman and Khanna, Preeya and Barati, Sapeeda and Morecraft, Robert and Kirst, Christoph and Ganguly, Karunesh},
title = {{Conserved role of primary motor cortex in the control of prehension in mice and macaques}},
journal = {Cell reports},
year = {2026},
month = jun,
volume = {45},
number = {6},
pages = {117419},
publisher = {Cell Press},
issn = {2211-1247},
doi = {10.1016/
url = {https://
pmid = {42228567},
pmcid = {PMC13379984}
}
RIS
TY - JOUR
AU - Aparicio, Francisco
AU - Ghuman, Harman
AU - Khanna, Preeya
AU - Barati, Sapeeda
AU - Morecraft, Robert
AU - Kirst, Christoph
AU - Ganguly, Karunesh
TI - Conserved role of primary motor cortex in the control of prehension in mice and macaques
T2 - Cell reports
J2 - Cell Rep
PY - 2026
DA - 2026/
VL - 45
IS - 6
SP - 117419
SN - 2211-1247
PB - Cell Press
DO - 10.1016/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1016/
"type": "article-journal",
"title": "Conserved role of primary motor cortex in the control of prehension in mice and macaques",
"container-title": "Cell reports",
"author": [
{
"family": "Aparicio",
"given": "Francisco"
},
{
"family": "Ghuman",
"given": "Harman"
},
{
"family": "Khanna",
"given": "Preeya"
},
{
"family": "Barati",
"given": "Sapeeda"
},
{
"family": "Morecraft",
"given": "Robert"
},
{
"family": "Kirst",
"given": "Christoph"
},
{
"family": "Ganguly",
"given": "Karunesh"
}
],
"container-title-short":
"volume": "45",
"issue": "6",
"page": "117419",
"DOI": "10.1016/
"PMID": "42228567",
"PMCID": "PMC13379984",
"ISSN": "2211-1247",
"publisher": "Cell Press",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
6,
1
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.7554/elife.111876 [code]
- Distinct sensorimotor encoding in tuft dendrites and somata associated with action, correction, and learning.Journal: eLifeIn common: statsmodels, seaborn, scikit-learn, 4 other tools, mouse, 6 references
- [2] doi:10.1038/s41467-026-73476-4 [code]
- Developmental molecular signatures define de novo cortico-brainstem circuit for skilled forelimb movement.Journal: Nature communicationsIn common: OpenCV, pandas, Matplotlib, 1 other tool, mouse, 6 references
- [3] doi:10.1038/s41593-026-02362-5 [code]
- Replay of procedural memory is independent of the hippocampus.Journal: Nature neuroscienceIn common: statsmodels, seaborn, scikit-learn, 4 other tools, mouse, 4 references
- [4] doi:10.1038/s41467-026-74569-w [code]
- Motor cortex directly excites the substantia nigra pars reticulata, the basal ganglia output nucleus.Journal: Nature communicationsIn common: pandas, NumPy, systems, mouse, 6 references
- [5] doi:10.1038/s41467-026-73518-x [code]
- Scg2 drives corticospinal circuit reorganization with spinal premotor interneurons and astrocytes for motor recovery after stroke in mice.Journal: Nature communicationsIn common: mouse, 7 references
- [6] doi:10.1016/j.isci.2026.117375 [code]
- Motor priming is associated with widespread recruitment into neural ensembles and more rapid ensemble transitions.Journal: iScienceIn common: OpenCV, statsmodels, seaborn, 5 other tools, systems, 1 reference
- [7] doi:10.1038/s41467-026-72057-9 [code]
- Sex-specific behavioral feedback modulates sensorimotor processing and drives flexible social behavior.Journal: Nature communicationsIn common: OpenCV, statsmodels, seaborn, 5 other tools, systems, 1 reference
- [8] doi:10.1038/s41593-026-02262-8 [code]
- Cheese3D enables sensitive detection and analysis of whole-face movement in mice.Journal: Nature neuroscienceIn common: OpenCV, seaborn, scikit-learn, 4 other tools, systems, mouse, 2 references
- [9] doi:10.1016/j.isci.2026.116825 [code]
- Social hierarchy shapes behavioral and transcriptional responses to chronic stress and ketamine in male mice.Journal: iScienceIn common: OpenCV, statsmodels, seaborn, 5 other tools, systems, mouse, 1 reference
- [10] doi:10.7554/elife.109717 [code]
- Retrosplenial cortex enables context-dependent goal-directed sensorimotor transformation.Journal: eLifeIn common: OpenCV, statsmodels, seaborn, 5 other tools, systems, mouse, 1 reference
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 2 repositories of the authors' code, each at its verified commit and with its license, 9 scripts, and 0 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:b84266994bfa76cf…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
