Skip to content

Instantly share code, notes, and snippets.

@AReineberg
Created July 15, 2018 18:50
Show Gist options
  • Save AReineberg/eaa0088350ebe15836c2d43aafab4c7a to your computer and use it in GitHub Desktop.
Save AReineberg/eaa0088350ebe15836c2d43aafab4c7a to your computer and use it in GitHub Desktop.
Grabs output from mris_anatomical_stats
usage() { echo "Usage: $0 [-i <mris_anatomical_stats output>]" 1>&2; exit 1; }
while getopts ":i:" o; do
case "${o}" in
i)
i=${OPTARG}
;;
*)
usage
;;
esac
done
shift "$((OPTIND-1))"
if [ -z "${i}" ]; then
usage
fi
name=`echo $i | cut -d "." -f 1`
output=${name}_stats.csv
if [ ! -f $output ]; then
touch $output
else
echo "WARNING: Scraper already used on this mris_anatomical_stats output. Resulting output may contain redundant information."
fi
echo "subject,thickness" > $output
mkdir temporary
csplit -s $i '/^structure/' '{*}'
rm -f xx00
mv xx* temporary/
for j in temporary/xx*; do
subj=`cat $j | grep structure | cut -d " " -f 3 | cut -d "/" -f 1 | tr -d "\""`
thick=`cat $j | grep "average cortical thickness" | tr -s " " | cut -d " " -f 5`
echo $subj,$thick >> $output
done
rm -fr temporary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment