PennLINC/CuBIDS

cubids-group Error: "local variable 'filepath' referenced before assignment"

fpichardo-umn opened this issue · 2 comments

I'm using cubids version 1.0.8 on Python version 3.9. Cubids-validate worked well, but I am having trouble with cubids-group. I ran the following command: cubids-group /PATH/TO/DATA/ /PATH/TO/OUTPUT/ES

I got the following error after running it with variations of the second command line argument (path versus just the file prefix):
Traceback (most recent call last):
File "/PATH/.local/bin/cubids-group", line 8, in
sys.exit(cubids_group())
File "/PATH/.local/lib/python3.9/site-packages/cubids/cli.py", line 328, in cubids_group
bod.get_TSVs(str(opts.output_prefix),)
File "/PATH/.local/lib/python3.9/site-packages/cubids/cubids.py", line 1121, in get_TSVs
big_df, summary = self.get_param_groups_dataframes()
File "/PATH/.local/lib/python3.9/site-packages/cubids/cubids.py", line 947, in get_param_groups_dataframes
self.get_param_groups_from_key_group(key_group)
File "/PATH/.local/lib/python3.9/site-packages/cubids/cubids.py", line 814, in get_param_groups_from_key_group
if mod in filepath:
UnboundLocalError: local variable 'filepath' referenced before assignment


Here's the relevant section of the cubids code that is referenced in the trace:

     matching_files = self.layout.get(return_type="file", scope="self",
                                     regex_search=True, **key_entities)

    # ensure files who's entities contain key_entities but include other
    # entities do not also get added to matching_files
    to_include = []
    for filepath in matching_files:
        f_key_group = _file_to_key_group(filepath)

        if f_key_group == key_group:
            to_include.append(filepath)

    # get the modality associated with the key group
    modalities = ['/dwi/', '/anat/', '/func/', '/perf/', '/fmap/']
    modality = ''
    for mod in modalities:
        if mod in filepath:
            modality = mod.replace('/', '').replace('/', '')
    if modality == '':
        print("Unusual Modality Detected")
        modality = 'other'

I'm including @ericfeczko here because he is assisting us with this project would like to be kept in the loop.

Accounting for the session (--acq-group-level session) did not fix the issue, as I had previously thought. It took longer for error to arise (over an hour), but the same exact error came up.

We have two samples with ~400 in one and ~700 in the other. This is why it takes so long to error out. Nothing else is output.

Accounting for the session (--acq-group-level session) and resolving some permissions issues on some of the files solved this.