Top Banner
Getting scripted in BrainVoyager QX June 18, 2007
33

Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

Aug 31, 2018

Download

Documents

lenga
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

Getting scripted in BrainVoyager QX

June 18, 2007

Page 2: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

2

Page 3: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

Contents

1 Familiarizing with the scripting environment 51.1 Creating a new scripting project . . . . . . . . . . . . . . . . . . . . 51.2 Appendix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2 The first function 92.1 Showing a messagebox . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.1.1 Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

3 Dealing with filenames 113.0.2 Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

3.1 Appendix: variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

4 Keeping track of the process 154.0.1 Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

5 Preprocessing via scripting 175.1 Slice scan time correction via a script . . . . . . . . . . . . . . . . . 17

5.1.1 Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

6 Preprocessing several FMR projects at once 216.1 Adding the FMR filenames array . . . . . . . . . . . . . . . . . . . . 216.2 Creating the loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

6.2.1 Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236.3 Appendix: arrays and loops . . . . . . . . . . . . . . . . . . . . . . . 24

6.3.1 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246.3.2 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

7 Creating several VTC files at once 297.0.3 Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

7.1 Appendix: arguments . . . . . . . . . . . . . . . . . . . . . . . . . . 33

3

Page 4: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

4 CONTENTS

Introduction

Welcome to the Getting Scripted Guide! Scripting in BrainVoyager QX has manyadvantages. The most obvious advantage is saving time by running processesovernight via scripts. It is easy to learn how to perform this via scripting. Afterpracticing only the first 6 steps of the Getting Scripted Guide it is already possibleto achieve this.The Getting Scripted Guide is created to gain familiarity with scripting in BrainVoy-ager QX in a goal-directed way. An attempt is made to make scripting in BrainVoy-ager QX accessible also for people with little prior knowledge about scripting. Incase the scripting concepts are known already, the appendices can be skipped.

Data

In the following examples we will be using 3 FMR projects that have been createdof the BrainVoyager QX sample data, but it should not be too difficult to apply theprinciples to your own data.

Other sources of information about scripting in BrainVoyager QX

The BrainVoyager QX scripting guide called ’Automation and Scripting guide forBrainVoyager QX’ can downloaded from the BrainVoyager wiki:http://wiki.brainvoyager.com/http://wiki.brainvoyager.com/BVQX_usage_guides . SampleQSA projects and scripts can be obtained from the ’Scripts’ page on the same wiki.

Page 5: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

Chapter 1

Familiarizing with the scriptingenvironment

1.1 Creating a new scripting project

A scripting project (*.qsa) in BrainVoyager QX is a collection of scripts (*.qs). Onlyone scripting project can be opened in BrainVoyager at the time. Each script hasits own name and tab. Open the scripting editor via the ’Edit Scripts...’ function ofthe ’Scripts’ option in the BrainVoyager QX menu (see figure 1.1).

Figure 1.1: Starting the script editor

Create a new script project (*.qsa) via the ’New Script Project’ option of thescript editor menu (see figure 1.2).

Figure 1.2: Creating a new script project in the script editor

Save the script project with the name ’PreprocessingProject’ in the default direc-

5

Page 6: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

6 CHAPTER 1. FAMILIARIZING WITH THE SCRIPTING ENVIRONMENT

tory for scripts and script projects, which is /(My) Documents/BVQXExtensions/Scripts/(see figure 1.3).

Figure 1.3: Location of scripts and script project

Also, give the first script a name. Initially it is called ’untitled.qs’. Save the scriptwith the name ’helpfunctions.qs’ via the ’Rename Script’ function in the ’File’ menu.

Page 7: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

1.2. APPENDIX 7

1.2 Appendix

Functions are a set of instructions to the computer that belong together. It is possi-ble to store several functions in the same script. The script is just a text file with theextension *.qs. In the BrainVoyager QX script editor, scripts appear as tabs (seefigure 1.4).

Figure 1.4: Functions, scripts and scripting projects in the editor

A collection of scripts that can be opened at a time in the BrainVoyager QXscript editor, can be saved as a script project. The scripts can also be savedseparately by using the script editor function ’Export Script’ function in the ’File’menu.A script can be imported in a script project via the function ’Import Script. . . ’ in the’File’ menu option.

Figure 1.5: Functions, scripts and scripting projects

Page 8: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

8 CHAPTER 1. FAMILIARIZING WITH THE SCRIPTING ENVIRONMENT

Page 9: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

Chapter 2

The first function

2.1 Showing a messagebox

A function is a collection of commands that the script editor can execute. It can berecognized via the ’()’. The begin and end of a function is indicated via the brackets{ and }.One script (*.qs) can contain several functions. When the script project is saved,the functions are shown in the ’defined functions’ window on the right side of thescript editor. Also, the functions are shown in the BrainVoyager QX ’Scripts’ menu.Write an empty function show_message() by using the keyword ’function’, thename for the function and the brackets { and }.

Figure 2.1: Function with messagebox

In the function space, type:MessageBox.information("The script will start now");This command instructs the script editor to show a message box with the text

“The script will start now”. Text is always written within double quotes “. . . ” andwill appear green in the script editor. The type of message box is an informationmessage box; this means that an exclamation mark icon is shown to indicate thatthis is very useful information. Always end a command with a semicolon ’;’.

Save the script project via the ’Save’ option in the ’File’ menu option or via thefloppy disk icon. The name of the function, show_message(), will appear in the

Figure 2.2: Activate the messagebox function from the Scripts menu

9

Page 10: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

10 CHAPTER 2. THE FIRST FUNCTION

’Defined functions’ window on the right. Now close the script editor.Activate the show_message() function via the BrainVoyager QX scripts menu:

Figure 2.3: Activate the messagebox function from the Scripts menu

When the function is selected, the message box will pop up:

Figure 2.4: The resulting messagebox

It is also possible to invoke the function by doubleclicking on the function namein the “Defined Functions” window.

2.1.1 Functionfunction show_message() {

MessageBox.information("The script will start now");

}

Page 11: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

Chapter 3

Dealing with filenames

There are several ways to use filenames in scripts, and the most frequently usedway is to write the name explicitly in the script. However, this is prone to errorssince it is easy to make spelling errors, the fileseparators ’/’ can be confusing forWindows users, and when files are moved or renamed the script has to be changedas well.

In this function, a file selection dialog will be used to select a file name.First, open the script editor via Scripts ¿ Edit scripts Create an empty function withthe name retrieve_filename():

We create a variable for the filename with the keyword ’var’:var filename =

A variable is an entity that can change value (see appendix). In this case, wefill the value of the variable ’filename’ via a file selection dialog:

var filename = FileDialog.getOpenFileName();When the function retrieve_filename() is invoked, the FileDialog will per-

form the action getOpenFileName() for us, so that the person who invoked thescript can select a file name at that time.

It is also possible to write the file name in the function itself:var filename = "C:/BVUserCafe/run1/Run1.fmr";

The paths are separated here by a forward slash “/” instead of a backslash“́’. This is the internal representation of the path. It is also possible to use thebackslash as file separator. The name consists of text, text is always written withindouble quotes: " ". In the script editor, text can be recognized easily, because itis shown in green.

Figure 3.1: Function to retrieve a filename

11

Page 12: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

12 CHAPTER 3. DEALING WITH FILENAMES

To prevent problems in scripting, please take care that the path and filenames donot contain spaces. During runtime, when the function retrieve_filename()is activated, the FileDialog will pop up:

Figure 3.2: File dialog from the function FileDialog.getOpenFileName()

The messagebox should show the selected file name (3.3):

Figure 3.3: Message box showing the selected filename

3.0.2 Functionfunction retrieve_filename() {

var filename = FileDialog.getOpenFileName();MessageBox.information ("Filename: " + filename);

}

Page 13: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

3.1. APPENDIX: VARIABLES 13

3.1 Appendix: variables

A variable is an entity that can hold a value. It can be compared to an empty basket,where a text or number can be stored (see left side of figure 3.4). In step 1, theexistence of the variable is declared by the keyword ’var’. In step 2, the variable isgiven the label ’fmrname’. This is the name one refers to in the program. The actualvalue of the variable is assigned in step 3, when variable ’fmrname’ is assigned thevalue c:/studdata/run1/run1.fmr.

Figure 3.4: Three steps to use a variable

Page 14: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

14 CHAPTER 3. DEALING WITH FILENAMES

Page 15: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

Chapter 4

Keeping track of the process

While the functions are being executed automatically, it would be nice to keep trackof the process. One possibility is to write remarks to the BrainVoyager QX Log tab.

One can send a message to BrainVoyager QX to display text in the log tab viathe commandBrainVoyagerQX.PrintToLog("your text goes here"). The parameteris here the same as in step 3: the text "Filename: ", a ’+’ sign to add more text,and the filename variable. Since the Log tab is not always open, first open the Logtab via the instruction BrainVoyagerQX.ShowLogTab(). This function does notask for extra parameters.

Change the function retrieve_filename() that was created in step 3 byadding printing to the Log tab.

Figure 4.1: Printing to the BrainVoyager QX Log tab

15

Page 16: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

16 CHAPTER 4. KEEPING TRACK OF THE PROCESS

4.0.1 Functionfunction retrieve_filename() {

var filename = FileDialog.getOpenFileName();MessageBox.information ("Filename: " + filename);BrainVoyagerQX.ShowLogTab();BrainVoyagerQX.PrintToLog("Filename: " + filename);

}

Page 17: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

Chapter 5

Preprocessing via scripting

This part describes one scripting exercise. The goal is to get an introduction topreprocessing via scripting, so that it will be possible to use this for your own datalater; the other preprocessing methods and much more is described in the Brain-Voyager QX scripting guide.

5.1 Slice scan time correction via a script

If the script editor was closed, open it via the Edit Scripts option of the Scriptsmenu. Create a new script via File > New script (see figure 5.1):

Figure 5.1: Creating a new script (*.qs)

Call the script preprocessing.qs. Create a new empty function called preprocess()(see figure 5.2):

Write a command to get the filename of an FMR project, like in the previousexercise:

var fmrfilename = FileDialog.getOpenFileName("*.fmr");This command will show the file dialog when the function ’preprocess()’ is exe-

cuted. In this case, we use a filter “*.fmr” so that only *.fmr files show up.Please note that in case a function does not seem to work, be sure that the error ismost likely to be just a spelling error, so don’t give up if something like that happensand just check if everything is spelled correctly and that the names of variables areconsistent. For the proper spelling of the scripting language, it is also possible tocheck the scripting guide.

Now we have the name of the FMR project, we can open it via the commandvar fmrproject = BrainVoyagerQX.OpenDocument(fmrfilename);

We will now apply slice scan time correction via scripting. The fmrproject vari-able has its own properties and functions, so we can use these. They will automati-

17

Page 18: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

18 CHAPTER 5. PREPROCESSING VIA SCRIPTING

Figure 5.2: Creating an empty function

Figure 5.3: Selecting the CorrectSliceTiming() function

cally appear when typing the ’.’ after ’fmrproject’. Select the CorrectSliceTiming()function (figure 5.3):

When the function is selected, the script editor also indicates which parame-ters the function needs to know to execute the function properly. In the case ofslice time correction, these parameters are shown in step 5 of the ’Preprocessingof FMR Projects’ (page 22 of the Getting Started Guide). The parameters are theinterpolation method and the slice scanning order. In the case of the BrainVoyagersample data, the slice scanning order is ascending interleaved for Siemens data.We will use the sinc interpolation method.In the scripting guide, the numbers belonging to the parameters are shown (chap-ter 1, section ’Preprocessing and intrasession alignment’, topic ’Slice scan timecorrection’). For interpolation, this is ’0’ for trilinear interpolation and ’1’ for sincinterpolation. The ’ascending interleaved 2’ method has value ’2’.The slice time correction method returns a Boolean value (true or false) whetherthe function succeeded, so we add ’var success’ on the left hand side:

For the preprocessing via scripting, BrainVoyager has a special command thatprovides the name of the preprocessed file. This can be done by asking the currentFMR project what is the preprocessed name (5.5):

We give the slice time corrected FMR the name ’nameofslicetimecorrectedfmr’.The name of the preprocessed FMR does not contain the path. We can nowclose the ’run1.fmr’ project via the command ’fmrproject.Close()’. The slice timecorrected FMR file is written to the hard disk, and the original FMR should still bevisible in the BrainVoyager QX window.

Page 19: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

5.1. SLICE SCAN TIME CORRECTION VIA A SCRIPT 19

Figure 5.4: var success on the left-hand side (lhs)

Figure 5.5: The preprocessed name property

5.1.1 Functionvar preprocess() {

var fmrfilename = retrieve_filename();var fmrproject = BrainVoyagerQX.OpenDocument(fmrfilename);var success = fmrproject.CorrectSliceTiming(2,1);var nameofslicetimecorrectedfmr = fmrproject.FileNameOfPreprocessdFMR;fmrproject.Close();

}

Page 20: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

20 CHAPTER 5. PREPROCESSING VIA SCRIPTING

Page 21: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

Chapter 6

Preprocessing several FMRprojects at once

In this step, we will perform slice scan time correction for several FMR projects atonce. The principles learned in this step can be applied to any kind of repeatedactions. To perform several times the same action, we only need to add 2 ingre-dients to our preprocess() function from step 5: an array and a loop. In the array,we store our FMR project names. An array is a stack of variables that can beconsidered as shelves. On each layer, we can store exactly one value. The loopis used to pick every time another value in the array. To start, create an emptyfunction with the name preprocess_fmrs(). Later we will copy relevant text ofthe preprocess() function.

6.1 Adding the FMR filenames array

First, create the empty array via ”var fmrnames = new Array(2)”. When the size ofthe array is indicated initially, it is easy to assign values to each layer of the arrayvia the square brackets [ ]. In the QSA scripting language that is used in Brain-Voyager, the first layer of the array is value 0, say, the ground floor. Therefore, touse the array, start always counting from 0. In other programming languages andconventions, this can be different. For example in Matlab one starts counting at 1.Assign the first value to the array viafmrnames[0] = FileDialog.OpenDocument("*.fmr", "Please open the first fmr");.Do the same for layer 1 and layer 2 (figure 6.1):

Figure 6.1: Create the array for fmr filenames and provide a mechanism to retrievethe filenames

Now the array is ready, and when the function is invoked, a file dialog will popup 3 times, with the title “Please open the first/second/third fmr”. Because this isthe first thing that is done in the function, everything later in the function can goautomatically and users do not need to be interrupted between preprocessing of

21

Page 22: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

22 CHAPTER 6. PREPROCESSING SEVERAL FMR PROJECTS AT ONCE

Figure 6.2: Create the empty loop

different fmr files. If you want, you can also manually type the name of the fmr files,like is shown in appendix 6a.

6.2 Creating the loop

We would like to ask the values stored in our FMR filenames array several times.Therefore the loop is introduced. For a loop, the following elements are required:

1. a start value

2. a stopping criterion

3. the step size

In QSA language, this is written in the following way:var counter; for (start value; stopping criterion; step size) {

}

In this case, the counter starts at 0. Give the counter the start value 0 viacounter = 0;. The loop stops when the length of the array has been reached.This stopping criterion is 3, because after layer 2 there are no values in the arrayany more. When the function is running, the length of the array can be determined,because it is a property of arrays. Refer to the length property via ¡array¿.¡length¿.Use this principle in the function as counter < fmrnames.length;. The counteris always incremented with 1. This can be written as ’counter++’, which means’counter + 1’. For an illustration of the loop concept, please see appendix 6b. Now,our empty loop looks like this (6.2):

Now copy last 4 lines of the preprocess() function, starting with ’var fmrproject’ in the for loop of the preprocess_fmrs() function, so that these instructionsare executed each time until the counter stops counting.

The only thing left to do now, is to change the single variable ’fmrfilename’ tothe array variable ’fmrnames’. In the square brackets [ ] of the fmrnames array,we place the counter. Save the function and run it from the BrainVoyager ’Scripts’menu option or by doubleclicking on the preprocess_fmrs() function in the’Defined Functions’ window of the script editor. In the data folders, the slice scantime corrected files can be found with the addition _SCSAI2.

Page 23: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

6.2. CREATING THE LOOP 23

6.2.1 Functionfunction preprocess_fmrs() {

var fmrnames = new Array(3);fmrnames[0] = FileDialog.getOpenFileName("*.fmr", "Please open the first fmr");fmrnames[1] = FileDialog.getOpenFileName("*.fmr", "Please open the second fmr");fmrnames[2] = FileDialog.getOpenFileName("*.fmr", "Please open the third fmr");

var counter;for (counter = 0; counter < fmrnames.length; counter++) {

var fmrproject = BrainVoyagerQX.OpenDocument(fmrnames[counter]);var success = fmrproject.CorrectSliceTiming(2,1);var nameofslicetimecorrectedfmr = fmrproject.FileNameOfPreprocessdFMR;fmrproject.Close();

}

}

Page 24: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

24 CHAPTER 6. PREPROCESSING SEVERAL FMR PROJECTS AT ONCE

6.3 Appendix: arrays and loops

6.3.1 Arrays

Creating the arrayAn array is a stack of values. It can be considered as shelves, where one can

store several values of the same kind. Just like in one-valued variables, first de-clare its existence with the keyword ’var’; for arrays, also ’new Array()’ has to beadded on the right hand side. The name given to this array is ’fmrnames’. In theexample below, the size of the array is immediately provided (by the number 3).This means that there are 3 levels.In QSA, one starts counting at 0 (see step one of figure 6.3). One can onlyaccess one level of the array at a time. The current level of array ’fmrnames’will be determined by the value of the variable ’counter’. In step 2, the valuec:/studdata/run1/run1.fmr is assigned to level 0 of the array. In step 3,the value c:/studdata/run2/run2.fmr is assigned to level 1 of the array. Instep 4, the value c:/studdata/run3/run3.fmr is assigned to level 2 of thearray.

Figure 6.3: Creating an array in 4 steps

Using the array

6.3.2 Loops

To access the values that are stored in an array, a loop can be used. The counter,which was introduced in step 1, starts counting at 0 (step 2). Each time a walk ismade to the shelves to pick the value of the layer that the counter indicates, thevalue of the counter is incremented by 1. This is indicated by ’++’.In the first walk, the value at level 0 is retrieved by asking the value of fmrnames[0],which isc:/studdata/run1/run1.fmr. When this also has been done for fmrnames[1]

Page 25: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

6.3. APPENDIX: ARRAYS AND LOOPS 25

Figure 6.4: Indicate that a variable with the name ’counter’ will be used

Page 26: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

26 CHAPTER 6. PREPROCESSING SEVERAL FMR PROJECTS AT ONCE

Figure 6.5: The initial value of the variable ’counter’ is set to 0

and fmrnames[2], the stop value is reached. The stop value, in step 4, is the lengthof the array, which is 3, because there are 3 layers.

Page 27: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

6.3. APPENDIX: ARRAYS AND LOOPS 27

Figure 6.6: Looping through the levels of the array

Page 28: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

28 CHAPTER 6. PREPROCESSING SEVERAL FMR PROJECTS AT ONCE

Page 29: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

Chapter 7

Creating several VTC files atonce

In this step, we use the same array and loop concepts as in the previous step, butnow apply them for creating VTC files.Via scripting, one can create VTC files in VMR, AC-PC and Talairach space. Whatwe will do now here, is creating 3 VTC files in Talairach space.First, create an empty script called ’quickvtcs.qs’. Then, create an empty func-tion called Create_quickly_3_VTCs(). In this function, we will create theVTC files with the BrainVoyager QX scripting command for Talairach space:var success = vmrproject.CreateVTCInTALSpace( <arguments> ); The arguments are thesame as the ones required via the BrainVoyager QX user interface (see also the ap-pendix). When BrainVoyager will create the VTCs, it needs to know the name of theFMR project, the initial alignment transformation file, the fine alignment transforma-tion file, the AC-PC alignment transformation file, the file with Talairach landmarks(*.tal) and a name for the newly created VTC. Because typing all filenames is a lotof error-prone work, we’ll simply use the FileDialog as in the previous steps. TheFMR dialog will pop up 3 times, as well as the dialogs to enter a new VTC name.Because we use the same transformation and Talairach files for all 3 dialogs, thesefiles need to be selected only once.

Because we need to address our request to create VTCs to a BrainVoyagerVMR project, write a line to get a vmr file name via a file dialog. Call the variablethat holds the name vmrname. Then, write code to open the VMR project whenthe function is invoked by providing the OpenDocument() function the name:

var docVMR = BrainVoyagerQX.OpenDocument(vmrname);The CreateVTCInTALSpace() function does not only want to know the FMR,

Talairach and transformation files that should be used, but also the resolution of

29

Page 30: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

30 CHAPTER 7. CREATING SEVERAL VTC FILES AT ONCE

Figure 7.1: (Should be performed 3 times)

the VTCs, the interpolation method and the bounding box intensity threshold. Inthe BrainVoyager QX user interface, these values can be set via the ’Create VTCOptions’ dialog (see right part of table). We create 3 variables that keep thesevalues. Then, we select the space.

var res = 3;The resolution variable is called ’res’ and its value is set to ’3’, reflecting the 3x3x3mm value in the dialog.

var interp = 1;The interpolation variable is called ’interp’ and its value is set to ’1’. This is trilinearinterpolation.

var bbithresh = 100;The bounding box intensity threshold is set by default to 100 in the user interface,so we’ll do the same.

docVMR.ExtendedTALSpaceForVTCCreation = false;Then, we’ll choose the VTC not to be in an extended space. This is done by settingthe VMR property ’ExtendedTALSpaceForVTCCreation’ to ’false’.

Now the function is almost ready. Since all the filenames and parameters are

Page 31: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

31

collected in the function, the only thing left to do is use the function CreateVTCIn-TALSpace() for the 3 FMR projects. This can be performed via the command:

var success = docVMR.CreateVTCInTALSpace(fmrName1, IA, FA, ACPC, TAL, newVTCname1, res, interp, bbithresh);

Page 32: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

32 CHAPTER 7. CREATING SEVERAL VTC FILES AT ONCE

7.0.3 Functionfunction Create_quickly_3_VTCs() {

var fmrName1 = FileDialog.getOpenFileName("*.fmr", "Please select FMR 1");var fmrName2 = FileDialog.getOpenFileName("*.fmr", "Please select FMR 2");var fmrName3 = FileDialog.getOpenFileName("*.fmr", "Please select FMR 3");var IA = FileDialog.getOpenFileName("*_IA.trf");var FA = FileDialog.getOpenFileName("*_FA.trf");var ACPC = FileDialog.getOpenFileName("*_ACPC.trf");var TAL = FileDialog.getOpenFileName("*.tal");var newVTCname1 = FileDialog.getSaveFileName("*.vtc", "Please enter a name for VTC 1");var newVTCname2 = FileDialog.getSaveFileName("*.vtc", "Please enter a name for VTC 2");var newVTCname3 = FileDialog.getSaveFileName("*.vtc", "Please enter a name for VTC 3");

var vmrname = FileDialog.getOpenFileName("*.vmr", "Please select the VMR");var docVMR = BrainVoyagerQX.OpenDocument(vmrname);

var res = 3;var interp = 1;var bbithresh = 100;docVMR.ExtendedTALSpaceForVTCCreation = false;

var success = docVMR.CreateVTCInTALSpace(fmrName1, IA, FA, ACPC, TAL, newVTCname1, res, interp, bbithresh);var success = docVMR.CreateVTCInTALSpace(fmrName2, IA, FA, ACPC, TAL, newVTCname2, res, interp, bbithresh);var success = docVMR.CreateVTCInTALSpace(fmrName3, IA, FA, ACPC, TAL, newVTCname3, res, interp, bbithresh);

}

Page 33: Getting scripted in BrainVoyager QXsupport.brainvoyager.com/...Scripts/gettingscriptedguideforbvqx... · 5.1 Slice scan time correction via a script ... 6 Preprocessing several FMR

7.1. APPENDIX: ARGUMENTS 33

7.1 Appendix: arguments

The argument(s) are the input for a function that can be entered via the valuesbetween ’( )’. To use a function without arguments, the parentheses to invoke thefunction can be left empty: ’function()’. Some functions cannot process withoutfurther information. For these functions, the extra information can be passed as ar-guments. They can be written between parentheses: function(information),for exampledocVMR.CreateVTCInTALSpace(fmrName, IA, FA, ACPC, TAL, newVTCname, res, interp, bbithresh);.In the figure 7.2 on the right is shown that only a VMR project can use the func-tion to create a VTC. The show_message() function can be used by anotherfunction or directly from the BrainVoyager QX ’Scripts...’ menu. The result of theshow_message() function is that it shows a message box. It does not return avalue. The result of the CreateVTCInTALSpace() function is that it creates aVTC file. It also returns a boolean value ’success’, which can be true or false. Thisvalue indicates whether the creation of the VTC file succeeded.

Figure 7.2: Input (arguments) and output of a function