Skip to content

Commit

Permalink
patch processing with CNMF
Browse files Browse the repository at this point in the history
  • Loading branch information
epnev committed Nov 12, 2017
1 parent 3580c3d commit fd854a6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
50 changes: 49 additions & 1 deletion @CNMF/CNMF.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
properties
file = ''; % path to file
Y; % raw data in X x Y ( x Z) x T format
data; % pointer to memory mapped file
Yr; % raw data in 2d matrix XY(Z) X T format
sn; % noise level for each pixel
A; % spatial components of neurons
Expand Down Expand Up @@ -59,6 +60,11 @@
merged_ROIs; % indeces of merged components
CI; % correlation image
contours; % contour coordinates for each spatial component
patches; % coordinates of each patch
patch_size = [64,64]; % size of each patch
overlap = [10,10]; % overlap between patches
memmaped = true; %
RESULTS % object array with results on each patch
indicator = 'GCaMP6f';
kernel;
kernels;
Expand All @@ -67,7 +73,7 @@
methods

%% construct object and set options
function obj = CNM(varargin)
function obj = CNMF(varargin)
obj.options = CNMFSetParms();
if nargin>0
obj.options = CNMFSetParms(obj.options, varargin{:});
Expand Down Expand Up @@ -350,5 +356,47 @@ function fit(obj,Y,options,K,gSig)
obj.updateTemporal(obj.p);
end

%% create memory mapped file for patch processing

function CNMF_patches(obj,filename,memmaped)
if exist('memmaped','var'); obj.memmaped = memmaped; end
if obj.memmaped
[filepath,name,ext] = fileparts(filename);
obj.file = fullfile(filepath,[name,'.mat']);
if exist(obj.file,'file')
obj.data = matfile(obj.file,'Writable',true);
else
obj.data = memmap_file(filename,1,[],5000);
end
else
obj.file = 'filename';
obj.data = read_file(filename);
end
obj.options = CNMFSetParms();
sizY = size(obj.data,'Y');
obj.dims = sizY(1:end-1);
obj.nd = length(obj.dims);
obj.minY = obj.data.nY;
obj.T = sizY(end);
end

%% construct patches
function createPatches(obj,patch_size,overlap)
if exist('patch_size','var'); obj.patch_size = patch_size; end
if exist('overlap','var'); obj.overlap = overlap; end
obj.patches = construct_patches(obj.dims,obj.patch_size,obj.overlap);
end

%% fit patches
function fitPatches(obj)
obj.options.refine_flag = false;
[obj.A,obj.b,obj.C,obj.f,obj.S,Pr,obj.RESULTS,obj.R] = ...
run_CNMF_patches(obj.data,obj.K,obj.patches,obj.gSig,obj.p,obj.options);
obj.bl = cell2mat(Pr.b);
obj.c1 = cell2mat(Pr.c1);
obj.neuron_sn = cell2mat(Pr.neuron_sn);
obj.g = cell2mat(Pr.gn);
end

end
end
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
traces2 = prctfilt(C2+YrA2,8,1000,100);

fitness2 = compute_event_exceptionality(traces2,0);
fitness_delta2, = compute_event_exceptionality(diff(traces2,[],2),0);
fitness_delta2 = compute_event_exceptionality(diff(traces2,[],2),0);

%%
keep2 = (fitness_delta2 < - 30 | fitness2 < - 35 | ROIvars2.rval_space> 0.8) & ROIvars2.sizeA > 20 & ROIvars2.sizeA < 200 & ROIvars2.rval_time> 0.75 ;
Expand Down

0 comments on commit fd854a6

Please sign in to comment.