Skip to content

Commit 7fe257d

Browse files
committed
Minor tweaks
1 parent f31afed commit 7fe257d

File tree

9 files changed

+83
-67
lines changed

9 files changed

+83
-67
lines changed

bidscoin/bids.py

Lines changed: 63 additions & 46 deletions
Large diffs are not rendered by default.

bidscoin/bidscoiner.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,15 @@ def bidscoiner(sourcefolder: str, bidsfolder: str, participant: list=(), force:
5757

5858
# Create a dataset description file if it does not exist
5959
dataset_file = bidsfolder/'dataset_description.json'
60-
generatedby = [{"Name":"BIDScoin", 'Version':__version__, 'Description:':'A flexible GUI application suite that converts source datasets to BIDS', 'CodeURL':'https://github.com/Donders-Institute/bidscoin'}]
60+
generatedby = [{'Name': 'BIDScoin',
61+
'Version': __version__,
62+
'Description:': 'A versatile GUI application suite that converts source datasets to BIDS',
63+
'CodeURL': 'https://github.com/Donders-Institute/bidscoin'}]
6164
if not dataset_file.is_file():
6265
LOGGER.info(f"Creating dataset description file: {dataset_file}")
6366
dataset_description = {'Name': 'REQUIRED. Name of the dataset',
6467
'GeneratedBy': generatedby,
65-
'BIDSVersion': str(bidsversion()),
68+
'BIDSVersion': bidsversion(),
6669
'DatasetType': 'raw',
6770
'License': 'RECOMMENDED. The license for the dataset. The use of license name abbreviations is RECOMMENDED for specifying a license. The corresponding full license text MAY be specified in an additional LICENSE file',
6871
'Authors': ['OPTIONAL. List of individuals who contributed to the creation/curation of the dataset'],
@@ -281,8 +284,8 @@ def bidscoiner(sourcefolder: str, bidsfolder: str, participant: list=(), force:
281284
outputdir = bidsfolder/subid/sesid # TODO: Support DICOMDIR with multiple subjects (as in PYDICOMDIR)
282285
if not force and outputdir.is_dir():
283286
datatypes = set()
284-
for datatype in [dtype for dtype in lsdirs(outputdir) if next(dtype.iterdir(), None)]: # See what non-empty datatypes we already have in the bids session-folder
285-
if datatype.name in bidsmap.dataformat(datasource.dataformat).datatypes: # See if the plugin may add data for this datatype
287+
for datatype in [dtype for dtype in lsdirs(outputdir) if next(dtype.iterdir(), None)]: # See what non-empty datatypes we already have in the bids session-folder
288+
if datatype.name in bidsmap.dataformat(datasource.dataformat).datatypes: # See if the plugin may add data for this datatype
286289
datatypes.add(datatype.name)
287290
if datatypes and not any(issubclass(cls, EventsParser) for _,cls in inspect.getmembers(plugin, inspect.isclass)): # Always allow events plugins to add data
288291
LOGGER.info(f">>> Skipping {name} processing: {outputdir} already contains {datatypes} data. Use the -f option to force processing if needed.")
@@ -304,7 +307,7 @@ def bidscoiner(sourcefolder: str, bidsfolder: str, participant: list=(), force:
304307
# Check/repair the run-indices using acq_time info in the scans_table
305308
bids.check_runindices(outputdir)
306309

307-
# Clean-up the temporary unpacked data
310+
# Clean up the temporary unpacked data
308311
if unpacked:
309312
shutil.rmtree(sesfolder)
310313

bidscoin/cli/_bidsparticipants.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ def get_parser():
2121
description=textwrap.dedent(__doc__),
2222
epilog='examples:\n'
2323
' bidsparticipants myproject/raw myproject/bids\n'
24-
' bidsparticipants myproject/raw myproject/bids -k participant_id age sex\n ')
24+
' bidsparticipants myproject/raw myproject/bids -b mybidsmap\n ')
2525
parser.add_argument('sourcefolder', help='The study root folder containing the raw source data folders')
2626
parser.add_argument('bidsfolder', help='The destination/output folder with the bids data')
27-
parser.add_argument('-k','--keys', help="Space separated list of the participants.tsv columns. Default: 'session_id' 'age' 'sex' 'size' 'weight'", nargs='+', default=['age', 'sex', 'size', 'weight'], metavar='KEY') # NB: session_id is default
2827
parser.add_argument('-d','--dryrun', help='Do not save anything, only print the participants info on screen', action='store_true')
2928
parser.add_argument('-b','--bidsmap', help='The study bidsmap file with the mapping heuristics. If the bidsmap filename is just the base name (i.e. no "/" in the name) then it is assumed to be located in the current directory or in bidsfolder/code/bidscoin. Default: bidsmap.yaml', metavar='NAME', default='bidsmap.yaml')
3029

bidscoin/utilities/bidsparticipants.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
from bidscoin.utilities import unpack
1616

1717

18-
def bidsparticipants(sourcefolder: str, bidsfolder: str, keys: list, bidsmap: str= 'bidsmap.yaml', dryrun: bool=False) -> None:
18+
def bidsparticipants(sourcefolder: str, bidsfolder: str, bidsmap: str='bidsmap.yaml', dryrun: bool=False) -> None:
1919
"""
2020
Main function that processes all the subjects and session in the sourcefolder to (re)generate the participants.tsv file in the BIDS folder.
2121
2222
:param sourcefolder: The root folder-name of the sub/ses/data/file tree containing the source data files
2323
:param bidsfolder: The name of the BIDS root folder
24-
:param keys: The keys that are extracted from the source data when populating the participants.tsv file
2524
:param bidsmap: The name of the bidsmap YAML-file. If the bidsmap pathname is just the base name (i.e. no "/" in the name) then it is assumed to be located in the current directory or in bidsfolder/code/bidscoin
2625
:param dryrun: Boolean to just display the participants info
2726
:return: Nothing

docs/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## [dev]
66

7-
## [4.6.2] - 2025-#-#
7+
## [4.6.2] - 2025-06-16
88

99
### Added
1010
- Make stripping the suffix from bids-values in run-items optional (GitHub issue #265)
@@ -14,6 +14,8 @@
1414
### Changed
1515
- Remove empty key-value pairs from the json sidecar files (GitHub issue #269)
1616
- Use `session_id` consistently (instead of `session`)
17+
- Allow `+` signs in labels of filenames (new in BIDS v1.11)
18+
- The logging level in the terminal output -- looks much nicer now!
1719

1820
## [4.6.1] - 2025-03-28
1921

docs/plugins.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The plugin programming interface
3434

3535
This paragraph describes the requirements and structure of plugins in order to allow users and developers to write their own plugin and extent or customize BIDScoin to their needs.
3636

37-
The main task of a plugin is to perform the actual conversion of the source data into a format that is part of the BIDS standard. BIDScoin offers the Python library module named ``bids`` to interact with bidsmaps and to provide the intended output names and metadata. Notably, the bids library contains a class named ``BidsMap()`` that provides various methods and other useful classes for building and interacting with bidsmap data. Bidsmap objects provide consecutive access to ``DataFormat()``, ``Datatype()``, ``RunItem()``, ``DataSource()`` and ``EventsParser`` objects, each of which comes with methods to interact with the corresponding sections of the bidsmap data. The RunItem objects can be used to obtain the mapping to the BIDS output names, and the DataSource object can read the source data attributes and properties. The DataSource object transparently handles dynamic values (including regular expressions) as well as the extended source data attributes. In addition, a plugin can implement a class named ``[DataFormat]Events()`` to read and convert stimulus presentation log data to task events files. This class inherits from the ``bidscoin.plugins.EventsParser`` abstract base class, and is required to make an initial parsing of the source data to a Pandas DataFrame (table).
37+
The main task of a plugin is to perform the actual conversion of the source data into a format that is part of the BIDS standard. BIDScoin offers the Python library module named ``bids`` to interact with bidsmaps and to provide the intended output names and metadata. Notably, the bids library contains a class named ``BidsMap()`` that provides various methods and other useful classes for building and interacting with bidsmap data. Bidsmap objects provide access (hierarchically) to ``DataFormat()``, ``Datatype()``, ``RunItem()``, ``DataSource()`` and ``EventsParser`` objects, each of which comes with methods to interact with the corresponding sections of the bidsmap data. The RunItem objects can be used to obtain the mapping to the BIDS output names, and the DataSource object can read the source data attributes and properties. The DataSource object transparently handles dynamic values (including regular expressions) as well as the extended source data attributes. In addition, a plugin can implement a class named ``[DataFormat]Events()`` to read and convert stimulus presentation log data to task events files. This class inherits from the ``bidscoin.plugins.EventsParser`` abstract base class, and is required to make an initial parsing of the source data to a Pandas DataFrame (table).
3838

3939
In short, the purpose of the plugin is to interact with the data, by providing methods from the abstract base classes ``bidscoin.plugins.PluginInterface`` and, optionally, ``bidscoin.plugins.EventsParser``. Most notably, plugins can implement the following methods:
4040

docs/tutorial.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ The tutorial below was written with the DCCN user in mind that wants to convert
1414
1. Setting up the environment
1515
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1616

17-
Depending on how BIDScoin was installed, you may have to set your Python environment settings before you can run BIDScoin commands from your command-line interface/shell. This is already done for you when you run a `BIDScoin play <./play.html>`__ instance in the cloud. In the DCCN compute cluster example below it is assumed that an `environment module <https://modules.sourceforge.net/>`__ is used to load your Linux Anaconda Python installation and that BIDScoin is installed in a `conda environment <https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-with-commands>`__ named "bidscoin". Run or adjust these commands to your computer system if needed:
17+
Depending on how BIDScoin was installed, you may have to set your Python environment settings before you can run BIDScoin commands from your command-line interface/shell. This is already done for you when you run a `BIDScoin play <./play.html>`__ instance in the cloud. In the DCCN, you can load a BIDScoin `environment module <https://modules.sourceforge.net/>`__ that manages the settings for you. External users may have to activate their `conda <https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-with-commands>`__ or `virtual environment <https://docs.python.org/3/tutorial/venv.html>`__.
1818

1919
.. code-block:: console
2020
21-
$ module add bidscoin # Load the DCCN bidscoin module with the PATH settings and Anaconda environment
22-
$ source activate /opt/bidscoin # Activate the Python virtual environment with the BIDScoin Python packages
21+
$ module load bidscoin # Load the DCCN PATH settings and Python environment (else activate your virtual enviroment)
2322
2423
Now you should be able to execute BIDScoin commands. Test this by running ``bidscoin`` to get a general workflow overview. Can you generate a list of all BIDScoin tools? What about the plugins? Test the bidscoin installation and make sure everything is OK
2524

@@ -30,8 +29,8 @@ Create a tutorial playground folder by executing these shell commands:
3029

3130
.. code-block:: console
3231
33-
$ bidscoin --download . # Download the tutorial data (use a "." for the current folder or a pathname of choice to save it elsewhere)
34-
$ cd ./bidscointutorial # Go to the downloaded data (replace "." with the full pathname if your data was saved elsewhere)
32+
$ bidscoin --download . # Download the tutorial data (use a "." for the current folder or a pathname of choice to save it elsewhere)
33+
$ cd ./bidscointutorial # Go to the downloaded data (replace "." with the full pathname if your data was saved elsewhere)
3534
3635
The new ``bidscointutorial`` folder contains a ``raw`` source-data folder and a ``bids_ref`` reference BIDS folder, i.e. the intended end product of this tutorial. In the raw folder you will find these DICOM Series folders (aka "runs")::
3736

docs/utilities.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,6 @@ The bidsparticipants tool is useful for (re-)generating a participants.tsv file
186186

187187
options:
188188
-h, --help show this help message and exit
189-
-k, --keys KEY [KEY ...]
190-
Space separated list of the participants.tsv columns. Default: 'session_id'
191-
'age' 'sex' 'size' 'weight'
192189
-d, --dryrun Do not save anything, only print the participants info on screen
193190
-b, --bidsmap NAME The study bidsmap file with the mapping heuristics. If the bidsmap filename
194191
is just the base name (i.e. no "/" in the name) then it is assumed to be
@@ -197,4 +194,4 @@ The bidsparticipants tool is useful for (re-)generating a participants.tsv file
197194

198195
examples:
199196
bidsparticipants myproject/raw myproject/bids
200-
bidsparticipants myproject/raw myproject/bids -k participant_id age sex
197+
bidsparticipants myproject/raw myproject/bids -b mybidsmap

tests/test_utilities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_bidsparticipants(raw_dicomdir, bids_dicomdir, bidsmap_dicomdir):
121121
if participantsfile.is_file(): # Compare newly generated data with reference data from test_bidscoiner
122122
with open(participantsfile) as fid:
123123
refdata = list(csv.reader(fid, delimiter='\t'))
124-
bidsparticipants.bidsparticipants(raw_dicomdir, bids_dicomdir, ['age', 'sex', 'size', 'weight'], bidsmap=bidsmap_dicomdir)
124+
bidsparticipants.bidsparticipants(raw_dicomdir, bids_dicomdir, bidsmap=bidsmap_dicomdir)
125125
with open(participantsfile) as fid:
126126
newdata = list(csv.reader(fid, delimiter='\t'))
127127
assert newdata == refdata

0 commit comments

Comments
 (0)