Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add required s1 and s2 variables in peerPC_cov.m #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 43 additions & 10 deletions behavior/predictNeuronsFromAllBeh.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,39 @@
%%
dat = load(fullfile(dataroot,sprintf('spont_%s_%s.mat',dall.db(d).mouse_name,dall.db(d).date)));

% Check if d+1 exists
if d+1 <= length(dall.db)
% If d+1 exists, load data for d+1
dat_2 = load(fullfile(dataroot, sprintf('spont_%s_%s.mat', dall.db(d+1).mouse_name, dall.db(d+1).date)));
else
% If d+1 does not exist, consider loading data for d-1 if d is not the first index
if d > 1
dat_2 = load(fullfile(dataroot, sprintf('spont_%s_%s.mat', dall.db(d-1).mouse_name, dall.db(d-1).date)));
end
end

% Determine the minimum number of rows across the relevant fields
minRows = min([size(dat.Fsp, 1), size(dat_2.Fsp, 1)]);

% Determine the minimum number of columns for Fsp
minColsFsp = min(size(dat.Fsp, 2), size(dat_2.Fsp, 2));

% Adjust the Fsp fields in both structures
dat.Fsp = dat.Fsp(1:minRows, 1:minColsFsp);
dat_2.Fsp = dat_2.Fsp(1:minRows, 1:minColsFsp);

% Since med and stat have the same row dimension as Fsp, adjust their rows to match
% (Assuming med does not need column adjustment as it is ?x3, and stat is likely a 1D array)

dat.med = dat.med(1:minRows, :);
dat_2.med = dat_2.med(1:minRows, :);

% Assuming 'stat' is an array of structures and needs to be resized based on rows
dat.stat = dat.stat(1:minRows);
dat_2.stat = dat_2.stat(1:minRows);

% Now, dat and dat_2 have their 'Fsp', 'med', and 'stat' fields adjusted to match in size

if isfield(dat.stat,'redcell')
Ff = dat.Fsp(~logical([dat.stat(:).redcell]), :);
med = dat.med(~logical([dat.stat(:).redcell]),:);
Expand Down Expand Up @@ -70,27 +103,27 @@
switch btype
%wmot = wmot * sign
case 1
x = zscore([dat.beh.runSpeed(:)],1,1);
x = zscore([dat_2.beh.runSpeed(:)],1,1);
case 2
x = zscore([dat.beh.pupil.area(:)],1,1);
x = zscore([dat_2.beh.pupil.area(:)],1,1);
case 3
x = zscore([dat.beh.whisker.motionSVD(:,1)],1,1);
x = zscore([dat_2.beh.whisker.motionSVD(:,1)],1,1);
case 4
x = zscore([dat.beh.runSpeed(:) dat.beh.pupil.area(:)],1,1);
x = zscore([dat_2.beh.runSpeed(:) dat.beh.pupil.area(:)],1,1);
case 5
x = zscore([dat.beh.runSpeed(:) wmot],1,1);
x = zscore([dat_2.beh.runSpeed(:) wmot],1,1);
case 6
x = zscore([dat.beh.pupil.area(:) wmot],1,1);
x = zscore([dat_2.beh.pupil.area(:) wmot],1,1);
case 7
x = zscore([dat.beh.runSpeed(:) dat.beh.pupil.area(:) wmot],1,1);
x = zscore([dat_2.beh.runSpeed(:) dat.beh.pupil.area(:) wmot],1,1);
case 8
x = zscore(dat.beh.face.motionSVD(:,1),1,1);
x = zscore(dat_2.beh.face.motionSVD(:,1),1,1);
case 9
x = dat.beh.face.motionSVD;
x = dat_2.beh.face.motionSVD;
x = x - mean(x,1);
x = x / std(x(:,1));
case 10
x = dat.beh.face.motionSVD;
x = dat_2.beh.face.motionSVD;
x = x - mean(x,1);
x = x / std(x(:,1));
x = [x zscore([dat.beh.runSpeed(:) dat.beh.pupil.area(:) wmot],1,1)];
Expand Down
2 changes: 2 additions & 0 deletions behavior/predictNeuronsFromFacePositions.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ function predictNeuronsFromFacePositions(dataroot,matroot)
x = reshape(x, [], np);
x = x';

ndims0 = [1 2 3 4 8 16 32 64 128];

ndims1 = ndims0(ndims0<=size(x,1) & ndims0<=size(v,1));

%% low rank regression
Expand Down
57 changes: 43 additions & 14 deletions behavior/predictPCsFromAllBeh.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,35 @@
%%
dat = load(fullfile(dataroot,sprintf('spont_%s_%s.mat',dall.db(d).mouse_name,dall.db(d).date)));

% Check if d+1 exists
if d+1 <= length(dall.db)
% If d+1 exists, load data for d+1
dat_2 = load(fullfile(dataroot, sprintf('spont_%s_%s.mat', dall.db(d+1).mouse_name, dall.db(d+1).date)));
else
% If d+1 does not exist, consider loading data for d-1 if d is not the first index
if d > 1
dat_2 = load(fullfile(dataroot, sprintf('spont_%s_%s.mat', dall.db(d-1).mouse_name, dall.db(d-1).date)));
end
end

% Determine the minimum number of columns for Fsp
minColsFsp = min(size(dat.Fsp, 2), size(dat_2.Fsp, 2));

% Adjust the Fsp fields in both structures
dat.Fsp = dat.Fsp(:, 1:minColsFsp);
dat_2.Fsp = dat_2.Fsp(:, 1:minColsFsp);

% Since med and stat have the same row dimension as Fsp, adjust their rows to match
% (Assuming med does not need column adjustment as it is ?x3, and stat is likely a 1D array)
dat.beh.runSpeed = dat.beh.runSpeed(1:minColsFsp)
dat_2.beh.runSpeed = dat_2.beh.runSpeed(1:minColsFsp)
dat_2.beh.pupil.area =dat_2.beh.pupil.area(1:minColsFsp)
dat.beh.pupil.area =dat.beh.pupil.area(1:minColsFsp)
dat_2.beh.whisker.motionSVD = dat_2.beh.whisker.motionSVD(1:minColsFsp,:)
dat.beh.whisker.motionSVD = dat.beh.whisker.motionSVD(1:minColsFsp,:)
dat_2.beh.face.motionSVD = dat_2.beh.face.motionSVD(1:minColsFsp,:)
dat.beh.face.motionSVD = dat.beh.face.motionSVD(1:minColsFsp,:)

if isfield(dat.stat,'redcell')
Ff = dat.Fsp(~logical([dat.stat(:).redcell]), :);
med = dat.med(~logical([dat.stat(:).redcell]),:);
Expand Down Expand Up @@ -75,37 +104,37 @@
%% loop over behavioral predictors

for btype = [1:10]
wmot = dat.beh.whisker.motionSVD(:,1);
wmot = wmot * sign(mean(mean(dat.beh.whisker.motionMask(:,:,1))));
wmot = dat_2.beh.whisker.motionSVD(:,1);
wmot = wmot * sign(mean(mean(dat_2.beh.whisker.motionMask(:,:,1))));
switch btype
%wmot = wmot * sign
case 1
x = zscore([dat.beh.runSpeed(:)],1,1);
x = zscore([dat_2.beh.runSpeed(:)],1,1);
case 2
x = zscore([dat.beh.pupil.area(:)],1,1);
x = zscore([dat_2.beh.pupil.area(:)],1,1);
case 3
x = zscore([dat.beh.whisker.motionSVD(:,1)],1,1);
x = zscore([dat_2.beh.whisker.motionSVD(:,1)],1,1);
case 4
x = zscore([dat.beh.runSpeed(:) dat.beh.pupil.area(:)],1,1);
x = zscore([dat_2.beh.runSpeed(:) dat_2.beh.pupil.area(:)],1,1);
case 5
x = zscore([dat.beh.runSpeed(:) wmot],1,1);
x = zscore([dat_2.beh.runSpeed(:) wmot],1,1);
case 6
x = zscore([dat.beh.pupil.area(:) wmot],1,1);
x = zscore([dat_2.beh.pupil.area(:) wmot],1,1);
case 7
x = zscore([dat.beh.runSpeed(:) dat.beh.pupil.area(:) wmot],1,1);
x = zscore([dat_2.beh.runSpeed(:) dat_2.beh.pupil.area(:) wmot],1,1);
case 8
x = zscore(dat.beh.face.motionSVD(:,1),1,1);
x = zscore(dat_2.beh.face.motionSVD(:,1),1,1);
case 9
x = dat.beh.face.motionSVD;
x = dat_2.beh.face.motionSVD;
x = x - mean(x,1);
x = x / std(x(:,1));
case 10
x = dat.beh.face.motionSVD;
x = dat_2.beh.face.motionSVD;
x = x - mean(x,1);
x = x / std(x(:,1));
x = [x zscore([dat.beh.runSpeed(:) dat.beh.pupil.area(:) wmot],1,1)];
x = [x zscore([dat_2.beh.runSpeed(:) dat_2.beh.pupil.area(:) wmot],1,1)];
end

x = x * 10;
x = x(1:end-(tdelay),:); % apply time delay
x = bin2d(x, tbin, 1);
Expand Down
6 changes: 3 additions & 3 deletions ephys/alignFaces30Hz.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ function alignFaces30Hz(ephysroot, matroot)


% load files
beh = load(fullfile(ephysroot, sprintf('%s_face_proc.mat',mouse_name)));
beh = load(fullfile(ephysroot, "faces", sprintf('%s_face_proc.mat',mouse_name)));
motSVD = beh.motionSVD;
tVid = beh.times; % times of movie frames in spike reference frame

load(fullfile(ephysroot, sprintf('spks%s_Feb18.mat',mouse_name)));
load(fullfile(ephysroot, "spks", sprintf('spks%s_Feb18.mat',mouse_name)));

%% extract spikes
stall = zeros(5e3,5500,'uint8');
Expand Down Expand Up @@ -93,4 +93,4 @@ function alignFaces30Hz(ephysroot, matroot)
save(fullfile(matroot, sprintf('%swithFaces_KS2.mat',mouse_name)), 'stall','Wh','iprobe',...
'motSVD','tspont','tVid','srate','brainLoc','areaLabels');

end
end
2 changes: 1 addition & 1 deletion ephys/masterAnalysis.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% runs all the analyses for the EPHYS recordings!
1% runs all the analyses for the EPHYS recordings!
function masterAnalysis(matroot)

mstr = {'Krebs','Waksman','Robbins'};
Expand Down
6 changes: 3 additions & 3 deletions mainfigs/fig2new.m
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ function fig2newnew(matroot)
hs{i}.Position(2) = hs{i}.Position(2)+.06;
hold all;
shadedErrorBar([1:1024],100*mean((cov_neur-squeeze(cov_res_beh(:,6,:,9)))./var_neur,2),...
std(100*(cov_neur-squeeze(cov_res_beh(:,6,:,9)))./var_neur,1,2)/sqrt(ndat-1),{'color','b','linewidth',1});
std(100*(cov_neur-squeeze(cov_res_beh(:,6,:,9)))./var_neur,1,2)/sqrt(ndat-1),'lineProps',{'color','b','linewidth',1});
shadedErrorBar([1:1024],100*mean(cov_neur./var_neur,2),...
std(100*cov_neur./var_neur,1,2)/sqrt(ndat-1),{'color',.8*[1 1 1],'linewidth',1});
std(100*cov_neur./var_neur,1,2)/sqrt(ndat-1),'lineProps',{'color',.8*[1 1 1],'linewidth',1});
shadedErrorBar([1:1024],100*mean((cov_neur-squeeze(cov_res_beh(:,3,:,7)))./var_neur,2),...
std(100*(cov_neur-squeeze(cov_res_beh(:,3,:,7)))./var_neur,1,2)/sqrt(ndat-1),{'color',[0 0.2 0],'linewidth',1});
std(100*(cov_neur-squeeze(cov_res_beh(:,3,:,7)))./var_neur,1,2)/sqrt(ndat-1),'lineProps',{'color',[0 0.2 0],'linewidth',1});
%axis([0 .06 0 .06]);
set(gca,'xtick',10.^[0 1 2])
text(.55,.9,{'max explainable'},'color',.6*[1 1 1],'fontsize',6)
Expand Down
2 changes: 1 addition & 1 deletion make_figs.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
% where data is stored (that you download from figshare)
dataroot = '/media/carsen/DATA2/grive/10krecordings/spont_paper/';
% where processed data and results are saved
matroot = '/media/carsen/DATA2/grive/10krecordings/spontResults/';
matroot = '/alzheimer/Roberto/Data_papers/spontResults/';


%% this will produce the figures
Expand Down
8 changes: 6 additions & 2 deletions multiDactivity/peerPC_cov.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function peerPC_cov(dataroot,matroot,useGPU,dex)
%Ff = randn(size(Ff));
Lblock = 60;
fractrain = 0.5;
[itrain, itest] = splitInterleaved(NT, Lblock, fractrain, 1);
[itrain, itest] = splitInterleaved(NT, Lbleock, fractrain, 1);
tic;
if useGPU
Ff = gpuArray(single(Ff));
Expand All @@ -72,6 +72,10 @@ function peerPC_cov(dataroot,matroot,useGPU,dex)
semilogx(sneur./varneur)

[u2,~,~] = svdecon(Ff(ntrain,itrain));

s1 = u' * Ff(ntrain,itest);
s2 = v' * Ff(ntest,itest);

cpc = corr(gather_try(s1(1,:)'), gather_try(Ff(ntrain,itest)' * u2(:,1)));
disp(cpc);
corrPC1(d) = cpc;
Expand All @@ -88,4 +92,4 @@ function peerPC_cov(dataroot,matroot,useGPU,dex)

%%

save(fullfile(matroot,'PCpredict.mat'),'cov_neur','var_neur','exampleV1','exampleV2', 'corrPC1');
save(fullfile(matroot,'PCpredict.mat'),'cov_neur','var_neur','exampleV1','exampleV2', 'corrPC1');
6 changes: 3 additions & 3 deletions process_data.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

% you should change this to your local data paths
% where you downloaded the 2P data
dataroot = '/media/carsen/DATA2/grive/10krecordings/spontData';
dataroot = '/alzheimer/Roberto/Data_papers/6163622/';

% where ephys data is
ephysroot = '/home/carsen/dm11/data/Spikes/eightprobes/';

% give a local folder for saving intermediate data (around 4-5GB)
matroot = '/media/carsen/DATA2/grive/10krecordings/spontResults';
matroot = '/alzheimer/Roberto/Data_papers/spontResults/';

mkdir(matroot)

% do you have a GPU? if not set to 0
useGPU = 1;

% should be in github folder
addpath(genpath('.'));
%addpath(genpath('.'));

% also download rastermap
% https://github.com/MouseLand/rastermap/
Expand Down