-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpublish_meta_analysis_report.m
90 lines (54 loc) · 2.65 KB
/
publish_meta_analysis_report.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
% Runs batch analyses and publishes HTML report with figures and stats to
% results/published_output in local study-specific analysis directory.
% Run this from the main mediation results directory (basedir)
close all
warning off, clear all, warning on
resultsdir = pwd;
fprintf('Creating HTML report for results in:\n%s\n', resultsdir);
% ------------------------------------------------------------------------
% Check that we have a valid MKDA Meta_activationFWE results dir
% ------------------------------------------------------------------------
is_mediation_dir = exist(fullfile(resultsdir, 'MC_Info.mat'));
%is_run = exist(fullfile(resultsdir, 'X-M-Y_effect.img'));
if ~is_mediation_dir
fprintf('%s\nis not a MKDA meta-analysis directory because MC_Info.mat is missing.\nSkipping report.\n', resultsdir);
return
end
% if ~is_run
% fprintf('Mediation does not appear to have run correctly because X-M-Y_effect.img is missing.\nSkipping report.\n');
% return
% end
% ------------------------------------------------------------------------
% Set HTML report filename and options
% ------------------------------------------------------------------------
pubdir = fullfile(resultsdir, 'published_output');
if ~exist(pubdir, 'dir'), mkdir(pubdir), end
pubfilename = ['MKDA_meta_analysis_report_' scn_get_datetime];
p = struct('useNewFigure', false, 'maxHeight', 800, 'maxWidth', 1600, ...
'format', 'html', 'outputDir', fullfile(pubdir, pubfilename), 'showCode', false);
% move old reports to 'older' dir
move_old_reports(pubdir, pubfilename)
% ------------------------------------------------------------------------
% Run and report status
% ------------------------------------------------------------------------
publish('Meta_results_batch_script.m', p);
myhtmlfile = fullfile(pubdir, pubfilename, 'Meta_results_batch_script.html');
if exist(myhtmlfile, 'file')
fprintf('Saved HTML report:\n%s\n', myhtmlfile);
web(myhtmlfile);
else
fprintf('Failed to create HTML report:\n%s\n', myhtmlfile);
end
function move_old_reports(pubdir, pubfilename)
olddir = fullfile(pubdir, 'OLDER_REPORTS');
if ~exist(olddir, 'dir'), mkdir(olddir); end
myreportwildcard = [pubfilename(1:end - 17) '*'];
oldfiles = dir(fullfile(pubdir, myreportwildcard));
if length(oldfiles) > 1
fprintf('Moving old reports named %s to OLDER_REPORTS folder.\n', myreportwildcard);
end
for i = 1:length(oldfiles)
myfile = fullfile(pubdir, oldfiles(i).name);
[SUCCESS,MESSAGE,MESSAGEID] = movefile(myfile, olddir);
end
end