From 3a316b72227726b0992399e51ec1dddc1f418a59 Mon Sep 17 00:00:00 2001
From: Stephen Smith <steve@fmrib.ox.ac.uk>
Date: Wed, 18 Jul 2007 14:56:01 +0000
Subject: [PATCH] *** empty log message ***

---
 melodic.tcl | 632 +++++++++++++++++-----------------------------------
 1 file changed, 201 insertions(+), 431 deletions(-)

diff --git a/melodic.tcl b/melodic.tcl
index 0e00d5d..7394f04 100644
--- a/melodic.tcl
+++ b/melodic.tcl
@@ -1,279 +1,217 @@
-#{{{ copyright and setup
-
-#   MELODIC - Multivariate Exploratory Linear Optimized Decomposition into 
-#             Independent Components
 #
-#   Christian Beckmann, Stephen Smith and Matthew Webster, FMRIB Image Analysis Group
+#   GUI for MELODIC
+#
+#   Stephen Smith & Christian Beckmann, FMRIB Analysis Group
 #
-#   Copyright (C) 2006 University of Oxford
+#   Copyright (C) 1999-2007 University of Oxford
 #
 #   TCLCOPYRIGHT
- 
-source [ file dirname [ info script ] ]/fslstart.tcl
 
+source [ file dirname [ info script ] ]/fslstart.tcl
 set VARS(history) {}
- 
-set VERSION [ exec sh -c "${FSLDIR}/bin/melodic -V | awk '{ print \$3 }'" ]
 
-#}}}
-#{{{ main GUI
-
-proc melodic { w } {
+#{{{ melodic:updatedim
 
-    #{{{ vars and setup
-
-global vars FSLDIR INMEDX argc argv PWD VERSION entries fmri
-
-toplevel $w
-wm title $w "MELODIC - v$VERSION"
-wm iconname $w "MELODIC"
-wm iconbitmap $w @${FSLDIR}/tcl/fmrib.xbm
+proc melodic:updatedim { w } {
 
-frame $w.f
+    global fmri
+    set f $fmri(statsf)
 
+    if { $fmri(dim_yn) == 1 } {
+	pack forget $f.dim.n
+    } else {
+	pack $f.dim.n -in $f.dim -side left -padx 5 -after $f.dim.yn
+    }
+    $w.nb compute_size
+}
 
 #}}}
+#{{{ melodic:updatethresh
 
-    NoteBook $w.nb -side top -bd 2 -tabpady {5 10} -arcradius 3
-    $w.nb insert 0 data -text "Data"    
-    $w.nb insert 1 filtering -text "Pre-stats"
-    $w.nb insert 2 melodic -text "MELODIC"
-
-    #{{{ Data
-set fmri(dataf) [ $w.nb getframe data ]
-#{{{ multiple analyses
-
-frame $w.multiple
-
-set fmri(multiple) 1
-LabelSpinBox $w.multiple.number -label "Number of analyses " -textvariable fmri(multiple) -range " 1 10000 1 "  -width 3 
-set fmri(level) 1
-set fmri(analysis) 0
-set fmri(inputtype) 2
+proc melodic:updatethresh { w } {
 
-button $w.multiple.setup -text "Select 4D data" -command "feat5:multiple_select $w 0 \"Select input data\" "
+    global fmri
+    set f $fmri(poststatsf).thresh
 
-pack $w.multiple.number $w.multiple.setup -in $w.multiple -side left -padx 5
+    if { $fmri(thresh_yn) == 0 } {
+	set fmri(mmthresh) 0
+	pack forget $f.n
+    } else {
+	set fmri(mmthresh) 0.5
+	pack $f.n -in $f -side left -padx 5 -after $f.yn
+    }
+}
 
 #}}}
+#{{{ melodic:apply
 
-#{{{ output directory
+proc melodic:apply { w } {
+    global fmri feat_files unwarp_files unwarp_files_mag initial_highres_files highres_files FSLDIR HOME
 
-set fmri(outputdir) ""
-FileEntry $w.outputdir -textvariable fmri(outputdir) -label " Output directory  " -title "Name the output directory" -width 35 -filedialog directory -filetypes { }
-#}}}
-
-frame $w.datamain
-#{{{ npts & ndelete
+    if { [ feat5:write $w 0 1 1 $fmri(feat_filename) ] } {
+	return 1
+    }
 
-frame $w.nptsndelete
+    set FSFROOT [ file rootname $fmri(feat_filename) ]
 
-#{{{ ndelete
+    catch { exec sh -c "$FSLDIR/bin/feat $FSFROOT" & } junk
 
-set fmri(ndelete) 0
-LabelSpinBox $w.ndelete -label "       Delete volumes " -textvariable fmri(ndelete) -range {0 200000 1 } -width 3
-balloonhelp_for $w.ndelete "The number of initial FMRI volumes to delete before any further
-processing. These should be the volumes that are not wanted because
-steady-state imaging has not yet been reached - typically two or three
-volumes."
-#}}}
+    set fmri(feat_filename) [ exec sh -c "${FSLDIR}/bin/tmpnam /tmp/feat" ].fsf
 
-pack $w.ndelete -in $w.nptsndelete -side left
+    update idletasks
+}
 
 #}}}
-#{{{ TR & highpass
 
-frame $w.trparadigm_hp
-
-#{{{ TR
-set fmri(tr) 3.0
-LabelSpinBox $w.tr -label "TR (s) " -textvariable fmri(tr) -range {0.001 200000 0.25 } 
-balloonhelp_for $w.tr "The time (in seconds) between scanning successive FMRI volumes."
-#}}}
+proc melodic { w } {
+    global fmri FSLDIR USER feat_files unwarp_files unwarp_files_mag initial_highres_files highres_files VARS argc argv PWD gui_ext HOME tempSpin
+ 
+    #{{{ main window
 
-pack $w.tr -in $w.trparadigm_hp -side left
+feat5:setupdefaults
 
-#}}}
-pack $w.nptsndelete $w.trparadigm_hp -in $w.datamain -side top -padx 5 -pady 3 -anchor w
+set tempSpin -1
 
-pack $w.multiple $w.datamain -in $fmri(dataf) -anchor w -side top
+toplevel $w
 
-#{{{ FSL logo
+set melodic_version [ fsl:exec "$FSLDIR/bin/melodic -V" -n ] 
+set fmri(version) [ lindex $melodic_version 2 ]
 
-set graphpic [ image create photo -file ${FSLDIR}/tcl/fsl-logo-tiny.ppm ]
-button $w.logo -image $graphpic -command "FmribWebHelp file: ${FSLDIR}/doc/index.html" -borderwidth 0
-pack $w.logo -in $fmri(dataf) -anchor e -side bottom -padx 5 -pady 5
+wm title      $w $melodic_version
+wm iconname   $w $melodic_version
+wm iconbitmap $w @${FSLDIR}/tcl/fmrib.xbm
 
-#}}}
+set fmri(inmelodic) 1
+set fmri(level) 1
+set fmri(analysis) 7
+set fmri(icaopt) 1
+set fmri(regstandard_res) 4
 
 #}}}
-    #{{{ Pre-statistics processing
+    #{{{ notebook
 
-set fmri(filteringf) [ $w.nb getframe filtering ]
+NoteBook $w.nb -side top -bd 2 -tabpady {5 10} -arcradius 3 
+$w.nb insert 0 misc      -text "Misc"    
+$w.nb insert 1 data      -text "Data"     
+$w.nb insert 2 filtering -text "Pre-Stats"  
+$w.nb insert 3 reg       -text "Registration"
+$w.nb insert 4 stats     -text "Stats"
+$w.nb insert 5 poststats -text "Post-Stats"
 
-set fmri(filtering_yn) 1
+#{{{ Misc
 
-#{{{ motion correction
+set fmri(miscf) [ $w.nb getframe misc ]
 
-LabelFrame $w.mc -text "Motion correction: "
-set fmri(mcf) $w.mc
-optionMenu2 $w.mc.menu fmri(mc) 0 "None" 1 "MCFLIRT"
-pack $w.mc.menu 
-balloonhelp_for $w.mc "You will normally want to apply motion correction; this attempts to
-remove the effect of subject head motion during the
-experiment. MCFLIRT uses FLIRT (FMRIB's Linear Registration Tool)
-tuned to the problem of FMRI motion correction, applying rigid-body
-transformations."
+feat5:misc_gui $w
 
+#}}}
+#{{{ Data
 
-set fmri(mc) 1
+set fmri(dataf) [ $w.nb getframe data ]
 
+feat5:data_gui $w
 
 #}}}
-#{{{ slice timing correction
-
-LabelFrame $w.st -text "Slice timing correction: "
-set fmri(stf) $w.st
-set fmri(st) 0
-set fmri(st_file) ""
-FileEntry $w.st_file -textvariable fmri(st_file) -label "" -title "Select a slice order/timings file" -width 20 -filedialog directory  -filetypes * 
-
-optionMenu2 $w.st.menu fmri(st) -command "melodic2:updatest $w" 0 "None" 1 "Regular up (0, 1, 2 ... n-1)" 2 "Regular down (n-1, n-2 ... 0)" 5 "Interleaved (0, 2, 4 ... 1, 3, 5 ... )" 3 "Use slice order file" 4 "Use slice timings file"
-pack $w.st.menu 
-
-balloonhelp_for $w.st  "Slice timing correction corrects each voxel's time-series for the fact
-that later processing assumes that all slices were acquired exactly
-half-way through the relevant volume's acquisition time (TR), whereas
-in fact each slice is taken at slightly different times.
-
-Slice timing correction works by using (Hanning-windowed) sinc
-interpolation to shift each time-series by an appropriate fraction of
-a TR relative to the middle of the TR period. It is necessary to know
-in what order the slices were acquired and set the appropriate option
-here.
-
-If a slice order file is to be used (e.g., to setup interleaved slice
-orderings), create a text file with a single number on each line,
-where the first line states which slice was acquired first, the second
-line states which slices was acquired second, etc. The first slice is
-numbered 1 not 0."
+#{{{ Pre-ICA
 
-#}}}
-#{{{ BET brain extraction
+set fmri(filteringf) [ $w.nb getframe filtering ]
 
-frame $w.bet
+feat5:prestats_gui $w
 
-label $w.bet.label -text "BET brain extraction"
+#}}}
+#{{{ ICA
 
-set fmri(bet_yn) 1
-checkbutton $w.bet.yn -variable fmri(bet_yn) -command "melodic2:updatebet $w"
+set fmri(statsf) [ $w.nb getframe stats ]
 
-balloonhelp_for $w.bet "This uses BET brain extraction to create a brain mask from the first
-volume in the FMRI data. This is normally better than simple
-intensity-based thresholding for getting rid of unwanted voxels in
-FMRI data. Note that here, BET is setup to run in a quite liberal way so that
-there is very little danger of removing valid brain voxels.
+set f $fmri(statsf)
 
-If the field-of-view of the image (in any direction) is less than 30mm
-then BET is turned off by default."
+#{{{ variance normalisation
 
+set fmri(varnorm) 1
+checkbutton $f.varnorm -variable fmri(varnorm) -text "Variance-normalise timecourses"
+balloonhelp_for $f.varnorm "When switched on, Melodic will rescale each time series so 
+that the estimation is more influenced by the voxel-wise 
+temporal dynamics and less by a voxels' mean signal. "
 
-set fmri(thresh) 10
-LabelSpinBox  $w.bet.thresh -label "  Threshold % " -textvariable fmri(thresh) -range {0.0 100 1 } -width 3
+#}}}
+#{{{ output components
 
-pack $w.bet.label $w.bet.yn -in $w.bet -side left
+frame $f.dim
 
-#}}}
-#{{{ spatial filtering
+set fmri(dim_yn) 1
+checkbutton $f.dim.yn -variable fmri(dim_yn) -text "Automatic dimensionality estimation" -command "melodic:updatedim $w"
 
-set fmri(smooth) 3
-LabelSpinBox  $w.smooth -label "Spatial smoothing FWHM (mm) " -textvariable fmri(smooth) -range {0.0 10000 1 } -width 3
+pack $f.dim.yn -in $f.dim -side left
 
-balloonhelp_for $w.smooth "This determines the extent of the spatial smoothing, carried out on
-each volume of the FMRI data set separately. This is intended to
-reduce noise without reducing interesting signal; this is successful as
-long as the underlying signal area is larger than the extent of
-the smoothing.
+balloonhelp_for $f.dim "In order to avoid overfitting, Melodic will attempt to estimate the number of 
+components from the data using Bayesian estimators for the model 
+order and use PCA to reduce the data prior to the IC estimation."
 
-To turn off spatial smoothing simply set FWHM to 0."
+set fmri(dim) 1
+LabelSpinBox $f.dim.n -label "Output components" -textvariable fmri(dim) -range { 1 200000 1}
 
 #}}}
-#{{{ temporal filtering
-
-frame $w.temp
+#{{{ ICA level
 
-label $w.temp.label -text "Temporal filtering    "
+optionMenu2 $f.icaopt fmri(icaopt) -command "feat5:updatereg $w" 1 "Single-session ICA" 2 "Multi-session temporal concatenation" 3 "Multi-session tensor ICA"
 
-set fmri(temphp_yn) 1
-label $w.temp.hplabel -text "Highpass (s)"
-checkbutton $w.temp.hp_yn -variable fmri(temphp_yn)
+balloonhelp_for $f.icaopt "
 
-set fmri(templp_yn) 0
+Here you can select the kind of ICA-based analysis you want to run.
 
-balloonhelp_for $w.temp " The high pass frequency cutoff point (in seconds) specifies 
-the longest temporal period you will allow.
+If you want to process a single-session FMRI dataset (or several
+datasets with the same setup, but independently of each other) then
+select \"Single-session ICA\". This runs a standard (space X time) ICA
+decomposition on each of the input datasets separately.
 
-\"Highpass temporal filtering\" uses a local fit of a 
-straight line (Gaussian-weighted within the line to give 
-a smooth response) to remove low frequency artefacts. It 
-is generally beneficial to remove global trends which 
-will - if not removed - often dominate the decomposition."
+If you want to process several sessions or subjects simultaneously,
+constraining the spatial maps to be the same across sessions/subjects,
+but with no constraint on the timecourses being the same, then you
+might want to choose the \"Multi-session temporal concatenation\"
+option. After transforming all sessions' 4D datasets into standard
+space, they are all temporally concatenated together, resulting in one
+large 4D dataset. Then a standard (space X time) ICA decomposition is
+run.
 
-set fmri(paradigm_hp) 100
-LabelSpinBox $w.paradigm_hp -textvariable fmri(paradigm_hp) -range {1.0 200000 5 } -width 5 
+If you want to process several sessions or subjects simultaneously,
+and you want to constrain both spatial maps and timecourses to be the
+same across the session/subjects, then you should choose the
+\"Multi-session tensor ICA\" option. After transforming all sessions'
+4D datasets into standard space, they are combined together and tensor
+(space X time X sessions/subjects) ICA is run.
 
 
-pack $w.temp.label $w.temp.hplabel $w.temp.hp_yn $w.paradigm_hp -in $w.temp -side top -side left
+For analysis of multi-session or multi-subject resting FMRI data, in
+order to find resting-state networks, we generally recommend using the
+temporal concatenation option. In all other cases in general we
+recommend using the Tensor ICA option."
 
 #}}}
 
-pack $fmri(mcf) $fmri(stf) $w.bet $w.smooth $w.temp -in $fmri(filteringf) -anchor w -pady 1 -padx 5
+pack $f.varnorm $f.dim $f.icaopt -in $f -anchor w -side top
 
 #}}}
-    #{{{ Melodic
-
-set fmri(melodicf) [ $w.nb getframe melodic ]
-
-set fmri(varnorm) 1
-checkbutton $w.varnorm -variable fmri(varnorm) -text "Variance-normalise timecourses"
-
-balloonhelp_for $w.varnorm "When switched on, Melodic will rescale each time series so 
-that the estimation is more influenced by the voxel-wise 
-temporal dynamics and less by a voxels' mean signal. "
-
-#{{{ output components
+#{{{ Post-ICA
 
-frame $w.dim
+set fmri(poststatsf) [ $w.nb getframe poststats ]
 
-set fmri(dim_yn) 1
-checkbutton $w.dim.yn -variable fmri(dim_yn) -text "Automatic dimensionality estimation" -command "melodic2:updatedim $w"
-
-pack $w.dim.yn -in $w.dim -side left
-
-balloonhelp_for $w.dim "In order to avoid overfitting, Melodic will attempt to estimate the number of 
-components from the data using Bayesian estimators for the model 
-order and use PCA to reduce the data prior to the IC estimation."
-
-set fmri(dim) 1
-LabelSpinBox $w.dim.n -label "Output components" -textvariable fmri(dim) -range { 1 200000 1}
-
-#}}}
+set f $fmri(poststatsf)
 
 #{{{ thresholding
 
-frame $w.thresh
+frame $f.thresh
 
 set fmri(thresh_yn) 1
-checkbutton $w.thresh.yn -variable fmri(thresh_yn) -text "Threshold IC maps" -command "melodic2:updatethresh $w"
+checkbutton $f.thresh.yn -variable fmri(thresh_yn) -text "Threshold IC maps" -command "melodic:updatethresh $w"
 
-balloonhelp_for $w.thresh "Melodic uses a mixture model approach to assign significance to individual 
+balloonhelp_for $f.thresh "MELODIC uses a mixture model approach to assign significance to individual 
 voxels within a spatial map. The mixture model of a single Gaussian 
 distribution (for the background noise within the spatial maps) and 
 2 Gamma distributions (which model the 'active' voxels contained in 
 the tails of the Gaussian) is fitted to the intensity histogram of 
 the Z-transformed IC maps using a restricted EM algorithm. 
 
-From this mixture model fit, Melodic calculates voxel-wise probabilities 
+From this mixture model fit, MELODIC calculates voxel-wise probabilities 
 of 'activation' (as the ratio of a voxels' intensity being in the 
 non-background class relative to probability of the intensity being 
 background noise).
@@ -283,305 +221,137 @@ where the probability of belonging to the non-background mixtures
 exceeds the probability of the voxel belonging to the background 
 noise Gaussian."
 
-set fmri(mmthresh) "0.5"
-entry $w.thresh.n -textvariable fmri(mmthresh) -width 10
+set fmri(mmthresh) 0.5
+LabelSpinBox  $f.thresh.n -label "" -textvariable fmri(mmthresh) -range {0.0 1 0.1 } -width 3
 
-pack $w.thresh.yn $w.thresh.n -in $w.thresh -side left
+pack $f.thresh.yn $f.thresh.n -in $f.thresh -side left
 
 #}}}
+#{{{ background image for group stats
 
-set fmri(ostats) 0
-checkbutton $w.ostats -variable fmri(ostats) -text "Output full stats folder"
-
-balloonhelp_for $w.ostats "
-When switched on, Melodic will save the thresholded IC 
-maps and the probability maps inside a folder \/stats. 
-This will substantially increase the amount of space used, 
-so only switch this on if you intend to use these maps."
+frame $f.bgimage
 
+label $f.bgimage.label -text "Background image "
+optionMenu2 $f.bgimage.menu fmri(bgimage) 1 "Mean highres" 2 "First highres" 3 "Mean functional" 4 "First functional" 5 "Standard space template"
 
-set fmri(report) 1
-checkbutton $w.report -variable fmri(report) -text "Create web page report"
+pack $f.bgimage.label $f.bgimage.menu -in $f.bgimage -side top -side left
 
+balloonhelp_for $f.bgimage "With \"Higher-level analysis\" you can select what image will be used
+as the background image for the activation colour overlays. The
+default of \"Mean highres\" is probably the best for relating
+activation to underlying structure. For a sharper underlying image,
+(but one which is not so representative of the group of subjects), you
+can instead choose to use the highres image from the first selected
+subject.
 
-pack $w.varnorm $w.dim  $w.thresh $w.ostats $w.report -in $fmri(melodicf) -anchor w -side top
+You can alternatively choose to use the original lowres functional
+data for the overlays, or the standard-space template image."
 
 #}}}
+#{{{ output options
 
-    pack $w.nb -in $w.f -side top -padx 5 -pady 5 -anchor w
-
-    #{{{ Button Frame
-
-    frame $w.btns
-    frame $w.btns.b -relief raised -borderwidth 1
- 
-    button $w.apply     -command "melodic2:apply $w keep" \
-        -text "Go" -width 5
-    bind $w.apply <Return> {
-        [winfo toplevel %W].apply invoke}
- 
-    button $w.cancel    -command "melodic2:destroy $w" \
-        -text "Exit" -width 5
-    bind $w.cancel <Return> {
-        [winfo toplevel %W].cancel invoke}
- 
-    button $w.help -command "FmribWebHelp file: ${FSLDIR}/doc/melodic2/index.html" \
-            -text "Help" -width 5
-    bind $w.help <Return> {
-        [winfo toplevel %W].help invoke}
-
-    pack $w.btns.b -side bottom -fill x
-    pack $w.apply $w.cancel $w.help -in $w.btns.b \
-        -side left -expand yes -padx 3 -pady 10 -fill y
- 
-    pack $w.f $w.btns -expand yes -fill both
-    $w.nb raise data
-#}}}
-}
-
-#}}}
-#{{{ melodic2:updatest
-
-proc melodic2:updatest { w } {
-    global fmri
+set fmri(ostats) 0
+checkbutton $f.ostats -variable fmri(ostats) -text "Output full stats folder"
 
-    if { $fmri(st) == 3 || $fmri(st) == 4 } {
-	pack $w.st_file -in $fmri(stf) -side left -padx 5
-    } else {
-	pack forget $w.st_file
-    }
-    $w.nb compute_size
-}
+balloonhelp_for $f.ostats "
+When switched on, Melodic will save the thresholded IC 
+maps and the probability maps inside a folder \/stats. 
+This will substantially increase the amount of space used, 
+so only switch this on if you intend to use these maps."
 
 #}}}
-#{{{ melodic2:updatebet
-
-proc melodic2:updatebet { w } {
 
-    global fmri
-
-    if { $fmri(bet_yn) == 1 } {
-	pack forget $w.bet.thresh
-    } else {
-	pack $w.bet.thresh -in $w.bet -side left -padx 5 -after $w.bet.yn
-    }
-}
+pack $f.thresh $f.bgimage $f.ostats -in $f -anchor w -side top
 
 #}}}
-#{{{ melodic2:updatedim
-
-proc melodic2:updatedim { w } {
+#{{{ Registration
 
-    global fmri
+set fmri(regf) [ $w.nb getframe reg ]
 
-    if { $fmri(dim_yn) == 1 } {
-	pack forget $w.dim.n
-    } else {
-	pack $w.dim.n -in $w.dim -side left -padx 5 -after $w.dim.yn
-    }
-    $w.nb compute_size
-}
+feat5:reg_gui $w
 
 #}}}
-#{{{ melodic2:updatethresh
 
-proc melodic2:updatethresh { w } {
+set fmri(level) 1
+set fmri(analysis) 7
 
-    global fmri
+set tmpval $fmri(paradigm_hp)
+feat5:updatelevel $w 
+set fmri(paradigm_hp) $tmpval
 
-    if { $fmri(thresh_yn) == 0 } {
-	set fmri(mmthresh) 0
-	pack forget $w.thresh.n
-    } else {
-	set fmri(mmthresh) "0.5"
-	pack $w.thresh.n -in $w.thresh -side left -padx 5 -after $w.thresh.yn
-    }
-}
+$w.nb raise data
 
 #}}}
-#{{{ melodic2:apply
+    #{{{ button Frame
 
-proc melodic2:apply { w dialog } {
-    global fmri HOME FSLDIR INMEDX entries feat_files logout
+frame $w.btns
     
-    for { set session 1 } { $session <= $fmri(multiple) } { incr session 1 } {
-
-	#{{{ setup filenames
-
-set INPUT [ remove_ext $feat_files($session) ]
+button $w.btns.apply -command "melodic:apply $w" -text "Go"
 
-set OUTPUT [ new_filename ${INPUT}.ica ]
-
-if { ! [ file writable [ file dirname $OUTPUT ] ] } {
-    set OUTPUT [ new_filename ${HOME}/[ file tail $OUTPUT ] ]
-}
-
-fsl:exec "mkdir $OUTPUT"
-
-cd $OUTPUT
-
-set logout ${OUTPUT}/report.log
-
-#}}}
-	#{{{ prestats
-
-#{{{ delete volumes
-
-set total_volumes [ exec sh -c "${FSLDIR}/bin/avwnvols $INPUT 2> /dev/null" ]
-
-if { $fmri(ndelete) > 0 } {
-    set total_volumes [ expr $total_volumes - $fmri(ndelete) ]
-    fsl:exec "${FSLDIR}/bin/avwroi $INPUT prefiltered_func_data $fmri(ndelete) $total_volumes"
-    set INPUT prefiltered_func_data
-}
+button $w.btns.save -command "feat_file:setup_dialog $w a a a [namespace current] *.fsf {Save Feat setup} {feat5:write $w 1 1 0} {}" -text "Save"
 
-set target_vol_number [ expr $total_volumes / 2 ]
-fsl:exec "${FSLDIR}/bin/avwroi $INPUT example_func $target_vol_number 1"
+button $w.btns.load -command "feat_file:setup_dialog $w a a a [namespace current] *.fsf {Load Feat setup} {feat5:load $w 1} {}" -text "Load"
 
-#}}}
-#{{{ motion correction
+button $w.btns.cancel -command "destroy $w" -text "Exit"
 
-if { $fmri(mc) != 0 } {
-    fsl:exec "${FSLDIR}/bin/mcflirt -in $INPUT -out prefiltered_func_data_mcf -refvol $target_vol_number" -t 15
-    set INPUT prefiltered_func_data_mcf
-}
+button $w.btns.help -command "FmribWebHelp file: ${FSLDIR}/doc/melodic3/index.html" -text "Help"
 
-#}}}
-#{{{ slice timing correction
+#{{{ Utils
 
-if { $fmri(st) > 0 } {
+menubutton $w.btns.utils -text "Utils" -menu $w.btns.utils.menu -relief raised -bd 2
 
-    set st_opts ""
-    
-    switch $fmri(st) {
-	2 {
-	    set st_opts "--down"
-	}
-	3 {
-	    set st_opts "--ocustom=$fmri(st_file)"
-	}
-	4 {
-	    set st_opts "--tcustom=$fmri(st_file)"
-	}
-    }
+menu $w.btns.utils.menu
 
-    fsl:exec "${FSLDIR}/bin/slicetimer -i $INPUT --out=prefiltered_func_data_st -r $fmri(tr) $st_opts"
-    set INPUT prefiltered_func_data_st
-}
+$w.btns.utils.menu add command -label "High-res FEAT stats colour rendering" -command { exec sh -c "${FSLDIR}/bin/Renderhighres$gui_ext" & }
 
 #}}}
-#{{{ BET
 
-if { $fmri(bet_yn) } {
-    fsl:exec "${FSLDIR}/bin/bet $INPUT prefiltered_func_data_bet -F"
-    set INPUT prefiltered_func_data_bet
-}
+#pack $w.btns.apply $w.btns.save $w.btns.load $w.btns.cancel $w.btns.help $w.btns.utils -in $w.btns -side left -expand yes
+pack $w.btns.apply $w.btns.save $w.btns.load $w.btns.cancel $w.btns.help -in $w.btns -side left -expand yes
 
 #}}}
-#{{{ filtering
-
-set thecommand "${FSLDIR}/bin/ip $INPUT filtered_func_data $fmri(thresh)"
-
-if { $fmri(smooth) > 0.01 } {
-    set thecommand "$thecommand -s [ expr $fmri(smooth) / 2.355 ]"
-}
-
-if { $fmri(temphp_yn) || $fmri(templp_yn) } {
-
-    set hp_sigma_vol -1
-    if { $fmri(temphp_yn) } {
-	set hp_sigma_sec [ expr $fmri(paradigm_hp) / 2.0 ]
-	set hp_sigma_vol [ expr $hp_sigma_sec / $fmri(tr) ]
-    }
-
-    set lp_sigma_vol -1
-    if { $fmri(templp_yn) } {
-	set lp_sigma_sec 2.8
-	set lp_sigma_vol [ expr $lp_sigma_sec / $fmri(tr) ]
-    }
-
-    set thecommand "$thecommand -t $hp_sigma_vol $lp_sigma_vol"
-
-}
-
-fsl:exec "$thecommand"
-
-set INPUT filtered_func_data
 
-#}}}
+    pack $w.nb -in $w -side top -anchor n -padx 10 -pady 10 
+    pack $w.btns -in $w -side bottom -fill x -padx 10 -pady 10 
 
-fsl:exec "rm -rf prefiltered_func_data*"
+    #{{{ load fsf file
 
-#}}}
-	#{{{ MELODIC
+if { $argc > 0 } {
 
-set thecommand "${FSLDIR}/bin/melodic -i $INPUT -o $OUTPUT -v --nobet --bgthreshold=$fmri(thresh) --tr=$fmri(tr)"
+    set inputname [ lindex $argv 0 ]
 
-set job_duration 20
-if { $fmri(dim_yn) == 1 } {
-    set thecommand "$thecommand -d 0"
-    if { $total_volumes > 400 } {
-	set job_duration 180
-    }
-} else {
-    set thecommand "$thecommand -d $fmri(dim)"
-    if { $fmri(dim) > 100 } {
-	set job_duration 180
+    if { [ string first / $inputname ] != 0 && [ string first ~ $inputname ] != 0 } {
+	set inputname ${PWD}/$inputname
     }
-}
-
-if { $fmri(thresh_yn) == 0 } {
-    set thecommand "$thecommand --no_mm"
-} else {
-    set thecommand "$thecommand --mmthresh=\"$fmri(mmthresh)\""
-}
-
-if { $fmri(varnorm) == 0 } {
-    set thecommand "$thecommand --vn"
-}
-
-if { $fmri(report) == 1 } {
-    set thecommand "$thecommand --report"
-}
-
-if { $fmri(ostats) == 1 } {
-    set thecommand "$thecommand --Ostats"
-}
 
-puts $thecommand
-fsl:exec "$thecommand" -t $job_duration
+    if { [ string compare [ file extension $inputname ] .fsf ] == 0 } {
 
-#}}}
-
-	puts "Done"
-
-	if { [ file exists report/00index.html ] } {
-	    puts "To view the output report point your web browser at\n${OUTPUT}/report/00index.html\n\n"
+	if { [ file readable $inputname ] } {
+	    puts "Loading FEAT setup file $inputname"
+	    feat5:load $w 1 $inputname
+	} else {
+	    MxPause "setup file $inputname doesn't exist!"
 	}
     }
 
-
-    update idletasks
-
-    if {$dialog == "destroy"} {
-        melodic2:destroy $w
-    }
 }
 
 #}}}
-#{{{ melodic2:destroy
+    #{{{ updates needed after the loading of settings
 
-# Summary:      Destroys melodic dialog box
-proc melodic2:destroy { w } {
-    destroy $w
+if { $fmri(perfsub_yn) } {
+    pack $fmri(temp).tcmenu -in $fmri(temp) -after $fmri(temp).ps_yn -side top -side left -padx 5
 }
 
 #}}}
-#{{{ call GUI and wait
 
-wm withdraw .
-melodic .rename
-tkwait window .rename
+    feat5:updateanalysis $w
+    $w.nb compute_size
+}
 
-#}}}
+if { ! [ info exists INGUI ] } {
+    wm withdraw .
+    melodic .r
+    tkwait window .r
+}
 
-- 
GitLab