getBehavioralInfos.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. function [behinfos] = getBehavioralInfos(subjdata,sesn)
  2. if nargin < 2
  3. if nargin< 1
  4. error('Provide subject data.');
  5. end
  6. sesn='all';
  7. end
  8. if strcmpi(sesn,'all')
  9. sesn=1:length(subjdata);
  10. end
  11. behinfos.ntrials=arrayfun(@(sn) size(subjdata{sn}.spikeseqs,1), sesn);
  12. behinfos.ncells=arrayfun(@(sn) size(subjdata{sn}.spikeseqs,2), sesn);
  13. catoffer1pr=[]; catoffer1rw=[]; catoffer1ev=[];
  14. catoffer2pr=[]; catoffer2rw=[]; catoffer2ev=[];
  15. catoffer1sd=[]; catchooseLR=[]; catchoose12=[];
  16. catexperrew=[];
  17. % #1 offer1 prob
  18. % #2 offer1 value (nominal units)
  19. % #3 offer1 EV
  20. % #4 offer2 prob
  21. % #5 offer2 value (nominal units)
  22. % #6 offer2 EV
  23. % #7 offer1 side (1=L, 2=R)
  24. % #8 chosen side (1=L, 2=R)
  25. % #9 chosen offer (1=1st, 2=2nd)
  26. % #10 experienced reward
  27. for sn=sesn
  28. catoffer1pr=cat(1,catoffer1pr,subjdata{sn}.behavior(:,1));
  29. catoffer1rw=cat(1,catoffer1rw,subjdata{sn}.behavior(:,2));
  30. catoffer1ev=cat(1,catoffer1ev,subjdata{sn}.behavior(:,1).*((subjdata{sn}.behavior(:,2)==1)+...
  31. (subjdata{sn}.behavior(:,2)==2).*2+...
  32. (subjdata{sn}.behavior(:,2)==3).*3));
  33. catoffer2pr=cat(1,catoffer2pr,subjdata{sn}.behavior(:,4));
  34. catoffer2rw=cat(1,catoffer2rw,subjdata{sn}.behavior(:,5));
  35. catoffer2ev=cat(1,catoffer2ev,subjdata{sn}.behavior(:,4).*((subjdata{sn}.behavior(:,5)==1)+...
  36. (subjdata{sn}.behavior(:,5)==2).*2+...
  37. (subjdata{sn}.behavior(:,5)==3).*3));
  38. catoffer1sd=cat(1,catoffer1sd,subjdata{sn}.behavior(:,7));
  39. catchooseLR=cat(1,catchooseLR,subjdata{sn}.behavior(:,8));
  40. catchoose12=cat(1,catchoose12,subjdata{sn}.behavior(:,9));
  41. catexperrew=cat(1,catexperrew,subjdata{sn}.behavior(:,10));
  42. end
  43. % unqexprr=unique(catexperrew);
  44. % catexperrew(catexperrew==unqexprr(1))=0;
  45. % catexperrew(catexperrew==unqexprr(2))=1;
  46. % catexperrew(catexperrew==unqexprr(3))=2;
  47. % catexperrew(catexperrew==unqexprr(4))=3;
  48. behinfos.offer1pr=catoffer1pr;
  49. behinfos.offer1rw=catoffer1rw;
  50. behinfos.offer1ev=catoffer1ev;
  51. behinfos.offer2pr=catoffer2pr;
  52. behinfos.offer2rw=catoffer2rw;
  53. behinfos.offer2ev=catoffer2ev;
  54. behinfos.choose12=catchoose12;
  55. behinfos.chooseLR=catchooseLR;
  56. behinfos.offer1sd=catoffer1sd; %offer1sd==1 means 1st offer is LEFT
  57. behinfos.experrew=catexperrew;
  58. behinfos.offer1var=behinfos.offer1pr.*(1-behinfos.offer1pr).*behinfos.offer1rw;
  59. behinfos.offer2var=behinfos.offer2pr.*(1-behinfos.offer2pr).*behinfos.offer2rw;
  60. behinfos.offerLev=behinfos.offer1ev.*(behinfos.offer1sd==1)+behinfos.offer2ev.*(behinfos.offer1sd==2);
  61. behinfos.offerRev=behinfos.offer2ev.*(behinfos.offer1sd==1)+behinfos.offer1ev.*(behinfos.offer1sd==2);
  62. behinfos.offerLvar=behinfos.offer1var.*(behinfos.offer1sd==1)+behinfos.offer2var.*(behinfos.offer1sd==2);
  63. behinfos.offerRvar=behinfos.offer2var.*(behinfos.offer1sd==1)+behinfos.offer1var.*(behinfos.offer1sd==2);
  64. % retrieve indices of trials first left, second right and first right second left
  65. behinfos.i1L1R=(behinfos.offer1rw==1 & behinfos.offer2rw==1 & behinfos.offer1sd==1);
  66. behinfos.i1L2R=(behinfos.offer1rw==1 & behinfos.offer2rw==2 & behinfos.offer1sd==1);
  67. behinfos.i1L3R=(behinfos.offer1rw==1 & behinfos.offer2rw==3 & behinfos.offer1sd==1);
  68. behinfos.i2L1R=(behinfos.offer1rw==2 & behinfos.offer2rw==1 & behinfos.offer1sd==1);
  69. behinfos.i2L2R=(behinfos.offer1rw==2 & behinfos.offer2rw==2 & behinfos.offer1sd==1);
  70. behinfos.i2L3R=(behinfos.offer1rw==2 & behinfos.offer2rw==3 & behinfos.offer1sd==1);
  71. behinfos.i3L1R=(behinfos.offer1rw==3 & behinfos.offer2rw==1 & behinfos.offer1sd==1);
  72. behinfos.i3L2R=(behinfos.offer1rw==3 & behinfos.offer2rw==2 & behinfos.offer1sd==1);
  73. behinfos.i3L3R=(behinfos.offer1rw==3 & behinfos.offer2rw==3 & behinfos.offer1sd==1);
  74. behinfos.i1R1L=(behinfos.offer1rw==1 & behinfos.offer2rw==1 & behinfos.offer1sd==2);
  75. behinfos.i1R2L=(behinfos.offer1rw==1 & behinfos.offer2rw==2 & behinfos.offer1sd==2);
  76. behinfos.i1R3L=(behinfos.offer1rw==1 & behinfos.offer2rw==3 & behinfos.offer1sd==2);
  77. behinfos.i2R1L=(behinfos.offer1rw==2 & behinfos.offer2rw==1 & behinfos.offer1sd==2);
  78. behinfos.i2R2L=(behinfos.offer1rw==2 & behinfos.offer2rw==2 & behinfos.offer1sd==2);
  79. behinfos.i2R3L=(behinfos.offer1rw==2 & behinfos.offer2rw==3 & behinfos.offer1sd==2);
  80. behinfos.i3R1L=(behinfos.offer1rw==3 & behinfos.offer2rw==1 & behinfos.offer1sd==2);
  81. behinfos.i3R2L=(behinfos.offer1rw==3 & behinfos.offer2rw==2 & behinfos.offer1sd==2);
  82. behinfos.i3R3L=(behinfos.offer1rw==3 & behinfos.offer2rw==3 & behinfos.offer1sd==2);
  83. behinfos.ifLsR=[find(behinfos.i1L1R); find(behinfos.i1L2R); find(behinfos.i1L3R);...
  84. find(behinfos.i2L1R); find(behinfos.i2L2R); find(behinfos.i2L3R);...
  85. find(behinfos.i3L1R); find(behinfos.i3L2R); find(behinfos.i3L3R)];
  86. behinfos.ifRsL=[find(behinfos.i1R1L); find(behinfos.i1R2L); find(behinfos.i1R3L);...
  87. find(behinfos.i2R1L); find(behinfos.i2R2L); find(behinfos.i2R3L);...
  88. find(behinfos.i3R1L); find(behinfos.i3R2L); find(behinfos.i3R3L)];
  89. % retrieve indices of trials with chosen offer (1=safe, 2=medium, 3=large)
  90. i1L23R=[find(behinfos.i1L2R); find(behinfos.i1L3R)];
  91. i23L1R=[find(behinfos.i2L1R); find(behinfos.i3L1R)];
  92. i1R23L=[find(behinfos.i1R2L); find(behinfos.i1R3L)];
  93. i23R1L=[find(behinfos.i2R1L); find(behinfos.i3R1L)];
  94. behinfos.ioff1L=[find(behinfos.i1L1R); i1L23R];
  95. behinfos.ioff1R=[find(behinfos.i1R1L); i1R23L];
  96. i1L23R(behinfos.choose12(i1L23R)==2)=[];
  97. i23L1R(behinfos.choose12(i23L1R)==1)=[];
  98. i1R23L(behinfos.choose12(i1R23L)==2)=[];
  99. i23R1L(behinfos.choose12(i23R1L)==1)=[];
  100. behinfos.ichn1L=[find(behinfos.i1L1R); i1L23R; i23R1L];
  101. behinfos.ichn1R=[find(behinfos.i1R1L); i1R23L; i23L1R];
  102. i2L13R=[find(behinfos.i2L1R); find(behinfos.i2L3R)];
  103. i13L2R=[find(behinfos.i1L2R); find(behinfos.i3L2R)];
  104. i2R13L=[find(behinfos.i2R1L); find(behinfos.i2R3L)];
  105. i13R2L=[find(behinfos.i1R2L); find(behinfos.i3R2L)];
  106. behinfos.ioff2L=[i2L13R; find(behinfos.i2L2R); i13R2L];
  107. behinfos.ioff2R=[i2R13L; find(behinfos.i2R2L); i13L2R];
  108. i2L13R(behinfos.choose12(i2L13R)==2)=[];
  109. i13L2R(behinfos.choose12(i13L2R)==1)=[];
  110. i2R13L(behinfos.choose12(i2R13L)==2)=[];
  111. i13R2L(behinfos.choose12(i13R2L)==1)=[];
  112. behinfos.ichn2L=[i2L13R; find(behinfos.i2L2R); i13R2L];
  113. behinfos.ichn2R=[i2R13L; find(behinfos.i2R2L); i13L2R];
  114. i3L12R=[find(behinfos.i3L1R); find(behinfos.i3L2R)];
  115. i12L3R=[find(behinfos.i1L3R); find(behinfos.i2L3R)];
  116. i3R12L=[find(behinfos.i3R1L); find(behinfos.i3R2L)];
  117. i12R3L=[find(behinfos.i1R3L); find(behinfos.i2R3L)];
  118. behinfos.ioff3L=[i3L12R; i12R3L; find(behinfos.i3L3R)];
  119. behinfos.ioff3R=[i3R12L; i12L3R; find(behinfos.i3R3L)];
  120. i3L12R(behinfos.choose12(i3L12R)==2)=[];
  121. i12L3R(behinfos.choose12(i12L3R)==1)=[];
  122. i3R12L(behinfos.choose12(i3R12L)==2)=[];
  123. i12R3L(behinfos.choose12(i12R3L)==1)=[];
  124. behinfos.ichn3L=[i3L12R; i12R3L; find(behinfos.i3L3R)];
  125. behinfos.ichn3R=[i3R12L; i12L3R; find(behinfos.i3R3L)];
  126. % this last check was for temp debugging but ok
  127. if ~ (length(behinfos.choose12) == (length([behinfos.ichn1L; behinfos.ichn1R; behinfos.ichn2L; behinfos.ichn2R; behinfos.ichn3L; behinfos.ichn3R])))
  128. error('behavioral data show incongruencies in accessing the actual chosen magnitudes');
  129. end
  130. end