nipy / nipype

Workflows and interfaces for neuroimaging packages
https://nipype.readthedocs.org/en/latest/
Other
749 stars 530 forks source link

Questions about Nipype that I can't find answers on google #3479

Open HuangHam opened 2 years ago

HuangHam commented 2 years ago

Thank you so much for such a great package! If I want to use Nipype for fMRI analyses based on SPM or FSL for example, does installing Nipype in a python environment suffice for all the analyses? Would the simple command "conda install Nipype" also automatically install all the SPM or FSL files that I will need? Or I have to download stand-alone SPM folder or install FSL separately from their official website and put them into my Nipype working directory?

Thanks for your help in advance!

effigies commented 2 years ago

Hi. Nipype does not install SPM or FSL for you. You need them installed somewhere accessible by your PATH, but otherwise they don't need to be anywhere specific for nipype.

HuangHam commented 2 years ago

got it. Thanks! Sorry a follow-up question. So now as we are running preproc.run('MultiProc', plugin_args={'n_procs': 8}), we get an error: 220601-15:25:56,686 nipype.workflow INFO: Workflow work_preproc settings: ['check', 'execution', 'logging', 'monitoring'] 220601-15:25:56,790 nipype.workflow INFO: Running in parallel. AttributeError: module 'scipy.sparse' has no attribute 'coo_array'

Do you have any ideas?

effigies commented 2 years ago

If you upgrade networkx, that issue should go away.

HuangHam commented 2 years ago

It worked! Thanks. However we kinda ran into another issue: No files were found matching anat template: /Users/jenkinslab-adm/Library/CloudStorage/Box-Box/fMRI_sara/output/work_preproc/_subject_id_17/selectfiles/data/sub-17/anat/sub17_T1w.nii.gz where the correct directory for our T1 file is: /Users/jenkinslab-adm/Library/CloudStorage/Box-Box/fMRI_sara/data/sub-17/anat/sub17_T1w.nii.gz somehow nipype just added the redundant:output/work_preproc/_subject_id_17/selectfiles/ Maybe it has something to do the line below that we copied from the tutorial?: preproc = Workflow(name='work_preproc', base_dir = 'output/')

effigies commented 2 years ago

When you set the base_dir='output/', that is telling nipype to construct the working directory in output/. A sub-node a will have working directory output/a, and a node c in a sub-workflow b will have working directory output/b/c. I would probably name my working directory something like scratch/ and keep it separate from my outputs.

What looks like is happening is that you're passing an input of 'data/sub-17/anat/sub17_T1w.nii.gz' to preproc.work_preproc.selectfiles. Since it's a relative path, it's being resolved to the working directory of preproc.selectfiles, output/work_preproc/_subject_id_17/selectfiles. You can turn a relative path into an absolute path with os.path.absolute().

HuangHam commented 2 years ago

amazing! It worked. Another question just to be sure: If I use SPM on Nipype, for example sliceTiming, I will not only need to install matlab on my computer, but also purchase matlab license is that correct? So it's not like Nipype can somehow let us use SPM without paying for matlab.

satra commented 2 years ago

you can use the standalone version of SPM. some details here: https://miykael.github.io/nipype_tutorial/notebooks/advanced_spmmcr.html

HuangHam commented 2 years ago

Oh! I see I see. Thank you very much! It has been super helpful!!

HuangHam commented 2 years ago

Sorry to bother you again. I encountered another weird error as I was trying to use SPM standalone. So I downloaded the SPM12 standalone and installed the MCR. However when I run this line: spm.SPMCommand.set_mlab_paths(matlab_cmd='spm12/run_spm12.sh /Applications/MATLAB/MATLAB_Compiler_Runtime/v713/ script', use_mcr=True) I get error: ValueError Traceback (most recent call last) File ~/opt/anaconda3/envs/fMRI/lib/python3.9/site-packages/nipype/utils/spm_docs.py:49, in _strip_header(doc) 48 try: ---> 49 index = doc.index(hdr) 50 except ValueError as e:

What is going on? I think I followed every step in that wikibook

HuangHam commented 2 years ago

Oh I figured out why. that the wiki page is outdated for new mac operating systems. See below: https://www.jiscmail.ac.uk/cgi-bin/wa-jisc.exe?A3=ind2105&L=SPM&E=quoted-printable&P=2575320&B=--_000_PR0P264MB0876F08C965F289F9A9B12D9A9259PR0P264MB0876FRAP_&T=text%2Fhtml;%20charset=iso-8859-1&pending=

HuangHam commented 2 years ago

Sorry i thought I fixed it. But I only fixed it with respect to if I run print(spm.SPMCommand().version), it gives me the correct SPM version. However when I run my workflow: preproc.run('MultiProc', plugin_args={'n_procs': 8}), it still gives error: OSError: No command "spm12/run_spm12.sh" found on host jenkinslab19-03.sas.upenn.edu How can it be?

satra commented 2 years ago

you may want to use absolute path here for spm12/run_spm12.sh:

spm.SPMCommand.set_mlab_paths(matlab_cmd='spm12/run_spm12.sh /Applications/MATLAB/MATLAB_Compiler_Runtime/v713/ script', use_mcr=True)
HuangHam commented 2 years ago

Ah! How can I have forgotten that. Thanks so much satra!

HuangHam commented 2 years ago

Sorry I got stuck at Normalize12. I got the error: Node normalize.a1 failed to run without any other clear error message. My workflow is: normalize = Node(spm.Normalize12(write_voxel_sizes=[2, 2, 2]), name="normalize")

preproc.connect([ #connect segmenta to normalize deformation field (segment, normalize, [('forward_deformation_field', 'deformation_file')]),#deformation_file didn't work?

send slice time corrected image to normalize

(slicetime, normalize, [('timecorrected_files', 'apply_to_files')]),
#smooth the normalized image
(normalize, smooth, [('normalized_files', 'in_files')])])

So essentially take the forward deformation_field from NewSegment and warp timecorrected_files. Do you have any thoughts on what could have gone wrong? All the input files seem to be correct.

HuangHam commented 2 years ago

looks like the cause is that I must set the jobtype to 'write'. Correct me if I'm wrong, maybe normalize12() itself can do segmentation? So the defaute estwrite can only take in the raw structural image? I see many examples online where they don't do segmentation at all but rather directly put anatomical file and TPM.nii into normalize12(). Is that equivalent to the way I'm doing it? (which I think is the matlab SPM way: Segment then normalize)