<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Co-activation analysis
In this analysis, I contrast the co-activation patterns between sets of related regions. That is, we seek to find voxels throught the brain that co-activate to a greater extent with one cluster than others
Step1:  The following two functions are all that is necessary to perform this analysis
Step2:  k = 3 co-activation contrast
Step3:  k = 9 co-activation contrast
In this analysis, I contrast sets of regions in the k = 9 clustering solution, grouped by their membership in a larger regions in k = 3
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import numpy as np
import seaborn as sns
from neurosynth.base.dataset import Dataset
dataset = Dataset.load("data/neurosynth_60_0.4.pkl")
Explanation: Co-activation analysis
In this analysis, I contrast the co-activation patterns between sets of related regions. That is, we seek to find voxels throught the brain that co-activate to a greater extent with one cluster than others
End of explanation
from coactivation import coactivation_contrast
from plotting import make_thresholded_slices
cut_coords = np.arange(-15, 60, 12) # I use the same z coordinates for each axial plot
Explanation: The following two functions are all that is necessary to perform this analysis:
coactivation_contrast peforms the analysis and returns an image for each region in the analysis. For each region, voxels in the image are those that co-activated to a greater extent with that region, than other regions in the analysis.
make_thresholded_slices takes a list of images and overlays them using nilearn's plot_roi
End of explanation
contrast_mas = coactivation_contrast(
    dataset, 'images/cluster_labels_k3.nii.gz', q = 0.001)
make_thresholded_slices(contrast_mas, sns.color_palette('Set1', 3), 
                       cut_coords=cut_coords, annotate=False)
Explanation: k = 3 co-activation contrast
End of explanation
# Here I define the groupings
posterior = [3, 6]
middle = [1, 5, 7, 9]
anterior = [2, 4, 8]
from plotting import nine_colors
contrast_mas = coactivation_contrast(
    dataset, 'images/cluster_labels_k9.nii.gz', posterior)
colors = list(reversed([c for i, c in enumerate(nine_colors) if i + 1 in posterior]))
make_thresholded_slices(list(reversed(contrast_mas)), colors, 
                       cut_coords=cut_coords, annotate=False)
make_thresholded_slices(list(reversed(contrast_mas)), colors, 
                       cut_coords=range(-60, 50, 18), display_mode='y', annotate=False)
contrast_mas = coactivation_contrast(
    dataset, 'images/cluster_labels_k9.nii.gz', middle)
colors = [c for i, c in enumerate(nine_colors) if i + 1 in middle]
make_thresholded_slices(contrast_mas, colors, 
                       cut_coords=cut_coords, annotate=False)
make_thresholded_slices(contrast_mas, colors, cut_coords=range(-60, 50, 18), display_mode='y', annotate=False)
contrast_mas = coactivation_contrast(
    dataset, 'images/cluster_labels_k9.nii.gz', anterior)
colors = [c for i, c in enumerate(nine_colors) if i + 1 in anterior]
make_thresholded_slices(contrast_mas, colors, 
                       cut_coords=cut_coords, annotate=False)
make_thresholded_slices(contrast_mas, colors, cut_coords=range(-60, 50, 18), 
                        display_mode='y', annotate=False)
Explanation: k = 9 co-activation contrast
In this analysis, I contrast sets of regions in the k = 9 clustering solution, grouped by their membership in a larger regions in k = 3
End of explanation
<END_TASK>