OSCR

Temporally structured motor and auditory representations in covert syllable production.

Code ↔ Paper

14 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 14 matches
  1. [1] § Materials and Methods › Decoding in Source Space. ↔ scripts/extract_vals_ROIs.py, lines 124–140 · score 0.86 · dorsal motor, pSTG, pSTS, aparc_sub, ventral motor, pars
  2. [2] § Results › Motor and Auditory Representations During Inner Speaking. ↔ scripts/extract_vals_ROIs.py, lines 124–140 · score 0.79 · aSTG, dorsal motor, pSTG, pSTS, ventral motor, SMG
  3. [3] § Results › Motor and Auditory Representations During Inner Speaking. ↔ scripts/Fig3GH.py, lines 33–40 · score 0.75 · p.Tri, aSTG, pSTG, pSTS, INS, op
  4. [4] § Materials and Methods › Decoding in Source Space. ↔ scripts/Source_space_decoding.py, lines 400–460 · score 0.71 · logistic regression, cross validation, source space, solver, stratified, classifier
  5. [5] § Materials and Methods › Cosine Similarity Analysis. ↔ scripts/Fig1E_cosine_similarity.py, lines 295–386 · score 0.70 · sided sign flip, cosine, template, separability, topographies, diagonal
  6. [6] § Materials and Methods › Temporal Generalization. ↔ scripts/Source_space_decoding.py, lines 400–460 · score 0.68 · logistic regression, cross validation, folds, solver, stratified, class
  7. [7] § Materials and Methods › Decoding in Source Space. ↔ scripts/Fig3C.py, lines 22–24 · score 0.66 · pSTG, pSTS, ventral motor, vMC, ROI, Figure 3
  8. [8] § Results › A Sequence of Neural Processes Underlies Inner Speaking. ↔ scripts/Fig1E_cosine_similarity.py, lines 529–588 · score 0.66 · hybrid matrix, upper triangle, lower triangle, cosine, topographies, permutation
  9. [9] § Results › A Sequence of Neural Processes Underlies Inner Speaking. ↔ scripts/Fig1F_decoding_source_cluster_peaks_Covert.py, lines 32–41 · score 0.57 · 356–433 ms, 356 ms, covert, peak, decoded, Figure 1
  10. [10] § Results › Passive Viewing vs. Covert Speech: Shared and Distinct Neural Processes. ↔ scripts/Fig1F_decoding_source_cluster_peaks_Covert.py, lines 32–41 · score 0.57 · 356–433 ms, 356 ms, Covert, peak, decoding, Figure 1
  11. [11] § Results › Passive Viewing vs. Covert Speech: Shared and Distinct Neural Processes. ↔ scripts/Fig1D_evokeds.py, lines 59–77 · score 0.56 · 356–433 ms, 356 ms, Covert, peak, Figure 1
  12. [12] § Results › A Sequence of Neural Processes Underlies Inner Speaking. ↔ scripts/Fig1D_evokeds.py, lines 59–77 · score 0.56 · 356–433 ms, 356 ms, peak, covert, Figure 1
  13. [13] § Materials and Methods › Temporal Generalization. ↔ scripts/Sensor_space_decoding.py, lines 90–98 · score 0.53 · logistic regression, lbfgs, solver, classifier, decoding
  14. [14] § Results › Passive Viewing vs. Covert Speech: Shared and Distinct Neural Processes. ↔ scripts/Sensor_space_decoding.py, lines 291–350 · score 0.51 · space decoding, cross validation, ROC AUC, shuffled, stratified, diagonal

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 · 853 lines · 25 KB · no license · 2 matches

  1. from pathlib import Path
  2. import numpy as np
  3. import pandas as pd
  4. import mne
  5. from mne import compute_source_morph
  6. from mne.stats import permutation_cluster_1samp_test
  7. from scipy import stats
  8. # ============================================================
  9. # DATASET SELECTION
  10. # ============================================================
  11. # Options:
  12. # "consonants"
  13. # "vowels"
  14. dataset_name = "vowels"
  15. # ============================================================
  16. # DATASET-SPECIFIC SETTINGS
  17. # ============================================================
  18. dataset_configs = {
  19. "consonants": {
  20. "mri_path": Path(
  21. "/.../mri_consonants" # <-- specify path to mri_consonants folder
  22. ),
  23. "data_file": Path(
  24. "/.../result_Covert.npy" # <-- specify path to result_Covert.py
  25. ),
  26. "out_dir": Path(
  27. "/.../" # <-- specify output folder
  28. ),
  29. "subject_codes": [
  30. "S01", "S02", "S03", "S04", "S05", "S06", "S07", "S08", "S09", "S10", "S11",
  31. "S12", "S13", "S14", "S15", "S16", "S17", "S18", "S19", "S20", "S21", "S22"
  32. ],
  33. "peaks_interest": [3, 4],
  34. "condition_label": "Covert",
  35. "contrast_labels": ["pa_vs_ta", "pa_vs_ka", "ta_vs_ka"],
  36. },
  37. "vowels": {
  38. "mri_path": Path(
  39. "/.../mri_vowels" # <-- specify path to mri_vowels folder
  40. ),
  41. "data_file": Path(
  42. "/.../result_tatuti_Covert.npy" # <-- specify path to result_tatuti_Covert.py
  43. ),
  44. "out_dir": Path(
  45. "/.../" # <-- specify output folder
  46. ),
  47. "subject_codes": [
  48. "S01", "S02", "S03", "S04", "S05", "S06", "S07", "S08", "S09"
  49. ],
  50. # Zero-indexed peak indices.
  51. "peaks_interest": [1, 2],
  52. "condition_label": "tatuti_Covert",
  53. "contrast_labels": ["ta_vs_tu", "ta_vs_ti", "tu_vs_ti"],
  54. },
  55. }
  56. if dataset_name not in dataset_configs:
  57. raise ValueError(
  58. f"dataset_name must be one of {list(dataset_configs.keys())}, "
  59. f"but got {dataset_name}"
  60. )
  61. cfg = dataset_configs[dataset_name]
  62. mri_path = cfg["mri_path"]
  63. data_file = cfg["data_file"]
  64. out_dir = cfg["out_dir"]
  65. subject_codes = cfg["subject_codes"]
  66. peaks_interest = cfg["peaks_interest"]
  67. condition_label = cfg["condition_label"]
  68. original_contrast_labels = cfg["contrast_labels"]
  69. out_dir.mkdir(parents=True, exist_ok=True)
  70. mne.set_config("SUBJECTS_DIR", str(mri_path), set_env=True)
  71. # ============================================================
  72. # GENERAL SETTINGS
  73. # ============================================================
  74. # Dataset shape expected:
  75. # subjects x peaks x contrasts x sources
  76. expected_n_sources = 5124
  77. # Set to True to average across contrasts before statistics/extraction.
  78. # Set to False to compute everything separately for each contrast.
  79. average_across_contrasts = False
  80. # Source-space settings
  81. subject_spacing = "ico4"
  82. fsaverage_stats_spacing = "ico6"
  83. # Statistics
  84. chance_level = 0.5
  85. p_threshold = 0.05
  86. cluster_pval_thresh = 0.05
  87. n_permutations = 1000
  88. cluster_seed = 23
  89. n_jobs = 5
  90. # Hemisphere / parcellation
  91. hemi = "lh"
  92. annotation = "aparc_sub"
  93. # Optional ROI visualization.
  94. # Keep False during extraction. If True, use fresh fsaverage labels for plotting.
  95. plot_rois = False
  96. # ============================================================
  97. # ROI DEFINITIONS
  98. # ============================================================
  99. # These are label indices in fsaverage aparc_sub, left hemisphere.
  100. aparc_dict = {
  101. "pSTS": [0, 1, 2],
  102. "insula": np.arange(42, 49),
  103. "pars triang": [104, 105, 106],
  104. "pars operc": [98, 99, 100, 101],
  105. "ventral SS": np.arange(111, 116),
  106. "dorsal SS": np.arange(116, 124),
  107. "ventral motor": np.arange(129, 136),
  108. "dorsal motor": np.arange(136, 144),
  109. "pSTG": [201, 204, 205, 206, 207, 208],
  110. "aSTG": [202, 203, 209, 210, 211],
  111. "SMG": np.arange(212, 222),
  112. "Aud": [223, 224],
  113. }
  114. roi_names = list(aparc_dict.keys())
  115. # ============================================================
  116. # LOAD SOURCE DECODING DATA
  117. # ============================================================
  118. if not data_file.exists():
  119. raise FileNotFoundError(f"Could not find data file: {data_file}")
  120. print("=" * 80)
  121. print(f"Dataset: {dataset_name}")
  122. print(f"MRI path: {mri_path}")
  123. print(f"Data file: {data_file}")
  124. print(f"Output directory: {out_dir}")
  125. print(f"Average across contrasts: {average_across_contrasts}")
  126. all_scores = np.load(data_file)
  127. print(f"\nLoaded data shape: {all_scores.shape}")
  128. if all_scores.ndim != 4:
  129. raise ValueError(
  130. f"Expected 4D array with shape "
  131. f"(subjects, peaks, contrasts, sources), got {all_scores.shape}"
  132. )
  133. if all_scores.shape[0] != len(subject_codes):
  134. raise ValueError(
  135. f"Subject mismatch: data has {all_scores.shape[0]} subjects, "
  136. f"but subject_codes has {len(subject_codes)} entries."
  137. )
  138. if all_scores.shape[-1] != expected_n_sources:
  139. raise ValueError(
  140. f"Source mismatch: expected {expected_n_sources} sources, "
  141. f"but data has {all_scores.shape[-1]} sources."
  142. )
  143. if max(peaks_interest) >= all_scores.shape[1]:
  144. raise ValueError(
  145. f"peaks_interest includes index {max(peaks_interest)}, "
  146. f"but data only has {all_scores.shape[1]} peaks."
  147. )
  148. n_original_contrasts = all_scores.shape[2]
  149. if len(original_contrast_labels) != n_original_contrasts:
  150. original_contrast_labels = [
  151. f"contrast_{i}" for i in range(n_original_contrasts)
  152. ]
  153. if average_across_contrasts:
  154. # Shape: subjects x peaks x 1 x sources
  155. all_scores_for_analysis = all_scores.mean(axis=2, keepdims=True)
  156. contrast_labels = ["mean_across_contrasts"]
  157. else:
  158. # Shape: subjects x peaks x contrasts x sources
  159. all_scores_for_analysis = all_scores.copy()
  160. contrast_labels = original_contrast_labels
  161. n_contrasts_for_analysis = all_scores_for_analysis.shape[2]
  162. print(f"Data used for analysis: {all_scores_for_analysis.shape}")
  163. print(f"Contrast labels: {contrast_labels}")
  164. print(f"Peaks of interest: {peaks_interest}")
  165. # ============================================================
  166. # SET UP FSAVERAGE SOURCE SPACES
  167. # ============================================================
  168. print("\nSetting up fsaverage source spaces...")
  169. src_fsaverage_ico4 = mne.setup_source_space(
  170. subject="fsaverage",
  171. spacing="ico4",
  172. subjects_dir=mri_path,
  173. add_dist=False,
  174. verbose="error",
  175. )
  176. src_fsaverage_ico6 = mne.setup_source_space(
  177. subject="fsaverage",
  178. spacing="ico6",
  179. subjects_dir=mri_path,
  180. add_dist=False,
  181. verbose="error",
  182. )
  183. n_sources_hemi = len(src_fsaverage_ico6[0]["vertno"])
  184. n_sources_fsaverage_ico6 = (
  185. len(src_fsaverage_ico6[0]["vertno"]) +
  186. len(src_fsaverage_ico6[1]["vertno"])
  187. )
  188. print(f"fsaverage ico6 sources per hemisphere: {n_sources_hemi}")
  189. print(f"fsaverage ico6 total sources: {n_sources_fsaverage_ico6}")
  190. adjacency_lh = mne.spatial_src_adjacency(
  191. src_fsaverage_ico6[:1],
  192. dist=None,
  193. verbose=None,
  194. )
  195. # ============================================================
  196. # READ LABELS FOR UNKNOWN/NONCORTICAL MASKING
  197. # ============================================================
  198. print("\nReading fsaverage aparc_sub labels for unknown/noncortical masking...")
  199. labels_lh_for_unknown = mne.read_labels_from_annot(
  200. subject="fsaverage",
  201. parc=annotation,
  202. hemi="lh",
  203. subjects_dir=mri_path,
  204. )
  205. labels_rh_for_unknown = mne.read_labels_from_annot(
  206. subject="fsaverage",
  207. parc=annotation,
  208. hemi="rh",
  209. subjects_dir=mri_path,
  210. )
  211. unknown_lh = [
  212. label for label in labels_lh_for_unknown
  213. if label.name == "unknown-lh"
  214. ]
  215. unknown_rh = [
  216. label for label in labels_rh_for_unknown
  217. if label.name == "unknown-rh"
  218. ]
  219. if len(unknown_lh) != 1:
  220. raise RuntimeError(f"Expected one unknown-lh label, found {len(unknown_lh)}")
  221. if len(unknown_rh) != 1:
  222. raise RuntimeError(f"Expected one unknown-rh label, found {len(unknown_rh)}")
  223. # ------------------------------------------------------------
  224. # Deal with unknown/noncortical labels
  225. # ------------------------------------------------------------
  226. print("\nMorphing unknown/noncortical labels to fsaverage6...")
  227. noncortical_lh = unknown_lh[0].morph(
  228. subject_from="fsaverage",
  229. subject_to="fsaverage6",
  230. smooth=0,
  231. grade=None,
  232. subjects_dir=mri_path,
  233. n_jobs=n_jobs,
  234. verbose=None,
  235. )
  236. noncortical_rh = unknown_rh[0].morph(
  237. subject_from="fsaverage",
  238. subject_to="fsaverage6",
  239. smooth=0,
  240. grade=None,
  241. subjects_dir=mri_path,
  242. n_jobs=n_jobs,
  243. verbose=None,
  244. )
  245. to_remove_lh = noncortical_lh.vertices[
  246. noncortical_lh.vertices < n_sources_hemi
  247. ]
  248. to_remove_rh = noncortical_rh.vertices[
  249. noncortical_rh.vertices < n_sources_hemi
  250. ]
  251. to_remove_all = np.concatenate(
  252. [
  253. to_remove_lh,
  254. to_remove_rh + n_sources_hemi,
  255. ]
  256. )
  257. print(f"Unknown/noncortical LH sources to remove: {len(to_remove_lh)}")
  258. print(f"Unknown/noncortical RH sources to remove: {len(to_remove_rh)}")
  259. # ============================================================
  260. # READ FRESH LABELS FOR ROI EXTRACTION AND MORPH TO FSAVERAGE6
  261. # ============================================================
  262. print("\nRe-reading fsaverage LH aparc_sub labels for ROI extraction...")
  263. labels_lh_for_extraction = mne.read_labels_from_annot(
  264. subject="fsaverage",
  265. parc=annotation,
  266. hemi="lh",
  267. subjects_dir=mri_path,
  268. )
  269. print("\nMorphing LH aparc_sub ROI labels to fsaverage6...")
  270. for label in labels_lh_for_extraction:
  271. label.morph(
  272. subject_from="fsaverage",
  273. subject_to="fsaverage6",
  274. smooth=0,
  275. grade=None,
  276. subjects_dir=mri_path,
  277. n_jobs=n_jobs,
  278. verbose=None,
  279. )
  280. n_labels_lh = len(labels_lh_for_extraction)
  281. print(f"Number of LH labels for extraction: {n_labels_lh}")
  282. # ============================================================
  283. # OPTIONAL ROI VISUALIZATION
  284. # ============================================================
  285. if plot_rois:
  286. Brain = mne.viz.get_brain_class()
  287. labels_lh_for_plotting = mne.read_labels_from_annot(
  288. subject="fsaverage",
  289. parc=annotation,
  290. hemi="lh",
  291. subjects_dir=mri_path,
  292. )
  293. brain = Brain(
  294. "fsaverage",
  295. "lh",
  296. subjects_dir=mri_path,
  297. cortex="low_contrast",
  298. background="white",
  299. size=(800, 600),
  300. )
  301. rng = np.random.default_rng(0)
  302. for roi_name, label_indices in aparc_dict.items():
  303. color = rng.random(3)
  304. for label_idx in label_indices:
  305. brain.add_label(
  306. labels_lh_for_plotting[label_idx],
  307. borders=False,
  308. color=color,
  309. )
  310. # ============================================================
  311. # PREALLOCATE OUTPUT ARRAYS
  312. # ============================================================
  313. n_subjects = len(subject_codes)
  314. n_peaks_interest = len(peaks_interest)
  315. n_rois = len(aparc_dict)
  316. # Subject-level values per aparc_sub label.
  317. # Shape: subjects x peaks_interest x contrasts x labels
  318. all_data_labels = np.full(
  319. (n_subjects, n_peaks_interest, n_contrasts_for_analysis, n_labels_lh),
  320. np.nan,
  321. dtype=float,
  322. )
  323. # Number of significant decoding sources per aparc_sub label.
  324. # Shape: peaks_interest x contrasts x labels
  325. num_dec_sources_label = np.zeros(
  326. (n_peaks_interest, n_contrasts_for_analysis, n_labels_lh),
  327. dtype=float,
  328. )
  329. # Percent significant sources per ROI.
  330. # Shape: peaks_interest x contrasts x ROIs
  331. final_results_percent = np.full(
  332. (n_peaks_interest, n_contrasts_for_analysis, n_rois),
  333. np.nan,
  334. dtype=float,
  335. )
  336. # Mean decoding values per ROI.
  337. # Shape: subjects x peaks_interest x contrasts x ROIs
  338. value_results = np.full(
  339. (n_subjects, n_peaks_interest, n_contrasts_for_analysis, n_rois),
  340. np.nan,
  341. dtype=float,
  342. )
  343. # ============================================================
  344. # CLUSTER-BASED SOURCE STATISTICS AND LABEL EXTRACTION
  345. # ============================================================
  346. t_threshold = -stats.distributions.t.ppf(
  347. p_threshold / 2.0,
  348. n_subjects - 1,
  349. )
  350. print("\nCluster-forming t-threshold:")
  351. print(f" p_threshold = {p_threshold}")
  352. print(f" t_threshold = {t_threshold:.4f}")
  353. for peak_out_idx, peak_idx in enumerate(peaks_interest):
  354. for contrast_out_idx, contrast_label in enumerate(contrast_labels):
  355. print("\n" + "=" * 80)
  356. print(
  357. f"Processing peak index {peak_idx} "
  358. f"({peak_out_idx + 1}/{n_peaks_interest}) | "
  359. f"{contrast_label}"
  360. )
  361. all_sts_data = []
  362. # ----------------------------------------------------
  363. # Morph each subject's ico4 source data to fsaverage ico6
  364. # ----------------------------------------------------
  365. for subject_idx, subject_code in enumerate(subject_codes):
  366. print(
  367. f" Morphing subject {subject_idx + 1}/{n_subjects}: "
  368. f"{subject_code}"
  369. )
  370. src_subject = mne.setup_source_space(
  371. subject=subject_code,
  372. spacing=subject_spacing,
  373. subjects_dir=mri_path,
  374. add_dist=False,
  375. verbose="error",
  376. )
  377. subject_values = all_scores_for_analysis[
  378. subject_idx,
  379. peak_idx,
  380. contrast_out_idx,
  381. :
  382. ]
  383. stc_subject = mne.SourceEstimate(
  384. subject_values,
  385. vertices=[
  386. src_subject[0]["vertno"],
  387. src_subject[1]["vertno"],
  388. ],
  389. tmin=0,
  390. tstep=1,
  391. subject=subject_code,
  392. verbose=None,
  393. )
  394. morph = compute_source_morph(
  395. src_subject,
  396. subject_from=subject_code,
  397. subject_to="fsaverage",
  398. spacing=6,
  399. subjects_dir=mri_path,
  400. verbose="error",
  401. )
  402. stc_fsaverage = morph.apply(stc_subject)
  403. all_sts_data.append(stc_fsaverage.data)
  404. all_sts_data = np.squeeze(np.asarray(all_sts_data, dtype=float))
  405. print(f" Morphed data shape: {all_sts_data.shape}")
  406. if all_sts_data.shape != (n_subjects, n_sources_fsaverage_ico6):
  407. raise RuntimeError(
  408. f"Unexpected morphed data shape: {all_sts_data.shape}. "
  409. f"Expected {(n_subjects, n_sources_fsaverage_ico6)}"
  410. )
  411. # ----------------------------------------------------
  412. # Remove unknown/noncortical sources by setting them to chance
  413. # ----------------------------------------------------
  414. all_sts_data_clean = all_sts_data.copy()
  415. all_sts_data_clean[:, to_remove_all] = chance_level
  416. # Data for statistics is centered on chance.
  417. stc_fsaverage_allsubj_4stats = all_sts_data_clean - chance_level
  418. # ----------------------------------------------------
  419. # LH statistics
  420. # ----------------------------------------------------
  421. data_lh = stc_fsaverage_allsubj_4stats[:, :n_sources_hemi].copy()
  422. # Avoid NaNs in permutation_cluster_1samp_test.
  423. # Removed sources are set to 0, so they should not pass the positive threshold.
  424. data_lh[:, to_remove_lh] = 0.0
  425. print(" Running LH cluster test...")
  426. t_obs_lh, clusters_lh, cluster_pv_lh, h0_lh = permutation_cluster_1samp_test(
  427. data_lh,
  428. n_permutations=n_permutations,
  429. out_type="indices",
  430. threshold=t_threshold,
  431. adjacency=adjacency_lh,
  432. tail=1,
  433. seed=cluster_seed,
  434. verbose=True,
  435. )
  436. good_cluster_inds_lh = np.where(cluster_pv_lh < cluster_pval_thresh)[0]
  437. print(f" Significant LH clusters: {good_cluster_inds_lh}")
  438. # ----------------------------------------------------
  439. # Collect significant source indices
  440. # ----------------------------------------------------
  441. sig_sources_lh = []
  442. for cluster_idx in good_cluster_inds_lh:
  443. sig_sources_lh.append(clusters_lh[cluster_idx][0])
  444. if len(sig_sources_lh) == 0:
  445. print(" No significant LH sources for this peak/contrast.")
  446. continue
  447. sig_sources_lh = np.unique(np.concatenate(sig_sources_lh))
  448. print(f" Number of significant LH source indices: {len(sig_sources_lh)}")
  449. # ----------------------------------------------------
  450. # Extract label-wise values
  451. # ----------------------------------------------------
  452. for label_idx, label in enumerate(labels_lh_for_extraction):
  453. label_vertices = label.vertices
  454. within_label_idx = np.intersect1d(
  455. label_vertices,
  456. sig_sources_lh,
  457. )
  458. n_intersect = len(within_label_idx)
  459. num_dec_sources_label[
  460. peak_out_idx,
  461. contrast_out_idx,
  462. label_idx,
  463. ] = n_intersect
  464. if n_intersect > 0:
  465. # Add chance level back because data_lh is centered on chance.
  466. all_data_labels[
  467. :,
  468. peak_out_idx,
  469. contrast_out_idx,
  470. label_idx,
  471. ] = np.nanmean(
  472. data_lh[:, within_label_idx] + chance_level,
  473. axis=1,
  474. )
  475. print(
  476. f" Label {label_idx:03d} | {label.name:35s} | "
  477. f"n significant sources = {n_intersect}"
  478. )
  479. # ============================================================
  480. # ROI-LEVEL PERCENT SIGNIFICANT SOURCES
  481. # ============================================================
  482. print("\n" + "=" * 80)
  483. print("Computing ROI-level percent significant sources...")
  484. for peak_out_idx, peak_idx in enumerate(peaks_interest):
  485. for contrast_out_idx, contrast_label in enumerate(contrast_labels):
  486. for roi_idx, roi_name in enumerate(roi_names):
  487. label_indices = np.asarray(aparc_dict[roi_name], dtype=int)
  488. label_percents = []
  489. for label_idx in label_indices:
  490. n_label_vertices = len(labels_lh_for_extraction[label_idx].vertices)
  491. if n_label_vertices == 0:
  492. continue
  493. label_percent = (
  494. num_dec_sources_label[
  495. peak_out_idx,
  496. contrast_out_idx,
  497. label_idx,
  498. ] / n_label_vertices
  499. )
  500. label_percents.append(label_percent)
  501. if len(label_percents) > 0:
  502. # This matches the original script: mean of sublabel percentages.
  503. final_results_percent[
  504. peak_out_idx,
  505. contrast_out_idx,
  506. roi_idx,
  507. ] = np.nanmean(label_percents)
  508. print(
  509. f" Peak {peak_idx} | {contrast_label:22s} | {roi_name:15s} | "
  510. f"percent = "
  511. f"{final_results_percent[peak_out_idx, contrast_out_idx, roi_idx]:.4f}"
  512. )
  513. # ============================================================
  514. # ROI-LEVEL DECODING VALUES
  515. # ============================================================
  516. print("\n" + "=" * 80)
  517. print("Computing ROI-level decoding values...")
  518. for peak_out_idx, peak_idx in enumerate(peaks_interest):
  519. for contrast_out_idx, contrast_label in enumerate(contrast_labels):
  520. for roi_idx, roi_name in enumerate(roi_names):
  521. label_indices = np.asarray(aparc_dict[roi_name], dtype=int)
  522. value_results[
  523. :,
  524. peak_out_idx,
  525. contrast_out_idx,
  526. roi_idx,
  527. ] = np.nanmean(
  528. all_data_labels[
  529. :,
  530. peak_out_idx,
  531. contrast_out_idx,
  532. label_indices,
  533. ],
  534. axis=1,
  535. )
  536. print(
  537. f" Peak {peak_idx} | {contrast_label:22s} | {roi_name:15s} | "
  538. f"group mean value = "
  539. f"{np.nanmean(value_results[:, peak_out_idx, contrast_out_idx, roi_idx]):.4f}"
  540. )
  541. # ============================================================
  542. # SAVE OUTPUTS
  543. # ============================================================
  544. contrast_mode_label = (
  545. "contrast_average"
  546. if average_across_contrasts
  547. else "contrast_separate"
  548. )
  549. base = f"roi_extraction_{dataset_name}_{condition_label}_{contrast_mode_label}"
  550. np.save(out_dir / f"{base}_all_data_labels.npy", all_data_labels)
  551. np.save(out_dir / f"{base}_num_dec_sources_label.npy", num_dec_sources_label)
  552. np.save(out_dir / f"{base}_percent_sig_sources.npy", final_results_percent)
  553. np.save(out_dir / f"{base}_roi_values.npy", value_results)
  554. np.savez(
  555. out_dir / f"{base}_all_outputs.npz",
  556. all_data_labels=all_data_labels,
  557. num_dec_sources_label=num_dec_sources_label,
  558. roi_percent_sig_sources=final_results_percent,
  559. roi_values=value_results,
  560. peaks_interest=np.asarray(peaks_interest),
  561. roi_names=np.asarray(roi_names, dtype=object),
  562. subject_codes=np.asarray(subject_codes, dtype=object),
  563. contrast_labels=np.asarray(contrast_labels, dtype=object),
  564. dataset_name=dataset_name,
  565. condition_label=condition_label,
  566. average_across_contrasts=average_across_contrasts,
  567. )
  568. # ------------------------------------------------------------
  569. # Save percent-significant sources, long format
  570. # ------------------------------------------------------------
  571. percent_rows = []
  572. for peak_out_idx, peak_idx in enumerate(peaks_interest):
  573. for contrast_out_idx, contrast_label in enumerate(contrast_labels):
  574. for roi_idx, roi_name in enumerate(roi_names):
  575. percent_rows.append(
  576. {
  577. "dataset": dataset_name,
  578. "condition": condition_label,
  579. "peak_index": peak_idx,
  580. "contrast": contrast_label,
  581. "roi": roi_name,
  582. "percent_sig_sources": final_results_percent[
  583. peak_out_idx,
  584. contrast_out_idx,
  585. roi_idx,
  586. ],
  587. }
  588. )
  589. percent_long_df = pd.DataFrame(percent_rows)
  590. percent_long_df.to_csv(
  591. out_dir / f"{base}_percent_sig_sources_long.csv",
  592. index=False,
  593. )
  594. # ------------------------------------------------------------
  595. # Save group-mean ROI values, long format
  596. # ------------------------------------------------------------
  597. value_group_rows = []
  598. value_group_mean = np.nanmean(value_results, axis=0)
  599. # Shape: peaks x contrasts x ROIs
  600. for peak_out_idx, peak_idx in enumerate(peaks_interest):
  601. for contrast_out_idx, contrast_label in enumerate(contrast_labels):
  602. for roi_idx, roi_name in enumerate(roi_names):
  603. value_group_rows.append(
  604. {
  605. "dataset": dataset_name,
  606. "condition": condition_label,
  607. "peak_index": peak_idx,
  608. "contrast": contrast_label,
  609. "roi": roi_name,
  610. "group_mean_value": value_group_mean[
  611. peak_out_idx,
  612. contrast_out_idx,
  613. roi_idx,
  614. ],
  615. }
  616. )
  617. value_group_df = pd.DataFrame(value_group_rows)
  618. value_group_df.to_csv(
  619. out_dir / f"{base}_roi_values_group_mean_long.csv",
  620. index=False,
  621. )
  622. # ------------------------------------------------------------
  623. # Save subject-level ROI values, long format
  624. # ------------------------------------------------------------
  625. rows = []
  626. for subject_idx, subject_code in enumerate(subject_codes):
  627. for peak_out_idx, peak_idx in enumerate(peaks_interest):
  628. for contrast_out_idx, contrast_label in enumerate(contrast_labels):
  629. for roi_idx, roi_name in enumerate(roi_names):
  630. rows.append(
  631. {
  632. "dataset": dataset_name,
  633. "condition": condition_label,
  634. "subject": subject_code,
  635. "peak_index": peak_idx,
  636. "contrast": contrast_label,
  637. "roi": roi_name,
  638. "value": value_results[
  639. subject_idx,
  640. peak_out_idx,
  641. contrast_out_idx,
  642. roi_idx,
  643. ],
  644. }
  645. )
  646. value_long_df = pd.DataFrame(rows)
  647. value_long_df.to_csv(
  648. out_dir / f"{base}_roi_values_subject_level_long.csv",
  649. index=False,
  650. )
  651. # ============================================================
  652. # SUMMARY
  653. # ============================================================
  654. print("\n" + "=" * 80)
  655. print("Done.")
  656. print("\nSaved outputs to:")
  657. print(out_dir)
  658. print("\nMain output arrays:")
  659. print(f" all_data_labels: {all_data_labels.shape}")
  660. print(f" num_dec_sources_label: {num_dec_sources_label.shape}")
  661. print(f" roi_percent_sig_sources: {final_results_percent.shape}")
  662. print(f" roi_values: {value_results.shape}")
  663. print("\nContrast labels:")
  664. for i, label in enumerate(contrast_labels):
  665. print(f" {i}: {label}")

extract_vals_ROIs.py, no license · at the source

Overview

Authors: Joan Orpella1,2, Francesco Mantegna2,3, Chantal Oderbolz1, M Florencia Assaneo4, David Poeppel2,5
  1. Department of Neuroscience, Georgetown University Medical Center, Washington, DC 20057
  2. Department of Psychology, New York University, New York, NY 10003
  3. Department of Engineering Science, Oxford University, Oxford OX1 3PJ, Oxfordshire, United Kingdom
  4. Institute of Neurobiology, National Autonomous University of Mexico, Juriquilla 76230, Querétaro, Mexico
  5. Center for Language, Music and Emotion, New York University, New York, NY 10003
Institutions: Georgetown University Medical Center (United States); New York University (United States); University of Oxford (United Kingdom); Universidad Nacional Autónoma de México (Mexico)
Dates: received 16 December 2025; accepted 27 July 2026; published online 31 August 2026; in print 15 September 2026
Type: Research article · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1073/pnas.2536563123 · PMID 42673473 · PMCID PMC13578806 · OpenAlex W7168277495
Open access: hybrid, a free copy (OpenAlex)
Preprint: osf.io/3vmek
Status: code verified
Categories: MEG (modality), human (organism), cognitive (subfield)
Methods: Spectral & time-frequency, Preprocessing, Statistics, Smoothing, state filtering, decompositions, Machine learning, Evoked potentials, Source localization, fMRI & imaging, Physiology & signal measures
Keywords: speech production, inner speech, magnetoencephalography, decoding, covert speech
MeSH: Auditory Cortex*, Motor Cortex*, Speech*, Speech Perception*, Adult, Female, Humans, Magnetoencephalography, Male, Phonetics, Young Adult (* major topic)
Topic: Neuroscience and Music Perception (Cognitive Neuroscience, Neuroscience), according to OpenAlex
Funding: NSF (2043717); NIDCD NIH HHS (R01 DC005660, 2R01DC05660)
Citations: not cited yet (Europe PMC); 69 references in the paper

Abstract

The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.

Repository

Its files are read in the Code ↔ Paper reader above, with 14 matches between paragraphs and lines of code.

OSF 3vmek

License: none: the authors keep all their rights
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Languages: Python (14)
Size: 104 files, 14 scripts
Software Heritage: not checked
Found in: “Data, Materials, and Software Availability”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: Matplotlib (13 files), NumPy (13 files), MNE-Python (9 files), SciPy (7 files), pandas (3 files), scikit-learn (3 files), statsmodels (1 file)
Availability: 1 check, the latest on 27 September 2026: the link answers (HTTP 200)
  • 27 September 2026: the link answers (HTTP 200)
14 files

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:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 14 scripts, each with its path and the digest of its content;
  • 14 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • 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.

Code and data availability statement

The paper has a code and data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

Read it in the paper: doi.org/10.1073/pnas.2536563123.

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, issue, pages, dates, 5 authors, 5 keywords, 11 MeSH terms, 2 funders, 58 references.

Cite

This paper

Orpella, J., Mantegna, F., Oderbolz, C., Assaneo, M. F., & Poeppel, D. (2026). Temporally structured motor and auditory representations in covert syllable production. Proceedings of the National Academy of Sciences of the United States of America, 123(37), e2536563123. https://doi.org/10.1073/pnas.2536563123

BibTeX

@article{orpella2026temporally,
author = {Orpella, Joan and Mantegna, Francesco and Oderbolz, Chantal and Assaneo, M Florencia and Poeppel, David},
title = {{Temporally structured motor and auditory representations in covert syllable production}},
journal = {Proceedings of the National Academy of Sciences of the United States of America},
year = {2026},
month = aug,
volume = {123},
number = {37},
pages = {e2536563123},
publisher = {National Academy of Sciences},
issn = {0027-8424},
doi = {10.1073/pnas.2536563123},
url = {https://doi.org/10.1073/pnas.2536563123},
pmid = {42673473},
pmcid = {PMC13578806}
}

RIS

TY - JOUR
AU - Orpella, Joan
AU - Mantegna, Francesco
AU - Oderbolz, Chantal
AU - Assaneo, M Florencia
AU - Poeppel, David
TI - Temporally structured motor and auditory representations in covert syllable production
T2 - Proceedings of the National Academy of Sciences of the United States of America
J2 - Proc Natl Acad Sci U S A
PY - 2026
DA - 2026/08/31
VL - 123
IS - 37
SP - e2536563123
SN - 0027-8424
PB - National Academy of Sciences
DO - 10.1073/pnas.2536563123
UR - https://doi.org/10.1073/pnas.2536563123
LA - en
ER -

CSL-JSON

{
"id": "10.1073/pnas.2536563123",
"type": "article-journal",
"title": "Temporally structured motor and auditory representations in covert syllable production",
"container-title": "Proceedings of the National Academy of Sciences of the United States of America",
"author": [
{
"family": "Orpella",
"given": "Joan"
},
{
"family": "Mantegna",
"given": "Francesco"
},
{
"family": "Oderbolz",
"given": "Chantal"
},
{
"family": "Assaneo",
"given": "M Florencia"
},
{
"family": "Poeppel",
"given": "David"
}
],
"container-title-short": "Proc Natl Acad Sci U S A",
"volume": "123",
"issue": "37",
"page": "e2536563123",
"DOI": "10.1073/pnas.2536563123",
"PMID": "42673473",
"PMCID": "PMC13578806",
"ISSN": "0027-8424",
"publisher": "National Academy of Sciences",
"URL": "https://doi.org/10.1073/pnas.2536563123",
"language": "en",
"issued": {
"date-parts": [
[
2026,
8,
31
]
]
}
}

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/s41467-026-75455-1 [code]
Shared latent representations of speech production for cross-patient speech decoding.
Journal: Nature communications
In common: statsmodels, scikit-learn, pandas, 3 other tools, cognitive, 5 references
[2] doi:10.1038/s41467-026-71284-4 [code]
Encoding of speech modes and loudness in ventral precentral gyrus.
Journal: Nature communications
In common: MNE-Python, scikit-learn, pandas, 3 other tools, cognitive, 4 references
[3] doi:10.1038/s41467-026-75745-8 [code]
A language network in the individualized functional connectomes of 1199 human brains doing arbitrary tasks.
Journal: Nature communications
In common: scikit-learn, pandas, SciPy, 2 other tools, cognitive, 5 references
[4] doi:10.1038/s41586-026-10691-5 [code]
Mapping the neuronal building blocks of human language with language models.
Journal: Nature
In common: statsmodels, scikit-learn, pandas, 3 other tools, cognitive, 4 references
[5] doi:10.1093/cercor/bhag075 [code]
Cortical dynamics of icon perception: effects of concreteness and attractiveness.
Journal: Cerebral cortex (New York, N.Y. : 1991)
In common: MNE-Python, statsmodels, scikit-learn, 4 other tools, MEG, cognitive, 2 references
[6] doi:10.1093/nc/niag029 [code]
A data-driven approach to identifying and evaluating connectivity-based neural correlates of conscious visual perception.
Journal: Neuroscience of consciousness
In common: MNE-Python, statsmodels, scikit-learn, 4 other tools, MEG, cognitive, 2 references
[7] doi:10.1038/s41467-026-74824-0 [code]
Learning regularities in noise engages both neural predictive activity and representational changes.
Journal: Nature communications
In common: MNE-Python, statsmodels, scikit-learn, 4 other tools, MEG, cognitive, 2 references
[8] doi:10.1038/s41467-026-71918-7 [code]
Developmental disinhibition gates language lateralization in childhood.
Journal: Nature communications
In common: MNE-Python, scikit-learn, pandas, 3 other tools, 3 references
[9] doi:10.1038/s41597-026-07350-9 [code]
An open multi-center MEG-EEG dataset for studying conscious visual perception.
Journal: Scientific data
In common: MNE-Python, statsmodels, scikit-learn, 4 other tools, MEG, 2 references
[10] doi:10.1038/s41467-026-75240-0 [code]
Dynamic acoustic-to-categorical representations of phonemes and prosody along ventral and dorsal speech streams.
Journal: Nature communications
In common: MNE-Python, scikit-learn, pandas, 3 other tools, MEG, cognitive, 2 references

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.

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.