From 107af3a1efc2b50109308b87fe7cdf5846169904 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Wed, 1 Feb 2023 11:35:13 +0000
Subject: [PATCH] TEST: New pyfeeds test for old feeds tests. Relies on
 "old_feeds" external data

---
 old_feeds/feedsInputs |   1 +
 old_feeds/feedsRun    | 397 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 398 insertions(+)
 create mode 100644 old_feeds/feedsInputs
 create mode 100755 old_feeds/feedsRun

diff --git a/old_feeds/feedsInputs b/old_feeds/feedsInputs
new file mode 100644
index 0000000..09f7c8a
--- /dev/null
+++ b/old_feeds/feedsInputs
@@ -0,0 +1 @@
+old_feeds
\ No newline at end of file
diff --git a/old_feeds/feedsRun b/old_feeds/feedsRun
new file mode 100755
index 0000000..1aced41
--- /dev/null
+++ b/old_feeds/feedsRun
@@ -0,0 +1,397 @@
+#!/usr/bin/env fsltclsh
+
+#{{{ FEEDS - FSL Evaluation and Example Data Suite
+
+#   Stephen Smith and Matthew Webster, FMRIB Image Analysis Group
+#
+#   Copyright (C) 2001-2011 University of Oxford
+#
+#   Part of FSL - FMRIB's Software Library
+#   http://www.fmrib.ox.ac.uk/fsl
+#   fsl@fmrib.ox.ac.uk
+#
+#   Developed at FMRIB (Oxford Centre for Functional Magnetic Resonance
+#   Imaging of the Brain), Department of Clinical Neurology, Oxford
+#   University, Oxford, UK
+#
+#
+#   LICENCE
+#
+#   FMRIB Software Library, Release 4.0 (c) 2007, The University of Oxford
+#   (the "Software")
+#
+#   The Software remains the property of the University of Oxford ("the
+#   University").
+#
+#   The Software is distributed "AS IS" under this Licence solely for
+#   non-commercial use in the hope that it will be useful, but in order
+#   that the University as a charitable foundation protects its assets for
+#   the benefit of its educational and research purposes, the University
+#   makes clear that no condition is made or to be implied, nor is any
+#   warranty given or to be implied, as to the accuracy of the Software,
+#   or that it will be suitable for any particular purpose or for use
+#   under any specific conditions. Furthermore, the University disclaims
+#   all responsibility for the use which is made of the Software. It
+#   further disclaims any liability for the outcomes arising from using
+#   the Software.
+#
+#   The Licensee agrees to indemnify the University and hold the
+#   University harmless from and against any and all claims, damages and
+#   liabilities asserted by third parties (including claims for
+#   negligence) which arise directly or indirectly from the use of the
+#   Software or the sale of any products based on the Software.
+#
+#   No part of the Software may be reproduced, modified, transmitted or
+#   transferred in any form or by any means, electronic or mechanical,
+#   without the express permission of the University. The permission of
+#   the University is not required if the said reproduction, modification,
+#   transmission or transference is done without financial return, the
+#   conditions of this Licence are imposed upon the receiver of the
+#   product, and all original and amended source code is included in any
+#   transmitted product. You may be held legally responsible for any
+#   copyright infringement that is caused or encouraged by your failure to
+#   abide by these terms and conditions.
+#
+#   You are not permitted under this Licence to use this Software
+#   commercially. Use for which any financial return is received shall be
+#   defined as commercial use, and includes (1) integration of all or part
+#   of the source code or the Software into a product for sale or license
+#   by or on behalf of Licensee to third parties or (2) use of the
+#   Software or any derivative of it for research with the final aim of
+#   developing software products for sale or license to a third party or
+#   (3) use of the Software or any derivative of it for research with the
+#   final aim of developing non-software products for sale or license to a
+#   third party, or (4) use of the Software to provide any service to an
+#   external organisation for which payment is received. If you are
+#   interested in using the Software commercially, please contact Isis
+#   Innovation Limited ("Isis"), the technology transfer company of the
+#   University, to negotiate a licence. Contact details are:
+#   innovation@isis.ox.ac.uk quoting reference DE/1112.
+
+#}}}
+
+
+#{{{ perror
+
+proc perror { testimage scale } {
+
+    global FSLDIR INDIR OUTDIR PTHRESH MAXPERROR
+
+    if { ! [ imtest $OUTDIR/$testimage ] } {
+	set PERROR 100
+	puts "No output image created"
+    } else {
+	exec sh -c "${FSLDIR}/bin/fslmaths $INDIR/$testimage -sub $OUTDIR/$testimage -sqr $OUTDIR/errsq -odt float"
+	exec sh -c "${FSLDIR}/bin/fslmaths $INDIR/$testimage -sqr $OUTDIR/meansq -odt float"
+
+	set PERROR [ expr int ( $scale * 10000.0 * sqrt ( \
+		[ exec ${FSLDIR}/bin/fslstats $OUTDIR/errsq -m ] / \
+		[ exec ${FSLDIR}/bin/fslstats $OUTDIR/meansq -m ] ) ) / 100.00 ]
+
+	puts "% error = $PERROR"
+    }
+
+    if { $PERROR > $PTHRESH } {
+	puts "Warning - test failed!"
+    }
+
+    if { $PERROR > $MAXPERROR } {
+	set MAXPERROR $PERROR
+    }
+
+    return $PERROR
+}
+
+#}}}
+#{{{ simpleperror
+
+proc simpleperror { a b denom } {
+
+    global PTHRESH MAXPERROR
+
+    set PERROR [ expr int ( 10000.0 * ( $a - $b ) / $denom ) / 100.00 ]
+
+    if { $PERROR < 0 } {
+	set PERROR [ expr 0 - $PERROR ]
+    }
+
+    puts "% error = $PERROR"
+
+    if { $PERROR > $PTHRESH } {
+	puts "Warning - test failed!"
+    }
+
+    if { $PERROR > $MAXPERROR } {
+	set MAXPERROR $PERROR
+    }
+
+    return $PERROR
+}
+
+
+#{{{ setup vars and first printouts
+
+
+set feeds_list "fdt fugue susan sienax bet2 feat melodic first fnirt"
+foreach f $feeds_list {
+    set feeds($f) 1
+}
+
+set OUTDIR  [ lindex $argv 0 ]
+set INDIR  "[ lindex $argv 1 ]/old_feeds"
+set FSLDIR $env(FSLDIR)
+
+set PTHRESH 1
+set MAXPERROR 0
+
+set INMEDX 0
+set INGUI 0
+source ${FSLDIR}/tcl/fslstart.tcl
+
+puts "\nFSL Evaluation and Example Data Suite\n"
+
+puts "start time       = [ exec date ]"
+puts "hostname         = [ exec hostname ]"
+puts "os               = [ exec uname -a ]\n"
+puts "Input directory  = $INDIR"
+puts "Output directory = $OUTDIR"
+puts "FSLDIR           = $FSLDIR"
+
+set logout $OUTDIR/LOG
+
+#}}}
+
+# to add ASAP:
+# filmbabe (make_flobs and filmbabe) / mm / randomise
+
+#{{{ FUGUE
+
+if { $feeds(fugue) } {
+
+puts "\nStarting PRELUDE & FUGUE at [ exec date ]"
+fsl:exec "${FSLDIR}/bin/prelude -c $INDIR/fieldmap -o $OUTDIR/unwrapped_phase"
+perror unwrapped_phase 0.5
+fsl:exec "${FSLDIR}/bin/fugue -i $INDIR/epi -p $OUTDIR/unwrapped_phase -d 0.295 -u $OUTDIR/unwarped_epi"
+perror unwarped_epi 0.2
+
+}
+
+#}}}
+#{{{ SUSAN
+
+if { $feeds(susan) } {
+
+puts "\nStarting SUSAN at [ exec date ]"
+fsl:exec "${FSLDIR}/bin/susan $INDIR/structural 2000 2 3 1 0 $OUTDIR/structural_susan"
+perror structural_susan 0.25
+
+}
+
+#}}}
+#{{{ SIENAX
+
+if { $feeds(sienax) } {
+
+puts "\nStarting SIENAX (including testing BET and FLIRT and FAST) at [ exec date ]"
+
+fsl:exec "${FSLDIR}/bin/imcp $INDIR/structural $OUTDIR/structural"
+fsl:exec "cd $OUTDIR ; ${FSLDIR}/bin/sienax structural -d -r"
+
+puts "checking error on BET:"
+perror structural_sienax/I_brain 0.2
+
+puts "checking error on FLIRT:"
+perror structural_sienax/I_stdmask 0.01
+
+puts "checking error on FAST:"
+puts "checking error on single-image binary segmentation:"
+perror structural_sienax/I_stdmaskbrain_seg 0.05
+puts "checking error on partial volume images:"
+perror structural_sienax/I_stdmaskbrain_pve_0 0.02
+perror structural_sienax/I_stdmaskbrain_pve_1 0.03
+perror structural_sienax/I_stdmaskbrain_pve_2 0.03
+
+puts "checking error on SIENAX volume outputs:"
+foreach sienastats { pgrey vcsf GREY WHITE BRAIN } {
+    set r [ exec sh -c "grep $sienastats $OUTDIR/structural_sienax/report.sienax | awk '{ print \$2 }'" ]
+    set d [ exec sh -c "grep $sienastats $INDIR/structural_sienax/report.sienax    | awk '{ print \$2 }'" ]
+    simpleperror $r $d 1600000
+}
+
+}
+
+#}}}
+#{{{ BET2
+
+if { $feeds(bet2) } {
+
+puts "\nStarting BET2 at [ exec date ]"
+
+fsl:exec "/bin/cp $INDIR/head_t?.nii.gz $OUTDIR"
+fsl:exec "cd $OUTDIR ; ${FSLDIR}/bin/bet head_t1 head_t1_brain -A2 head_t2"
+
+puts "checking error on T1 brain extraction:"
+perror head_t1_brain 0.05
+puts "checking error on skull and scalp surfaces:"
+perror head_t1_brain_inskull_mesh .01
+perror head_t1_brain_outskull_mesh .01
+perror head_t1_brain_outskin_mesh .01
+
+}
+
+#}}}
+#{{{ FEAT
+
+if { $feeds(feat) } {
+
+puts "\nStarting FEAT at [ exec date ]"
+
+# fix FEAT setup file to use INDIR, OUTDIR and FSLDIR
+fsl:exec "cp ${INDIR}/fmri.feat/design.fsf ${OUTDIR}/design.fsf"
+fsl:echo ${OUTDIR}/design.fsf "
+set fmri(regstandard) ${FSLDIR}/data/standard/MNI152_T1_2mm_brain
+set feat_files(1) ${INDIR}/fmri
+set highres_files(1) ${INDIR}/structural_brain
+set fmri(outputdir) ${OUTDIR}/fmri.feat"
+
+# run FEAT
+fsl:exec "${FSLDIR}/bin/feat ${OUTDIR}/design.fsf"
+
+puts "checking error on filtered functional data:"
+perror fmri.feat/filtered_func_data 0.1
+puts "checking error on raw Z stat images:"
+perror fmri.feat/stats/zstat1 0.02
+perror fmri.feat/stats/zstat2 0.02
+perror fmri.feat/stats/zfstat1 0.02
+puts "checking error on thresholded Z stat images:"
+perror fmri.feat/thresh_zstat1 0.02
+perror fmri.feat/thresh_zstat2 0.02
+perror fmri.feat/thresh_zfstat1 0.02
+puts "checking error on registration images:"
+perror fmri.feat/reg/example_func2highres 0.02
+perror fmri.feat/reg/example_func2standard 0.02
+
+#{{{ check error on largest cluster of Talairached zfstat1
+
+puts "checking error on position of largest cluster of Talairached zfstat1:"
+
+set iptr [ open ${INDIR}/fmri.feat/cluster_zfstat1_std.txt r ]
+gets $iptr line
+gets $iptr line
+scan $line "%f %f %f %f %f %f %f %f %f" D(1) D(2) D(3) D(4) D(5) D(6) D(7) D(8) D(9)
+close $iptr
+
+set iptr [ open ${OUTDIR}/fmri.feat/cluster_zfstat1_std.txt r ]
+gets $iptr line
+gets $iptr line
+scan $line "%f %f %f %f %f %f %f %f %f %f %f" R(1) R(2) R(3) R(4) R(5) R(6) R(7) R(8) R(9) R(10) R(11)
+close $iptr
+
+simpleperror $D(4) $R(6) 500
+simpleperror $D(5) $R(7) 500
+simpleperror $D(6) $R(8) 500
+simpleperror $D(7) $R(9) 500
+simpleperror $D(8) $R(10) 500
+simpleperror $D(9) $R(11) 500
+
+#}}}
+
+}
+
+#}}}
+#{{{ MELODIC
+
+if { $feeds(melodic) } {
+
+puts "\nStarting MELODIC at [ exec date ]"
+
+fsl:exec "${FSLDIR}/bin/melodic -i $INDIR/fmri -o $OUTDIR/fmri.ica --tr=3 --seed=2"
+
+fsl:exec "${FSLDIR}/bin/fslcc $INDIR/fmri.ica/melodic_IC $OUTDIR/fmri.ica/melodic_IC > $OUTDIR/fmri.ica/fslcc.txt"
+
+set MAXV 0
+set MAXA 0
+set iptr [ open $OUTDIR/fmri.ica/fslcc.txt r ]
+while { ( [ gets $iptr line ] >= 0 ) } {
+    scan $line "%d %d %f" A B C
+    if { $A == 52 } {
+	if { $C > $MAXV } {
+	    set MAXV $C
+	}
+    }
+    if { $A == 39 } {
+	if { $C > $MAXA } {
+	    set MAXA $C
+	}
+    }
+}
+close $iptr
+
+if { $MAXA < $MAXV } {
+    set MAXV $MAXA
+}
+
+simpleperror $MAXV 1 60
+
+}
+
+#}}}
+#{{{ FIRST
+
+if { $feeds(first) } {
+
+puts "\nStarting FIRST at [ exec date ]"
+fsl:exec "${FSLDIR}/bin/first_flirt $INDIR/structural $OUTDIR/structural_to_std_sub"
+fsl:exec "${FSLDIR}/bin/run_first -i $INDIR/structural -t $OUTDIR/structural_to_std_sub.mat -n 20 -o $OUTDIR/structural_first_L_Hipp -m ${FSLDIR}/data/first/models_336_bin/L_Hipp_bin.bmv"
+perror structural_first_L_Hipp 0.01
+
+}
+
+#}}}
+#{{{ FDT
+
+if { $feeds(fdt) } {
+
+puts "\nStarting FDT (bedpost) at [ exec date ]"
+
+fsl:exec "cp -r $INDIR/fdt_subj1 $OUTDIR"
+fsl:exec "unset FSLMACHINELIST; ${FSLDIR}/bin/bedpostx $OUTDIR/fdt_subj1 -n 1"
+
+puts "checking error on bedpost output:"
+perror fdt_subj1.bedpostX/dyads1 .005
+perror fdt_subj1.bedpostX/mean_f1samples .005
+perror fdt_subj1.bedpostX/mean_ph1samples .003
+perror fdt_subj1.bedpostX/mean_th1samples .002
+perror fdt_subj1.bedpostX/merged_f1samples .005
+perror fdt_subj1.bedpostX/merged_ph1samples .003
+perror fdt_subj1.bedpostX/merged_th1samples .002
+
+}
+
+if { $feeds(fnirt) } {
+puts "\nStarting FNIRT at [ exec date ]"
+fsl:exec "cp -r $INDIR/feeds_fnirt* $OUTDIR"
+fsl:exec "cp -r $INDIR/sad* $OUTDIR"
+fsl:exec "cp -r $INDIR/happy* $OUTDIR"
+set cwd [ pwd ]
+cd $OUTDIR
+fsl:exec "${FSLDIR}/bin/fnirt --config=feeds_fnirt"
+cd $cwd
+perror feeds_fnirt_sad2happy 0.1
+}
+
+#}}}
+
+#{{{ finish up
+puts "\nend time = [ exec date ]\n"
+
+if { $MAXPERROR < $PTHRESH } {
+    puts "\nAll tests passed"
+    exit 0
+} else {
+    puts "\nWarning - not all tests passed"
+    exit 1
+}
+
+
+#}}}
-- 
GitLab