Skip to content

NF: AFNI 3dNetCorr as afni.NetCorr #3263

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 5 commits into from
Mar 12, 2021
Merged

Conversation

aghayoor
Copy link
Contributor

This is a WIP to afni NetCorr to nipype

@aghayoor
Copy link
Contributor Author

@effigies : Hi Chris, this is WIP commit to add afni NetCorr to nipype.

Everything works well when I call the interface like this:

ncorr = afni.NetCorr()
ncorr.inputs.in_file = '<workflowDir>/bandpass/bold_trimmed_wmcsfreg_bp.nii'
ncorr.inputs.mask = mniBrainMask
ncorr.inputs.in_rois = mniLabels
ncorr.inputs.ts_wb_corr = True
ncorr.inputs.ts_wb_Z = True
ncorr.inputs.fish_z = True
ncorr.inputs.nifti = True
ncorr.inputs.out_file = '<workflowDir>/correlation/sub0.tp1.ncorr'
ncorr.run()

However, when I wrap this interface in a MapNode, the workflow runs with no error, but it does not write the outputs.

ncorr = pe.Node(interface=afni.NetCorr(), name='correlation')
ncorr.inputs.ts_out = True
ncorr.inputs.ts_label = True
ncorr.inputs.ts_wb_strlabel = True
ncorr.inputs.nifti = True
ncorr.inputs.ts_wb_corr = True
ncorr.inputs.ts_wb_Z = True
ncorr.inputs.fish_z = True
ncorr.inputs.out_file = 'sub0.tp1.ncorr'
workflow.connect(bandpass, 'out_file', ncorr, 'in_file')
workflow.connect(inputsSpec, 'inputMNILables', ncorr, 'in_rois')
workflow.connect(inputsSpec, 'inputMNIBrainMask', ncorr, 'mask')

Do you have any advice on this?

@effigies
Copy link
Member

The outputs should be in the workflow's working directory... Can you show the tree of that directory?

@aghayoor
Copy link
Contributor Author

The outputs should be in the workflow's working directory... Can you show the tree of that directory?

Here is the tree:
Screen Shot 2020-10-26 at 2 51 32 PM

I expected to see the output .netcc file and correlation maps in the correlation directory.

@effigies
Copy link
Member

This may be a case where unused outputs are not saved. Try using the configuration option remove_unnecessary_outputs. See https://miykael.github.io/nipype_tutorial/notebooks/basic_execution_configuration.html.

@aghayoor
Copy link
Contributor Author

This may be a case where unused outputs are not saved. Try using the configuration option remove_unnecessary_outputs. See https://miykael.github.io/nipype_tutorial/notebooks/basic_execution_configuration.html.

Well that was the case here. Thank you!
Is it possible to avoid deleting those files without changing the configuration?

@effigies
Copy link
Member

If the output is used as the input to another node, then it won't be deleted. While you're debugging a workflow, it's useful to have on, and then go back to the default when you're in production.

@aghayoor
Copy link
Contributor Author

@effigies : Thanks! Can you please review and merge this pull request?

Comment on lines 2618 to 2730
if not isdefined(self.inputs.out_file):
prefix = self._gen_fname(self.inputs.in_file, suffix="_netcorr")
else:
prefix = self.inputs.out_file

# All outputs should be in the same directory as the prefix
out_dir = os.path.dirname(os.path.abspath(prefix))

outputs["out_matrix"] = (
fname_presuffix(prefix, suffix="_000", use_ext=False, newpath=out_dir) + ".netcc"
)
Copy link
Member

Choose a reason for hiding this comment

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

What is the output file called? I would expect, if I set netcorr.inputs.out_file, the output file is called exactly that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@effigies : the netcorr.inputs.out_file defines the prefix for the output.
Afni 3dNetCorr doesn't have actual output options, but it uses the prefix to write out the correlation matrix and correlation maps to the output directory.
This added function finds and returns the convention filename for the output correlation matrix.

I am also interested to return the correlation maps return to a subdirectory in the output directory. The number of these correlation maps depends on the number of regions in the input ROI label map. Do you have any idea how I can those to the output as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@effigies : Thanks for the approval.
also, do you have any idea on this?
Please let me know if my question needs more clarification

Copy link
Member

Choose a reason for hiding this comment

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

Ah, sorry, missed this. Assuming these files exist, you can use glob to get them. See an example here:

class FEAT(FSLCommand):
"""Uses FSL feat to calculate first level stats
"""
_cmd = "feat"
input_spec = FEATInputSpec
output_spec = FEATOutputSpec
def _list_outputs(self):
outputs = self._outputs().get()
is_ica = False
outputs["feat_dir"] = None
with open(self.inputs.fsf_file, "rt") as fp:
text = fp.read()
if "set fmri(inmelodic) 1" in text:
is_ica = True
for line in text.split("\n"):
if line.find("set fmri(outputdir)") > -1:
try:
outputdir_spec = line.split('"')[-2]
if os.path.exists(outputdir_spec):
outputs["feat_dir"] = outputdir_spec
except:
pass
if not outputs["feat_dir"]:
if is_ica:
outputs["feat_dir"] = glob(os.path.join(os.getcwd(), "*ica"))[0]
else:
outputs["feat_dir"] = glob(os.path.join(os.getcwd(), "*feat"))[0]
print("Outputs from FEATmodel:", outputs)
return outputs

Also, can you run make specs and commit the new file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! That was very helpful.

@effigies effigies changed the title WIP: Afni NetCorr NF: AFNI 3dNetCorr as afni.NetCorr Oct 27, 2020
@effigies
Copy link
Member

effigies commented Nov 5, 2020

@aghayoor Just a reminder that I left a review when you have time.

@effigies
Copy link
Member

Hi @aghayoor, any chance of finishing this one up before a release?

@aghayoor
Copy link
Contributor Author

Hi @effigies , I was out of office for about two weeks. Thanks for your comments. I will try to address all of your comments by the end of this week.

Afni 3dNetCorr is added to nipype.
For more details, please see:
https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dNetCorr.html
@aghayoor
Copy link
Contributor Author

aghayoor commented Mar 2, 2021

@effigies Hi, I addressed your comments. Could please review this new PR?

@aghayoor
Copy link
Contributor Author

aghayoor commented Mar 2, 2021

@effigies : addressed your comment. Thanks for catching that.

Co-authored-by: Chris Markiewicz <effigies@gmail.com>
@codecov
Copy link

codecov bot commented Mar 2, 2021

Codecov Report

Merging #3263 (c00dd2f) into master (47fe00b) will increase coverage by 0.00%.
The diff coverage is 70.27%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3263   +/-   ##
=======================================
  Coverage   64.70%   64.70%           
=======================================
  Files         302      302           
  Lines       39869    39906   +37     
  Branches     5288     5290    +2     
=======================================
+ Hits        25796    25822   +26     
- Misses      12984    12995   +11     
  Partials     1089     1089           
Flag Coverage Δ
unittests 64.70% <70.27%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
nipype/interfaces/afni/__init__.py 100.00% <ø> (ø)
nipype/interfaces/afni/preprocess.py 81.33% <70.27%> (-0.47%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 47fe00b...c00dd2f. Read the comment docs.

aghayoor added 2 commits March 3, 2021 21:24
This file was automatically generated by running "make specs"
@aghayoor
Copy link
Contributor Author

aghayoor commented Mar 4, 2021

Hi @effigies , I added correlation maps to the output of this module and I also committed the output file of make specs. Please review and let me know if you have any comments.

@aghayoor
Copy link
Contributor Author

Hi @effigies , just a reminder that I updated the PR. Please review when you have time. Thanks!

@effigies effigies merged commit 10388b0 into nipy:master Mar 12, 2021
@effigies
Copy link
Member

Thanks for the bump!

@effigies effigies added this to the 1.6.1 milestone May 1, 2021
@effigies effigies mentioned this pull request Nov 11, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants