SNIRF2BIDS: a GUI-based tool for converting functional near-infrared spectroscopy data to the Brain Imaging Data Structure in R.
4 blocks of code here have a permanent identifier (oscr:b:…), listed with the matches below: citable for good, with a page of its own. Select a match and press Cite to copy it. What a block identifier is.
The 6 matches
- [1] § Handling Files that Could Not Be Converted ↔ inst/shiny/myapp/app.R, lines 172 to 283 · score 0.73 · log.txt, Conversion failed, Conversion complete, mne bids, notification, messages · block
oscr:b:8XXNCXTGRGK8V-U· Report a mismatch - [2] § Installation and Setup ↔ R/convert.R, lines 16 to 75 · score 0.62 · Python environment, Miniconda, MNE BIDS, command, reticulate, installation · block
oscr:b:FR47RYRDKFP7J-6· Report a mismatch - [3] § Main GUI and General Workflow ↔ R/convert.R, lines 95 to 198 · score 0.54 · subject ID, description.json, task mapping, MNE, BIDS formatted, root · block
oscr:b:D0AQX9GZP17CW-A· Report a mismatch - [4] § Define the Hierarchical Folder Structure and File-Naming Scheme › Step 3: Define Experimental Setup ↔ R/experimentalDesign.R, lines 46 to 111 · score 0.54 · took place, fNIRS, afternoon, day, declares, morning · block
oscr:b:GBYKWH83VN3BJ-8· Report a mismatch - [5] § Presentation of (NIRS-)BIDS and Existing Software Tools ↔ R/convert.R, lines 16 to 75 · score 0.52 · raw bids, MNE BIDS, channels, Python, export · block
oscr:b:FR47RYRDKFP7J-6· Report a mismatch - [6] § Handling Files that Could Not Be Converted ↔ R/convert.R, lines 95 to 198 · score 0.51 · log.txt, raw bids, notification, Error, mne, SNIRF · block
oscr:b:D0AQX9GZP17CW-A· Report a mismatch
Paper
Loaded from Europe PMC by your browser; OSCR does not store it: 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
- #### SETUP ####
- library(reticulate)
- library(rhdf5)
- library(jsonlite)
- library(here)
- vendor_hooks_path <- here("R", "functions", "vendor_hooks.R")
- # Always normalize paths for Windows compatibility
- vendor_hooks_path <- normalizePath(vendor_hooks_path, winslash = "/", mustWork = FALSE)
- # old version (use local venv)
- # reticulate::use_virtualenv(venv_path, required = TRUE)
- # connect previously created python environment + packages
- #' Activate MNE Python environment
- #'
- #' Sets up or activates the required conda environment for MNE.
- #' @export
- activate_mne_env <- function () {
- # Step 0: Ensure unattended install
- Sys.setenv(CONDA_ALWAYS_YES = "true")
- # Step 1: Ensure Miniconda exists
- if (reticulate::miniconda_path() == "" || !file.exists(reticulate::miniconda_path())) {
- message("Installing Miniconda...")
- reticulate::install_miniconda()
- # Alternative code to accept ToS automatically
- # (Can be run in command line, currently not running if executed within activate_mne_env)
- # conda_bin <- file.path(reticulate::miniconda_path(), "condabin", "conda.bat")
- # for (ch in c("https://repo.anaconda.com/pkgs/main",
- #"https://repo.anaconda.com/pkgs/r",
- #"https://repo.anaconda.com/pkgs/msys2")) {
- #system2(conda_bin, c("tos", "accept", "--override-channels", "--channel", ch),
- #stdout = TRUE, stderr = TRUE, wait = TRUE)
- #}
- }
- # Step 2: Now it's safe to query conda
- conda_envs <- reticulate::conda_list()[["name"]]
- # Step 3: Create env if missing
- if (!"mne-env" %in% conda_envs) {
- message("Creating mne-env...")
- reticulate::conda_create("mne-env", packages = "python=3.10")
- reticulate::conda_install(
- "mne-env",
- packages = c("mne", "numpy", "scipy", "mne-bids", "matplotlib", "pandas"),
- channel = "conda-forge"
- )
- }
- # Step 4: Activate env
- reticulate::use_condaenv("mne-env", required = TRUE)
- # Step 5: Import Python modules
- mne <- reticulate::import("mne")
- mnebids <- reticulate::import("mne_bids")
- h5py <- reticulate::import("h5py")
- pathlib <- reticulate::import("pathlib")
- # Return objects (important!)
- list(
- mne = mne,
- mnebids = mnebids,
- h5py = h5py,
- pathlib = pathlib,
- BIDSPath = mnebids$BIDSPath,
- write_raw_bids = mnebids$write_raw_bids
- )
- }
- #### ACCESS THE PATH TO SAVE THE CONVERTED VALUES ####
- make_output_folder <- function(file_path_reactive) {
- reactive({
- file_path <- file_path_reactive()
- if (is.null(file_path) || file_path == "") return(NULL)
- basename(dirname(file_path))
- })
- }
- #### CONVERT ROUTINE (ONE FILE) ####
- # Function that reads a source SNIRF file, checks for manufacturer name
- # If routine = "json", it checks for a description.json file in the same folder containing the SNIRF
- # Reads subject ID and experiment description from there
- # And then deducts the task name and session number based on task mapping
- # If routine = "folder", it reads the subject ID, session number and task name from the folder structure
- #' snirf2bids function for conversion
- #'
- #' @param source_snirf SNIRF to be converted
- #' @param converted_root Output folder for converted SNIRFs
- #' @param experiment_description Subject, session and task metadata - only for "json" routine
- #' @param routine Switch between "json" and "folder"
- #' @param py_env List. Python environment returned by activate_mne_env()
- #' @export
- snirf2bids <- function (source_snirf, converted_root, experiment_description = NULL, routine = c("json", "folders"), py_env) {
- routine <- match.arg(routine)
- log_file <- file.path(converted_root, "log.txt")
- if (routine == "json") {
- task_map <- read.csv(experiment_description, colClasses = c("session" = "character"))
- json_path <- check_description_json(source_snirf) # Use NIRx vendor hook
- # Read the JSON content
- json_content <- fromJSON(json_path)
- # Convert the JSON content to a data frame
- file_tags <- as.data.frame(t(unlist(json_content)), stringsAsFactors = FALSE)
- # Add the subfolder name as a column
- file_tags$subfolder <- basename(dirname(json_path))
- # IF the information inside description.json matches experiment description, create regular BIDS path with corresponding info
- if (any(task_map$name == file_tags$experiment)) {
- # Read task and session from the experiment overview
- file_tags$task <- task_map$task[task_map$name == file_tags$experiment]
- file_tags$session <- task_map$session[task_map$name == file_tags$experiment]
- bids_path <- py_env$BIDSPath(
- subject = file_tags$subject,
- session = file_tags$session,
- task = file_tags$task,
- root = converted_root
- )
- }
- # ELSE create BIDS path inside "no_mapping" folder with session "999"
- else {
- file_tags$task <- gsub("[-_/]", "", file_tags$experiment) # Remove BIDS non-conforming characters from the string
- file_tags$session <- "999"
- no_mapping_path <- file.path(converted_root, "no_mapping")
- dir.create(no_mapping_path, recursive = TRUE, showWarnings = FALSE)
- bids_path <- py_env$BIDSPath(
- subject = file_tags$subject,
- session = file_tags$session,
- task = file_tags$task,
- root = no_mapping_path
- )
- }
- # Load data with MNE and convert to BIDS format
- raw <- py_env$mne$io$read_raw_snirf(source_snirf, preload = FALSE)
- tryCatch({
- py_env$write_raw_bids(raw, bids_path) # this will cause an error, i.e., FileExistsError because the "overwrite=T" parameter is missing
- }, error = function(e) {
- py_last_error() # restore previous exception
- error <- py_last_error()
- writeLines(error$message, log_file)
- showNotification(error$message, type = "error")
- })
- }
- # In "folders" routine, extract subject ID, session number and task name from folder structure
- else if (routine == "folders"){
- # Split path into components
- path_parts <- strsplit(normalizePath(source_snirf), "[/\\\\]")[[1]]
- if (length(path_parts) < 4) {
- stop("Path is too short to extract subject/session/task structure")
- }
- # Extract last elements relative to file
- task <- path_parts[length(path_parts) - 1]
- session <- path_parts[length(path_parts) - 2]
- subject <- path_parts[length(path_parts) - 3]
- file_tags <- data.frame(
- subject = subject,
- session = session,
- task = task
- )
- bids_path <- py_env$BIDSPath(
- subject = subject,
- session = session,
- task = task,
- root = converted_root
- )
- raw <- py_env$mne$io$read_raw_snirf(source_snirf, preload = FALSE)
- tryCatch({
- py_env$write_raw_bids(raw, bids_path) # this will cause an error, i.e., FileExistsError because the "overwrite=T" parameter is missing
- }, error = function(e) {
- py_last_error() # restore previous exception
- error <- py_last_error()
- writeLines(error$message, log_file)
- showNotification(error$message, type = "error")
- })
- }
- }
- #### NO MAPPING OVERVIEW ####
- create_no_mapping_overview <- function(converted_root) {
- no_mapping_dir <- file.path(converted_root, "no_mapping")
- # Do nothing if the directory does not exist
- if (!dir.exists(no_mapping_dir)) {
- return(invisible(NULL))
- }
- # List all converted SNIRF files
- files <- list.files(
- path = no_mapping_dir,
- pattern = "_nirs\\.snirf$",
- recursive = TRUE,
- full.names = TRUE
- )
- # If there is no such file, do nothing
- if (length(files) == 0) {
- return(invisible(NULL))
- }
- # Extract ID, task and filename
- unmapped_df <- data.frame(
- ID = stringr::str_extract(basename(files), "^sub-[^_]+"),
- task = stringr::str_match(
- basename(files),
- "_task-([^_]+)"
- )[, 2],
- filename = basename(files),
- stringsAsFactors = FALSE
- )
- # Only list each file once
- unmapped_df <- unique(unmapped_df)
- # Write to csv
- write.csv(
- unmapped_df,
- file.path(no_mapping_dir, "unmapped_recordings.csv"),
- row.names = FALSE
- )
- invisible(unmapped_df)
- }
- #### CONVERT ROUTINE (ONE FOLDER) ####
- # Helper function that finds all .snirf files in a specific folder
- get_snirf_files <- function(folder) {
- list.files(folder, pattern = "\\.snirf$", ignore.case = TRUE, full.names = TRUE)
- }
- # Runs SNIRF2BIDS with lapply on data directory
- #' snirf2bids function for conversion
- #'
- #' @param source_root Input folder for raw SNIRFs
- #' @param converted_root Output folder for converted SNIRFs
- #' @param experiment_description Subject, session and task metadata - only for "json" routine
- #' @param routine Switch between "json" and "folder"
- #' @param py_env List. Python environment returned by activate_mne_env()
- #' @export
- convert_root <- function(source_root, converted_root, experiment_description = NULL,
- routine = c("json", "folders"), py_env) {
- routine <- match.arg(routine)
- # Find all SNIRFs in the folder and subfolders
- all_snirfs <- list.files(source_root, pattern = "\\.snirf$", recursive = TRUE, full.names = TRUE)
- # Process them one by one
- for (snirf_path in all_snirfs) {
- cat("Processing:", snirf_path, "\n")
- snirf2bids(
- source_snirf = snirf_path,
- converted_root = converted_root,
- experiment_description = experiment_description,
- routine = routine,
- py_env = py_env
- )
- }
- create_no_mapping_overview(converted_root)
- }
convert.R at commit fddbd6d, no license · at the source
Overview
- University of Tübingen, Department of Psychology, Clinical Psychology & Psychotherapy, Tübingen, Germany
- German Center for Mental Health (DZPG), Tübingen, Germany
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
fddbd6db85a32695bd0ef524d65f893f7891bef6, 7 August 2026Availability: 1 check, the latest on 26 September 2026: the link answers
- 26 September 2026: the link answers
8 files
- R/
Readme.R , R, 101 lines - R/
convert.R , R, 288 lines, 4 matches - R/
datasetDescription.R , R, 117 lines - R/
experimentalDesign.R , R, 195 lines, 1 match - R/
launchApp.R , R, 16 lines - R/
taskMapping.R , R, 124 lines - R/
vendor_hooks.R , R, 26 lines - inst/
shiny/ , R, 285 lines, 1 matchmyapp/ app.R
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://
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://
BibTeX
@article{lorenzdelaigue2
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/
url = {https://
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/
VL - 13
IS - Suppl 3
SP - S32603
SN - 2329-423X
PB - Society of Photo-Optical Instrumentation Engineers
DO - 10.1117/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1117/
"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":
"volume": "13",
"issue": "Suppl 3",
"page": "S32603",
"DOI": "10.1117/
"PMID": "42757085",
"PMCID": "PMC13585469",
"ISSN": "2329-423X",
"publisher": "Society of Photo-Optical Instrumentation Engineers",
"URL": "https://
"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.10.2.023515
- Using preregistration as a tool for transparent fNIRS study design.Journal: NeurophotonicsIn common: fNIRS, methods / tools, 6 references, author Philipp A. Schroeder
- [2] doi:10.1117/1.nph.9.s2.s24001 [code]
- Optical imaging and spectroscopy for the study of the human brain: status report.Journal: NeurophotonicsIn common: fNIRS, methods / tools, 5 references
- [3] 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: NeurophotonicsIn common: fNIRS, methods / tools, 4 references
- [4] doi:10.1038/s41597-025-05654-w
- An fNIRS dataset for Multimodal Speech Comprehension in Normal Hearing Individuals and Cochlear Implant Users.Journal: Scientific dataIn common: fNIRS, methods / tools, 4 references
- [5] doi:10.1038/s41597-024-04136-9 [code]
- NIRS-BIDS: Brain Imaging Data Structure Extended to Near-Infrared Spectroscopy.Journal: Scientific dataIn common: fNIRS, methods / tools, 4 references
- [6] doi:10.1117/1.nph.10.2.023513
- Wearable, high-density fNIRS and diffuse optical tomography technologies: a perspective.Journal: NeurophotonicsIn common: fNIRS, 4 references
- [7] doi:10.1038/s41597-026-06790-7 [code]
- FAIR m-BIDS: Advancing brain data utilization through multimodal and FAIR principles.Journal: Scientific dataIn common: methods / tools, 4 references
- [8] doi:10.1162/imag.a.974 [code]
- Multimodal fNIRS-EEG sensor fusion: Review of data-driven methods and perspective for naturalistic brain imaging.Journal: Imaging neuroscience (Cambridge, Mass.)In common: fNIRS, methods / tools, 3 references
- [9] doi:10.3389/fnrgo.2024.1286586 [code]
- Optimizing spatial specificity and signal quality in fNIRS: an overview of potential challenges and possible options for improving the reliability of real-time applications.Journal: Frontiers in neuroergonomicsIn common: fNIRS, methods / tools, 3 references
- [10] doi:10.1117/1.nph.9.1.015004
- Characterizing reproducibility of cerebral hemodynamic responses when applying short-channel regression in functional near-infrared spectroscopy.Journal: NeurophotonicsIn common: fNIRS, 3 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.
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: 1 repository of the authors' code, each at its verified commit and with its license, 8 scripts, and 6 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:1cc7bdc8505d2550…
Add the badge to the code's README
If you are an author or a maintainer of this paper's code, you can add this badge. It says what OSCR knows of the paper (its code, its validated tracing map) and links the code to this page. Paste one of these snippets under the README's title. Keep the two marks around it, so that the badge can be replaced in place and is never added twice. OSCR changes nothing in your repository.
Markdown
<!-- oscr-badge:start -->
[](https://openscicode.org/badge/doi/10.1117/1.nph.13.s3.s32603)
<!-- oscr-badge:end -->reStructuredText
.. oscr-badge:start
.. image:: https://openscicode.org/badge/doi/10.1117/1.nph.13.s3.s32603.svg
:target: https://openscicode.org/badge/doi/10.1117/1.nph.13.s3.s32603
:alt: OSCR
.. oscr-badge:endHTML
<!-- oscr-badge:start -->
<a href="https://openscicode.org/badge/doi/10.1117/1.nph.13.s3.s32603"><img src="https://openscicode.org/badge/doi/10.1117/1.nph.13.s3.s32603.svg" alt="OSCR"></a>
<!-- oscr-badge:end -->On GitHub, open the README, choose Edit (the pencil), paste the snippet under the title, then "Commit changes".
If you choose to, you can have the badge kept up to date for you, with oscr badge --write from the command line or with the GitHub Action in your repository's workflows. Every other form and option (a card, AsciiDoc, LaTeX, shields.io) is on the badge 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: code errors and mismatches between the code and the paper about this paper and its code, from readers and its authors, beside the paper and its tracing map.
Report a mismatch between the code and the paper · Report a code error (signed in)
Reproductions: reports from readers who ran the authors' code and did not get the paper's result, what they ran, with which environment, commit and data.
Report a reproduction failure (signed in)
Versions of its code: the releases of its code tied to a version of this paper (the preprint, the accepted manuscript, the version of record…), each with the tracing map versioned with it.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
