Skip to content

Commit 587a682

Browse files
committed
integrate mkdocs for documentation
1 parent 0cc634b commit 587a682

15 files changed

+518
-8
lines changed

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/README.md

docs/bids_convert_and_upload.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
### 4. BIDS Conversion and Upload Pipeline ⚙️ (`convert_to_bids_and_upload.py`)
2+
3+
The pipeline is designed to ensure:
4+
5+
1. Source files (EEG only) are preserved in a BIDS-compatible structure.
6+
7+
2. EEG recordings are converted to BIDS format using MNE and validated against the BIDS standard.
8+
9+
3. Behavioral and experimental metadata (also called other files in general in context on this project) are included and checked against project expectations.
10+
11+
4. Project metadata is populated (dataset_description.json). This is required as a part of BIDS standard.
12+
13+
5. The dataset is registered in Dataverse and optionally pushed/uploaded automatically.
14+
15+
#### 1. Entry Point (`bids_process_and_upload()`)
16+
17+
- Reads project configuration (<project_name>_config.toml) to check if a other computer (non eeg files) was used. (otherFilesUsed: true)
18+
19+
- Iterates over each processed file and extracts identifiers. For example, for a file named `sub-001_ses-001_task-Default_run-001_eeg.xdf`, it extracts:
20+
21+
- Subject ID (sub-XXX) - 001 (`str` is accepted)
22+
23+
- Session ID (ses-YYY) - 001 (`str` is accepted)
24+
25+
- Run number (run-ZZZ) - 001 (`int` is accepted)
26+
27+
- Task name (task-Name) - Default (`str` is accepted)
28+
29+
- Constructs the absolute path to the .xdf file from the project root.
30+
31+
- Calls BIDS.convert_to_bids() to handle conversion and validation.
32+
33+
- After all files are processed:
34+
35+
- Populates dataset_description.json.
36+
37+
- Generates JSON metadata (`generate_json_file.py`).
38+
39+
- Creates/links a Dataverse dataset (`create_dataverse.py`).
40+
41+
- Initializes a DataLad dataset and links with Dataverse (`create_and_add_files_to_datalad_dataset.py`, `add_sibling_dataverse_in_folder.py`).
42+
43+
- Pushes data to Dataverse automatically (--yes) or via user confirmation.
44+
45+
#### 2. Convert to BIDS (`convert_to_bids()`)
46+
This function handles the core conversion of a XDF files to BIDS format and constructs the dataset structure. It performs the following steps:
47+
48+
1. Copy raw/behavioral/experiment files via `copy_source_files_to_bids()` (See section).
49+
50+
2. Build a `BIDSPath` for the EEG recording:
51+
52+
- Subject, session, run, task extracted from filename.
53+
54+
- File format: EEGLAB (.set) chosen to avoid BrainVision memory issues.
55+
56+
3. The function checks if the BIDS file already exists:
57+
58+
- If it does, it logs and doesn"t reconvert.
59+
60+
- If --redo_bids_conversion is specified, it overwrites existing files. This flag is passed from the command line while running `lslautobids run`.
61+
62+
4. If the file doesn't exist or is to be overwritten, it proceeds with conversion:
63+
64+
- Load `.xdf` with `create_raw_xdf()`. (See section).
65+
66+
- Apply anonymization (daysback_min + anonymizationNumber from project TOML config).
67+
68+
- Write EEG data into BIDS folder via `write_raw_bids().`
69+
70+
5. Validate results with `validate_bids()`. The function raises an error if validation fails and returns 0; otherwise returns 1 for success. (See section).
71+
72+
6. The convertt_to_bids() function returns a status code indicating the result of the conversion:
73+
74+
- 1: Successful BIDS conversion and validation
75+
76+
- 2: BIDS conversion already done i.e. file already existed, skipped conversion and validation
77+
78+
- 0: BIDS Conversion done but validation failure
79+
80+
#### 3. Copy Source Files (`copy_source_files_to_bids()`)
81+
This function ensures that the original source files (EEG and other/behavioral files) are also a part our dataset. These files can't be directly converted to BIDS format but we give the user the option to include them in the BIDS directory structure in a pseudo-BIDS format for completeness.
82+
83+
- Copies the .xdf into the following structure:
84+
`<BIDS_ROOT>/sourcedata/sub-XXX/ses-YYY/sub-XXX_ses-YYY_task-Name_run-ZZZ_eeg.xdf`
85+
86+
- Adds `_raw` suffix to distinguish original files.
87+
88+
- If a file already exists, logs a message and skips copying.
89+
90+
If otherFilesUsed=True in project config file:
91+
92+
1. Behavioral files are copied via `_copy_behavioral_files()`.
93+
94+
- Validates required files against TOML config (`OtherFilesInfo`). In this config we add the the extensions of the expected other files. For example, in our testproject we use EyeList 1000 Plus eye tracker which generates .edf and .csv files. So we add these extensions as required other files. We also have mandatory labnotebook and participant info files in .tsv format.
95+
- Renames files to include sub-XXX_ses-YYY_ prefix if missing.
96+
- Deletes the other files in the project_other directory that are not listed in `OtherFilesInfo` in the project config file. It doesn"t delete from the source directory, only from out BIDS dataset.
97+
98+
2. Experimental files are copied via `_copy_experiment_files().`
99+
100+
- Gathers files from the experiment folder.
101+
- Copies into BIDS `misc/` directory i.e. `<BIDS_ROOT>/misc/`
102+
- Compresses into experiment.tar.gz.
103+
- Removes the uncompressed folder.
104+
105+
There is a flag in the `lslautobids run` command called `--redo_other_pc` which when specified, forces overwriting of existing other and experiment files in the BIDS dataset. This is useful if there are updates or corrections to the other/behavioral data that need to be reflected in the BIDS dataset.
106+
107+
#### 4. Create Raw XDF (`create_raw_xdf()`)
108+
This function reads the XDF file and creates an MNE Raw object. It performs the following steps:
109+
- Select EEG stream using match_streaminfos(type="EEG").
110+
111+
- Resample to the highest nominal sampling rate across streams (fs_new).
112+
113+
- Read .xdf with `read_raw_xdf()`, enabling interpolation and marker prefixing.
114+
115+
- Annotate missing values (annotate_nan) and clean invalid annotations (negative onset).
116+
117+
- Map known channel labels to MNE channel types (e.g., heog → eog, bipoc → misc). This is done using a predefined dictionary of channel mappings for our lab setup. This can be extended in future versions to include user-defined mappings.
118+
119+
This produces a clean, memory-efficient Raw object ready for BIDS conversion.
120+
121+
#### 5. BIDS Validation (`validate_bids()`)
122+
This function validates the generated BIDS files using the `bids-validator` package. It performs the following steps:
123+
- Walks through the BIDS directory.
124+
- Skips irrelevant files: (`.xdf`, `.tar.gz`, behavioral files, hidden/system files.)
125+
- Uses `BIDSValidator` to validate relative paths.
126+
- If any file fails validation, logs an error and returns 0 ; Otherwise, logs success and returns 1.
127+
128+
#### 6. Populate dataset_description.json (`populate_dataset_description_json()`)
129+
This function generates the `dataset_description.json` file required by the BIDS standard. It performs the following steps:
130+
- Gathers metadata from the project configuration file (title, authors, license, etc.) from the project TOML config file.
131+
- Calls make_dataset_description() from mne_bids.
132+
- Overwrites existing file with updated values.
133+
134+
#### 7. Datalad and Dataverse Integration
135+
This part of the pipeline manages version control and data sharing using DataLad and Dataverse. After conversion, the following steps occur:
136+
137+
- `generate_json_file()` → Generates supplementary metadata JSONs.
138+
- `create_dataverse()` → Creates a new dataset in Dataverse. Returns DOI + status.
139+
- `create_and_add_files_to_datalad_dataset()` → Initializes DataLad repo, adds files.
140+
- `add_sibling_dataverse_in_folder()` → Links DataLad dataset to Dataverse (if new dataset).
141+
- push_files_to_dataverse() uploads files to Dataverse. It automatically uploads if --yes is set (This flag is set in `lslautobids run`), otherwise the function prompts user (y/n).
142+

docs/cli.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### 1. CLI Module (`cli.py`)
2+
3+
The command-line interface provides the main entry point for the application:
4+
5+
- **Commands**: `gen-proj-config`, `run`, `gen-dv-config`, `help`
6+
- **Module mapping**: Maps commands to their respective modules
7+
- **Argument handling**: Processes and forwards command-line arguments
8+
9+
#### Key Points
10+
11+
1. `lslautobids en-proj-config` and `lslautobids gen-dv-config` commands generate configuration files for the project and Dataverse, respectively. This allows users to set up their project and Dataverse connection details easily before running the conversion and upload process
12+
2. The `lslautobids run` command executes the main conversion and upload process, using the configurations generated earlier. This command runs the entire pipeline from reading XDF files, converting them to BIDS format, integrating with DataLad, and uploading to Dataverse.
13+
3. The `lslautobids help` command provides usage information for the CLI, listing available commands and their descriptions.

docs/configuration.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
### 2. Configuration System
2+
3+
The configuration system manages dataversse and project-specific settings using YAML and TOML files.
4+
5+
#### 1. Dataverse and Project Root Configuration (`gen_dv_config.py`)
6+
7+
This module generates a global configuration file for Dataverse and project root directories. This is a one-time setup per system. This file is stored in `~/.config/lslautobids/autobids_config.yaml` and contains:
8+
- Paths for BIDS, projects, and project_other directories : This allows users to specify where their eeg data, behavioral data, and converted BIDS data are stored on their system. This paths should be relative to the home/users directory of your system and string format.
9+
10+
- Dataverse connection details: Base URL, API key, and parent dataverse name for uploading datasets. Base URL is the URL of the dataverse server (e.g. https://darus.uni-stuttgart.de), API key is your personal API token for authentication (found in your dataverse account settings), and parent dataverse name is the name of the dataverse under which datasets will be created (this can be found in the URL when you are in the dataverses page just after 'dataverse/'). For example, if the URL is `https://darus.uni-stuttgart.de/dataverse/simtech_pn7_computational_cognitive_science`, then the parent dataverse name is `simtech_pn7_computational_cognitive_science`.
11+
12+
**Commands and arguments**
13+
14+
The command to generate the dataverse configuration file is:
15+
```
16+
lslautobids gen-dv-config
17+
```
18+
_Currently, the package doesn't allow you to have multiple dataverse configurations. This will be added in future versions and can be easily adapted_
19+
20+
However for testing purposes, we create a separate test configuration file `~/.config/lslautobids/test-autobids_config.yaml` which is used when running the tests.
21+
22+
#### 2. Project Configuration (`gen_project_config.py`)
23+
This module generates a project-specific configuration file in TOML format. This file is stored in the `projects/<PROJECT_NAME>/<PROJECT_NAME>_config.toml` file and contains:
24+
- Project metadata: Title, description, license, and authors, etc.
25+
26+
**Commands and arguments**
27+
28+
The command to generate the project configuration file is:
29+
```
30+
lslautobids gen-proj-config --project <projectname>
31+
```
32+
- `--project <projectname>`: Specifies the name of the project for which the configuration file is to be generated. This argument is *required*.
33+
- `--standalone_toml` : (Optional) If provided, the generated configuration file will be a standalone TOML file in the current directory, without being placed in the project directory.
34+
- `--custom_dv_config` : (Optional) Path to a custom YAML configuration file (dataverse and project root configuration) for Dataverse and project root directories. If not provided, the default path `~/.config/lslautobids/autobids_config.yaml` will be used. This is specified to allow flexibility in using different configurations for different projects or testing purposes.

docs/contributions.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
First of all, thanks for the interest!
2+
3+
We welcome all kinds of contribution, including, but not limited to code, documentation, examples, configuration, issue creating, etc.
4+
5+
Be polite and respectful, and follow the code of conduct.
6+
7+
## Bug reports and discussions
8+
9+
If you think you found a bug, feel free to open an [issue](https://github.com/s-ccs/LSLAutoBIDS/issues).
10+
Focused suggestions and requests can also be opened as issues.
11+
Before opening a pull request, start an issue or a discussion on the topic, please.
12+
13+
## Working on an issue
14+
15+
If you found an issue that interests you, comment on that issue what your plans are.
16+
If the solution to the issue is clear, you can immediately create a pull request (see below).
17+
Otherwise, say what your proposed solution is and wait for a discussion around it.
18+
19+
!!! tip
20+
Feel free to ping us after a few days if there are no responses.
21+
22+
If your solution involves code (or something that requires running the package locally), check the developer's documentation.
23+
Otherwise, you can use the GitHub interface directly to create your pull request.

docs/datalad_integration.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### 4. DataLad Integration (`datalad_create.py`)
2+
3+
The DataLad integration module manages the creation and updating of DataLad datasets for version control of the BIDS dataset. This function initializes a DataLad dataset at a given project path.
4+
The function performs the following steps:
5+
1. Initialize commit message. It first sets a initialization message : "LSL Auto BIDS: new files found and added".
6+
2. If flag == 0 (new dataset), the message is overwritten with "LSL Auto BIDS: new datalad dataset created".
7+
3. Further, if flag == 0 we try to create a new DataLad dataset in the specified path (dataset_path) using `dl.create()`. This is similar to running `datalad create` from the command line for datalad CLI or `git init` for git CLI. This function is executed using :
8+
9+
`dl.create(dataset_path, force=True)`
10+
11+
Here, since the directory may already contain files (BIDS directory in our case), we use force=True to allow creation of the dataset even if files already exist and it is not an empty directory.
12+
13+
4. If it raises an exception (e.g., if the path is not a directory or if DataLad already exists ), it logs an error and exits the program.
14+
15+
5. This function also changes the current working directory to the dataset_path using `os.chdir(dataset_path)` so subsequent DataLad operations (like `datalad save`, `datalad push`) run in the context of this dataset.
16+
17+
6. This function also manages the .gitattributes file to ensure that large files are handled by git-annex and small text/metadata files are handled by git. This is done by appending specific patterns to the .gitattributes file. For example:
18+
`*.csv annex.largefiles=nothing` means .csv files are treated as small files and stored directly in git. Similarly, * annex.largefiles=largerthan=100kb` means files larger than 100kb are managed by git-annex.
19+
20+
7. Finally, it saves the changes to the DataLad dataset using `dl.save()` with the appropriate commit message. This save command stages all changes (new files, modified files) and commits them to the DataLad dataset.
21+
22+
8. If flag!=0 (existing dataset), it skips the initialization step and directly saves any new changes to the existing DataLad dataset.

docs/dataverse_integration.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
### 5. Dataverse Integration
2+
3+
#### 1. Dataverse Dataset Creation (`dataverse_dataset_create.py`)
4+
This module handles the creation of a new dataset in Dataverse using the `pyDataverse` library. The function performs the following steps:
5+
6+
1. Initialize `dataset.json` file path and read the JSON content. (See section)
7+
2. Sets up a Dataverse API connection using the base URL and API key from the global configuration file (`autobids_config.yaml`). This dataset then loads the `dataset.json` into the Dataset. This json metadata populates the dataset metadata in Dataverse (title, authors, description, etc.), where we will eventually upload our datalad compatible BIDS dataset.
8+
3. The dataset JSON is validated using `ds.validate_json()`. If the validation passes only then we proceed to create the dataset in Dataverse using `dv.create_dataset()`.
9+
4. The function also checks if that dataset already exists in Dataverse (based on title) to avoid duplicates. For example, one dataverse dataset can contain data from multiple participants/subjects and we usually create a single dataset for the entire project but run the conversion for each subject separately. So we check if a dataset with the same title already exists in Dataverse.
10+
- Get all the datasets (pids) in the specified parent dataverse using `api.get_dataverse(parent_dataverse_name)`.
11+
- Check if that the PID specified in the response matches the Dataverse PID specified in the project config file. If it does, we log a message and skip creation.
12+
5. If no existing dataset is found, we create a new dataset using `api.create_dataset(parent_dataverse_name, ds.json())`. We then populate the returned dataset ID and DOI in the project configuration file (<project_name>_config.toml) for using in future runs.
13+
6. This function returns the dataset DOI and status code ( 1= dataverse dataset exists, 0= new dataset created)
14+
15+
#### 2. Linking DataLad to Dataverse (`link_datalad_dataverse.py`)
16+
This module links the local DataLad dataset to the remote Dataverse dataset as a sibling. The function performs the following steps:
17+
1. It first checks if the Dataverse is already created in the previous runs or it is just created in the current run (flag==0). If flag==0, it proceeds to link the DataLad dataset to Dataverse.
18+
2. It runs the command `datalad add-sibling-dataverse dataverse_base_url doi_id`. This command adds the Dataverse as a sibling to the local DataLad dataset, allowing for synchronization and data management between the two. For lslautobids, we currently only allow to deposit data to Dataverse. In future version, we shall also add user controlled options for adding other siblings like github, gitlab, OpenNeuro, AWS etc.
19+
20+
We chose Dataverse as it serves as both a repository and a data sharing platform, making it suitable for our needs. It also integrates well with DataLad and allows sharing datasets with collaborators or the public.
21+
22+
Dataverse also provides features like versioning, but only after we publish the dataset. In our case, we keep the dataset in draft mode until we are ready to publish it (i.e. until all the participants/subjects data is uploaded). So we use DataLad for version control during the development and conversion phase to assure complete provenance of the dataset.
23+
24+
25+
#### 4 Generating dataset JSON Metadata (`generate_dataset_json.py`)
26+
27+
This module generates the `dataset.json` file required for creating a dataset in Dataverse. The function performs the following steps:
28+
29+
1. Gathers metadata from the project configuration file (<project_name>_config.toml) such as title, authors, description, license, etc.
30+
2. Constructs a JSON structure that conforms to the Dataverse dataset metadata schema. This includes fields like title, author list, description, keywords, license, etc.
31+
3. Writes the constructed JSON to a file named `dataset.json` in the project directory. This file is then used when creating the dataset in Dataverse.
32+
33+
#### 5. Upload to Dataverse (`upload_to_dataverse.py`)
34+
35+
This module handles the uploading of files from the local DataLad dataset to the remote Dataverse dataset. The function performs the following steps:
36+
1. It runs the command `datalad push --to dataverse` to push the files from the local DataLad dataset to the linked Dataverse dataset. This command uploads all changes (new files, modified files) to Dataverse.
37+
2. If the `--yes` flag is set (in `lslautobids run`), it automatically pushes the files without user confirmation. Otherwise, it prompts the user for confirmation before proceeding with the upload.

docs/developers_documentation.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ LSLAutoBIDS is a Python tool series designed to automate the following tasks seq
5959
- [Running Tests](#running-tests)
6060

6161

62-
## Architecture - TODO
63-
64-
The system follows a modular architecture with clear separation of concerns:
65-
<TODO: Add architecture diagram here>
66-
6762
## Core Components
6863

6964
### 1. CLI Module (`cli.py`)

0 commit comments

Comments
 (0)