function varargout = Plot1Pdata(varargin) % Plot1Pdata is a GUI allow to load imaging data form CNMF-E and behavior % data from Bpod, it can show data (ROI position, DF traces, DF with single % trials, heatmap of DF with individual trial); % Plot1Pdata also allow to visualize and delete some detected neurons by CNMF-E, which % you believe are not real neurons. (by shape of ROI, DF traces....) % Inputs: % - imaging data (CNMF-E) % - sample rate (hz) % - trial number % - behavior data (Bpod) % Outputs: % - imaging data after delete some non-neurons % % % PLOT1PDATA MATLAB code for Plot1Pdata.fig % PLOT1PDATA, by itself, creates a new PLOT1PDATA or raises the existing % singleton*. % % H = PLOT1PDATA returns the handle to a new PLOT1PDATA or the handle to % the existing singleton*. % % PLOT1PDATA('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in PLOT1PDATA.M with the given input arguments. % % PLOT1PDATA('Property','Value',...) creates a new PLOT1PDATA or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Plot1Pdata_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Plot1Pdata_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % ------------------------------------------------------------------------ % Xian Zhang, email: xzhang@cshl.edu %------------------------------------------------------------------------- % Last Modified by Xian v2.5 28-Feb-2018 14:23:54 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Plot1Pdata_OpeningFcn, ... 'gui_OutputFcn', @Plot1Pdata_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before Plot1Pdata is made visible. function Plot1Pdata_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to Plot1Pdata (see VARARGIN) % Choose default command line output for Plot1Pdata handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes Plot1Pdata wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = Plot1Pdata_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global neuron global dir_nm % clear; clc; if ~exist('nam', 'var') || isempty(nam) try load .dir.mat; %load previous path catch dir_nm = [cd(), filesep]; %use the current path end [file_nm, dir_nm] = uigetfile(fullfile(dir_nm, '*.mat')); if dir_nm~=0 save .dir.mat dir_nm; else fprintf('no file was selected. STOP!\N'); return; end nam = [dir_nm, file_nm]; % full name of the data file [~, file_nm, file_type] = fileparts(nam); end nam_mat = [dir_nm, file_nm, '.mat']; data = matfile(nam_mat); neuron = data.neuron; if ~isempty(neuron) try ROINumber = size(neuron.C,1); set(handles.listbox2, 'String',{num2str([1:ROINumber]')}); end else errordlg('Error! No data were selected!'); return; end % --- Executes on selection change in listbox2. function listbox2_Callback(hObject, eventdata, handles) % hObject handle to listbox2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns listbox2 contents as cell array % contents{get(hObject,'Value')} returns selected item from listbox2 global neuron global TrialTypes sample_rate = str2double(get(handles.edit1,'string')); nTrials = str2double(get(handles.edit2,'string')); ROI_num = get(handles.listbox2,'Value'); A = full(neuron.A); C = neuron.C; if ~isempty(TrialTypes) % sort all trails according to trial type [B I] = sort(TrialTypes); temp = reshape(C(ROI_num,:),length(C(ROI_num,:))/nTrials,nTrials); temp_sort = temp(:,I); temp_trace = reshape(temp_sort,size(temp_sort,1)*size(temp_sort,2),1); % plot DF traces axes (handles.axes4) plot(temp_trace) box off axis([0 length(temp_trace) min(C(ROI_num,:)) max(C(ROI_num,:))]) set(gca,'FontSize',8) xlabel('Frame #','fontsize',8) ylabel('DF #','fontsize',8) % plot ROI position axes (handles.axes2) ROI = reshape(A(:,ROI_num),size(neuron.Cn,1),size(neuron.Cn,2)); imagesc(ROI) axis off % plot heatmap axes (handles.axes3) imagesc(temp_sort'); set(gca,'FontSize',8) xlabel('Frame #','fontsize',8) ylabel('Trial #','fontsize',8) colorbar else % plot DF traces axes (handles.axes4) plot(C(ROI_num,:)) box off axis([0 size(C,2) min(C(ROI_num,:)) max(C(ROI_num,:))]) set(gca,'FontSize',8) xlabel('Frame #','fontsize',8) ylabel('DF #','fontsize',8) % plot ROI position axes (handles.axes2) ROI = reshape(A(:,ROI_num),size(neuron.Cn,1),size(neuron.Cn,2)); imagesc(ROI) axis off % plot heatmap axes (handles.axes3) temp = reshape(C(ROI_num,:),length(C(ROI_num,:))/nTrials,nTrials); imagesc(temp'); set(gca,'FontSize',8) xlabel('Frame #','fontsize',8) ylabel('Trial #','fontsize',8) colorbar end % --- Executes during object creation, after setting all properties. function listbox2_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) global TrialTypes % clear; clc; if ~exist('nam', 'var') || isempty(nam) try load .dir.mat; %load previous path catch dir_nm = [cd(), filesep]; %use the current path end [file_nm, dir_nm] = uigetfile(fullfile(dir_nm, '*.mat')); if dir_nm~=0 save .dir.mat dir_nm; else fprintf('no file was selected. STOP!\N'); return; end nam = [dir_nm, file_nm]; % full name of the data file [~, file_nm, file_type] = fileparts(nam); end nam_mat = [dir_nm, file_nm, '.mat']; data = matfile(nam_mat); SessionData = data.SessionData; TrialTypes = SessionData.TrialTypes; % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) global neuron A = neuron.A; C = neuron.C; ROI_num = get(handles.listbox2,'Value'); nTrials = str2double(get(handles.edit2,'string')); % delete this neuron C(ROI_num,:) = []; A(:,ROI_num) = []; % refresh ROI number in the listbox try CellNumber = size(A,2); if ROI_num > CellNumber value = CellNumber; else value = ROI_num; end set(handles.listbox2, 'String',{num2str([1:CellNumber]')},'value',value); end % update ploting % plot DF traces axes (handles.axes4) plot(C(value,:)) box off axis([0 size(C,2) min(C(value,:)) max(C(value,:))]) set(gca,'FontSize',8) xlabel('Frame #','fontsize',8) ylabel('DF #','fontsize',8) % plot ROI position axes (handles.axes2) ROI = reshape(A(:,value),size(neuron.Cn,1),size(neuron.Cn,2)); imagesc(ROI) axis off % plot heatmap axes (handles.axes3) temp = reshape(C(value,:),length(C(value,:))/nTrials,nTrials); imagesc(temp'); set(gca,'FontSize',8) xlabel('Frame #','fontsize',8) ylabel('Trial #','fontsize',8) colorbar % save them into the neuron structure neuron.A = A; neuron.C = C; % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in pushbutton4. function pushbutton4_Callback(hObject, eventdata, handles) global neuron global dir_nm hw = waitbar(0.5,'saving data...'); cd(dir_nm) save neuron neuron % save('Sorted.mat','-v7.3') close(hw) % clear all; clc; % hObject handle to pushbutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double % --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit2_Callback(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit2 as text % str2double(get(hObject,'String')) returns contents of edit2 as a double % --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end