TacAMv8.m

From OpenWetWare

Jump to: navigation, search

% TacAMv8.m % Reads in a random stimulus sequence generated by optseq (for n runs) % and selected lists of stimuli % then assigns a (non-repeated) stimulus to each event in the sequence

% number of stimulus types numstimtype = 2; % stimulus names for filename output stimtypes = { 'AM','TM'}; % number of runs numruns = 4; % number of stimuli per run numstim = 150; % how long each stimulus lasts stimtime = 2; % max number of stim totalstims = numruns*numstim; % Array containing stim types stimseq = zeros(numruns, numstim); % Array containing clip names to save to disk clipfile = cell(numruns,numstim);


% Read in clips cd /Volumes/data1/stimuli/NIHStimuli/ASD/ [Actionmovies, numActionmovies] = ReadPaths('ActionMoviesList.txt'); [Toolmovies, numToolmovies] = ReadPaths('ToolMoviesList.txt'); txt = sprintf('Read in %i actionmovies, %i toolmovies. ',numActionmovies,numToolmovies); disp(txt);


% change to directory that contains stimulus order files cd /Users/mbeauchamp/data1/UT/TacAM

% Stimulus prefix (from optseq2) out = 'Tacv8';

for i = 1:numruns % Read in stimulus sequences % in optseq, first column is "real time", second is stim type (numeric code) % third is duration, fourth is stim type (name) % this is a hack to get around 0-10 if i < 10 fname = [out,'-00',num2str(i),'.par']; else fname = [out,'-0',num2str(i),'.par']; end

[stimonset,stimtype,stimlength,stimname,junk] = textread(fname,'%f%n%f%s%f','delimiter',' ');

% optseq has the annoying habit of not listing multiple nulls in a row; % convert so each run has exactly the same number of stimuli j = 1; for ctr = 1:length(stimname)

   for k=1:stimlength(ctr)/stimtime

stimseq(i,j) = stimtype(ctr);

       j = j + 1;

end end

end % end reading in stimulus sequence files


% Go through each run, assigning stimuli % For now, we use a simple algorithm, assuming that the total number of % each clip type is less than the number of presentations % we also ignore that there are different categories of stimuli % e.g. might get 4 flippers, no pitcher by change % could change so that it picks one from each category, etc. am = randperm(numActionmovies); amctr = 1; tm = randperm(numToolmovies); tmctr = 1; % if have too few clips, just make consecutive permutations e.g. for tool stills % ts = [ randperm(numToolstills) randperm(numToolstills)]; tsctr = 1;

for i=1:numruns am = randperm(numActionmovies); amctr = 1; tm = randperm(numToolmovies); tmctr = 1; for j=1:numstim switch stimseq(i,j) case 0, clipfile{i,j} = 'NULL'; case 1, clipfile{i,j} = Actionmovies(am(amctr)); amctr = amctr + 1; case 2, clipfile{i,j} = Toolmovies(tm(tmctr)); tmctr = tmctr + 1; otherwise, disp('ERROR: UNPLANNED STIMULUS TYPE!') end end end


% New version of presentation stimulus presentation program wants the order and the stimuli themselves fname = [out '.txt' ] %fname = ['Tacv7.txt'];


fid = fopen(fname,'wt'); fprintf(fid,'{\n');  % initial { for 2D array for i=1:numruns

   j=1;
   fprintf(fid,'{"%s"',char(clipfile{i,j}));

for j=2:numstim

       % comma before every one except the first one

fprintf(fid,',"%s"',char(clipfile{i,j}));

   end
   if i < numruns fprintf(fid,'},\n'); end;  % don't need comma after very last one

end fprintf(fid,'}\n};\n');  % final }; for 2D array fclose(fid);

% check to make sure file is OK; note that have to manually delete very % last "," in the file cmd = ['!cat ',fname]; eval(cmd)


% write out timing of each stimulus for use as regressors by 3dDeconvolve % with -stim_times option % create a separate regressor for each clip type, with the time of each % stimlus in each run on a separate row (then if we don't use all runs, % just ignore those rows, or swap order of rows if run ordering is % different; can't do this with column format % parameters

% actual number of runs actualnumruns = 2; stimvals = [1 2];

% TR for timing purposes tr = 2; for i=1:numstimtype

   fname = char(strcat(out,stimtypes(i),'.txt'));
   fid = fopen(fname,'wt');
   fprintf(fid,); % 
   for j=1:actualnumruns   % assume we have at least one stim of each type per run; if not we need to include a "*"
       curtime = 0;
       for k=1:numstim
           if ( isequal( stimseq(j,k) , stimvals(i) ) )
              	fprintf(fid,'%i ',curtime); % time of each stimulus, separated by spaces
           end
           curtime = curtime + tr;
       end
       fprintf(fid,'\n'); % end of the run, go to next line
   end
   fclose(fid); % end of that stimulus, close file
   cmd = ['!cat ',fname];
   eval(cmd)

end

Personal tools