# Dataset basics¶

• [OCH16] - CoSMoMVPA manuscript
• [HHS+09a] - PyMVPA manuscript, which inspired CoSMoMVPA data structures
• [NPDH06] - an early MVPA review paper

## Make sure your setup works¶

• have set paths properly in `.cosmomvpa.cfg` (described here)
• have tested that you can load and save data from and to the paths in `.cosmomvpa.cfg`.

## Very first exercise¶

We will start with a more complicated analysis first without explaining too much of the rationale now; that is left for later. Briefly, we will run a searchlight analysis using neural data while a participant viewed images of six different categories. The output is an information map that indicates where in the brain the distributed patterns are consistent yet different for the different categories.

In this first exercise, you only have to add one line of code. To do this exercise, open the file linked to by Hint - this is a code skeleton because it has code left out. Make a new file in the Matlab / GNU Octave editor, paste the file contents, and the fill in the missing code. Run the code and a nifti file will be generated. You can visualize this using MRIcron or other fMRI data viewers.

## Load and view anatomical dataset¶

Using some basic CoSMoMVPA functions we start loading a single NIFTI image of an anatomical scan. Use the function cosmo fmri dataset to load the nifti file of the brain of subject s01 (`brain.nii`) and assign the result to a struct ‘ds’. What is contained in this struct?

Make a histogram of all voxels, and a second histogram of the non-zero voxels of the brain. There are two ‘bumps’ - what do they represent?

Display the dataset in saggital orientation.

Set anterior voxels to zero, and display the result.

Advanced exercise: set all voxels around a center voxel at `i=150,j=100,k=50` within a 40-voxel radius to zero, and display the result.

Before starting any analysis, it is usually necessary to indicate the targets (conditions) and chunks (indicating independence of data; for fRMI data, typically runs) for each row in a dataset’s `.samples` field.

Using the function in cosmo fmri dataset load the dataset for subject s01 (`glm_T_stats_perrun.nii`).

• Set the `.sa.targets`, `.sa.chunks` and `.sa.labels`:

• The stimulus labels for each run of the fMRI study were monkey, lemur, mallard, warbler, ladybug, and lunamoth – in that order. This dataset contains summary statistics (T statistics from the general linear model analysis, GLM) for each stimulus for each of ten runs. The runs are vertically stacked by run. For example, the first row contains the summary voxel-wise responses for monkey in run 1, the second row contains that for lemur in run 1, and the seventh row contains monkey from run 2, etc.

• Add samples atributes (dataset.sa) as follows.

• numeric labels for the targets,aka stimulus labels, in the samples attribute field dataset.sa.targets
• add another sample attribute for the chunks, aka run labels, in the field dataset.sa.chunks.
• optional: add a third sample attribute with labels (string representation) showing human-readable labels of the conditions.
• Load the VT mask, find where there are non-zero values in the mask, and apply it to the dataset using cosmo slice.

• Now use cosmo fmri dataset with the `mask`, `targets` and `chunks` parameters; set `.sa.labels` as before, and verify you get the same dataset structure as before.

Advanced exercise: using cosmo slice, can you show the same figure as in the advanved exercise above where all voxels around a center voxels were set to zero?

### Operations on datasets¶

Now that you are familiar with the dataset, let’s play around a little.

• Load the `glm_T_stats_perrun.nii` data with the VT mask for any subject.

• Slice samples in various ways (using cosmo slice):

• Get dataset with data in chunks 1 and 2
• Get dataset with data in conditions 1 and 3 (monkeys and mallards)
• Get one dataset with data that has all the primate data (monkey and lemur) and another dataset has only the bugs data (ladybug and lunamoth).
• Calculate the average pattern for primates and the average pattern for bugs.
• Subtract bugs from primates.
• Save the result as a dataset.

• Convert the dataset into a nifti format using the function cosmo map2fmri.

• Visualize the results using `imagesc` or cosmo plot slices, or save the nifti as a file and use some other software like AFNI’s or FSL’s viewer.

Optional exercise: use a whole-brain mask.