Skip to content
Snippets Groups Projects
melodic.tcl 11.8 KiB
Newer Older
Mark Jenkinson's avatar
Mark Jenkinson committed
#
Stephen Smith's avatar
Stephen Smith committed
#   GUI for MELODIC
#
#   Stephen Smith & Christian Beckmann, FMRIB Analysis Group
Mark Jenkinson's avatar
Mark Jenkinson committed
#
Stephen Smith's avatar
Stephen Smith committed
#   Copyright (C) 1999-2007 University of Oxford
Mark Jenkinson's avatar
Mark Jenkinson committed
#
#   TCLCOPYRIGHT
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
source [ file dirname [ info script ] ]/fslstart.tcl
Mark Jenkinson's avatar
Mark Jenkinson committed
set VARS(history) {}

Stephen Smith's avatar
Stephen Smith committed
#{{{ melodic:updatelevel

proc melodic:updatelevel { w } {

    global fmri

    feat5:updatereg $w

    pack forget $fmri(poststatsf).models.subject_mat $fmri(poststatsf).models.subject_con
    if { $fmri(icaopt) > 1 } {
	pack $fmri(poststatsf).models.subject_mat $fmri(poststatsf).models.subject_con -in $fmri(poststatsf).models -after $fmri(poststatsf).models.ts_con -anchor w -side top
    }

    $w.nb compute_size
}

#}}}
Stephen Smith's avatar
Stephen Smith committed
#{{{ melodic:updatedim
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
proc melodic:updatedim { w } {
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
    global fmri
    set f $fmri(statsf)
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
    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
}
Mark Jenkinson's avatar
Mark Jenkinson committed

#}}}
Stephen Smith's avatar
Stephen Smith committed
#{{{ melodic:updatethresh
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
proc melodic:updatethresh { w } {
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
    global fmri
    set f $fmri(poststatsf).thresh
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
    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
    }
}
Mark Jenkinson's avatar
Mark Jenkinson committed

#}}}
Stephen Smith's avatar
Stephen Smith committed
#{{{ melodic:apply
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
proc melodic:apply { w } {
    global fmri feat_files unwarp_files unwarp_files_mag initial_highres_files highres_files FSLDIR HOME
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
    if { [ feat5:write $w 0 1 1 $fmri(feat_filename) ] } {
	return 1
    }
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
    set FSFROOT [ file rootname $fmri(feat_filename) ]
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
    catch { exec sh -c "$FSLDIR/bin/feat $FSFROOT" & } junk
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
    set fmri(feat_filename) [ exec sh -c "${FSLDIR}/bin/tmpnam /tmp/feat" ].fsf
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
    update idletasks
}
Mark Jenkinson's avatar
Mark Jenkinson committed

#}}}

Stephen Smith's avatar
Stephen Smith committed
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
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
feat5:setupdefaults
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
set tempSpin -1
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
toplevel $w
Mark Jenkinson's avatar
Mark Jenkinson committed

catch { exec sh -c "${FSLDIR}/bin/melodic -V | grep '\[0-9\]'" } melodicversion
set fmri(version) [ lindex $melodicversion 2 ]
Mark Jenkinson's avatar
Mark Jenkinson committed

wm title      $w $melodicversion
wm iconname   $w $melodicversion
Stephen Smith's avatar
Stephen Smith committed
wm iconbitmap $w @${FSLDIR}/tcl/fmrib.xbm
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
set fmri(inmelodic) 1
set fmri(level) 1
set fmri(analysis) 7
set fmri(icaopt) 1
set fmri(regstandard_res) 4
Mark Jenkinson's avatar
Mark Jenkinson committed

#}}}
Stephen Smith's avatar
Stephen Smith committed
    #{{{ notebook
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
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"
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
#{{{ Misc
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
set fmri(miscf) [ $w.nb getframe misc ]
Stephen Smith's avatar
Stephen Smith committed
feat5:misc_gui $w
Stephen Smith's avatar
Stephen Smith committed
#}}}
#{{{ Data
Stephen Smith's avatar
Stephen Smith committed
set fmri(dataf) [ $w.nb getframe data ]
Stephen Smith's avatar
Stephen Smith committed
feat5:data_gui $w
Stephen Smith's avatar
Stephen Smith committed
#{{{ Pre-ICA
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
set fmri(filteringf) [ $w.nb getframe filtering ]
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
feat5:prestats_gui $w
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
#}}}
#{{{ ICA
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
set fmri(statsf) [ $w.nb getframe stats ]
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
set f $fmri(statsf)
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
#{{{ variance normalisation
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
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. "
Stephen Smith's avatar
Stephen Smith committed
#}}}
#{{{ output components
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
frame $f.dim
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
set fmri(dim_yn) 1
checkbutton $f.dim.yn -variable fmri(dim_yn) -text "Automatic dimensionality estimation" -command "melodic:updatedim $w"
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
pack $f.dim.yn -in $f.dim -side left
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
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."
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
set fmri(dim) 1
LabelSpinBox $f.dim.n -label "Output components" -textvariable fmri(dim) -range { 1 200000 1}
Mark Jenkinson's avatar
Mark Jenkinson committed

#}}}
Stephen Smith's avatar
Stephen Smith committed
#{{{ ICA level
Mark Jenkinson's avatar
Mark Jenkinson committed

optionMenu2 $f.icaopt fmri(icaopt) -command "melodic:updatelevel $w" 1 "Single-session ICA" 2 "Multi-session temporal concatenation" 3 "Multi-session Tensor-ICA"
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
balloonhelp_for $f.icaopt "
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
Here you can select the kind of ICA-based analysis you want to run.
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
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.
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
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.
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
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.
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
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."
Stephen Smith's avatar
Stephen Smith committed
pack $f.varnorm $f.dim $f.icaopt -in $f -anchor w -side top
Mark Jenkinson's avatar
Mark Jenkinson committed

#}}}
Stephen Smith's avatar
Stephen Smith committed
#{{{ Post-ICA
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
set fmri(poststatsf) [ $w.nb getframe poststats ]
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
set f $fmri(poststatsf)
Mark Jenkinson's avatar
Mark Jenkinson committed

#{{{ thresholding

Stephen Smith's avatar
Stephen Smith committed
frame $f.thresh
Mark Jenkinson's avatar
Mark Jenkinson committed

set fmri(thresh_yn) 1
Stephen Smith's avatar
Stephen Smith committed
checkbutton $f.thresh.yn -variable fmri(thresh_yn) -text "Threshold IC maps" -command "melodic:updatethresh $w"
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
balloonhelp_for $f.thresh "MELODIC uses a mixture model approach to assign significance to individual 
Mark Jenkinson's avatar
Mark Jenkinson committed
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. 

Stephen Smith's avatar
Stephen Smith committed
From this mixture model fit, MELODIC calculates voxel-wise probabilities 
Mark Jenkinson's avatar
Mark Jenkinson committed
of 'activation' (as the ratio of a voxels' intensity being in the 
non-background class relative to probability of the intensity being 
background noise).
Voxels above a certain threshold level are overlayed on top of 
an example volume. The default level of 0.5 will report any voxel 
where the probability of belonging to the non-background mixtures 
exceeds the probability of the voxel belonging to the background 
noise Gaussian."

Stephen Smith's avatar
Stephen Smith committed
set fmri(mmthresh) 0.5
Stephen Smith's avatar
Stephen Smith committed
entry $f.thresh.n -textvariable fmri(mmthresh) -width 10
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
pack $f.thresh.yn $f.thresh.n -in $f.thresh -side left
Mark Jenkinson's avatar
Mark Jenkinson committed

#}}}
Stephen Smith's avatar
Stephen Smith committed
#{{{ background image for group stats
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
frame $f.bgimage
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
label $f.bgimage.label -text "Background image "
Stephen Smith's avatar
Stephen Smith committed
optionMenu2 $f.bgimage.menu fmri(bgimage) 1 "Mean highres" 3 "Mean functional" 5 "Standard space template"
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
pack $f.bgimage.label $f.bgimage.menu -in $f.bgimage -side top -side left
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
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.
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
You can alternatively choose to use the original lowres functional
data for the overlays, or the standard-space template image."
Mark Jenkinson's avatar
Mark Jenkinson committed

#}}}
Stephen Smith's avatar
Stephen Smith committed
#{{{ output options
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
set fmri(ostats) 0
checkbutton $f.ostats -variable fmri(ostats) -text "Output full stats folder"
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
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."
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
#}}}
#{{{ model

frame $f.models

FileEntry $f.models.ts_mat      -textvariable fmri(ts_model_mat)      -label " Timeseries model                 " -title "Timeseries design.mat model" -width 35 -filedialog directory -filetypes *.mat
FileEntry $f.models.ts_con      -textvariable fmri(ts_model_con)      -label " Timeseries contrasts           " -title "Timeseries design.con contrasts" -width 35 -filedialog directory -filetypes *.con
FileEntry $f.models.subject_mat -textvariable fmri(subject_model_mat) -label " Session/subjects model       " -title "Session/subjects design.mat model" -width 35 -filedialog directory -filetypes *.mat
FileEntry $f.models.subject_con -textvariable fmri(subject_model_con) -label " Session/subjects contrasts " -title "Session/subjects design.con contrasts" -width 35 -filedialog directory -filetypes *.con

balloonhelp_for $f.models "If you select a timeseries \"design.mat\" model and \"design.con\"
contrast file (e.g. as used in a first-level FEAT model-based FMRI
analysis), these will be used by MELODIC in ordering the ICA
components, and in providing richer timeseries reporting information.

If you are doing multi-session/multi-subjects ICA, you can also
optionally select a subject \"design.mat\" model and \"design.con\"
contrast file (e.g. as used in a higher-level FEAT model-based FMRI
analysis). These will be used by MELODIC in ordering the ICA
components, and in providing richer reporting information about the
multiple sessions/subjects."

pack $f.models.ts_mat $f.models.ts_con -in $f.models -anchor w -side top

Mark Jenkinson's avatar
Mark Jenkinson committed
#}}}

Stephen Smith's avatar
Stephen Smith committed
pack $f.thresh $f.bgimage $f.ostats -in $f -anchor w -side top
Stephen Smith's avatar
Stephen Smith committed
pack $f.models -in $f -anchor w -side top -pady 20
Mark Jenkinson's avatar
Mark Jenkinson committed

#}}}
Stephen Smith's avatar
Stephen Smith committed
#{{{ Registration
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
set fmri(regf) [ $w.nb getframe reg ]
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
feat5:reg_gui $w
Stephen Smith's avatar
Stephen Smith committed
set fmri(level) 1
set fmri(analysis) 7
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
set tmpval $fmri(paradigm_hp)
feat5:updatelevel $w 
set fmri(paradigm_hp) $tmpval
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
$w.nb raise data
Mark Jenkinson's avatar
Mark Jenkinson committed

#}}}
Stephen Smith's avatar
Stephen Smith committed
    #{{{ button Frame
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
frame $w.btns
Mark Jenkinson's avatar
Mark Jenkinson committed
    
Stephen Smith's avatar
Stephen Smith committed
button $w.btns.apply -command "melodic:apply $w" -text "Go"
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
button $w.btns.save -command "feat_file:setup_dialog $w a a a [namespace current] *.fsf {Save Feat setup} {feat5:write $w 0 1 0} {}" -text "Save"
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
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"
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
button $w.btns.cancel -command "destroy $w" -text "Exit"
Matthew Webster's avatar
Matthew Webster committed
button $w.btns.help -command "FmribWebHelp file: ${FSLDIR}/doc/redirects/melodic.html" -text "Help"
Stephen Smith's avatar
Stephen Smith committed
#{{{ Utils
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
menubutton $w.btns.utils -text "Utils" -menu $w.btns.utils.menu -relief raised -bd 2
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
menu $w.btns.utils.menu
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
$w.btns.utils.menu add command -label "High-res FEAT stats colour rendering" -command { exec sh -c "${FSLDIR}/bin/Renderhighres$gui_ext" & }
Stephen Smith's avatar
Stephen Smith committed
#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
Stephen Smith's avatar
Stephen Smith committed
    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 
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
    #{{{ load fsf file
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
if { $argc > 0 } {
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
    set inputname [ lindex $argv 0 ]
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
    if { [ string first / $inputname ] != 0 && [ string first ~ $inputname ] != 0 } {
	set inputname ${PWD}/$inputname
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
    if { [ string compare [ file extension $inputname ] .fsf ] == 0 } {
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
	if { [ file readable $inputname ] } {
	    puts "Loading FEAT setup file $inputname"
	    feat5:load $w 1 $inputname
	} else {
	    MxPause "setup file $inputname doesn't exist!"
Stephen Smith's avatar
Stephen Smith committed
    #{{{ updates needed after the loading of settings
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
if { $fmri(perfsub_yn) } {
    pack $fmri(temp).tcmenu -in $fmri(temp) -after $fmri(temp).ps_yn -side top -side left -padx 5
Stephen Smith's avatar
Stephen Smith committed
    melodic:updatelevel $w
Stephen Smith's avatar
Stephen Smith committed
    feat5:updateanalysis $w
    $w.nb compute_size
}
Mark Jenkinson's avatar
Mark Jenkinson committed

Stephen Smith's avatar
Stephen Smith committed
if { ! [ info exists INGUI ] } {
    wm withdraw .
    melodic .r
    tkwait window .r
}
Mark Jenkinson's avatar
Mark Jenkinson committed