nipype icon indicating copy to clipboard operation
nipype copied to clipboard

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

Open HuangHam opened this issue 2 years ago • 15 comments

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!

HuangHam avatar May 31 '22 20:05 HuangHam

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.

effigies avatar May 31 '22 20:05 effigies

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?

HuangHam avatar Jun 01 '22 19:06 HuangHam

If you upgrade networkx, that issue should go away.

effigies avatar Jun 01 '22 19:06 effigies

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/')

HuangHam avatar Jun 01 '22 20:06 HuangHam

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().

effigies avatar Jun 01 '22 20:06 effigies

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.

HuangHam avatar Jun 01 '22 22:06 HuangHam

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

satra avatar Jun 01 '22 22:06 satra

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

HuangHam avatar Jun 01 '22 22:06 HuangHam

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 avatar Jun 02 '22 15:06 HuangHam

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 avatar Jun 02 '22 16:06 HuangHam

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?

HuangHam avatar Jun 02 '22 17:06 HuangHam

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)

satra avatar Jun 02 '22 17:06 satra

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

HuangHam avatar Jun 02 '22 17:06 HuangHam

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 avatar Jun 03 '22 15:06 HuangHam

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)

HuangHam avatar Jun 03 '22 15:06 HuangHam