Skip to content

Commit

Permalink
protocol creator
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsayal committed Jul 11, 2023
1 parent d380842 commit 8405ded
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 0 deletions.
62 changes: 62 additions & 0 deletions scripts-01-protocolcreator/Main_Behav_D12.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
clear, clc;

outputFolder = fullfile('..','data','prt');

%% PRT Parameters
PRTParameters = struct();

PRTParameters.FileVersion = 2;
PRTParameters.Resolution = 'Volumes';
PRTParameters.ExperimentName = 'VisualPerception_CrossInhibition';
PRTParameters.BackgroundColor = [0 0 0];
PRTParameters.TextColor = [255 255 255];
PRTParameters.TimeCourseColor = [1 1 1];
PRTParameters.TimeCourseThick = 3;
PRTParameters.ReferenceFuncColor = [0 0 80];
PRTParameters.ReferenceFuncThick = 2;

%% PRT Conditions
condNames = {'Static','Coherent','Incoherent','NonAdapt','Ambiguous_aCoh','Ambiguous_aInCoh','Ambiguous_aNA','MAE'};

blockDuration = [ 6 12 12 12 6 6 6 3 ]; %in volumes (think TR = 1000ms)

blockColor = [170 170 170 ; 150 210 240 ; 150 170 200 ; 150 130 160 ; ...
200 170 100 ; 200 170 120 ; 200 170 140 ; ...
120 120 120];

PRTParameters.nCond = length(condNames);

PRTConditions = struct();

for c = 1:PRTParameters.nCond

PRTConditions.(condNames{c}).Color = blockColor(c,:);
PRTConditions.(condNames{c}).BlockDuration = blockDuration(c);
PRTConditions.(condNames{c}).Intervals = [];
PRTConditions.(condNames{c}).NumBlocks = 0;

end

%% Run Behav D12 R1
%SEQ = [ 1 2 5 6 1 3 5 6 1 4 5 6 1 2 5 6 1 3 5 6 1 4 5 6 1 2 5 6 1 3 5 6 1 4 5 6 1 2 5 6 1 3 5 6 1 4 5 6];
SEQ = [ 1 2 5 8 1 3 6 8 1 4 7 8 1 2 5 8 1 3 6 8 1 4 7 8 1 2 5 8 1 3 6 8 1 4 7 8 1 2 5 8 1 3 6 8 1 4 7 8 ];

[ PRTConditions_R1 ] = buildIntervals( SEQ , PRTConditions );

generatePRT( PRTParameters , PRTConditions_R1 , 'RunBehav_D12_R1' , outputFolder );

%% Run Behav D12 R2
%SEQ = [ 1 2 5 6 1 4 5 6 1 3 5 6 1 2 5 6 1 4 5 6 1 3 5 6 1 2 5 6 1 4 5 6 1 3 5 6 1 2 5 6 1 4 5 6 1 3 5 6 ];
SEQ = [ 1 2 5 8 1 4 7 8 1 3 6 8 1 2 5 8 1 4 7 8 1 3 6 8 1 2 5 8 1 4 7 8 1 3 6 8 1 2 5 8 1 4 7 8 1 3 6 8 ];

[ PRTConditions_R2 ] = buildIntervals( SEQ , PRTConditions );

generatePRT( PRTParameters , PRTConditions_R2 , 'RunBehav_D12_R2' , outputFolder );

%% Run Behav D12 R3
%SEQ = [ 1 3 5 6 1 4 5 6 1 2 5 6 1 3 5 6 1 4 5 6 1 2 5 6 1 3 5 6 1 4 5 6 1 2 5 6 1 3 5 6 1 4 5 6 1 2 5 6 ];
SEQ = [ 1 3 6 8 1 4 7 8 1 2 5 8 1 3 6 8 1 4 7 8 1 2 5 8 1 3 6 8 1 4 7 8 1 2 5 8 1 3 6 8 1 4 7 8 1 2 5 8 ];

[ PRTConditions_R3 ] = buildIntervals( SEQ , PRTConditions );

generatePRT( PRTParameters , PRTConditions_R3 , 'RunBehav_D12_R3' , outputFolder );
62 changes: 62 additions & 0 deletions scripts-01-protocolcreator/Main_Behav_D6.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
clear, clc;

outputFolder = fullfile('..','data','prt');

%% PRT Parameters
PRTParameters = struct();

PRTParameters.FileVersion = 2;
PRTParameters.Resolution = 'Volumes';
PRTParameters.ExperimentName = 'VisualPerception_CrossInhibition';
PRTParameters.BackgroundColor = [0 0 0];
PRTParameters.TextColor = [255 255 255];
PRTParameters.TimeCourseColor = [1 1 1];
PRTParameters.TimeCourseThick = 3;
PRTParameters.ReferenceFuncColor = [0 0 80];
PRTParameters.ReferenceFuncThick = 2;

%% PRT Conditions
condNames = {'Static','Coherent','Incoherent','NonAdapt','Ambiguous_aCoh','Ambiguous_aInCoh','Ambiguous_aNA','MAE'};

blockDuration = [ 6 6 6 6 6 6 6 3 ]; %in volumes (think TR = 1000ms)

blockColor = [170 170 170 ; 150 210 240 ; 150 170 200 ; 150 130 160 ; ...
200 170 100 ; 200 170 120 ; 200 170 140 ; ...
120 120 120];

PRTParameters.nCond = length(condNames);

PRTConditions = struct();

for c = 1:PRTParameters.nCond

PRTConditions.(condNames{c}).Color = blockColor(c,:);
PRTConditions.(condNames{c}).BlockDuration = blockDuration(c);
PRTConditions.(condNames{c}).Intervals = [];
PRTConditions.(condNames{c}).NumBlocks = 0;

end

%% Run Behav D6 R1
%SEQ = [ 1 2 5 6 1 3 5 6 1 4 5 6 1 2 5 6 1 3 5 6 1 4 5 6 1 2 5 6 1 3 5 6 1 4 5 6 1 2 5 6 1 3 5 6 1 4 5 6];
SEQ = [ 1 2 5 8 1 3 6 8 1 4 7 8 1 2 5 8 1 3 6 8 1 4 7 8 1 2 5 8 1 3 6 8 1 4 7 8 1 2 5 8 1 3 6 8 1 4 7 8];

[ PRTConditions_R1 ] = buildIntervals( SEQ , PRTConditions );

generatePRT( PRTParameters , PRTConditions_R1 , 'RunBehav_D6_R1' , outputFolder );

%% Run Behav D6 R2
%SEQ = [ 1 2 5 6 1 4 5 6 1 3 5 6 1 2 5 6 1 4 5 6 1 3 5 6 1 2 5 6 1 4 5 6 1 3 5 6 1 2 5 6 1 4 5 6 1 3 5 6 ];
SEQ = [ 1 2 5 8 1 4 7 8 1 3 6 8 1 2 5 8 1 4 7 8 1 3 6 8 1 2 5 8 1 4 7 8 1 3 6 8 1 2 5 8 1 4 7 8 1 3 6 8 ];

[ PRTConditions_R2 ] = buildIntervals( SEQ , PRTConditions );

generatePRT( PRTParameters , PRTConditions_R2 , 'RunBehav_D6_R2' , outputFolder );

%% Run Behav D6 R3
%SEQ = [ 1 3 5 6 1 4 5 6 1 2 5 6 1 3 5 6 1 4 5 6 1 2 5 6 1 3 5 6 1 4 5 6 1 2 5 6 1 3 5 6 1 4 5 6 1 2 5 6 ];
SEQ = [ 1 3 6 8 1 4 7 8 1 2 5 8 1 3 6 8 1 4 7 8 1 2 5 8 1 3 6 8 1 4 7 8 1 2 5 8 1 3 6 8 1 4 7 8 1 2 5 8 ];

[ PRTConditions_R3 ] = buildIntervals( SEQ , PRTConditions );

generatePRT( PRTParameters , PRTConditions_R3 , 'RunBehav_D6_R3' , outputFolder );
92 changes: 92 additions & 0 deletions scripts-01-protocolcreator/Main_MRI_D12.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
clear, clc;

outputFolder = fullfile('..','data','prt');

%% PRT Parameters
PRTParameters = struct();

PRTParameters.FileVersion = 2;
PRTParameters.Resolution = 'Volumes';
PRTParameters.ExperimentName = 'VisualPerception_CrossInhibition';
PRTParameters.BackgroundColor = [0 0 0];
PRTParameters.TextColor = [255 255 255];
PRTParameters.TimeCourseColor = [1 1 1];
PRTParameters.TimeCourseThick = 3;
PRTParameters.ReferenceFuncColor = [0 0 80];
PRTParameters.ReferenceFuncThick = 2;

%% PRT Conditions
condNames = {'Static','Coherent','Incoherent','NonAdapt',...
'Coh_aCoh','Coh_aInCoh','Coh_aNA',...
'InCoh_aCoh','InCoh_aInCoh','InCoh_aNA',...
'MAE','Report','Discard'};

blockDuration = [ 6 12 12 12 6 6 6 6 6 6 3 3 4 ]; %in volumes (think TR = 1000ms)

blockColor = [170 170 170 ; 0 115 190 ; 216 83 25 ; 236 177 32 ; ...
110 115 190 ; 150 83 25 ; 190 177 32 ; ...
150 115 190 ; 100 83 25 ; 120 177 32 ; ...
120 160 120; 120 220 120; 50 50 50];

PRTParameters.nCond = length(condNames);

PRTConditions = struct();

for c = 1:PRTParameters.nCond

PRTConditions.(condNames{c}).Color = blockColor(c,:);
PRTConditions.(condNames{c}).BlockDuration = blockDuration(c);
PRTConditions.(condNames{c}).Intervals = [];
PRTConditions.(condNames{c}).NumBlocks = 0;

end

%% Trials
trials = [ 1 2 5 11 12 ;
1 2 8 11 12 ;
1 3 6 11 12 ;
1 3 9 11 12 ;
1 4 7 11 12 ;
1 4 10 11 12 ];

%% Run MRI D12 R1
SEQ = [13 reshape(trials([1 3 2 6 5 4 1 3 2 6 5 4],:)',1,60) 1 13];

[ PRTConditions_R1 ] = buildIntervals( SEQ , PRTConditions );

generatePRT( PRTParameters , PRTConditions_R1 , 'RunMRI_D12_R1' , outputFolder );

%% Run MRI D12 R2
SEQ = [13 reshape(trials([1 3 5 2 4 6 1 3 5 2 4 6],:)',1,60) 1 13];

[ PRTConditions_R2 ] = buildIntervals( SEQ , PRTConditions );

generatePRT( PRTParameters , PRTConditions_R2 , 'RunMRI_D12_R2' , outputFolder );

%% Run MRI D12 R3
SEQ = [13 reshape(trials([5 3 1 6 4 2 5 3 1 6 4 2],:)',1,60) 1 13];

[ PRTConditions_R3 ] = buildIntervals( SEQ , PRTConditions );

generatePRT( PRTParameters , PRTConditions_R3 , 'RunMRI_D12_R3' , outputFolder );

%% Run MRI D12 R4
SEQ = [13 reshape(trials([4 5 6 2 3 1 4 5 6 2 3 1],:)',1,60) 1 13];

[ PRTConditions_R4 ] = buildIntervals( SEQ , PRTConditions );

generatePRT( PRTParameters , PRTConditions_R4 , 'RunMRI_D12_R4' , outputFolder );

%% Run MRI D12 R5
SEQ = [13 reshape(trials([1 6 2 5 3 4 1 6 2 5 3 4],:)',1,60) 1 13];

[ PRTConditions_R5 ] = buildIntervals( SEQ , PRTConditions );

generatePRT( PRTParameters , PRTConditions_R5 , 'RunMRI_D12_R5' , outputFolder );

%% Run MRI D12 R6
SEQ = [13 reshape(trials([6 1 5 2 4 3 6 1 5 2 4 3],:)',1,60) 1 13];

[ PRTConditions_R6 ] = buildIntervals( SEQ , PRTConditions );

generatePRT( PRTParameters , PRTConditions_R6 , 'RunMRI_D12_R6' , outputFolder );
7 changes: 7 additions & 0 deletions scripts-01-protocolcreator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# scripts-01-protocolcreator
Scripts for generating the protocol files for the Inhibition experiment. These files are in BrainVoyager format (.prt).

## Files:
- `Main_Behav_D6.m`: generate the protocol files for the behavioral runs with adaptation duration of 6 seconds.
- `Main_Behav_D12.m`: generate the protocol files for the behavioral runs with adaptation duration of 12 seconds.
- `Main_MRI_D12.m`: generate the protocol files for the MRI runs with adaptation duration of 12 seconds.
18 changes: 18 additions & 0 deletions scripts-01-protocolcreator/buildIntervals.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function [ PRTConditions ] = buildIntervals( Sequence , PRTConditions )

condNames = fieldnames(PRTConditions);
currentTime = 0;

for t = 1:length(Sequence)

PRTConditions.(condNames{Sequence(t)}).Intervals = ...
[PRTConditions.(condNames{Sequence(t)}).Intervals ; ...
currentTime+1 currentTime+PRTConditions.(condNames{Sequence(t)}).BlockDuration];

PRTConditions.(condNames{Sequence(t)}).NumBlocks = PRTConditions.(condNames{Sequence(t)}).NumBlocks + 1;

currentTime = currentTime+PRTConditions.(condNames{Sequence(t)}).BlockDuration;

end

end
60 changes: 60 additions & 0 deletions scripts-01-protocolcreator/generatePRT.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function [ ] = generatePRT( PRTParameters , PRTConditions , runName , outputFolder )

%outputFolder = fullfile(pwd,'PRTs_AF');

if ~exist(outputFolder,'dir')
mkdir(outputFolder);
end

outputFileName = [ runName '.prt'];

% --- Create new file using parameters

prtFile = fopen( fullfile(outputFolder,outputFileName) , 'wt' );

% delimiter tab
del = char(9);

% --- FILE HEADER
fprintf(prtFile, '\n');
fprintf(prtFile, 'FileVersion:%s%s%i \n\n', del, del, PRTParameters.FileVersion);
fprintf(prtFile, 'ResolutionOfTime:%s%s \n\n', del, PRTParameters.Resolution);
fprintf(prtFile, 'Experiment:%s%s%s%s \n\n', del, del, del, PRTParameters.ExperimentName);
fprintf(prtFile, 'BackgroundColor:%s%s \n', del, num2str(PRTParameters.BackgroundColor));
fprintf(prtFile, 'TextColor:%s%s%s%s \n\n', del, del, del, num2str(PRTParameters.TextColor));
fprintf(prtFile, 'TimeCourseColor:%s%s \n', del, num2str(PRTParameters.TimeCourseColor));
fprintf(prtFile, 'TimeCourseThick:%s%i \n', del, PRTParameters.TimeCourseThick);
fprintf(prtFile, 'ReferenceFuncColor:%s%s \n', del, num2str(PRTParameters.ReferenceFuncColor));
fprintf(prtFile, 'ReferenceFuncThick:%s%i \n\n', del, PRTParameters.ReferenceFuncThick);
fprintf(prtFile, 'NrOfConditions:%s%s%i \n \n', del, del, PRTParameters.nCond);

% -- Conditions
condNames = fieldnames(PRTConditions);

for c = 1:PRTParameters.nCond

% Write the name of the condition
fprintf(prtFile, '%s \n', condNames{c});

% Write the number of blocks
fprintf(prtFile, '%i \n', PRTConditions.(condNames{c}).NumBlocks);

for i = 1:size(PRTConditions.(condNames{c}).Intervals,1)

% Write to file
fprintf(prtFile, '%i%s%i \n', PRTConditions.(condNames{c}).Intervals(i,1), del, PRTConditions.(condNames{c}).Intervals(i,2));

end

% Write condition color
fprintf(prtFile, 'Color:%s%i %i %i \n', del, PRTConditions.(condNames{c}).Color);

fprintf(prtFile, '\n');

end

fclose(prtFile);

fprintf('[generatePRT] %s file exported.\n',outputFileName);

end

0 comments on commit 8405ded

Please sign in to comment.