Attachment 'marsbarbatchextract.m'
Download 1 % MarsBaR batch script to show off MarsBaR batching
2 % See http://marsbar.sourceforge.net
3 %Adapted by J Grahn
4
5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 %Need to be IN directory where con images are.
7 %%%%%%%%%%%%%%%%%%%%%%%%%%%
8
9 root_dir = '/imaging/jessica/Beat/RFX/';
10 %sesses = {'sess1','sess2' 'sess3'};
11 con_dir = 'cons/' %where contrast images are, subdirectory of root directory
12 con_dirname = 'AudVis' %this is prefixed to the text files that contain the extracted data
13 % Directory to store (and load) ROIs
14 roi_dir = fullfile(root_dir, 'ROIs'); %where rois are, subdirectory of root directory
15 % roi_dir = '/imaging/jessica/anatomy toolboxes/rois';
16 % MarsBaR version check
17 if isempty(which('marsbar'))
18 error('Need MarsBaR on the path');
19 end
20 v = str2num(marsbar('ver'));
21 if v < 0.35
22 error('Batch script only works for MarsBaR >= 0.35');
23 end
24 marsbar('on'); % needed to set paths etc
25
26 % SPM version check. We need this to guess which model directory to use and
27 % to get the SPM configured design name.
28 spm_ver = spm('ver');
29 sdirname = [spm_ver '_ana'];
30 if strcmp(spm_ver, 'SPM99')
31 conf_design_name = 'SPMcfg.mat';
32 else
33 spm_defaults;
34 conf_design_name = 'SPM.mat';
35 end
36
37 % Set up the SPM defaults, just in case
38 spm('defaults', 'fmri');
39
40 % We will do estimation for all ROIs in this directory: remove prefix as
41 % necessary to get right filter to load the files
42 roinames = dir(fullfile(roi_dir, 'roi*_roi.mat'))
43
44 P = dir(fullfile(root_dir,con_dir,'*.img')); % get images from contrast directory where they are stored
45 V = spm_vol(P);
46 D = strvcat(V(:).name); %load images into format for Marsbar
47
48 for roi_no = 1:length(roinames)
49 roi_array{roi_no} = maroi(fullfile(roi_dir, roinames(roi_no).name));
50
51 % Extract data
52 Y = get_marsy(roi_array{roi_no}, D, 'mean');%get the values
53 %mars_arm('save', 'roi_data', 'test.mat');
54 [datamean datavar o] = summary_data(Y, 'mean'); %assign the mean extractions for each ROI and each image to variable called datamean
55 regionname{roi_no} = char(region_name(Y)); %note the regionname
56 if roi_no ==1
57 data = datamean;
58 regionnames = char(regionname{roi_no});
59 else
60 data = [data datamean];
61 regionnames = strvcat([regionnames ' ' char(regionname{roi_no})]);
62 end
63 %data{roi_no} = datamean;
64
65 %[Y Yvar o] = summary_data(o, 'median');
66 % % MarsBaR estimation
67 % E = estimate(D, Y);
68 %
69 % % Add contrast, return model, and contrast index
70 % [E Ic] = add_contrasts(E, 'stim_hrf', 'T', [1 0 0]);
71 %
72 % % Get, store statistics
73 % stat_struct(ss) = compute_contrasts(E, Ic);
74 %
75 % % And fitted time courses
76 % [this_tc dt] = event_fitted(E, event_spec, event_duration);
77 %
78 % % Make fitted time course into ~% signal change
79 % tc(:, ss) = this_tc / block_means(E) * 100;
80 end
81 %assign concatenated data to file and save data, regionnames, and image
82 %file list to 3 separate files.
83
84 fname = [con_dirname 'extracteddata.txt'] %this file contains as many columns as ROIS extracted, and as many rows as you have con images
85 save(fname, 'data', '-ascii');
86
87 fname2 = [con_dirname 'imgnames.txt']; %the list of the con images extracted from
88 fid = fopen(fname2, 'w');
89 fprintf(fid,'%s\n', P.name);
90 fclose(fid);
91
92 fname3 = [con_dirname 'regions.txt']; %the list of the rois extracted
93 fid = fopen(fname3, 'w');
94 fprintf(fid, regionnames);
95 fclose(fid);
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.