Skip to content

[FIX] modified afni's cat_matvec to accept empty string opposed to opkey #2943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 18, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions nipype/interfaces/afni/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,11 +617,15 @@ class CatMatvec(AFNICommand):

def _format_arg(self, name, spec, value):
if name == 'in_file':
return spec.argstr % (' '.join([i[0] + ' -' + i[1]
for i in value]))
xfm_args=''
for v in value:
if len(v[1])>0:
xfm_args += ' ' + v[0] + ' -' + v[1] + ' '
else:
xfm_args += ' ' + v[0] + ' '
return spec.argstr % (xfm_args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be clearer to continue writing this as a comprehension, using the x if y else z idiom, but we can use more verbose variable names to make the logic clearer. I also think it would be useful to include a comment:

# Concatenate a series of filenames, with optional opkeys
return ' '.join('%s -%s' % (mfile, opkey) if opkey else mfile
                for mfile, opkey in value)

I dropped the initial spec.argstr %, just because spec.argstr is "%s", so there's no real point, but you could keep it if you wanted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this is more elegant, I changed it and confirmed it passed my test for formatting.

return super(CatMatvec, self)._format_arg(name, spec, value)


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you re-add this? Python style guidelines suggest 2 lines between classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

class CenterMassInputSpec(CommandLineInputSpec):
in_file = File(
desc='input file to 3dCM',
Expand Down