-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconvertTrust_BIDS.m
executable file
·118 lines (105 loc) · 5.22 KB
/
convertTrust_BIDS.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
function convertTrust_BIDS(subj)
maindir = pwd;
% Partner is Friend=3, Stranger=2, Computer=1
% Reciprocate is Yes=1, No=0
% cLeft is the left option
% cRight is the right option
% high/low value option will randomly flip between left/right
%
% subj = subject number
fname = sprintf('summary_misses_task-trust.csv');
fid2 = fopen(fname,'a');
try
for r = 0:4
run_misses = 0;
fname = fullfile(maindir,'psychopy','logs',num2str(subj),sprintf('sub-%03d_task-trust_run-%d_raw.csv',subj,r));
if exist(fname,'file')
fid = fopen(fname,'r');
else
fprintf('sub-%d -- Investment Game, Run %d: No data found.\n', subj, r+1)
continue;
end
C = textscan(fid,[repmat('%f',1,14) '%s' repmat('%f',1,9)],'Delimiter',',','HeaderLines',1,'EmptyValue', NaN);
fclose(fid);
outcomeonset = C{20}; % should be locked to the presentation of the partner cue (at least 500 ms before choice screen)
choiceonset = C{11}; % should be locked to the presentation of the partner cue (at least 500 ms before choice screen)
RT = C{16};
Partner = C{4};
reciprocate = C{3};
response = C{15}; % high/low -- build in check below to check recording
trust_val = C{13}; % 0-8 (with '999' for no response)
cLeft = C{6};
cRight = C{8};
options = [cLeft cRight];
fname = sprintf('sub-%03d_task-trust_run-%02d_events.tsv',subj,r+1);
output = fullfile(maindir,'bids',['sub-' num2str(subj)],'func');
if ~exist(output,'dir')
mkdir(output)
end
fid = fopen(fullfile(output,fname),'w');
fprintf(fid,'onset\tduration\ttrial_type\tresponse_time\ttrust_value\tchoice\tcLow\tcHigh\n');
for t = 1:length(choiceonset)
% output check
if trust_val(t) == 999
if strcmp(response{t},'high') && (max(options(t,:)) ~= trust_val(t))
error('response output incorrectly recorded for trial %d', t)
end
end
if (Partner(t) == 1)
trial_type = 'computer';
elseif (Partner(t) == 2)
trial_type = 'stranger';
elseif (Partner(t) == 3)
trial_type = 'friend';
end
% "String values containing tabs MUST be escaped using double quotes.
% Missing and non applicable values MUST be coded as "n/a"."
% http://bids.neuroimaging.io/bids_spec.pdf
%fprintf(fid,'onset\tduration\ttrial_type\tresponse_time\ttrust_value\tchoice\n');
if trust_val(t) == 999
fprintf(fid,'%f\t%f\t%s\t%f\t%s\t%s\t%d\t%d\n',choiceonset(t),3,'missed_trial',3,'n/a','n/a',min(options(t,:)),max(options(t,:)));
run_misses = run_misses + 1;
else
if trust_val(t) == 0
fprintf(fid,'%f\t%f\t%s\t%f\t%d\t%s\t%d\t%d\n',choiceonset(t),RT(t),['choice_' trial_type ],RT(t),0,response{t},min(options(t,:)),max(options(t,:))); %should always be 'low'
else
if reciprocate(t) == 1
fprintf(fid,'%f\t%f\t%s\t%f\t%d\t%s\t%d\t%d\n',choiceonset(t),RT(t),['choice_' trial_type],RT(t),trust_val(t),response{t},min(options(t,:)),max(options(t,:)));
fprintf(fid,'%f\t%f\t%s\t%f\t%d\t%s\t%d\t%d\n',outcomeonset(t),1,['outcome_' trial_type '_recip'],RT(t),trust_val(t),response{t},min(options(t,:)),max(options(t,:)));
else
fprintf(fid,'%f\t%f\t%s\t%f\t%d\t%s\t%d\t%d\n',choiceonset(t),RT(t),['choice_' trial_type],RT(t),trust_val(t),response{t},min(options(t,:)),max(options(t,:)));
fprintf(fid,'%f\t%f\t%s\t%f\t%d\t%s\t%d\t%d\n',outcomeonset(t),1,['outcome_' trial_type '_defect'],RT(t),trust_val(t),response{t},min(options(t,:)),max(options(t,:)));
end
end
end
end
fclose(fid);
rand_trial = randsample(1:36,1);
if trust_val(rand_trial) == 999
%fprintf('sub-%d -- Investment Game, Run %d: On trial %d, Participant did not respond.\n',subj, r+1, rand_trial);
else
if reciprocate(rand_trial)
participant = (8 - trust_val(rand_trial)) + ((trust_val(rand_trial) * 3)/2);
friend = (trust_val(rand_trial) * 3)/2;
else
participant = 8 - trust_val(rand_trial);
friend = (trust_val(rand_trial) * 3);
end
if (Partner(rand_trial) == 1)
trial_type = 'Computer';
elseif (Partner(rand_trial) == 2)
trial_type = 'Stranger';
elseif (Partner(rand_trial) == 3)
trial_type = 'Friend';
end
%fprintf('sub-%d -- Investment Game, Run %d: On trial %d, Participant WINS $%.2f and %s WINS $%.2f.\n', subj, r+1, rand_trial, participant, trial_type, friend);
end
fprintf(fid2,'sub-%d,run-%d,%d\n', subj, r+1, run_misses);
end
fclose(fid2);
catch ME
disp(ME.message)
msg = sprintf('check line %d', ME.stack.line);
disp(msg);
keyboard
end