Functional specialization of mPFC-BLA and mPFC-NAc pathways in affective state representation.
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 · 279 lines · 9.5 KB · MIT
- """Batch CaImAn processing for one-photon calcium imaging TIFF files.
- This script performs motion correction, CNMF source extraction, seeded CNMF
- refinement, component filtering, and export of fluorescence traces and spatial
- metadata. Paths, animal identifiers, and day ranges are provided on the command
- line so the pipeline can be reused without editing the source code.
- """
- from __future__ import annotations
- import argparse
- import glob
- import os
- import time
- from pathlib import Path
- import cv2
- import numpy as np
- import pandas as pd
- from scipy.ndimage import center_of_mass
- import caiman as cm
- from caiman.motion_correction import MotionCorrect
- from caiman.source_extraction.cnmf import cnmf, params
- from caiman.source_extraction.cnmf.utilities import detrend_df_f
- try:
- cv2.setNumThreads(0)
- except Exception:
- pass
- def parse_args() -> argparse.Namespace:
- parser = argparse.ArgumentParser(
- description="Run the CaImAn extraction pipeline on a batch of TIFF files."
- )
- parser.add_argument(
- "--tif-root",
- required=True,
- type=Path,
- help="Directory containing input TIFFs organized as <mouse>/<day>/<file>.tif.",
- )
- parser.add_argument(
- "--output-dir",
- required=True,
- type=Path,
- help="Directory where CaImAn outputs will be written.",
- )
- parser.add_argument(
- "--mice",
- required=True,
- help="Comma-separated animal/sample identifiers, e.g. 'Mouse01,Mouse02'.",
- )
- parser.add_argument(
- "--days",
- default="1-14",
- help="Day range or list. Examples: '1-14' or '1,2,5'. Default: 1-14.",
- )
- parser.add_argument(
- "--suffixes",
- default="motor training-Ch1-Z1",
- help="Comma-separated TIFF filename stems to process, without '.tif'.",
- )
- parser.add_argument("--frame-rate", default=13.088, type=float)
- parser.add_argument("--decay-time", default=1.162, type=float)
- parser.add_argument("--frames-window", default=300, type=int)
- return parser.parse_args()
- def parse_int_selection(selection: str) -> list[int]:
- if "-" in selection:
- start, end = selection.split("-", 1)
- return list(range(int(start), int(end) + 1))
- return [int(item.strip()) for item in selection.split(",") if item.strip()]
- def caiman_params(fnames: list[str], frame_rate: float, decay_time: float) -> params.CNMFParams:
- opts_dict = {
- "fnames": fnames,
- "fr": frame_rate,
- "decay_time": decay_time,
- # Motion correction.
- "strides": (48, 48),
- "overlaps": (24, 24),
- "max_shifts": (6, 6),
- "max_deviation_rigid": 3,
- "pw_rigid": True,
- # Source extraction and deconvolution.
- "p": 1,
- "nb": 2,
- "rf": 15,
- "K": 4,
- "gSig": [8, 8],
- "stride": 6,
- "method_init": "greedy_roi",
- "rolling_sum": True,
- "only_init": True,
- "ssub": 1,
- "tsub": 1,
- "merge_thr": 0.85,
- # Component evaluation.
- "min_SNR": 3.0,
- "rval_thr": 0.90,
- "use_cnn": False,
- "min_cnn_thr": 0.99,
- "cnn_lowest": 0.1,
- }
- return params.CNMFParams(params_dict=opts_dict)
- def start_cluster():
- return cm.cluster.setup_cluster(backend="local", n_processes=None, single_thread=False)
- def remove_caiman_logs() -> None:
- for log_file in glob.glob("*_LOG_*"):
- os.remove(log_file)
- def process_tiff(
- file_path: Path,
- save_path: Path,
- base_name: str,
- frame_rate: float,
- decay_time: float,
- frames_window: int,
- ) -> None:
- start_time = time.time()
- step_start = start_time
- fnames = [str(file_path)]
- opts = caiman_params(fnames, frame_rate, decay_time)
- save_path.mkdir(parents=True, exist_ok=True)
- print("-------------------------------------")
- print("Working on", file_path)
- print(" - Done setting up parameters")
- cluster, dview, n_processes = start_cluster()
- print(" - Done creating cluster", n_processes)
- try:
- mc = MotionCorrect(fnames, **opts.get_group("motion"))
- mc.motion_correct(save_movie=True)
- border_to_0 = 0 if mc.border_nan == "copy" else mc.border_to_0
- print(" - Done motion correction, cost", (time.time() - step_start) / 60, "minutes")
- step_start = time.time()
- fname_new = cm.save_memmap(
- mc.mmap_file,
- base_name="memmap_",
- order="C",
- border_to_0=border_to_0,
- )
- yr, dims, frames = cm.load_memmap(fname_new)
- images = np.reshape(yr.T, [frames] + list(dims), order="F")
- print(" - Done memory mapping, image shape=", images.shape, "cost", (time.time() - step_start) / 60, "minutes")
- step_start = time.time()
- cm.stop_server(dview=dview)
- cluster, dview, n_processes = start_cluster()
- cnm_model = cnmf.CNMF(n_processes, params=opts, dview=dview)
- cnm_model.fit(images)
- print(" - Done CNMF fitting, cost", (time.time() - step_start) / 60, "minutes")
- step_start = time.time()
- corr_img = cm.local_correlations(images.transpose(1, 2, 0))
- corr_img[np.isnan(corr_img)] = 0
- np.save(save_path / f"{base_name}-localCorrImg.npy", corr_img)
- print(" - Done getting correlation image, cost", (time.time() - step_start) / 60, "minutes")
- step_start = time.time()
- cnm_refit = cnm_model.refit(images, dview=dview)
- cnm_refit.estimates.evaluate_components(images, cnm_refit.params, dview=dview)
- print(" - Done seeded CNMF and component evaluation, cost", (time.time() - step_start) / 60, "minutes")
- save_outputs(cnm_refit, dims, save_path, base_name, frames_window)
- finally:
- cm.stop_server(dview=dview)
- remove_caiman_logs()
- print(" - The whole process took", (time.time() - start_time) / 60, "minutes")
- print(" - All clusters cleaned\n")
- def save_outputs(cnm_model, dims, save_path: Path, base_name: str, frames_window: int) -> None:
- accepted = cnm_model.estimates.idx_components
- metrics = pd.DataFrame(
- {
- "accepted_neuron": accepted,
- "SNR": cnm_model.estimates.SNR_comp[accepted],
- "spatial_correlation": cnm_model.estimates.r_values[accepted],
- }
- )
- selected = metrics[(metrics["SNR"] > 3) & (metrics["spatial_correlation"] >= 0.9)]
- candidate_neurons = selected["accepted_neuron"].values.tolist()
- spatial_components = cnm_model.estimates.A.toarray()
- x_coords: list[float] = []
- y_coords: list[float] = []
- final_neurons: list[int] = []
- for neuron_idx in candidate_neurons:
- image = spatial_components[:, neuron_idx].reshape(dims[1], dims[0])
- x_coord, y_coord = center_of_mass(image)
- if 20 < x_coord < dims[0] - 20 and 20 < y_coord < dims[1] - 20:
- x_coords.append(x_coord)
- y_coords.append(y_coord)
- final_neurons.append(neuron_idx)
- if not final_neurons:
- print(" - No neurons passed filtering.")
- return
- pd.DataFrame({"neuronIndex": final_neurons, "x": x_coords, "y": y_coords}).to_csv(
- save_path / f"{base_name}-C.csv"
- )
- selected[selected["accepted_neuron"].isin(final_neurons)].to_excel(
- save_path / f"{base_name}-allNeuronEvaluation.xlsx"
- )
- fluorescence = cnm_model.estimates.C[final_neurons, :]
- spikes = cnm_model.estimates.S[final_neurons, :]
- pd.DataFrame(fluorescence.T).to_csv(save_path / f"{base_name}-F.csv")
- pd.DataFrame(spikes.T).to_csv(save_path / f"{base_name}-S.csv")
- cnm_model.estimates.detrend_df_f(quantileMin=8, frames_window=frames_window)
- dff = cnm_model.estimates.F_dff[final_neurons, :]
- pd.DataFrame(dff.T).to_csv(save_path / f"{base_name}-DFF.csv")
- spatial = cnm_model.estimates.A[:, final_neurons].toarray()
- denoised = cnm_model.estimates.C[final_neurons, :]
- background_spatial = cnm_model.estimates.b
- background_temporal = cnm_model.estimates.f
- denoised_dff = detrend_df_f(
- spatial,
- background_spatial,
- denoised,
- background_temporal,
- frames_window=frames_window,
- )
- pd.DataFrame(denoised_dff).T.to_csv(save_path / f"{base_name}-DDFF.csv")
- cnm_model.save(save_path / f"{base_name}.hdf5")
- print(" - Done with DFF, fluorescence, and spikes", dff.T.shape, fluorescence.T.shape, spikes.T.shape)
- print(" - Done saving seeded CNMF results in HDF5")
- def main() -> None:
- args = parse_args()
- mice = [item.strip() for item in args.mice.split(",") if item.strip()]
- days = parse_int_selection(args.days)
- suffixes = [item.strip() for item in args.suffixes.split(",") if item.strip()]
- for mouse_name in mice:
- mouse_folder = mouse_name.replace(" ", "")
- for day_idx in days:
- day = f"day {day_idx}"
- for suffix in suffixes:
- file_path = args.tif_root / mouse_name / day / f"{suffix}.tif"
- base_name = f"{mouse_folder}-{day.replace(' ', '-')}-{suffix.replace(' ', '-')}"
- save_path = args.output_dir / mouse_folder
- if file_path.exists():
- process_tiff(
- file_path=file_path,
- save_path=save_path,
- base_name=base_name,
- frame_rate=args.frame_rate,
- decay_time=args.decay_time,
- frames_window=args.frames_window,
- )
- else:
- print("-------------------------------------")
- print(file_path, "does not exist.\n")
- print("Done.")
- if __name__ == "__main__":
- main()
CaImAn_Pipeline.py at commit 1360d78, under MIT · at the source
Overview
- Department of Pharmacology and Physiology, School of Medicine and Health Sciences, The George Washington University, Washington, DC, United States
- Department of Anatomy and Neurobiology, University of Tennessee Health Science Center, Memphis, United States
- Department of Computer Science, School of Engineering and Applied Science, The George Washington University, Washington, DC, United States
- Department of Pharmacology and Toxicology, Medical College of Wisconsin, Milwaukee, United States
- Department of Physics, Columbia College of Arts and Sciences, The George Washington University, Washington, DC, United States
- Neuroscience Institute, University of Tennessee Health Science Center, Memphis, United States
Abstract
Effective emotional processing, crucial for adaptive behavior, is mediated by the medial prefrontal cortex (mPFC) via connections to the basolateral amygdala (BLA), and nucleus accumbens (NAc), traditionally considered functionally similar in modulating reward and aversion responses. However, the functional specialization of the mPFC→BLA and mPFC→NAc pathways in representing affective states remains unclear. We found that while overall firing patterns appeared consistent across emotional states, deeper analysis revealed distinct variabilities. Specifically, mPFC→BLA neurons, especially ‘center-ON’ neurons, exhibited heightened activity during behaviors classically associated with anxiety-like states, suggesting their involvement in aversive behavioral regulation. Conversely, mPFC→NAc neurons were more active during exploratory and approach-related behaviors, implicating them in the processing of positively valenced behavioral states. Notably, mPFC→NAc neurons showed significant pattern decorrelation during social interactions, suggesting a pivotal role in processing social preference. Additionally, repeated win/
Reproduced under the paper's license (CC BY), from the paper cited above.
Repositories
Its files are read in the Code ↔ Paper reader above.
xiaoqiansun0104/caiman-based-ca2-processing
1360d78dcc7d00ab5ece8af13f1a7660142bc410, 17 June 2026Availability: 1 check, the latest on 27 September 2026: the link answers
- 27 September 2026: the link answers
4 files
- CaImAn/
CaImAn_Pipeline.py , Python, 279 lines - CaImAn/
Functions.py , Python, 169 lines - LICENSE, License, 21 lines
- README.md, Text, 102 lines
doi:10.5061/dryad.02v6wwqkj
Availability: 1 check, the latest on 27 September 2026: the link answers (HTTP 200)
- 27 September 2026: the link answers (HTTP 200)
The paper's code and data availability statement is in the Data section.
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;
- 2 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
No dataset and no data link were found in the paper.
Data availability
All data supporting the findings of this study, along with the code used for data analysis, are available upon reasonable request and have been deposited in Dryad (https://
The following dataset was generated:
Lai CH, Park G, Xu P, Sun X, Ge Q, Jin Z, Betts S, Liu X, Liu Q, Simha R, Zeng C, Lu H, Du J. 2026. Functional specialization of mPFC-BLA and mPFC-NAc pathways in affective state representation. Dryad Digital Repository.
Reproduced under the paper's license (CC BY), from the paper cited above.
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 1, 27 September 2026: the first record
Recorded: type, language, journal, volume, pages, dates, 13 authors, 1 keyword, 11 MeSH terms, 4 funders, 43 references.
Cite
This paper
Lai, C.-H., Park, G., Xu, P., Sun, X., Ge, Q., Jin, Z., Betts, S., Liu, X., Liu, Q.-S., Simha, R., Zeng, C., Lu, H., & Du, J. (2026). Functional specialization of mPFC-BLA and mPFC-NAc pathways in affective state representation. eLife, 14, RP105528. https://
BibTeX
@article{lai2026function
author = {Lai, Chien-Hsien and Park, Gyeongah and Xu, Pan and Sun, Xiaoqian and Ge, Qian and Jin, Zhen and Betts, Sarah and Liu, Xiaojie and Liu, Qing-Song and Simha, Rahul and Zeng, Chen and Lu, Hui and Du, Jianyang},
title = {{Functional specialization of mPFC-BLA and mPFC-NAc pathways in affective state representation}},
journal = {eLife},
year = {2026},
month = aug,
volume = {14},
pages = {RP105528},
publisher = {eLife Sciences Publications, Ltd},
issn = {2050-084X},
doi = {10.7554/
url = {https://
pmid = {42565461},
pmcid = {PMC13451018}
}
RIS
TY - JOUR
AU - Lai, Chien-Hsien
AU - Park, Gyeongah
AU - Xu, Pan
AU - Sun, Xiaoqian
AU - Ge, Qian
AU - Jin, Zhen
AU - Betts, Sarah
AU - Liu, Xiaojie
AU - Liu, Qing-Song
AU - Simha, Rahul
AU - Zeng, Chen
AU - Lu, Hui
AU - Du, Jianyang
TI - Functional specialization of mPFC-BLA and mPFC-NAc pathways in affective state representation
T2 - eLife
J2 - eLife
PY - 2026
DA - 2026/
VL - 14
SP - RP105528
SN - 2050-084X
PB - eLife Sciences Publications, Ltd
DO - 10.7554/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.7554/
"type": "article-journal",
"title": "Functional specialization of mPFC-BLA and mPFC-NAc pathways in affective state representation",
"container-title": "eLife",
"author": [
{
"family": "Lai",
"given": "Chien-Hsien"
},
{
"family": "Park",
"given": "Gyeongah"
},
{
"family": "Xu",
"given": "Pan"
},
{
"family": "Sun",
"given": "Xiaoqian"
},
{
"family": "Ge",
"given": "Qian"
},
{
"family": "Jin",
"given": "Zhen"
},
{
"family": "Betts",
"given": "Sarah"
},
{
"family": "Liu",
"given": "Xiaojie"
},
{
"family": "Liu",
"given": "Qing-Song"
},
{
"family": "Simha",
"given": "Rahul"
},
{
"family": "Zeng",
"given": "Chen"
},
{
"family": "Lu",
"given": "Hui"
},
{
"family": "Du",
"given": "Jianyang"
}
],
"container-title-short":
"volume": "14",
"page": "RP105528",
"DOI": "10.7554/
"PMID": "42565461",
"PMCID": "PMC13451018",
"ISSN": "2050-084X",
"publisher": "eLife Sciences Publications, Ltd",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
8,
7
]
]
}
}
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.1038/s42003-026-10089-z [code]
- Medial prefrontal cortex neurons integrate amygdala and hypothalamic oxytocin signals to mediate stress-induced social alterations.Journal: Communications biologyIn common: OpenCV, pandas, SciPy, 2 other tools, mouse, 3 references, author Pan Xu
- [2] doi:10.1038/s41593-026-02315-y [code]
- The representational geometry of emotional states in basolateral amygdala.Journal: Nature neuroscienceIn common: h5py, pandas, SciPy, 2 other tools, mouse, 4 references
- [3] doi:10.1038/s41592-026-03154-2 [code]
- Simultaneous single-cell calcium imaging of neuronal population activity and brain-wide BOLD fMRI.Journal: Nature methodsIn common: CaImAn, OpenCV, h5py, 4 other tools, mouse
- [4] doi:10.1016/j.xpro.2026.104659 [code]
- Protocol for simultaneous in vivo two-photon imaging and locomotion quantification during olfactory stimulation and pharmacology in walking Drosophila.Journal: STAR protocolsIn common: CaImAn, OpenCV, h5py, 4 other tools
- [5] doi:10.1126/sciadv.adv3770 [code]
- Evolution of a central dopamine circuit underlies adaptation of a light-evoked sensorimotor response in the blind cavefish.Journal: Science advancesIn common: CaImAn, OpenCV, h5py, 4 other tools
- [6] doi:10.7554/elife.109571 [code]
- Rank- and threat-dependent social modulation of innate defensive behaviors.Journal: eLifeIn common: pandas, SciPy, Matplotlib, 1 other tool, mouse, 3 references
- [7] doi:10.1038/s41592-026-03179-7 [code]
- Voltage imaging of neurons distributed across entire brains of larval zebrafish.Journal: Nature methodsIn common: CaImAn, OpenCV, h5py, 3 other tools
- [8] 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, h5py, pandas, 3 other tools, mouse, 1 reference
- [9] 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, h5py, pandas, 3 other tools, 1 reference
- [10] doi:10.1016/j.isci.2026.116206 [code]
- Gut distension evokes rapid neural dynamics in vagal and hindbrain populations of larval zebrafish.Journal: iScienceIn common: CaImAn, OpenCV, pandas, 3 other tools
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, 2 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:b43d77bb66b4edb6…
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.
