-
Notifications
You must be signed in to change notification settings - Fork 7
/
convertSharedReward_BIDS.m
executable file
·118 lines (96 loc) · 4.46 KB
/
convertSharedReward_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 convertSharedReward_BIDS(subj)
maindir = pwd;
try
fname = sprintf('summary_misses_task-sharedreward.csv');
fid2 = fopen(fname,'a');
for r = 0:1
run_misses = 0;
fname = fullfile(maindir,'psychopy','logs',num2str(subj),sprintf('sub-%03d_task-sharedreward_run-%d_raw.csv',subj,r));
if exist(fname,'file')
fid = fopen(fname,'r');
else
fprintf('sub-%d -- Gambling Game, Run %d: No data found.\n', subj, r+1)
continue;
end
C = textscan(fid,repmat('%f',1,19),'Delimiter',',','HeaderLines',1,'EmptyValue', NaN);
fclose(fid);
% Partner is Friend=3, Stranger=2, Computer=1
% Feedback is Reward=3, Neutral=2, Punishment=1
onset = C{10};
RT = C{13};
duration = C{17};
block_types = C{6};
Partner = C{5};
feedback = C{3};
fname = sprintf('sub-%03d_task-sharedreward_run-%02d_events.tsv',subj,r+1); % need to make fMRI run number consistent with this?
output = fullfile(maindir,'bids',['sub-' num2str(subj)],'func');
if ~exist(output,'dir')
mkdir(output)
end
myfile = fullfile(output,fname);
fid = fopen(myfile,'w');
fprintf(fid,'onset\tduration\ttrial_type\tresponse_time\n');
for t = 1:length(onset);
%fprintf(fid,'onset\tduration\ttrial_type\tresponse_time\n');
if (feedback(t) == 1) && (Partner(t) == 1)
trial_type = 'computer_punish';
elseif (feedback(t) == 1) && (Partner(t) == 2)
trial_type = 'stranger_punish';
elseif (feedback(t) == 1) && (Partner(t) == 3)
trial_type = 'friend_punish';
elseif (feedback(t) == 2) && (Partner(t) == 1)
trial_type = 'computer_neutral';
elseif (feedback(t) == 2) && (Partner(t) == 2)
trial_type = 'stranger_neutral';
elseif (feedback(t) == 2) && (Partner(t) == 3)
trial_type = 'friend_neutral';
elseif (feedback(t) == 3) && (Partner(t) == 1)
trial_type = 'computer_reward';
elseif (feedback(t) == 3) && (Partner(t) == 2)
trial_type = 'stranger_reward';
elseif (feedback(t) == 3) && (Partner(t) == 3)
trial_type = 'friend_reward';
end
switch block_types(t)
case 1, block_type = 'computer_punish';
case 2, block_type = 'computer_reward';
case 3, block_type = 'stranger_punish';
case 4, block_type = 'stranger_reward';
case 5, block_type = 'friend_punish';
case 6, block_type = 'friend_reward';
end
if RT(t) == 999 %missed response
fprintf(fid,'%f\t%f\t%s\t%s\n',onset(t),duration(t),'missed_trial','n/a');
run_misses = run_misses + 1;
else
fprintf(fid,'%f\t%f\t%s\t%f\n',onset(t),duration(t),['event_' trial_type],RT(t));
end
block_starts = [1 9 17 25 33 41 49 57 65];
if ismember(t,block_starts)
fprintf(fid,'%f\t%f\t%s\t%s\n',onset(t),33.5,['block_' block_type],'n/a');
end
end
fclose(fid);
rand_trial = randsample(1:72,1);
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
if feedback(rand_trial) == 1 %punish
fprintf('sub-%d -- Gambling Game, Run %d: On trial %d, Participant LOSES $5 and %s LOSES $5.\n', subj, r+1, rand_trial, trial_type);
elseif feedback(rand_trial) == 2 %neutral
fprintf('sub-%d -- Gambling Game, Run %d: On trial %d, Participant sees a card with a 5 on it.\n', subj, r+1, rand_trial);
elseif feedback(rand_trial) == 3 %reward
fprintf('sub-%d -- Gambling Game, Run %d: On trial %d, Participant WINS $5 and %s WINS $5.\n', subj, r+1, rand_trial, trial_type);
end
fprintf(fid2,'sub-%d,run-%d,%d\n', subj, r+1, run_misses);
end
catch ME
disp(ME.message)
msg = sprintf('check line %d', ME.stack.line);
disp(msg);
keyboard
end