Skip to main content
formatted list of files as code, removed thanks
Source Link

I'm processing a batch of subjects data recursively, calling the script within the parent directory.

For example, I have the parent directory: /home/subjects

/home/subjects 

and the subdirectories which contain the data: /home/subjects/0393 /home/subjects/0389 /home/subjects/9920 (Around 250 subjects)

/home/subjects/0393 /home/subjects/0389 /home/subjects/9920 (Around 250 subjects) 

Each file in each subdirectory has the file extension ".nii". I have composed a code, which calls a number of commands from a neuroscience program, searching for that particular file extension as the input. The input to the first command "fslroi" is the .nii file ($file), while the output file of that command is "rawdata.nii". As you can see the output from one command, is the input to the next etc

for file in $(find ./ -name "*.nii") do fslroi $file rawdata.nii 0 33 gunzip rawdata.nii.gz -f fslroi rawdata.nii rawnodif 0 1 bet rawnodif rawnodif_brain -m -g 0.2 -f 0.3 fslmaths rawnodif -mas rawnodif_brain_mask rawnodif_brain gunzip rawnodif_brain_mask.nii.gz -f done 

However, this code is inadequate as I am unable to save the output into the particular subdirectory. Thus, as I am processing several subjects the code will not work as everything is being saved to the parent directory.

Could someone please be able to give me any hints to how I can modify the code to save the output according to the input ".nii" file?

Thanks,

Alistair

I'm processing a batch of subjects data recursively, calling the script within the parent directory.

For example, I have the parent directory: /home/subjects

and the subdirectories which contain the data: /home/subjects/0393 /home/subjects/0389 /home/subjects/9920 (Around 250 subjects)

Each file in each subdirectory has the file extension ".nii". I have composed a code, which calls a number of commands from a neuroscience program, searching for that particular file extension as the input. The input to the first command "fslroi" is the .nii file ($file), while the output file of that command is "rawdata.nii". As you can see the output from one command, is the input to the next etc

for file in $(find ./ -name "*.nii") do fslroi $file rawdata.nii 0 33 gunzip rawdata.nii.gz -f fslroi rawdata.nii rawnodif 0 1 bet rawnodif rawnodif_brain -m -g 0.2 -f 0.3 fslmaths rawnodif -mas rawnodif_brain_mask rawnodif_brain gunzip rawnodif_brain_mask.nii.gz -f done 

However, this code is inadequate as I am unable to save the output into the particular subdirectory. Thus, as I am processing several subjects the code will not work as everything is being saved to the parent directory.

Could someone please be able to give me any hints to how I can modify the code to save the output according to the input ".nii" file?

Thanks,

Alistair

I'm processing a batch of subjects data recursively, calling the script within the parent directory.

For example, I have the parent directory:

/home/subjects 

and the subdirectories which contain the data:

/home/subjects/0393 /home/subjects/0389 /home/subjects/9920 (Around 250 subjects) 

Each file in each subdirectory has the file extension ".nii". I have composed a code, which calls a number of commands from a neuroscience program, searching for that particular file extension as the input. The input to the first command "fslroi" is the .nii file ($file), while the output file of that command is "rawdata.nii". As you can see the output from one command, is the input to the next etc

for file in $(find ./ -name "*.nii") do fslroi $file rawdata.nii 0 33 gunzip rawdata.nii.gz -f fslroi rawdata.nii rawnodif 0 1 bet rawnodif rawnodif_brain -m -g 0.2 -f 0.3 fslmaths rawnodif -mas rawnodif_brain_mask rawnodif_brain gunzip rawnodif_brain_mask.nii.gz -f done 

However, this code is inadequate as I am unable to save the output into the particular subdirectory. Thus, as I am processing several subjects the code will not work as everything is being saved to the parent directory.

Could someone please be able to give me any hints to how I can modify the code to save the output according to the input ".nii" file?

Source Link
ap123
  • 41
  • 3

Direct recursive shell script output to each subdirectory, not parent directory

I'm processing a batch of subjects data recursively, calling the script within the parent directory.

For example, I have the parent directory: /home/subjects

and the subdirectories which contain the data: /home/subjects/0393 /home/subjects/0389 /home/subjects/9920 (Around 250 subjects)

Each file in each subdirectory has the file extension ".nii". I have composed a code, which calls a number of commands from a neuroscience program, searching for that particular file extension as the input. The input to the first command "fslroi" is the .nii file ($file), while the output file of that command is "rawdata.nii". As you can see the output from one command, is the input to the next etc

for file in $(find ./ -name "*.nii") do fslroi $file rawdata.nii 0 33 gunzip rawdata.nii.gz -f fslroi rawdata.nii rawnodif 0 1 bet rawnodif rawnodif_brain -m -g 0.2 -f 0.3 fslmaths rawnodif -mas rawnodif_brain_mask rawnodif_brain gunzip rawnodif_brain_mask.nii.gz -f done 

However, this code is inadequate as I am unable to save the output into the particular subdirectory. Thus, as I am processing several subjects the code will not work as everything is being saved to the parent directory.

Could someone please be able to give me any hints to how I can modify the code to save the output according to the input ".nii" file?

Thanks,

Alistair