Package: compile-dcm2bids-config
compile-dcm2bids-configCombinedcm2bidsandd2bconfig files into a single config file while preserving the integrity of each separate config file's variousIntendedForfields.InstallationFor the basic functionality:pipinstallcompile-dcm2bids-configIf you have config files written in YAML you can install theyamlextra, for example:pipinstall'compile-dcm2bids-config[yaml]'Usage$compile-dcm2bids-config--help
usage:compile-dcm2bids-config[-h][-oOUT_FILE][-v]in_file[in_file...]Combinemultipledcm2bidsconfigfilesintoasingleconfigfile.

positionalarguments:in_fileTheJSONconfigfilestocombine

optionalarguments:-h,--helpshowthishelpmessageandexit-oOUT_FILE,--out-fileOUT_FILEThefiletowritethecombinedconfigfileto.Ifnotspecifiedoutputsarewrittentostdout.-v,--versionshowprogram'sversionnumberandexitGetting StartedSuppose you have two config files:example/config1.json:{"descriptions":[{"dataType":"anat","modalityLabel":"SWI","criteria":{"SeriesDescription":"*SWI*"}},{"dataType":"fmap","modalityLabel":"fmap","criteria":{"SidecarFilename":"*echo-4*"},"IntendedFor":0}]}example/config2.json:{"descriptions":[{"dataType":"dwi","modalityLabel":"dwi","criteria":{"SeriesDescription":"*DWI*"}},{"dataType":"anat","modalityLabel":"SWI","criteria":{"SeriesDescription":"*SWI*"}},{"id":"my-func","dataType":"func","modalityLabel":"bold","customLabels":"task-rest","criteria":{"SeriesDescription":"rs_fMRI"},"sidecarChanges":{"SeriesDescription":"rsfMRI"}},{"dataType":"fmap","modalityLabel":"fmap","criteria":{"SidecarFilename":"*echo-3*"},"IntendedFor":[0,"my-func"]}]}Then we can combine the two using the following command (outputs are written to stdout by default):$compile-dcm2bids-configexample/config1.jsonexample/config2.json{"descriptions":[{"dataType":"anat","modalityLabel":"SWI","criteria":{"SeriesDescription":"*SWI*"}},{"dataType":"fmap","modalityLabel":"fmap","criteria":{"SidecarFilename":"*echo-4*"},"IntendedFor":0},{"dataType":"dwi","modalityLabel":"dwi","criteria":{"SeriesDescription":"*DWI*"}},{"dataType":"anat","modalityLabel":"SWI","criteria":{"SeriesDescription":"*SWI*"}},{"id":"my-func","dataType":"func","modalityLabel":"bold","customLabels":"task-rest","criteria":{"SeriesDescription":"rs_fMRI"},"sidecarChanges":{"SeriesDescription":"rsfMRI"}},{"dataType":"fmap","modalityLabel":"fmap","criteria":{"SidecarFilename":"*echo-3*"},"IntendedFor":[2,"my-func"]}]}Notice that theIntendedForfields have been updated appropriately.Python APIYou can also use this tool from within python:importjsonfrompathlibimportPathfrompprintimportppfromcompile_dcm2bids_configimportcombine_configconfig1=json.loads(Path("example/config1.json").read_text())config2=json.loads(Path("example/config2.json").read_text())all_together=combine_config([config1,config2])pp(all_together)The result being:{'descriptions':[{'dataType':'anat','modalityLabel':'SWI','criteria':{'SeriesDescription':'*SWI*'}},{'dataType':'fmap','modalityLabel':'fmap','criteria':{'SidecarFilename':'*echo-4*'},'IntendedFor':0},{'dataType':'dwi','modalityLabel':'dwi','criteria':{'SeriesDescription':'*DWI*'}},{'dataType':'anat','modalityLabel':'SWI','criteria':{'SeriesDescription':'*SWI*'}},{'id':'my-func','dataType':'func','modalityLabel':'bold','customLabels':'task-rest','criteria':{'SeriesDescription':'rs_fMRI'},'sidecarChanges':{'SeriesDescription':'rsfMRI'}},{'dataType':'fmap','modalityLabel':'fmap','criteria':{'SidecarFilename':'*echo-3*'},'IntendedFor':[2,'my-func']}]}YAML Configuration FilesThis package can handledcm2bids(ord2b) configuration files written in YAML, the user just has to install thePyYAMLpackage, either separately:pipinstallpyyamlor all at once via the installation "extra":pipinstall'compile-dcm2bids-config[yaml]'If PyYAML is available, then configuration files ending with.ymlor.yamlcan be passed as input files:compile-dcm2bids-configconfig1.jsonconfig2.yaml>combined.jsonThe combined configuration file can also be formatted as YAML by adding the--to-yamlflag:compile-dcm2bids-config--to-yamlconfig1.jsonconfig2.yaml>combined.yamlContributingHave or install a recent version ofpoetry(version >= 1.1)Fork the repoSetup a virtual environment (however you prefer)Runpoetry installRunpre-commit installAdd your changes (adding/updating tests is always nice too)Commit your changes + push to your forkOpen a PR