afni_proc.py command not found in when running script

Hi AFNI experts!

I’m now using afni_proc.py to generate the script for my resting state preprocessing. I followed example 11 and wrote them into a file named preprocess.sh. I hope to just run this file and get the script.

However, when I run this file using ./preprocess.sh or tcsh preprocess.sh, error occurs., as follows:

** error: unknown trailing arguments : [‘\r’]

** failed command (get_user_opts):

afni_proc.py -subj_id cyf

-blocks: Command not found.
-copy_anat: Command not found.
-anat_follower_ROI: Command not found.
-anat_follower_ROI: Command not found.
-anat_follower_ROI: Command not found.
-anat_follower_ROI: Command not found.
-anat_follower_erode: Command not found.
-dsets: Command not found.
-tcat_remove_first_trs: Command not found.
-tlrc_base: Command not found.
-tlrc_NL_warp: Command not found.
-volreg_align_to: Command not found.
-volreg_align_e2a: Command not found.
-volreg_tlrc_warp: Command not found.
-regress_ROI_PC: Command not found.
-regress_make_corr_vols: Command not found.
-regress_anaticor_fast: Command not found.
-regress_anaticor_label: Command not found.
-regress_censor_motion: Command not found.
-regress_censor_outliers: Command not found.
-regress_apply_mot_types: Command not found.
-regress_est_blur_epits: Command not found.
-regress_est_blur_errts: Command not found.
-regress_run_clustsim: Command not found.

However if I just copy those script contents in that file, I can get the generated scripts. They can generate a file named proc.cyf and give me the execution command: tcsh -xef proc.cyf |& tee output.proc.cyf.
I guess this is right. But why can’t I just run the script file to get this command? Could you please tell me what’s wrong?

The contents of the file I use are as follows:

afni_proc.py -subj_id cyf
-blocks despike tshift align tlrc volreg blur mask regress
-copy_anat cyf/SUMA/cyf_SurfVol.nii
-anat_follower_ROI aaseg anat cyf/SUMA/aparc.a2009s+aseg.nii
-anat_follower_ROI aeseg epi cyf/SUMA/aparc.a2009s+aseg.nii
-anat_follower_ROI FSvent epi cyf/SUMA/cyf_vent.nii
-anat_follower_ROI FSWe epi cyf/SUMA/cyf_WM.nii
-anat_follower_erode FSvent FSWe
-dsets cyf/pre_rest_cyf.nii
-tcat_remove_first_trs 10
-tlrc_base MNI_avg152T1+tlrc
-tlrc_NL_warp
-volreg_align_to MIN_OUTLIER
-volreg_align_e2a
-volreg_tlrc_warp
-regress_ROI_PC FSvent 3
-regress_make_corr_vols aeseg FSvent
-regress_anaticor_fast
-regress_anaticor_label FSWe
-regress_censor_motion 0.2
-regress_censor_outliers 0.1
-regress_apply_mot_types demean deriv
-regress_est_blur_epits
-regress_est_blur_errts
-regress_run_clustsim no

Thank you!

Hi-

I think the problem is that there is some subtle white space after the "" characters at the end of the lines.

The “" character tells the interpreter to keep treating what follows on the next line as more of the same command (for humans, it’s nice to be able to space a command out to many lines to read it pieces, rather than have wrap-around annoyance splitting words weirdly). However, if there is a space after the backslash, then that doesn’t happen (”\ " gets interpreted differently than ""). And therefore the whole afni_proc.py command isn’t being found.

So, you could edit the ends of lines manually, or you could use a handy tool that Rick wrote to help fix these kinds of things:


file_tool -show_bad_all -infile INPUT_FILE -prefix  FIXED_INPUT_FILE

The above would look for “bad” characters and "\ " at the ends of lines.

–pt

Hi pt ~

Thanks for your prompt reply!

I guess it is VirtualBox that makes this problem. Perhaps the linux system can’t use the scripts created under windows through VirtualBox. I have tried to create a same file under linux and it succeeded just now.

I’ll try Rick’s handy tool you mentioned later to see if this can handle. Thank you again!

Best
Tracy

I’d be curious to know whether the “file_tool -show_bad_all …” script finds bad characters in the original script, still-- it’s possible that bad characters snuck into the file at some point (-> blame Windows…).

But, anyways, glad you have a working afni_proc script to start your Monday.

–pt

Hi Tracy,

The end of line characters are different for Windows than
they are for Unix (and again different for OS X). The file_tool
output should actually state which “file type” your script is, and
it should be able to convert it to Unix.

That file type issue is different from bad backslashes and
other strange characters (which is common too)l

  • rick

Hi pt~

Ha ha, yes I blamed windows and just tried the script. It did work! And runs as follows for your reference:

– will fix any bad char check errors in fixed_preprocess.sh
file ‘preprocess.sh’: missing final newline
preprocess.sh has 0 bad characters

– missing final newline was added
** non-Unix check output file ‘fixed_preprocess.sh’ exists, will overwrite
– will fix any non-Unix check errors in fixed_preprocess.sh
fixed_preprocess.sh file type: DOS
** bad backslash output file ‘fixed_preprocess.sh’ exists, will overwrite
– will fix any bad backslash errors in fixed_preprocess.sh
→ FIXED file written to fixed_preprocess.sh

Thank you for reply! Hope I can enjoy Afni the following days :slight_smile:

Tracy

Hi Rick

Thanks for your really clear explanation. I can always learn from your reply!

Yes I have tried your script and it works! The outputs are just as you said. Thank you again!

Tracy