A modular command-line tool that converts behavioral survey data from Excel files into BIDS-compliant JSON and TSV files for neuroimaging data repositories.
- π Excel to BIDS Conversion: Automatically converts Excel survey data to BIDS format
- π§© Modular Architecture: Clean separation of concerns across multiple modules
- β Data Validation: Comprehensive validation of input data and BIDS compliance
- π Flexible Demographics: Support for complex demographic data with custom data types
- π·οΈ Multiple Data Types: Handles Likert scales, categorical data, and free-text responses
- π§ Robust Error Handling: Detailed logging and error reporting
- π¦ Single-File Option: Combined version for easy deployment
- π Fast Setup: Quick installation with uv package manager
Don't worry about virtual environments! We've made it super simple:
Just download and run - everything is handled automatically:
# Linux/macOS
./behave_easy.sh -d data -r resources -o output -s YourStudy
# Windows
behave_easy.bat -d data -r resources -o output -s YourStudyThe easy launcher will:
- β Automatically detect if you need a virtual environment
- β Automatically create one if missing
- β Automatically install all required packages
- β Automatically activate the environment
- β Run the conversion with your data
No technical knowledge required! π
The main script now detects and handles virtual environments automatically:
# Just run it - the script handles everything!
python behave.py -d data -r resources -o output -s YourStudyIf packages are missing, the script will ask: "Would you like me to install the missing packages? (y/n)"
Just type y and press Enter!
The fastest way to get started is using our setup script with uv:
# Clone the repository
git clone https://github.com/MRI-Lab-Graz/behave.git
cd behave
# Run the setup script (creates virtual environment and installs dependencies)
chmod +x uv_setup.sh
./uv_setup.sh
# Activate the environment
source .behave/bin/activate # On Linux/macOS
# or
.behave\Scripts\activate # On Windows# Clone the repository
git clone https://github.com/MRI-Lab-Graz/behave.git
cd behave
# Create virtual environment
python -m venv .behave
source .behave/bin/activate # On Linux/macOS
# or
.behave\Scripts\activate # On Windows
# Install dependencies
pip install -r requirements.txtFor simple deployment, you can use the combined version without installation:
# Download just the combined file
wget https://raw.githubusercontent.com/MRI-Lab-Graz/behave/main/behave_combined.py
# Install dependencies
pip install pandas openpyxl
# Run directly
python behave_combined.py --help# Convert behavioral data to BIDS format
python behave.py -d data -r resources -o output -s StudyName --debug
# Using the single-file version
python behave_combined.py StudyName /path/to/data /path/to/output --debugpython behave.py [OPTIONS]
Options:
-d, --data PATH Path to data folder containing session files
-r, --resources PATH Path to resources folder with questionnaire definitions
-o, --output PATH Path to output folder for BIDS data
-s, --study TEXT Study identifier (e.g., "StudyXYZ")
--debug Enable debug logging
--anonymize Anonymize question descriptions
--skip-validation Skip BIDS validation
--log-file PATH Log to file instead of console
-h, --help Show help messagepython behave_combined.py STUDY_NAME DATA_PATH OUTPUT_PATH [OPTIONS]
Arguments:
STUDY_NAME Name of the study
DATA_PATH Path to data folder
OUTPUT_PATH Path to output folder
Options:
--debug Enable debug logging
--anonymize Anonymize question names
-h, --help Show help messageyour-project/
βββ data/
β βββ StudyName/
β βββ demographics.xlsx # Participant demographics
β βββ participants_dataset.xlsx # Variable definitions
β βββ session1.xlsx # Session data files
βββ resources/
β βββ questionnaire1.xlsx # Task definitions
β βββ questionnaire2.xlsx
βββ output/
βββ StudyName/
βββ rawdata/ # BIDS output folder
βββ participants.tsv
βββ participants.json
βββ dataset_description.json
βββ task-questionnaire1_beh.json
βββ sub-001/
βββ ses-1/
βββ beh/
βββ sub-001_ses-1_task-questionnaire1_beh.tsv
Contains participant demographic information:
| id | age | gender | education | ... |
|---|---|---|---|---|
| 001 | 25 | 1 | 3 | ... |
| 002 | 32 | 2 | 2 | ... |
| VariableName | DataType | Description | Levels |
|---|---|---|---|
| age | integer | Age in years | |
| gender | cat_num | Gender | 1:Male; 2:Female; 3:Other |
| education | cat_num | Education level | 1:High School; 2:Bachelor; 3:Master |
| Key | Value |
|---|---|
| Name | My BIDS Dataset |
| BIDSVersion | 1.8.0 |
| DatasetType | raw |
| Authors | John Doe; Jane Smith |
| License | CC0 |
Contains responses for all participants:
| id | ses | QUESTIONNAIRE1_item1 | QUESTIONNAIRE1_item2 | ... |
|---|---|---|---|---|
| 001 | 1 | 3 | 5 | ... |
| 002 | 1 | 2 | 4 | ... |
| itemname | itemdescription | likert_scale | levels | leveldescription | levels.1 | leveldescription.1 |
|---|---|---|---|---|---|---|
| item1 | How do you feel? | 5 | 1 | Very bad | 2 | Bad |
| item2 | Rate your mood | 5 | 1 | Very low | 2 | Low |
| key name | description |
|---|---|
| TaskName | Mood Assessment |
| Instructions | Please rate how you feel |
| key name | description |
|---|---|
| ResponseTime | Response time in milliseconds |
| Notes | Additional notes |
The tool generates a complete BIDS-compliant dataset:
participant_id age gender education
sub-001 25 1 3
sub-002 32 2 2
{
"participant_id": {
"Description": "Unique participant identifier"
},
"age": {
"Description": "Age in years"
},
"gender": {
"Description": "Gender",
"Levels": {
"1": "Male",
"2": "Female",
"3": "Other"
}
}
}{
"item1": {
"Description": "How do you feel?",
"Levels": {
"1": "Very bad",
"2": "Bad",
"3": "Neutral",
"4": "Good",
"5": "Very good"
}
}
}item1 item2 item3
3 5 2
The tool can be configured through the config.py module:
@dataclass
class BehaveConfig:
# File requirements
min_required_sheets: int = 3
# Data processing
anonymize_questions: bool = False
missing_value_replacement: str = 'n/a'
missing_value_code: int = -999
# BIDS settings
bids_version: str = "1.8.0"# Convert a simple study
python behave.py \
--data ./data \
--resources ./resources \
--output ./bids_output \
--study "PilotStudy" \
--debug# Anonymize question descriptions
python behave.py \
-d ./data \
-r ./resources \
-o ./output \
-s "Study001" \
--anonymize \
--log-file conversion.log# Using the combined version
python behave_combined.py "MyStudy" ./data ./output --debugIssue: "delimiter" must be a 1-character string
Solution: This was a bug in earlier versions. Update to the latest version.
Issue: Missing required Excel sheets Solution: Ensure your questionnaire files have at least 3 sheets (items, task description, non-likert).
Issue: BIDS validation errors Solution: Check that all required fields are present in your dataset description.
Always use --debug flag for detailed logging:
python behave.py --debug [other options]Save logs to file for later analysis:
python behave.py --log-file conversion.log [other options]- Python 3.8+
- pandas >= 1.3.0
- openpyxl >= 3.0.0
- colorama (for colored terminal output)
The tool is built with a modular architecture:
config.py: Configuration and constantsexcel_handler.py: Excel file loading and processingvalidators.py: Data validation and BIDS compliancebids_converter.py: Main conversion logicbehave.py: Main orchestrator scriptbehave_combined.py: Single-file version
# Run with test data
python behave.py \
--data ./data/template \
--resources ./resources \
--output ./test_output \
--study "TestStudy" \
--debug- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
git clone https://github.com/your-username/behave.git
cd behave
./uv_setup.sh
source .behave/bin/activateThis project is licensed under the MIT License - see the LICENSE file for details.
- MRI-Lab Graz - Original development
- BIDS Community - For the BIDS specification
- Contributors - For improvements and bug fixes
- π Bug Reports: GitHub Issues
- π‘ Feature Requests: GitHub Discussions
- π§ Email: your-email@example.com
Made with β€οΈ by the MRI-Lab Graz team
Convert behavioral Excel files into BIDS-compatible JSON and TSV files.
Arguments:
-d,--data: Path to the folder containing raw behavioral data.-r,--resources: Path to the resources folder (must contain Excel files likedemographics.xlsxandparticipants_variables.xlsx).-o,--output: Output folder where BIDS files will be saved.-s,--study: Study name (e.g.,template).--debug: Optional. Enables detailed debug logging.-h,--help: Show help message and exit.
Ensure your data is organized using the following structure (a sample is included in the repository).
The example folder is named /data/template, but you should rename this folder to match your own study ID β for example, /data/best_study_ever.
Each session should have its own sessionX.xlsx file (session1.xlsx, session2.xlsx, etc.).
Even for cross-sectional studies with only one session, a session1.xlsx file is still required.
π Important: Do not rename the following core files β they must always be named exactly as shown:
demographics.xlsxparticipants_dataset.xlsx
These filenames are required by the BEHAVE script to function correctly.
behave/
βββ data/
β βββ template/
β βββ session1.xlsx (1 sheets)
β βββ demographics.xlsx (1 sheets)
β βββ participants_dataset.xlsx (1 sheets)
βββ resources/
β βββ testquest.xlsx β (task definition with 3 sheets)
To successfully run BEHAVE, you need the following Excel files organized with specific column structures. Here's what they should look like:
The demographics.xlsx and participants_dataset.xlsx files work together to define participant-level information:
-
demographics.xlsxcontains the raw participant data β similar to theparticipants.tsvfile in BIDS. -
participants_dataset.xlsxprovides the metadata for each column indemographics.xlsx, including variable names, descriptions, and data type (similar to the participants.json)
In short, demographics.xlsx holds the data, while participants_dataset.xlsx describes and defines it.
Location: data/STUDY_NAME/demographics.xlsx
Purpose: Provides subject-level information such as age, sex, and group.
Example Columns: First column is required, rest is up to you!
| Column | Description |
|---|---|
id |
Subject ID (e.g., sub-001) |
ses |
Session number (e.g., 1) |
age |
Age in years |
sex |
Biological sex (coded numerically) |
size |
Height or body size |
weight |
Weight in kilograms |
group |
Experimental group assignment |
Example:
id ses age sex size weight group
sub-001 1 34 2 190 100 2
sub-002 1 20 2 184 80 3
Location: data/STUDY_NAME/participants_dataset.xlsx
Purpose: Defines and describes each participant-level variable. Has two sheets:
| Column | Description |
|---|---|
VariableName |
Name of the variable (e.g., age, sex) |
Description |
Human-readable description of the variable |
DataType |
Data type (string, integer, cat_num) |
Levels |
Value mappings for categorical variables (if any) |
Example:
VariableName Description DataType Levels
id Participant ID string
age Age in years integer
sex Biological sex cat_num 1: Male; 2: Female
Note: "cat_num" expects to specify Levels as key:value.
| Column | Example Value |
|---|---|
Name |
BIDSVersion |
My Bids dataset |
1.7.0 |
Used to auto-generate dataset_description.json.
Location: data/STUDY_NAME/session1.xlsx
Purpose: Contains item-level responses from a behavioral task.
Required Columns:
| Column | Description |
|---|---|
id |
Subject ID (sub-001, etc.) |
ses |
Session number |
testquest01... |
One column per task item (e.g., Likert response) |
Example:
id ses testquest01 testquest02 testquest03 ...
sub-001 1 0 1 3
sub-002 1 2 1 2
Each item must match a variable defined in the corresponding task file in the /resources/ folder.
Each behavioral task should be described using an Excel file inside the resources/ folder. This file guides how the item-level responses in sessionX.xlsx are interpreted.
Sheet 1 should include the following structure:
| Column Name | Description |
|---|---|
itemname |
Unique column name matching those in sessionX.xlsx (e.g., testquest01) |
itemdescription |
Full question or prompt presented to participants |
likert_scale |
Number of scale levels (0 if non-likert) |
levels |
Response code (e.g., 0, 1, 2, ...) |
leveldescription |
Text description for each level (must pair with a levels value) |
Additional pairs of levels and leveldescription can be added for multi-scale items.
File: resources/example_task.xlsx
Sheet 1: (Item Metadata)
| itemname | itemdescription | likert_scale | levels | leveldescription | ... |
|---|---|---|---|---|---|
| testquest01 | I feel confident in my ability to complete tasks at work. | 4 | 0 | Rarely or none of the time | ... |
| testquest02 | I enjoy participating in group discussions and activities. | 4 | 1 | Some or a little of the time | ... |
| testquest03 | I often feel stressed when managing multiple responsibilities. | 4 | 2 | Occasionally or a moderate amount of time | ... |
βΉοΈ You may include additional levels/leveldescription columns if needed (e.g., for 5-point or alternative scales).
- Every
itemnamemust match a column insessionX.xlsx. likert_scaledefines how many levels exist (e.g., 4 for a 0β3 scale).- You must provide matching
levelsandleveldescriptionpairs. - If your item is not a Likert scale, set
likert_scaleto0.
Purpose: Describes the behavioral task for the BIDS sidecar JSON file (task-[name]_beh.json).
This sheet should contain key-value pairs that correspond to standard BIDS fields describing behavioral tasks.
| Column Name | Description |
|---|---|
Key name |
The BIDS-compliant JSON field name (e.g., TaskName, Instructions) |
Description |
Human-readable explanation of the field |
Data type |
Expected data type: string, number, URI, etc. |
Info |
The value to include in the JSON (this is what BEHAVE will extract and write into the .json file) |
| Key name | Description | Data type | Info |
|---|---|---|---|
TaskName |
Name of the task. Becomes part of the filename. | string | testquest |
Instructions |
Text shown to participants before the task | string | You should be honest... |
TaskDescription |
Longer description of the task | string | Some info about the test |
CogAtlasID |
URI for Cognitive Atlas task term | string | Not categorised |
CogPOID |
URI for CogPO term | string | Not categorised |
InstitutionName |
Institution responsible for the task | string | University of Graz |
InstitutionAddress |
Address of the institution | string | Kopernikusgasse |
InstitutionalDepartmentName |
Department name at the institution | string | MRI Lab Graz |
- Only one row per key is required.
- This information is used to automatically generate the
task-[taskname]_beh.jsonfile in your BIDS output. - Task names are sanitized automatically (e.g.,
test questβtestquest).
python behave_together.py [-h] -b BIDS_DIR -t TASKS [TASKS ...] [--all]
Gather behavioral BIDS data across multiple tasks into a single wide CSV.
Arguments:
-b,--bids_dir: Top-level BIDS directory.-t,--tasks: List of task names to include (e.g.,-t ADS GNG).--all: Optional. Automatically gather all tasks found viatask-*_beh.json.-h,--help: Show help message and exit.
git clone https://github.com/your-username/behave.git
cd behave
Run the setup script to create a virtual environment and install required packages:
-
Windows:
uv_setup.bat -
macOS/Linux:
./uv_setup.sh
source .behave/bin/activate
To deactivate later:
deactivate
Ensure Python 3.8+ is installed.
The following Python packages will be installed automatically via the setup script:
pandasβ Data manipulationopenpyxlβ Excel readingnumpyβ Numerical operationscolorama(optional) β Colored terminal output
Standard libraries used (no installation needed):
os,json,logging,re
If uv is not yet installed, follow these steps:
Go to the uv releases page and download:
uv-x86_64-pc-windows-msvc.zip
Extract it to:
C:\Users\YourUsername\Programs\uv\
You should now have uv.exe in that folder.
-
Open Environment Variables via system settings.
-
Edit your
Pathunder User variables. -
Add:
C:\Users\YourUsername\Programs\uv\
Open a new terminal and run:
uv --version
You should see the version number printed.
