Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
PSYCH 727
OUTLINE FOR THIS LAB The purpose of this laboratory session is to familiarise you with the Linux environment and the shell, MATLAB, and the data we are working with (fMRI images). Today we will cover: 1. Setting Up Remote Access to the Lab VM 2. Linux file structure 3. Introduction to Linux and the Shell 4. Introduction to MATLAB 5. Introduction to MRI data 1. SETTING UP REMOTE ACCESS TO THE LAB VM To begin, we have to access the Virtual Machine (VM) we have set up for storing and analysing data in this course. To do so, follow these steps: • Open x2go • Enter the following settings for your session o Host = fospsychprd01.its.auckland.ac.nz o Session type = XFCE • Log into your session with your UoA password 2 • Open a Terminal Window (look for the computer screen icon at the top of your VM session) 2. LINUX FILE STRUCTURE / (root) bin course home rrob042 jblo001 At the top of the file structure in Linux is the root directory that holds everything else. We refer to it using a slash character / on its own; this is the leading slash in for instance the following path: /home/rrob042. The home directory path looks different on different operating systems. On Linux it looks like e.g. /home/rrob042, whereas on Windows it would be C:\Users\rrob042. When you start the shell, you are in your home directory by default, but for this course we will actually not work in our home directories (we will work in /course, see below). Inside the root directory are several other directories, such as bin, which is where some built- in programs are stored. We have created another directory called course to store all course materials. / (root) bin course home Data Software UserFolders 3 $ $ whoami rrob042 dadd001 rrob042 In course there are several folders: Data, install, Software, and UserFolders. Inside UserFolders you will find a directory that is named after your UPI; this is the directory in which you will be working during this course. So instead of e.g. /home/rrob042 we will be working in /course/UserFolders/rrob042. 3. INTRODUCTION TO THE LINUX SHELL Linux is an open source operating system that was developed in the mid-1990s. It is a powerful tool as you can do complex things with a few keystrokes. It is very useful for neuroimaging where we have thousands of files per participant (e.g., you can rename all files with one command). The “shell” (also known as “bash”) is the way in which the user communicates with the computer. We type commands into the shell, the shell “translates” these commands and orders the computer to execute the command (usually to run a programme or “script”). It is called a “shell” because it encases the complexities of the operating system so it is easier to interact with. Basic Shell Commands: Navigation The part of the operating system responsible for managing files and directories is called the file system. It organizes our data into files, which hold information, and directories (also called “folders”), which hold files or other directories. Several commands are used to create, inspect, rename, and delete files and directories. To start exploring them, we will use a shell window: The dollar sign (or another character) is a prompt, which shows us that the shell is waiting for input; your shell may also add information (e.g., your user name) before the prompt. When typing in commands listed here, do not type the prompt, only the commands that follow it. Type the command whoami, then press the Enter key to send the command to the shell. The command’s output is the ID of the current user, i.e., it shows us who the shell thinks we are: When we type whoami, the shell: • finds a program called whoami, • runs that program, • displays that program’s output, then • displays a new prompt to tell us that it’s ready for more commands. 4 $ pwd /Users/rrob042 $ ls Desktop media $ cd Desktop $ cd rrob042 -bash: cd: rrob042: No such file or directory $ cd .. $ pwd /Users/rrob042 Next, let’s find out where we are by running a command called pwd (which stands for “print working directory”). At the moment, our current working directory is our default directory, i.e., the home directory. Here, the computer’s response is /Users/rrob042, which is my home directory: Now let’s learn the command that will let us see the contents of our own filesystem. We can see what’s in our home directory by running ls, which stands for “listing”: Now we can change our location to a different directory, so we are no longer located in our home directory. The command to change locations is cd followed by a directory name to change our working directory. cd stands for “change directory”, which is a bit misleading: the command doesn’t change the directory, it changes the shell’s idea of what directory we are in. Let’s say we want to move to the Desktop. We can use the following command to get there: We now know how to go down the directory tree: how do we go up? We might try: Why do we get this error? With our methods so far, cd can only see sub-directories inside your current directory. There are different ways to see directories above your current location; we’ll start with the simplest. There is a shortcut in the shell to move up one directory level that looks like this: As mentioned above, .. is a special directory name meaning “the directory containing this one”, or more succinctly, the parent of the current directory. If we run run cd .. and then type pwd, we’re back in /Users/rrob042: So far, when specifying directory names we have been using relative paths. When you use a relative path with a command like ls or cd, it tries to find that location from where we are, rather than from the root (beginning) of the file system. However, it is possible to specify the absolute path to a directory by including its entire path from the root directory, which is indicated by a leading slash (see section 2). The leading / tells the computer to follow the path 5 $ cp -r /course/labs/Lab1 /course/UserFolders/UPI from the root of the file system, so it always refers to exactly one directory, no matter where we are when we run the command. Now we will copy a directory for this lab into our won personal directories in /course/UserFolders. This directory contains a single anatomical MRI image that we will be using in this lab. 6 $ matlab Current working directory Workspace (variable list) Contents of current directory History of commands Command window cd /course/UserFolders/UPI spm fmri INTRODUCTION TO MATLAB To start MATLAB just type matlab into the shell: In the Command Window or shell we can run and debug our code. You can use all the basic shell commands from section 1 (cd, ls, etc.) in the MATLAB shell. INTRODUCTION TO MRI DATA Let’s explore some real brain data. Running SPM Make sure you are in the right directory (in this case, the directory containing anat.nii is probably a good place, but it might the directory for the subject or the study): Open SPM: 7 A note about image file types. DICOM (Digital Imaging and Communications in Medicine) format. Raw data from the scanner; must be converted to Analyze or nifti format for analysis. Analyze format. Each image has two files: .hdr (header file containing metadata) and .img (the actual image). Nifti (Neuroimaging Informatics Technology Initiative) format. In this format, images can be stored in the two file presentation (.hdr/.img) or a one file presentation (.nii). A critical advance over Analyze format is that nifti files store the orientation of the image in an unambiguous manner. Moreover, time can be included as a fourth dimension. For more information, see https://brainder.org/2012/09/23/the-nifti-file-format/ 8 A note about xyz coordinate systems. xyz coordinates refer to the location of any given voxel (3D pixel) or element in the 3D image/matrix. However, there are two types of “spaces” or coordinate systems when dealing with MRI images: voxel space and world space (or mm space). Below is a 2D example of each coordinate system. You will notice that all the values in voxel space are positive, while world space includes positive and negative values (relative to the “origin” or the coordinate, 0 0 0). Display In the GUI (Graphics User Interface) for SPM, click on ‘Display’, and select the ‘anat.nii’ file to view the structural image. You should see the following image: Exercise: Images are actually just 3D matrices of numbers: each value in the matrix corresponds to an intensity value of a voxel in the brain. If you click anywhere on the image, you will see that below the coordinates will update as well as the intensity value. Using this knowledge, complete the following table: Coordinates (world space) Intensity Value Observations