Skip to content

Commit 7dcf4fd

Browse files
committed
meta-analysis walkthrough added
1 parent b756db0 commit 7dcf4fd

File tree

5 files changed

+567
-3
lines changed

5 files changed

+567
-3
lines changed

Second_level_analysis_template_scripts/a2_second_level_toolbox_check_dependencies.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,11 @@
8686
% CANlab Second-level analysis scripts
8787
% -----------------------------------------------------------------------
8888

89-
checkfile = which(['Second_level_analysis_template_scripts' filesep '0_begin_here_readme']);
90-
toolboxdir = fileparts(checkfile);
89+
% checkfile = which(['Second_level_analysis_template_scripts' filesep '0_begin_here_readme']);
90+
% toolboxdir = fileparts(checkfile);
91+
92+
checkfile = what(['Second_level_analysis_template_scripts' filesep 'core_scripts_to_run_without_modifying']);
93+
if ~isempty(checkfile), toolboxdir = fileparts(checkfile.path); else, toolboxdir = []; end
9194

9295
if ~exist(toolboxdir, 'dir') % Try to find and add it
9396
toolboxdir = fullfile(mainrepodir, 'CANlab_help_examples', 'Second_level_analysis_template_scripts');

Second_level_analysis_template_scripts/core_scripts_to_run_without_modifying/z_batch_publish_analyses.m

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,41 @@ function z_batch_publish_analyses(varargin)
3636
% Add the study-specific scripts to the top of the path.
3737
% Load saved data.
3838

39+
% As the paths in a_set_up_paths_always_run_first.m can change, we can
40+
% re-duplicate the functionality of a_set_up_paths_always_run_first here
41+
% without actually needing to hard-code the basedir, because we are already
42+
% assuming we are in the basedir. So we will check for the file
43+
% a_set_up_paths_always_run_first, but then run its elements.
44+
3945
scriptname = fullfile(pwd, 'scripts', 'a_set_up_paths_always_run_first.m');
4046

4147
if ~exist(scriptname, 'file')
4248
error('Run from base directory (basedir) of 2nd-level analysis folder.');
49+
4350
else
44-
run(scriptname)
51+
% run stuff in a_set_up_paths_always_run_first
52+
% run(scriptname)
53+
54+
basedir = pwd;
55+
datadir = fullfile(basedir, 'data');
56+
resultsdir = fullfile(basedir, 'results');
57+
scriptsdir = fullfile(basedir, 'scripts');
58+
figsavedir = fullfile(resultsdir, 'figures');
59+
60+
addpath(scriptsdir)
61+
62+
if ~exist(resultsdir, 'dir'), mkdir(resultsdir); end
63+
if ~exist(figsavedir, 'dir'), mkdir(figsavedir); end
64+
65+
% Display helper functions: Called by later scripts
66+
67+
dashes = '----------------------------------------------';
68+
printstr = @(dashes) disp(dashes);
69+
printhdr = @(str) fprintf('%s\n%s\n%s\n', dashes, str, dashes);
70+
4571
end
4672

73+
4774
printhdr('Running analyses:');
4875
disp(analyses_to_run)
4976

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
%% Multi-level kernel density (MKDA) meta-analysis example: Agency database
2+
% The starting point for coordinate-based meta-analysis (CBMA) is a text file
3+
% with the information entered from published studies. In this example, the
4+
% information is contained in the file "Agency_meta_analysis_database.txt"
5+
% It is in the Neuroimaging_Pattern_Masks repository on Github.
6+
%
7+
% This file should be on your Matlab path:
8+
% Neuroimaging_Pattern_Masks/CANlab_Meta_analysis_maps/2011_Agency_Meta_analysis/Agency_meta_analysis_database.txt
9+
10+
%% Section 1: Locate the coordinate database file
11+
%
12+
13+
dbfilename = 'Agency_meta_analysis_database.txt';
14+
dbname = which(dbfilename);
15+
16+
if isempty(dbname), error('Cannot locate the file %s\nMake sure it is on your Matlab path.', dbfilename); end
17+
18+
%% Section 2:
19+
%
20+
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
%% Multi-level kernel density (MKDA) meta-analysis example: Agency database
2+
% The starting point for coordinate-based meta-analysis (CBMA) is a text file
3+
% with the information entered from published studies. In this example, the
4+
% information is contained in the file "Agency_meta_analysis_database.txt"
5+
% It is in the Neuroimaging_Pattern_Masks repository on Github.
6+
%
7+
% This file should be on your Matlab path:
8+
% Neuroimaging_Pattern_Masks/CANlab_Meta_analysis_maps/2011_Agency_Meta_analysis/Agency_meta_analysis_database.txt
9+
10+
%% Section 1: Locate the coordinate database file
11+
% When you set up your own database, several rules apply. Formatting the spreadsheet
12+
% so it loads correctly can sometimes be the hardest part of running a
13+
% meta-analysis.
14+
%
15+
% See https://canlabweb.colorado.edu/wiki/doku.php/help/meta/meta_analysis_mkda
16+
%
17+
% And https://canlabweb.colorado.edu/wiki/doku.php/help/meta/database
18+
%
19+
% Here are some rules for setting up the file:
20+
% 1 The variable "dbname" in the workspace should specify the name of your coordinate database file
21+
% 2 The database must be a text file, tab delimited
22+
% 3 The 1st row of the database must contain the number of columns as its 1st and only entry
23+
% 4 The 2nd row of database must contain variable names (text, no spaces or special characters)
24+
% 5 The 3rd - nth rows of the database contains data
25+
% 6 Talairach coordinates are indicated by T88 in CoordSys variable
26+
% 7 coordinate fields should be called x, y, and z
27+
% 8 Do NOT use Z, or any other field name in clusters structure
28+
%
29+
% The second row of your database should contain names for each variable
30+
% you have coded. Some variables should be named with special keywords,
31+
% because they are used in the meta-analysis code. Other variables can be named
32+
% anything, as long as there are *no spaces or special characters* in the
33+
% name (e.g., !@#$%^&*(){}[] ~`\/|<>,.?/;:"''+=).
34+
% Anything that you could not name a variable in Matlab will also not work
35+
% here.
36+
% Here are the variable names with special meaning. They are case-sensitive:
37+
%
38+
% Subjects : Sample size of the study to which the coordinate belongs
39+
% FixedRandom : Study used fixed or random effects.
40+
% Values should be Fixed or Random.
41+
% Fixed effects coordinates will be automatically
42+
% downweighted
43+
% SubjectiveWeights : A coordinate or contrast weighting vector based on FixedRandom
44+
% and whatever else you want to weight by; e.g., study reporting threshold
45+
% The default is to use FixedRandom only if available
46+
% x, y, z : X, Y, and Z coordinates
47+
% study : name of study
48+
% Contrast : unique indices (e.g., 1:k) for each independent
49+
% contrast. This is a required variable!
50+
% All rows belonging to the same contrast should
51+
% (almost) always have the same values for every
52+
% variable other than x, y, and z.
53+
% CoordSys : Values should be MNI or T88, for MNI space or Talairach space
54+
% Talairach coordinates will be converted to MNI using
55+
% Matthew Brett's transform
56+
57+
dbfilename = 'Agency_meta_analysis_database.txt';
58+
dbname = which(dbfilename);
59+
60+
if isempty(dbname), error('Cannot locate the file %s\nMake sure it is on your Matlab path.', dbfilename); end
61+
62+
%% Section 2: Read in and set up the coordinate database
63+
% -------------------------------------------------------------------------
64+
65+
% First, create a new directory for the analysis and go there:
66+
analysisdir = fullfile(pwd, 'Agency_meta_analysis_example');
67+
mkdir(analysisdir)
68+
cd(analysisdir)
69+
70+
% Read in the database and save it in a structure variable called "DB"
71+
clear DB
72+
read_database;
73+
74+
% Create SubjectiveWeights
75+
% DB.SubjectiveWeights = zeros(size(DB.x));
76+
% DB.SubjectiveWeights(strcmp(DB.FixedRandom, 'Random')) = 1;
77+
% DB.SubjectiveWeights(strcmp(DB.FixedRandom, 'Fixed')) = 0.75;
78+
79+
% Prepare the database by checking fields and separating contrasts,
80+
% specifying a 10 mm radius for integrating coordinates:
81+
DB = Meta_Setup(DB, 10);
82+
83+
% Meta_Setup automatically saves a file called SETUP.mat in your folder as well.
84+
drawnow, snapnow
85+
close
86+
87+
%% Check and clean up any variables that need recoding
88+
% This is a good time to examine the DB structure to check whether the variables
89+
% you entered look as intended (numeric or text), and clean up any
90+
% variables that need recoding.
91+
% Sometimes, if text characters are entered
92+
% in the spreadsheet in a column of numbers, the entire column will be read
93+
% in as text.
94+
% Other times, variable entries with the same intended category/level will
95+
% have different names, e.g., yes vs. Yes (all entries are
96+
% case-sensitive). You can either fix these in the spreadsheet (best) or
97+
% re-code them here.
98+
%
99+
% There is no re-coding needed for this dataset, but here is an example:
100+
% e.g.,
101+
% wh = strcmp(DB.Increased_craving, 'yes'); DB.Increased_craving(wh) = {'Yes'};
102+
103+
% If you do re-code, do this afterwards:
104+
% save SETUP -append DB
105+
106+
%% Select a subset of contrasts
107+
% The function Meta_Select_Contrasts allows you to select a subset of the
108+
% database (DB variable) based on a combination of selected levels on
109+
% multiple variables. We will skip that for this example, but if you do
110+
% select variables, it is a good idea to create a subfolder for the
111+
% analysis with selected coordinates, and save the DB variable in SETUP.mat
112+
% in that folder, along with other results you may generate.
113+
114+
%% Convolve with spheres and set up the study indicator dataset
115+
% -------------------------------------------------------------------------
116+
% This step prepares the dataset for meta-analysis and runs the entire
117+
% analysis. It then generates results maps.
118+
%
119+
% It will generate new files for the analysis, so it is a good idea to
120+
% create and go to a subfolder that will contain files for this analysis.
121+
% Many meta-analysis projects involve several analyses, in several
122+
% sub-folders.
123+
124+
modeldir = fullfile(analysisdir, 'MKDA_all_contrasts');
125+
mkdir(modeldir)
126+
cd(modeldir)
127+
128+
Meta_Activation_FWE('all', DB, 100, 'nocontrasts', 'noverbose');
129+
130+
% Note: For a "final" analysis, 10,000 iterations are recommended
131+
% Because we typically care about inferences at the "tails" of the
132+
% sampling distribution (i.e., voxels with low P-values)
133+
%
134+
% Note: You can also use Meta_Activation_FWE to do each piece separately:
135+
%
136+
% Meta_Activation_FWE('setup') % sets up the analysis
137+
% Meta_Activation_FWE('mc', 10000) % Adds 10,000 Monte Carlo iterations
138+
%
139+
% A file is saved every 10 iterations, so if there are existing saved iterations
140+
% this will find them and add more.
141+
%
142+
% Meta_Activation_FWE('results') % generates results maps
143+
144+
drawnow
145+
snapnow
146+

0 commit comments

Comments
 (0)