The script presented in this section is already a really useful script for the repeated application of basic fMRI analysis steps. You might want to use the script as a template for developing your own scripts. You find the script in the xx folder under the name "PreprocessSubjects.vbs". Only the VBScript version is presented but you should have no problems to transform it into JScript or PerlScript.
This script demonstrates the most important steps for preprocessing fMRI data. It runs across several subjects each having several runs. It finds the data of each subject by building the correct pathes and filenames by using information about subjects and runs. This requires, of course, that a consistent scheme for saving data to disk must exist. The script starts with FMR files and produces preprocessed FMR files as well as VTC files. You will find other scripts which demonstrate how FMR files and other documents are created from raw data. Files which can not yet be created via scripts (i.e. stimulation protocol files, spatial transformation files) must be created first and are here provided as input.
TIP You might want to load the actual script file into BrainVoyager in order to get a more readable colour-coded version.
' PreprocessSubjects.vbs
Set BrainVoyager = CreateObject("BrainVoyager.1")
' Get the path to the script file (function
defined below)
path_root = GetScriptPath()
Dim
SubjectList
SubjectList = Array("IG",
"JB", "JW", "MW")
' Outer loop runs across subjects in array "SubjectList"
For Each Subject In
SubjectList
path = path_root + Subject + "\"
' Inner loop runs across all runs of
a subject within a session
For run = 1 To
4
' Create the file name to an fmr file
FMR_file = Subject + "_Run" + CStr(run)
+ ".fmr"
Set doc = BrainVoyager.OpenDocument(path + FMR_file)
doc.LinkStimulationProtocol
path + "allgemein.prt"
doc.SetZoomLevel
2
'Create the file name for the new preprocessed FMR file
NewFMRfile = Subject + "_Run" + Cstr(run)
+ "_sc.fmr"
NewSTCprefix = "R" + CStr(run)
+ "_slice_sc-"
doc.SliceTimeCorrection
2081, 100, 0, NewFMRfile, NewSTCprefix
doc.Close
pathToVMR = path + "3DT1\"
VMRfile = Subject + "_3DT1.vmr"
Set docVMR =
BrainVoyager.OpenDocument(pathToVMR
+ VMRfile)
VTCfile = Subject + "_Run" + CStr(run)
+ "_sc.vtc"
TRF2D3Dfile = Subject + "_2D3D_Run" + CStr(run) + ".trf"
TRFACPCfile = Subject + "_3DT1_acpc.trf"
TALfile = Subject + "_3DT1_tal.tal"
Call docVMR.CreateVTC(path + NewFMRfile, pathToVMR
+ TRF2D3Dfile, _
Call docVMR.CreateVTC(pathToVMR
+ TRFACPCfile, pathToVMR + TALfile, path + VTCfile)
docVMR.Close
VMRfile = Subject + "_3DT1_tal.vmr"
Set doc = BrainVoyager.OpenDocument(pathToVMR + VMRfile)
Call doc.LinkVTC(path + VTCfile, 0)
Call doc.MotionCorrection3D()
Call doc.TemporalSmoothingFD3D(3, 260)
Call doc.SpatialSmoothingFD3D(1, 14)
doc.Close
Next
Next
BrainVoyager.Exit
' A function to retrieve the path to the script
file
' using either BrainVoyager or the WScript object
Function GetScriptPath()
If BrainVoyager.ScriptLaunchedByBV()
Then
GetScriptPath = BrainVoyager.GetCurrentFolder()
Else
ScriptName = WScript.ScriptFullName
GetScriptPath = Left(ScriptName,
InstrRev(ScriptName, "\"))
End If
End Function