khanlab / snakebids

Snakemake + BIDS
https://snakebids.readthedocs.io
MIT License
17 stars 13 forks source link

Wildcards added via cli are not deduplicated #422

Closed pvandyken closed 3 months ago

pvandyken commented 6 months ago

If a wildcard is specified via the CLI (e.g. --wildcards-COMP ...), it is merely appended to the list of wildcards specified in the config.yaml without any deduplication. This creates a spurious downstream error:

KeyError in file /scratch/knavynde/skeletonize/skeletonize/workflow/rules/setup.smk, line 31:
'pop from an empty set'
  File "/scratch/knavynde/skeletonize/skeletonize/workflow/Snakefile", line 7, in <module>
  File "/scratch/knavynde/skeletonize/skeletonize/workflow/rules/setup.smk", line 31, in <module>
  File "/home/knavynde/.local/pipx/venvs/snakemake/lib/python3.11/site-packages/snakebids/core/input_generation.py", line 311, in generate_inputs
  File "/home/knavynde/.local/pipx/venvs/snakemake/lib/python3.11/site-packages/snakebids/core/datasets.py", line 832, in from_iterable
  File "/home/knavynde/.local/pipx/venvs/snakemake/lib/python3.11/site-packages/snakebids/core/input_generation.py", line 520, in _get_components
  File "/home/knavynde/.local/pipx/venvs/snakemake/lib/python3.11/site-packages/snakebids/core/input_generation.py", line 591, in _get_component
  File "/home/knavynde/.local/pipx/venvs/snakemake/lib/python3.11/site-packages/snakebids/core/input_generation.py", line 752, in _parse_bids_path

This occurs when snakebids checks that all wildcards have been matched. It's simply comparing the number of specified wildcards to the number of found wildcards. But when some wildcards have been specified multiple times, the specified wildcards will be greater than the found.

Can be resolved simply by incorporating deduplication. The meanwhile workaround is to not specify wildcards from the CLI that have already been listed in config.