Error when running tutorial - typeerror: _init_ missing 2 required positional arguments: 'dataType' and 'modalityLabel'

Hello!

I am currently going through the tutorial on the dcm2bids website (First steps - Dcm2Bids).


I have installed it using a new conda environment (running python3.9) and have followed all the stages up until dcm2bids -d sourcedata/example_dcm/In/ -p 'DC15' -c /cubric/collab/505_subiculum/Scene_gen/code/dcm2bids_config_tutorial.json --forceDcm2niix
INFO:dcm2bids.dcm2bids:--- dcm2bids start ---
INFO:dcm2bids.dcm2bids:OS:version: Linux-3.10.0-1062.el7.x86_64-x86_64-with-glibc2.17
INFO:dcm2bids.dcm2bids:python:version: 3.9.16 (main, May 15 2023, 23:46:34) [GCC 11.2.0]
INFO:dcm2bids.dcm2bids:dcm2bids:version: 2.1.7
INFO:dcm2bids.dcm2bids:dcm2niix:version: v1.0.20220720
INFO:dcm2bids.dcm2bids:participant: sub-DC15
INFO:dcm2bids.dcm2bids:session: 
INFO:dcm2bids.dcm2bids:config: /cubric/collab/505_subiculum/Scene_gen/code/dcm2bids_config_tutorial.json
INFO:dcm2bids.dcm2bids:BIDS directory: /cubric/collab/505_subiculum/Scene_gen
WARNING:dcm2bids.version:Your using dcm2bids version 2.1.7
WARNING:dcm2bids.version:A new version exists : 2.1.9
WARNING:dcm2bids.version:Check https://github.com/unfmontreal/Dcm2Bids
WARNING:dcm2bids.dcm2niix:Previous dcm2niix directory output found:
WARNING:dcm2bids.dcm2niix:/cubric/collab/505_subiculum/Scene_gen/tmp_dcm2bids/sub-DC15
WARNING:dcm2bids.dcm2niix:'force' argument is set to True
WARNING:dcm2bids.dcm2niix:Cleaning the previous directory and running dcm2niix
INFO:dcm2bids.utils:Running ['dcm2niix', '-b', 'y', '-ba', 'y', '-z', 'y', '-f', '%3s_%f_%p_%t', '-o', PosixPath('/cubric/collab/505_subiculum/Scene_gen/tmp_dcm2bids/sub-DC15'), PosixPath('sourcedata/example_dcm/In')]
INFO:dcm2bids.dcm2niix:Check log file for dcm2niix output
INFO:dcm2bids.sidecar:Sidecars pairing:
Traceback (most recent call last):
  File "/cubric/data/c1639425/miniconda3/envs/python3.9/bin/dcm2bids", line 10, in <module>
    sys.exit(main())
  File "/cubric/data/c1639425/miniconda3/envs/python3.9/lib/python3.9/site-packages/dcm2bids/dcm2bids.py", line 248, in main
    return app.run()
  File "/cubric/data/c1639425/miniconda3/envs/python3.9/lib/python3.9/site-packages/dcm2bids/dcm2bids.py", line 127, in run
    parser.build_acquisitions(self.participant)
  File "/cubric/data/c1639425/miniconda3/envs/python3.9/lib/python3.9/site-packages/dcm2bids/sidecar.py", line 226, in build_acquisitions
    acq = Acquisition(participant,
TypeError: __init__() missing 2 required positional arguments: 'dataType' and 'modalityLabel'

At first I thought it might be a problem with the .json config file, however I have now copied and pasted the same one as from the tutorial and still get this error. I have also checked, as recommended, with the JSON validator and it all looks good. I’m sure there is a simple explanation for this, but I’m a bit stuck as there is nothing similar online that I have found.

Kind regards,
Sam

Hi @El-Suri and welcome to neurostars!

Please share how you installed dcm2bids. Depending on how you installed it, it is possible that you are working with a non-stable development release. Have you tried using the Docker container (docker pull unfmontreal/dcm2bids:2.1.9_latest_dcm2niix)?

Please also share your command you used to run dcm2bids and the contents of your original config file that is failing.

Also note that a big refactor of dcm2bids with version 3 will be coming soon.

Best,
Steven

Hi Steven, thank you.

I installed dcm2bids using conda install -c conda-forge dcm2bids in a conda environment with python3.9. Unfortunately I cannot use docker on my university system, however I have instead tried it after installing the singularity container. Running

singularity exec dcm2bids_latest.sif dcm2bids -d sourcedata/example_dcm/In/ -p 505 -c code/dcm2bids_config_tutorial.json

I receive the same error as before (TypeError: Acquisition.init() missing 2 required positional arguments: ‘dataType’ and ‘modalityLabel’).

I have pasted the json file below (as a new user I can’t upload a document apparently).

Sounds great re the refactor!

Thanks for your help,
Sam


{
  "descriptions": [
    {
      "id": "id_task-rest",
      "datatype": "func",
      "suffix": "bold",
      "customEntities": "task-rest",
      "criteria": {
        "SeriesDescription": "Axial EPI-FMRI (Interleaved I to S)*"
      },
      "sidecarChanges": {
        "TaskName": "rest"
      }
    },
    {
      "datatype": "fmap",
      "suffix": "epi",
      "customEntities": "dir-AP",
      "criteria": {
        "SeriesDescription": "EPI PE=AP*"
      },
      "intendedFor": "id_task-rest"
    },
    {
      "datatype": "fmap",
      "suffix": "epi",
      "customEntities": "dir-PA",
      "criteria": {
        "SeriesDescription": "EPI PE=PA*"
      },
      "intendedFor": "id_task-rest"
    }	
  ]
}

Hi @El-Suri,

Your JSON is using conventions from the refactor (I guess the documentation page updated before the new releases were distributed).

To use the new version, try cloning the dcm2bids repo, and then in your conda environment, cd to the cloned repo and run pip install -e ..

If that doesn’t work, you can try making a version 2 compatible JSON. This would involve changing all instances of customEntities to customLabels, removing the idfields, and changing IntendedFor fields to instead map to the index of the run each fmap is asssoxiated with. For example, if a fmap is associated with a BOLD run that is the first item in your config, you would put 0 as the IntendedFor . If the BOLD run was second in the confit list, it would be 1, and so forth.

Also, your JSON looks to be exactly the same as the tutorial, which is not good, as that assumes that your acquisition naming conventions are the same as theirs, which is probably not the case. Make sure to change it to match your acquisition.

Best,
Steven

1 Like

Hi Steven,

I followed your steps installing from the git repo and it all works perfectly now - many thanks!

Sam

1 Like

Hi @El-Suri,
We just released our latest pre-release dcm2bids version (3.0.0rc1).
If you are new to dcm2bids I suggest you to give it a try.
Moreover we now provide binaries so no need for a conda or pip installation.
Finally, we developed a lot of new cool features that could help you build your config file even more easily.
If you have any question, don’t hesitate.
Best,
Arnaud

1 Like

Hello,
I have very similar problem. dcm2bids and dcm2niix are installed via conda on university CentOS 7 server. dcm2bids output and config file are below. I have checked .json file generated by dcm2niix, there are no “datatype”, “DataType” or “suffix” fields which, I assume, python code is looking for. In the
config file, I have tried to delete “searchMethod” and “defaceTpl” rows, but without any progress.
Thanks for any input,
Rene

DCM2BIS OUTPUT:

INFO    | --- dcm2bids start ---
INFO    | Running the following command: dcm2bids -d PROJECT/dicom/123456 -o PROJECT/bids -c ~/.PROJECT/etc/config-bids.json -p 123456 -s 01
INFO    | OS version: Linux-3.10.0-1160.6.1.el7.x86_64-x86_64-with-glibc2.10
INFO    | Python version: 3.8.17 | packaged by conda-forge | (default, Jun 16 2023, 07:06:00) [GCC 11.4.0]
INFO    | dcm2bids version: 3.0.1
INFO    | dcm2niix version: v1.0.20230411
INFO    | Checking for software update
INFO    | Currently using the latest version of dcm2bids.
INFO    | Currently using the latest version of dcm2niix.
INFO    | participant: sub-123456
INFO    | session: ses-01
INFO    | config: ~/.PROJECT/etc/config-bids.json
INFO    | BIDS directory: PROJECT/bids
INFO    | Auto extract entities: False
INFO    | Validate BIDS: False

INFO    | Running: dcm2niix -b y -ba y -z y -f %3s_%f_%p_%t -o PROJECT/bids/tmp_dcm2bids/sub-123456_ses-01 PROJECT/dicom/123456
INFO    | Check log file for dcm2niix output

INFO    | SIDECAR PAIRING
INFO    | No Pairing  <-  001_123456_localizer_19810230162321_i00002
INFO    | No Pairing  <-  001_123456_localizer_19810230162321_i00001
INFO    | No Pairing  <-  001_123456_localizer_19810230162321_i00003
Traceback (most recent call last):
  File "~/lib/anaconda3/bin/dcm2bids", line 10, in <module>
    sys.exit(main())
  File "~/lib/anaconda3/lib/python3.8/site-packages/dcm2bids/cli/dcm2bids.py", line 119, in main
    app = Dcm2BidsGen(**vars(args)).run()
  File "~/lib/anaconda3/lib/python3.8/site-packages/dcm2bids/dcm2bids_gen.py", line 104, in run
    parser.build_acquisitions(self.participant)
  File "~/lib/anaconda3/lib/python3.8/site-packages/dcm2bids/sidecar.py", line 394, in build_acquisitions
    acq = Acquisition(participant,
TypeError: __init__() missing 2 required positional arguments: 'datatype' and 'suffix'

CONFIG-BIDS.JSON FILE

{
    "searchMethod": "fnmatch",
    "defaceTpl": "pydeface --outfile {dstFile} {srcFile}",
    "descriptions": [
        {
            "dataType": "anat",
            "modalityLabel": "T1w",
            "criteria": {
                "SeriesDescription": "*t1_mprage_sag_iso_0.9"
            }
        },
        {
            "dataType": "anat",
            "modalityLabel": "T2w",
            "criteria": {
                "SeriesDescription": "*t2_spc_sag_p2_iso_0.9"
            }
        },
	{
            "dataType": "func",
            "modalityLabel": "bold",
            "customLabels": "task-rest_flip-5_acq-reference",
            "criteria": {
                "SeriesDescription": "*Reference_scan_2"
            }
        }
    ]
}

Hi @rene.labounek and welcome to Neurostars!

Try changing dataType to datatype and modalityLabel to suffix in the config?

Best,
Steven

Thanks @Steven it helped and the command has passed. However, it ignores my settings and does not add following string into the bids filename.

"customLabels": "task-rest_flip-5_acq-reference",

or

"customlabels": "task-rest_flip-5_acq-reference",

And, I still get:

INFO    | Auto extract entities: False
INFO    | Validate BIDS: False

Is it that something goes wrong or something like “BIS Validator” is just turned off?
But it gets outside of the topic of the current thread, so I will google documentation and forums further.

Best,
Rene

Regarding documentation “customLabels” were changed to “custom_entities”. And, it works for me.

2 Likes

Just came here to say THANK YOU

you saved me! I just encountered a VERY similar situation

2 Likes