OSCR

SNIRF2BIDS: a GUI-based tool for converting functional near-infrared spectroscopy data to the Brain Imaging Data Structure in R.

Code ↔ Paper

6 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 6 matches
  1. [1] § Handling Files that Could Not Be Converted ↔ inst/shiny/myapp/app.R, lines 172–283 · score 0.73 · log.txt, Conversion failed, Conversion complete, mne bids, notification, messages
  2. [2] § Installation and Setup ↔ R/convert.R, lines 16–75 · score 0.62 · Python environment, Miniconda, MNE BIDS, command, reticulate, installation
  3. [3] § Main GUI and General Workflow ↔ R/convert.R, lines 95–198 · score 0.54 · subject ID, description.json, task mapping, MNE, BIDS formatted, root
  4. [4] § Define the Hierarchical Folder Structure and File-Naming Scheme › Step 3: Define Experimental Setup ↔ R/experimentalDesign.R, lines 46–111 · score 0.54 · took place, fNIRS, afternoon, day, declares, morning
  5. [5] § Presentation of (NIRS-)BIDS and Existing Software Tools ↔ R/convert.R, lines 16–75 · score 0.52 · raw bids, MNE BIDS, channels, Python, export
  6. [6] § Handling Files that Could Not Be Converted ↔ R/convert.R, lines 95–198 · score 0.51 · log.txt, raw bids, notification, Error, mne, SNIRF

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

R · 288 lines · 9.3 KB · no license · 4 matches

  1. #### SETUP ####
  2. library(reticulate)
  3. library(rhdf5)
  4. library(jsonlite)
  5. library(here)
  6. vendor_hooks_path <- here("R", "functions", "vendor_hooks.R")
  7. # Always normalize paths for Windows compatibility
  8. vendor_hooks_path <- normalizePath(vendor_hooks_path, winslash = "/", mustWork = FALSE)
  9. # old version (use local venv)
  10. # reticulate::use_virtualenv(venv_path, required = TRUE)
  11. # connect previously created python environment + packages
  12. #' Activate MNE Python environment
  13. #'
  14. #' Sets up or activates the required conda environment for MNE.
  15. #' @export
  16. activate_mne_env <- function () {
  17. # Step 0: Ensure unattended install
  18. Sys.setenv(CONDA_ALWAYS_YES = "true")
  19. # Step 1: Ensure Miniconda exists
  20. if (reticulate::miniconda_path() == "" || !file.exists(reticulate::miniconda_path())) {
  21. message("Installing Miniconda...")
  22. reticulate::install_miniconda()
  23. # Alternative code to accept ToS automatically
  24. # (Can be run in command line, currently not running if executed within activate_mne_env)
  25. # conda_bin <- file.path(reticulate::miniconda_path(), "condabin", "conda.bat")
  26. # for (ch in c("https://repo.anaconda.com/pkgs/main",
  27. #"https://repo.anaconda.com/pkgs/r",
  28. #"https://repo.anaconda.com/pkgs/msys2")) {
  29. #system2(conda_bin, c("tos", "accept", "--override-channels", "--channel", ch),
  30. #stdout = TRUE, stderr = TRUE, wait = TRUE)
  31. #}
  32. }
  33. # Step 2: Now it's safe to query conda
  34. conda_envs <- reticulate::conda_list()[["name"]]
  35. # Step 3: Create env if missing
  36. if (!"mne-env" %in% conda_envs) {
  37. message("Creating mne-env...")
  38. reticulate::conda_create("mne-env", packages = "python=3.10")
  39. reticulate::conda_install(
  40. "mne-env",
  41. packages = c("mne", "numpy", "scipy", "mne-bids", "matplotlib", "pandas"),
  42. channel = "conda-forge"
  43. )
  44. }
  45. # Step 4: Activate env
  46. reticulate::use_condaenv("mne-env", required = TRUE)
  47. # Step 5: Import Python modules
  48. mne <- reticulate::import("mne")
  49. mnebids <- reticulate::import("mne_bids")
  50. h5py <- reticulate::import("h5py")
  51. pathlib <- reticulate::import("pathlib")
  52. # Return objects (important!)
  53. list(
  54. mne = mne,
  55. mnebids = mnebids,
  56. h5py = h5py,
  57. pathlib = pathlib,
  58. BIDSPath = mnebids$BIDSPath,
  59. write_raw_bids = mnebids$write_raw_bids
  60. )
  61. }
  62. #### ACCESS THE PATH TO SAVE THE CONVERTED VALUES ####
  63. make_output_folder <- function(file_path_reactive) {
  64. reactive({
  65. file_path <- file_path_reactive()
  66. if (is.null(file_path) || file_path == "") return(NULL)
  67. basename(dirname(file_path))
  68. })
  69. }
  70. #### CONVERT ROUTINE (ONE FILE) ####
  71. # Function that reads a source SNIRF file, checks for manufacturer name
  72. # If routine = "json", it checks for a description.json file in the same folder containing the SNIRF
  73. # Reads subject ID and experiment description from there
  74. # And then deducts the task name and session number based on task mapping
  75. # If routine = "folder", it reads the subject ID, session number and task name from the folder structure
  76. #' snirf2bids function for conversion
  77. #'
  78. #' @param source_snirf SNIRF to be converted
  79. #' @param converted_root Output folder for converted SNIRFs
  80. #' @param experiment_description Subject, session and task metadata - only for "json" routine
  81. #' @param routine Switch between "json" and "folder"
  82. #' @param py_env List. Python environment returned by activate_mne_env()
  83. #' @export
  84. snirf2bids <- function (source_snirf, converted_root, experiment_description = NULL, routine = c("json", "folders"), py_env) {
  85. routine <- match.arg(routine)
  86. log_file <- file.path(converted_root, "log.txt")
  87. if (routine == "json") {
  88. task_map <- read.csv(experiment_description, colClasses = c("session" = "character"))
  89. json_path <- check_description_json(source_snirf) # Use NIRx vendor hook
  90. # Read the JSON content
  91. json_content <- fromJSON(json_path)
  92. # Convert the JSON content to a data frame
  93. file_tags <- as.data.frame(t(unlist(json_content)), stringsAsFactors = FALSE)
  94. # Add the subfolder name as a column
  95. file_tags$subfolder <- basename(dirname(json_path))
  96. # IF the information inside description.json matches experiment description, create regular BIDS path with corresponding info
  97. if (any(task_map$name == file_tags$experiment)) {
  98. # Read task and session from the experiment overview
  99. file_tags$task <- task_map$task[task_map$name == file_tags$experiment]
  100. file_tags$session <- task_map$session[task_map$name == file_tags$experiment]
  101. bids_path <- py_env$BIDSPath(
  102. subject = file_tags$subject,
  103. session = file_tags$session,
  104. task = file_tags$task,
  105. root = converted_root
  106. )
  107. }
  108. # ELSE create BIDS path inside "no_mapping" folder with session "999"
  109. else {
  110. file_tags$task <- gsub("[-_/]", "", file_tags$experiment) # Remove BIDS non-conforming characters from the string
  111. file_tags$session <- "999"
  112. no_mapping_path <- file.path(converted_root, "no_mapping")
  113. dir.create(no_mapping_path, recursive = TRUE, showWarnings = FALSE)
  114. bids_path <- py_env$BIDSPath(
  115. subject = file_tags$subject,
  116. session = file_tags$session,
  117. task = file_tags$task,
  118. root = no_mapping_path
  119. )
  120. }
  121. # Load data with MNE and convert to BIDS format
  122. raw <- py_env$mne$io$read_raw_snirf(source_snirf, preload = FALSE)
  123. tryCatch({
  124. py_env$write_raw_bids(raw, bids_path) # this will cause an error, i.e., FileExistsError because the "overwrite=T" parameter is missing
  125. }, error = function(e) {
  126. py_last_error() # restore previous exception
  127. error <- py_last_error()
  128. writeLines(error$message, log_file)
  129. showNotification(error$message, type = "error")
  130. })
  131. }
  132. # In "folders" routine, extract subject ID, session number and task name from folder structure
  133. else if (routine == "folders"){
  134. # Split path into components
  135. path_parts <- strsplit(normalizePath(source_snirf), "[/\\\\]")[[1]]
  136. if (length(path_parts) < 4) {
  137. stop("Path is too short to extract subject/session/task structure")
  138. }
  139. # Extract last elements relative to file
  140. task <- path_parts[length(path_parts) - 1]
  141. session <- path_parts[length(path_parts) - 2]
  142. subject <- path_parts[length(path_parts) - 3]
  143. file_tags <- data.frame(
  144. subject = subject,
  145. session = session,
  146. task = task
  147. )
  148. bids_path <- py_env$BIDSPath(
  149. subject = subject,
  150. session = session,
  151. task = task,
  152. root = converted_root
  153. )
  154. raw <- py_env$mne$io$read_raw_snirf(source_snirf, preload = FALSE)
  155. tryCatch({
  156. py_env$write_raw_bids(raw, bids_path) # this will cause an error, i.e., FileExistsError because the "overwrite=T" parameter is missing
  157. }, error = function(e) {
  158. py_last_error() # restore previous exception
  159. error <- py_last_error()
  160. writeLines(error$message, log_file)
  161. showNotification(error$message, type = "error")
  162. })
  163. }
  164. }
  165. #### NO MAPPING OVERVIEW ####
  166. create_no_mapping_overview <- function(converted_root) {
  167. no_mapping_dir <- file.path(converted_root, "no_mapping")
  168. # Do nothing if the directory does not exist
  169. if (!dir.exists(no_mapping_dir)) {
  170. return(invisible(NULL))
  171. }
  172. # List all converted SNIRF files
  173. files <- list.files(
  174. path = no_mapping_dir,
  175. pattern = "_nirs\\.snirf$",
  176. recursive = TRUE,
  177. full.names = TRUE
  178. )
  179. # If there is no such file, do nothing
  180. if (length(files) == 0) {
  181. return(invisible(NULL))
  182. }
  183. # Extract ID, task and filename
  184. unmapped_df <- data.frame(
  185. ID = stringr::str_extract(basename(files), "^sub-[^_]+"),
  186. task = stringr::str_match(
  187. basename(files),
  188. "_task-([^_]+)"
  189. )[, 2],
  190. filename = basename(files),
  191. stringsAsFactors = FALSE
  192. )
  193. # Only list each file once
  194. unmapped_df <- unique(unmapped_df)
  195. # Write to csv
  196. write.csv(
  197. unmapped_df,
  198. file.path(no_mapping_dir, "unmapped_recordings.csv"),
  199. row.names = FALSE
  200. )
  201. invisible(unmapped_df)
  202. }
  203. #### CONVERT ROUTINE (ONE FOLDER) ####
  204. # Helper function that finds all .snirf files in a specific folder
  205. get_snirf_files <- function(folder) {
  206. list.files(folder, pattern = "\\.snirf$", ignore.case = TRUE, full.names = TRUE)
  207. }
  208. # Runs SNIRF2BIDS with lapply on data directory
  209. #' snirf2bids function for conversion
  210. #'
  211. #' @param source_root Input folder for raw SNIRFs
  212. #' @param converted_root Output folder for converted SNIRFs
  213. #' @param experiment_description Subject, session and task metadata - only for "json" routine
  214. #' @param routine Switch between "json" and "folder"
  215. #' @param py_env List. Python environment returned by activate_mne_env()
  216. #' @export
  217. convert_root <- function(source_root, converted_root, experiment_description = NULL,
  218. routine = c("json", "folders"), py_env) {
  219. routine <- match.arg(routine)
  220. # Find all SNIRFs in the folder and subfolders
  221. all_snirfs <- list.files(source_root, pattern = "\\.snirf$", recursive = TRUE, full.names = TRUE)
  222. # Process them one by one
  223. for (snirf_path in all_snirfs) {
  224. cat("Processing:", snirf_path, "\n")
  225. snirf2bids(
  226. source_snirf = snirf_path,
  227. converted_root = converted_root,
  228. experiment_description = experiment_description,
  229. routine = routine,
  230. py_env = py_env
  231. )
  232. }
  233. create_no_mapping_overview(converted_root)
  234. }

convert.R at commit fddbd6d, no license · at the source

Overview

Authors: Raphaël Lorenz-de Laigue1,2, Jennifer Svaldi1,2, Philipp A. Schroeder1,2
  1. University of Tübingen, Department of Psychology, Clinical Psychology & Psychotherapy, Tübingen, Germany
  2. German Center for Mental Health (DZPG), Tübingen, Germany
Institutions: University of Tübingen (Germany)
Journal: Neurophotonics, volume 13, issue Suppl 3, article S32603
Dates: received 1 April 2026; accepted 13 August 2026; published online 17 September 2026; in print August 2026
Type: Methods article · Language: English
License: CC BY
Identifiers: DOI 10.1117/1.nph.13.s3.s32603 · PMID 42757085 · PMCID PMC13585469 · OpenAlex W7213517912
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: fNIRS (modality), methods / tools (subfield)
Keywords: BIDS, data sharing, R, conversion, open-source software
Journal subjects: fNIRS Commons: Datasets and Tools for Open, Reproducible Science
Topic: Optical Imaging and Spectroscopy Techniques (Radiology, Nuclear Medicine and Imaging, Medicine), according to OpenAlex
Funding: Deutsches Zentrum für Psychische Gesundheit (TÜ2D)
Citations: not cited yet (Europe PMC); 38 references in the paper

Abstract

Significance: Optical imaging with functional near-infrared spectroscopy (fNIRS) often produces complex datasets. The Brain Imaging Data Structure specification (BIDS) has evolved to harmonize fNIRS recordings and to facilitate data sharing, transparency, and reproducibility. However, the conversion of raw fNIRS recordings and associated metadata into BIDS format remains time-consuming and error-prone.

Aim: We aim to present SNIRF2BIDS, an R package that streamlines the conversion of fNIRS data to the BIDS format through a graphical user interface.

Approach: SNIRF2BIDS automates dataset restructuring, metadata organization, and file naming in accordance with the current BIDS specification. The SNIRF2BIDS-GUI requires R (≥4.0.0), including recent versions of shiny (≥1.13) and rlang (≥1.1.7). The backend for conversion configures Python and MNE-BIDS to be available for R via reticulate (≥1.45). After initial setup, the tool operates locally without requiring data transfer to online platforms.

Results: We demonstrate the functionality of SNIRF2BIDS in a step-by-step tutorial, guiding users from raw fNIRS recordings to fully BIDS-compliant datasets.

Conclusions: SNIRF2BIDS enables standardized organization of fNIRS datasets, thereby reducing manual work and minimizing the risk of human error. It fosters data sharing, thus supporting reproducible workflows and meta-scientific progress in the growing fNIRS research community.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repository

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

raphael-lorenzdelaigue/snirf2bids

License: none: the authors keep all their rights
State: the link answers, verified on 26 September 2026
Evidence: files inventoried
Commit: fddbd6db85a32695bd0ef524d65f893f7891bef6, 7 August 2026
Languages: R (8)
Size: 37 files, 8 scripts
Software Heritage: not archived
Found in: “Code and Data Availability”
Holds: environment (DESCRIPTION), documentation
Not found: README, license file, CITATION.cff, tests, continuous integration
Tools: tidyverse (4 files), reticulate (2 files)
Availability: 1 check, the latest on 26 September 2026: the link answers
  • 26 September 2026: the link answers
8 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;
  • 8 scripts, each with its path and the digest of its content;
  • 6 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

All data and code reported in this paper are openly available on Github: https://github.com/raphael-lorenzdelaigue/snirf2bids.

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, issue, pages, dates, 3 authors, 5 keywords, 1 funder, 25 references.

Cite

This paper

Lorenz-de Laigue, R., Svaldi, J., & Schroeder, P. A. (2026). SNIRF2BIDS: a GUI-based tool for converting functional near-infrared spectroscopy data to the Brain Imaging Data Structure in R. Neurophotonics, 13(Suppl 3), S32603. https://doi.org/10.1117/1.nph.13.s3.s32603

BibTeX

@article{lorenzdelaigue2026snirf2bids,
author = {Lorenz-de Laigue, Raphaël and Svaldi, Jennifer and Schroeder, Philipp A.},
title = {{SNIRF2BIDS: a GUI-based tool for converting functional near-infrared spectroscopy data to the Brain Imaging Data Structure in R}},
journal = {Neurophotonics},
year = {2026},
month = aug,
volume = {13},
number = {Suppl 3},
pages = {S32603},
publisher = {Society of Photo-Optical Instrumentation Engineers},
issn = {2329-423X},
doi = {10.1117/1.nph.13.s3.s32603},
url = {https://doi.org/10.1117/1.nph.13.s3.s32603},
pmid = {42757085},
pmcid = {PMC13585469}
}

RIS

TY - JOUR
AU - Lorenz-de Laigue, Raphaël
AU - Svaldi, Jennifer
AU - Schroeder, Philipp A.
TI - SNIRF2BIDS: a GUI-based tool for converting functional near-infrared spectroscopy data to the Brain Imaging Data Structure in R
T2 - Neurophotonics
J2 - Neurophotonics
PY - 2026
DA - 2026/08/01
VL - 13
IS - Suppl 3
SP - S32603
SN - 2329-423X
PB - Society of Photo-Optical Instrumentation Engineers
DO - 10.1117/1.nph.13.s3.s32603
UR - https://doi.org/10.1117/1.nph.13.s3.s32603
LA - en
ER -

CSL-JSON

{
"id": "10.1117/1.nph.13.s3.s32603",
"type": "article-journal",
"title": "SNIRF2BIDS: a GUI-based tool for converting functional near-infrared spectroscopy data to the Brain Imaging Data Structure in R",
"container-title": "Neurophotonics",
"author": [
{
"family": "Lorenz-de Laigue",
"given": "Raphaël"
},
{
"family": "Svaldi",
"given": "Jennifer"
},
{
"family": "Schroeder",
"given": "Philipp A."
}
],
"container-title-short": "Neurophotonics",
"volume": "13",
"issue": "Suppl 3",
"page": "S32603",
"DOI": "10.1117/1.nph.13.s3.s32603",
"PMID": "42757085",
"PMCID": "PMC13585469",
"ISSN": "2329-423X",
"publisher": "Society of Photo-Optical Instrumentation Engineers",
"URL": "https://doi.org/10.1117/1.nph.13.s3.s32603",
"language": "en",
"issued": {
"date-parts": [
[
2026,
8,
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.1117/1.nph.13.s3.s32602 [code]
Cedalion tutorial: a Python-based framework for comprehensive analysis of multimodal fNIRS and DOT from the lab to the everyday world.
Journal: Neurophotonics
In common: fNIRS, methods / tools, 4 references
[2] doi:10.1117/1.nph.13.2.025001 [code]
Surface-based image reconstruction optimization for high-density functional near-infrared spectroscopy.
Journal: Neurophotonics
In common: fNIRS, 3 references
[3] doi:10.1038/s41597-026-07215-1 [code]
The Brain, Body, and Behavior Dataset (BBBD): Multimodal Recordings during Educational Videos.
Journal: Scientific data
In common: methods / tools, 3 references
[4] doi:10.1117/1.nph.13.3.035009
Single-subject detection of speech network activation using functional near-infrared spectroscopy.
Journal: Neurophotonics
In common: fNIRS, 2 references
[5] doi:10.3390/s26061848
Unsupervised Dynamic Time Warping Clustering for Robust Functional Network Identification in fNIRS Motor Tasks.
Journal: Sensors (Basel, Switzerland)
In common: fNIRS, 2 references
[6] doi:10.1038/s41467-026-76939-w [code]
HIPPIE: a generative model for electrophysiological analysis across species, technologies, and modalities.
Journal: Nature communications
In common: reticulate, tidyverse, methods / tools
[7] doi:10.1080/10618600.2026.2639081 [code]
Probabilistic Joint and Individual Variation Explained (ProJIVE) for Data Integration.
Journal: Journal of computational and graphical statistics : a joint publication of American Statistical Association, Institute of Mathematical Statistics, Interface Foundation of North America
In common: reticulate, tidyverse, methods / tools
[8] doi:10.21203/rs.3.rs-9676637/v1 [code]
A Comprehensive Benchmarking of Spatial Deconvolution and Domain Detection Methods across Diverse Tissues and Spatial Transcriptomic Technologies
Journal: Research Square (preprint)
In common: reticulate, tidyverse, methods / tools
[9] doi:10.1038/s42255-026-01539-3 [code]
A cross-species atlas of the dorsal vagal complex reveals neural mediators of the effects of cagrilintide on energy balance.
Journal: Nature metabolism
In common: reticulate, tidyverse, methods / tools
[10] doi:10.1093/bib/bbag331 [code]
SPOmiAlign: a modality-agnostic computational framework for multimodal spatial omics alignment enabled by a feature matching foundation model.
Journal: Briefings in bioinformatics
In common: reticulate, tidyverse, methods / 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.

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.