Hello MRtrix experts,
Just wondering if it is possible to store the output of mrstats in a variable such that it can be written to a csv file?
Thank you!
Hello MRtrix experts,
Just wondering if it is possible to store the output of mrstats in a variable such that it can be written to a csv file?
Thank you!
Hi,
yes by adding " > stats.txt " to the mrstats command.
Best,
Parmida
the “>” didn’t work for me using this command.
Does anyone else have any tips to output mrstats to a file using the for_each command?
for_each *mask.mif : mrstats IN -mask …/…/…/cerebellum_template/stats_fdc/t1_significance_mask.mif
I think it’s because for_each
doesn’t print the output of a command. My way around this is to create my own for loop for commands where I want the output printed. Here for a bash terminal
I usually create a file with all files/participants to be processed:
ls *mask.mif > list.txt
Then loop through each file:
for file in `cat list.txt` ; do echo ${file} ; mrstats ${file} -mask …/…/…/cerebellum_template/stats_fdc/t1_significance_mask.mif > ${file:0:end-4}_stats.csv ; done
Hope this works
Nick
You’ll have to escape the >
.
For instance:
for_each *mask.mif : mrstats IN -mask …/…/…/cerebellum_template/stats_fdc/t1_significance_mask.mif -output count '>' NAME.stats
I’d recommend testing this via for_each -test
.
Thanks Max - this does work, kinda. It looks like it overwrites
every previous loop so only the stats from the last loop file is in the output file.
Thanks so much for this Nic, I’ve given this a go… but I keep getting this error?
-bash: end-4: substring expression < 0
Hi, the code seems to work fine for me - perhaps your text file has some lines that are less that four characters long?
also if Max’s code works apart from creating a new output file each time, you can substitute ‘>’ by ‘>>’ to append the output to the same file (each row will be the output of one input file).
Or if you want separate output files, try replacing NAME by UNI and see if that works.