4. Musbid 1st Level Analysis - mind-lab-bos/MBI_Project_MRI_Analysis GitHub Wiki
Once the Conn pre-processing has finished (page 3), please complete the following steps for the 1st level analysis of the Musbid Task data.
Behavioral data transformation
Before starting the 1st level analysis on SPM, onsets for each musical stimuli need to be extracted for each participant. Ensure that the output file from the mus-bid task (YYMMDDFLLLS_mus-bid-biddata.txt) has been uploaded from the MRI computer into the /Music_MCI/NU_MCI_Behavioral_Data/MRI_mus-bid_task folder on Dropbox. On the lab laptop, go into the /Music_MCI/NU_MCI_Behavioral_Data/MRI_mus-bid_task folder. If you plan to run this on your local computer, download the whole MRI_mus-bid_task folder. (Note: You will have to change file the path in the script.)
Open the Musbid_Automated.Rmd script, and click the green arrow in the top right corner of each of the 3 sections of the script. The outputs should be as follows: musbid_stim_onset.csv, musbid_liking_onset.csv, musbid_familiarity_onset.csv. Every time the script is run, the previous versions of the output files will be overwritten. Check to make sure the most recent participant's data is included in each of these .csv files (Note: if this is a returning participant, their data will output directly under their session 1 data (not at the bottom of the file)).
Preparing for the 1st level analysis
First time only: Create a folder called mus_bid_data in your /home/ directory.
- Copy the template folder (
/work/mindlab/Projects/mci/mci_spm_musbid/sub-NNN-XXXXS/) to your home directory on discovery. You can to this with the "Copy" and "Paste" buttons on discovery
If that does not work, you can use the following code in terminal.
cp -R /work/mindlab/Projects/mci/mci_spm_musbid/sub-NNN-FLLLS/ /home/<yourusername>/mus_bid_data/
- Rename the template folder with the three digit numeric identifier the participant was assigned during the bids conversion ("NNN" in the above example; details on how to find this below) and the last part of their participant ID (first letter of their first name, first three letters of their last name, session number).
To find out the three digit numeric identifier for the data you are working on, go into the following file (/work/mindlab/NUBIC/MCI_Study/raw_bids/README.txt) and note the three digits associated with the data you are currently working on. For example, if you were analyzing participant 210719BFOR3's data, you would note that the three numeric digit's on the README file are "041", so the subject's folder would read sub-041-BFOR3. See the instructions in 5. Face Name 1st Level Analysis for an image.
- The next step is to copy the preprocessed data into this new folder you have created using either the "Copy" and "Paste" buttons (
/work/mindlab/Projects/GammaMBI/CONN_Project/Current_Subs/sub-NNN/func/swausub-NNN_task-musbid_bold.nii) or the command below.
cp /work/mindlab/Projects/GammaMBI/CONN_Project/Current_Subs/sub-NNN/func/swausub-NNN_task-musbid_bold.nii /home/<yourusername>/mus_bid_data/sub-NNN-FLLLS/ (replacing NNN with subject number in README; Note: if the participant had multiple runs for mus-bid, you might need to add "run-XX_" before "bold.nii" - please reference the file name in the Current_Subs folder)
Converting from 4D to 3D using SPM
- Open up a MatLab GUI on discovery and type the following in the command line:
addpath('/work/mindlab/Programs/spm12')
spm fmri
-
In the SPM GUI, select the button that says
Batch, which will open up the batch editor. -
In the batch, navigate to
SPM > Util > 4D to 3D File Conversion. This will add "4D to 3D File Conversion" to your Module List (left panel).

- Double click each of the fields listed below and select the following information to fill them.
-
4D Volume --> Select the swausub-XXX_task-musbid_bold.nii volume you copied into your
homedirectory,/home/<yourusername>/mus_bid_data/<subjectfolder>/swausub-XXX_task-musbid_bold.niifrom the popup window. (Ensure this file is listed in the bottom part of the popup window then clickDone.) -
Output Directory --> select the folder you want the files outputted to. In this case, it will be the
/home/<yourusername>/mus_bid_data/<subjectfolder>/mus-bid_slicesfolder.

- Click the green triangle button on the left corner of the batch window to Run the batch. This could take a few minutes, so make sure you do not type anything in the MatLab command window while this is processing. Once the batch has run, close out the batch window.
1st Level Analysis
- Now you are ready for the 1st level analysis! First, you need to copy the template batch to your home (only the first time you do the analysis). You can use the "Copy" and "Paste" buttons to copy this file:
cp /work/mindlab/Projects/mci_spm_musbid/musbid_pipline_newbp.mator use the code below
cp /work/mindlab/Projects/mci/mci_spm_musbid/musbid_pipline_newbp.mat /home/<yourusername>/mus_bid_data/
- The musbid_pipline_newbp.mat batch contains all the modules you will need for the 1st level analysis. To open this pipeline, follow the steps below:
a. Click Specify 1st-level
b. In Batch Editor, Click File> Load Batch
c. Load musbid_pipline_newbp.mat (from your home directory)
- Input Directory, Scans, and Trigger onsets for 3 models: Stimuli, Liking, Familiarity. Note that you should only have to be making changes to the three
fMRI model specificationmodules unless the participant has missing data for a particular condition.

Stimuli Model
- (Output)
Directory←/home/<yourusername>/mus_bid_data/<subjectfolder>/mus-bid_spm/stimuli/. - Scans ← all of the files in
/home/<yourusername>/mus_bid_data/<subjectfolder>/mus-bid_slices/. (There should be 1440) - Onsets ← copy onset numbers from
/Dropbox/Music_MCI/NU_MCI_Behavioral_data/mus-bid_task/musbid_stim_onset.csv.
Open musbid_stim_onset.csv and scroll to the participant's ID. Copy the numbers in the ss row for that participant and paste them into the Onsets slot in SPM. Use regular copy/paste methods to copy the numbers to the clipboard on Matlab (arrow all the way to the left of the screen). Once you have pasted the values into the clipboard, copy them again and paste them into SPM using "control + v" (rather than "command + v"). There should be 6 for self-selected, 10 for familiar-western. Include nw and bp in the updated-bp condition on SPM for a total of 8 onsets.
Liking Model
- (Output)
Directory←/home/<yourusername>/mus_bid_data/<subjectfolder>/mus-bid_spm/liking/. - Scans ← all of the files in
/home/<yourusername>/mus_bid_data/<subjectfolder>/mus-bid_slices/. (Same 1440 files as the stimuli model) - Onsets ← copy onsets from
/Dropbox/Music_MCI/NU_MCI_Behavioral_data/mus-bid_task/musbid_liking_onset.csv. Use technique described above.
Familiarity Model
- (Output)
Directory←/home/<yourusername>/mus_bid_data/<subjectfolder>/mus-bid_spm/familiarity/. - Scans ← all of the files in
/home/<yourusername>/mus_bid_data/<subjectfolder>/mus-bid_slices/. (Same 1440 files as the stimuli and liking models) - Onsets ← copy onsets from
/Dropbox/Music_MCI/NU_MCI_Behavioral_data/mus-bid_task/musbid_familiarity_onset.csv. Use technique described above.
Very Important Note: If you find that a subject is missing a set of onsets (for example, the participant has no onset row for "hate" liking ratings), delete that condition where onsets are missing, and edit contrast manager to reflect the changes.
When all 4 onset levels for familiarity and liking are present, the contrasts should be the following:
main effects: [1 0 0 0], [0 1 0 0], [0 0 1 0], [0 0 0 1]
linear contrasts: [-3 -1 1 3]
familiarity comparisons: [1 1 -1 -1], [-1 -1 1 1]
When 1 onset level is missing, the contrasts should be changed to the following (the exact arrangement of numbers should depend on which onset is missing):
main effects: [1 0 0], [0 1 0], [0 0 1]
linear contrasts: [-4 1 3] or [-3 -1 4]
familiarity comparisons: [2 -1 -1], [-2 1 1]
-
Once you have double checked that all Directories, Scans, and Onsets are correct, click the Run (green triangle) on the top left of the batch window.
-
After the analysis has finished, check all of the subfolders in the subject's
mus-bid_spmfolder. They should have the following files. Note that the number of conn and beta files will differ for each folder based on the number of contrasts associated with each.

-
Save the batch to the participant's
mus-bid_spmfolder (/home/<yourusername>/mus_bid_data/<subjectfolder>). To save the batch, click on the File > Save Batch. You can name the batch using the participant's ID. -
Edit the .txt files to specify each contrast performed for each participant's stimuli, liking, and familiarity analyses. The stimuli contrasts should remain the same for all participants, but the liking and familiarity contrasts .txt files might need to be edited to match the exact contrasts performed for each participant. After you finish editing the .txt files, save them, and rename them (replace the FLLLS with subject ID, e.g., BFOR1).
-
After completing the analysis, copy the subject folder from your home directory to /work/mindlab/Projects/mci/mci_spm_musbid/pre/ (or post/).
You could also use rsync command in terminal:
rsync -rltDvu /home/<yourusername>/mus_bid_data/<subjectfolder> /work/mindlab/Projects/mci/mci_spm_musbid/pre/ (or post/)
- Change the permissions on the folder you just rsync'd into /work/mindlab/ so anyone in the lab can access your data.
chmod -R 770 /work/mindlab/Projects/mci/mci_spm_musbid/pre/<subjectfolder>