Dcm2bids error: "should contains only alphanumeric characters"

Hi everyone,

I’m getting an odd error when trying to use dcm2bids on my DICOM files. Each patient’s directory has the structure sub_x_0000x and that seems to cause an error, but previously processing of these files worked so I’m not sure what is going on.

Traceback (most recent call last):
  File "/home/ls/miniconda3/bin/dcm2bids", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/ls/miniconda3/lib/python3.12/site-packages/dcm2bids/cli/dcm2bids.py", line 105, in main
    participant = Participant(args.participant, args.session)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ls/miniconda3/lib/python3.12/site-packages/dcm2bids/participant.py", line 22, in __init__
    self.name = name
    ^^^^^^^^^
  File "/home/ls/miniconda3/lib/python3.12/site-packages/dcm2bids/participant.py", line 42, in name
    raise NameError(f"Participant '{self._name.replace('sub-', '')}' "
NameError: Participant 'sub_1_00002' should contains only alphanumeric characters.

Any tips are very appreciated, thank you!

Hi @LM99,

Please return the full dcm2bids command and config file when reporting issues.

Also, subject ids must be in the form of sub-{ID}. The ID cannot contain dashes or underscores.

Best,
Steven

Thank you for your reply! I think I misunderstood how the command works, I thought the subject ID had to be the same as the name of the directory with that subject’s DICOM files. My command was then

dcm2bids -d bids/sourcedata/ -p sub_1_00002 -c dcm2bids_config.json --auto_extract_entities

to match the subject’s directory called sub_1_00002. So just to clarify, the ID could be anything because the command doesn’t use that flag in order to identify subject directories? So I could just use -p sub-00002 for this person?

Hi @LM99.

The input dicom directory (-d) can be named whatever, but the -p argument will dictate what the BIDS participant label is. It looks like you are passing in all of your sourcedata to the command, perhaps you should organize your dicoms into subject specific folders.

Best,
Steven

Ok I see! Sorry I should have clarified, sourcedata looks like this:

sourcedata/
├── sub-1_00002
│ ├── 101
│ ├── 201
├── sub-1_00003
│ ├── 101
│ ├── 201
└── sub-1_00004
├── 101
├── 201

…and I thought -d needs to specify the directory containing all subject folders, and then -p would identify them. I think I understand now, -d needs to be the subject folder and not the folder with the entire dataset (-> so I’ll need to loop through the subject folders in sourcedata), and -p does not need to match the name of the subject folder but it will give the BIDS files their label so it should match the ID contained in the subject folder name in my case (-> so in that loop generating the dcm2bids command I’ll need to generate -p which removes the underscores and just leaves the numbers)

Exactly! That should work.

1 Like

Just out of curiosity can anyone confirm that alphanumeric characters for -p are a new requirement that came with dcm2bids >=3.0.0? I’m quite sure we’ve previously used a script where IDs and directory names had underscores which worked fine in the command without changing the IDs

Hi @LM99,

You can see here that the fix to not allow BIDS-unvalid names began in June 2023 for the release candidate of version 3.0.0: use only alphanumric characters · UNFmontreal/Dcm2Bids@6b79575 · GitHub

Best,
Steven

1 Like