diff --git a/Bearphys.fig b/Bearphys.fig new file mode 100644 index 0000000..74741fc Binary files /dev/null and b/Bearphys.fig differ diff --git a/Bearphys.m b/Bearphys.m new file mode 100644 index 0000000..ca7565f --- /dev/null +++ b/Bearphys.m @@ -0,0 +1,447 @@ +function varargout = Bearphys(varargin) +% BEARPHYS MATLAB code for Bearphys.fig +% BEARPHYS, by itself, creates a new BEARPHYS or raises the existing +% singleton*. +% +% H = BEARPHYS returns the handle to a new BEARPHYS or the handle to +% the existing singleton*. +% +% BEARPHYS('CALLBACK',hObject,eventData,handles,...) calls the local +% function named CALLBACK in BEARPHYS.M with the given input arguments. +% +% BEARPHYS('Property','Value',...) creates a new BEARPHYS or raises the +% existing singleton*. Starting from the left, property value pairs are +% applied to the GUI before Bearphys_OpeningFcn gets called. An +% unrecognized property name or invalid value makes property application +% stop. All inputs are passed to Bearphys_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 + +% Edit the above text to modify the response to help Bearphys + +% Last Modified by GUIDE v2.5 23-Jan-2017 17:29:07 + +% Begin initialization code - DO NOT EDIT +gui_Singleton = 1; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @Bearphys_OpeningFcn, ... + 'gui_OutputFcn', @Bearphys_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 Bearphys is made visible. +function Bearphys_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 Bearphys (see VARARGIN) + +% Choose default command line output for Bearphys +handles.output = hObject; + +% The data struct contains infor about the currently active sweepsets +data.number_active=0; +data.sweepset_handles=sweepset.empty(0,20); +data.sweepset_SIN=zeros(0,20); %sins are specific identifyers for every sweepset + +setappdata(handles.output,'data',data); + +% Update handles structure +guidata(hObject, handles); + +% Add listener for being closed +set(handles.output,'CloseRequestFcn',{@close_req, handles}) + +% --- Outputs from this function are returned to the command line. +function varargout = Bearphys_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 open_file. +function open_file_Callback(hObject, eventdata, handles) +% hObject handle to open_file (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +new_sweepset=sweepset('user_select','on'); +if ~isvalid(new_sweepset) %user pressed cancel + return +end + +% update data struct +data=getappdata(handles.output,'data'); +data.number_active=data.number_active+1; +data.sweepset_handles(data.number_active)=new_sweepset; +new_sweepset.settings.SIN=rand(1); %10000 possibilities +data.sweepset_SIN(data.number_active)=new_sweepset.settings.SIN; + +setappdata(handles.output,'data',data); +setappdata(handles.output,'paired_sweepset',new_sweepset); + +% listeners to see if anything changes in the sweepsets +listeners=getappdata(handles.output,'listeners'); +listeners=[listeners addlistener(new_sweepset,'state_change',@(scr, ev) update_everything(scr, ev, handles))]; +listeners=[listeners addlistener(new_sweepset,'sweepset_closed',@(scr, ev) sweepset_closed(scr, ev, handles,new_sweepset.settings.SIN))]; +setappdata(handles.output,'listeners',listeners); + +update_everything(handles.output,'empty',handles); + +% Make all the buttons visible +buttons_visible(handles,'on'); + +% --- Executes on slider movement. +function sweep_selector_Callback(hObject, eventdata, handles) +% hObject handle to sweep_selector (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,'Value') returns position of slider +% get(hObject,'Min') and get(hObject,'Max') to determine range of slider + current_sweepset=getappdata(handles.output,'paired_sweepset'); + test_type=whos('current_sweepset'); + + if strcmp(test_type.class,'sweepset') + current_sweepset.move_sweep(round(get(hObject,'Value'))); + end + +% --- Executes during object creation, after setting all properties. +function sweep_selector_CreateFcn(hObject, eventdata, handles) +% hObject handle to sweep_selector (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: slider controls usually have a light gray background. +if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor',[.9 .9 .9]); +end + +% --- Executes on button press in substract_baseline. +function substract_baseline_Callback(hObject, eventdata, handles) +% hObject handle to substract_baseline (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hint: get(hObject,'Value') returns toggle state of substract_baseline + current_sweepset=getappdata(handles.output,'paired_sweepset'); + test_type=whos('current_sweepset'); + + if strcmp(test_type.class,'sweepset') + current_sweepset.substract_baseline + notify(current_sweepset,'state_change') + end + +% --- Executes on button press in measure. +function measure_Callback(hObject, eventdata, handles) +% hObject handle to measure (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + current_sweepset=getappdata(handles.output,'paired_sweepset'); + test_type=whos('current_sweepset'); + + if strcmp(test_type.class,'sweepset') + if ishandle(current_sweepset.handles.measurement) + else + current_sweepset.handles.measurement=measure(current_sweepset); + notify(current_sweepset,'state_change') + end + end + +% --- Executes on button press in firing_frequency. +function firing_frequency_Callback(hObject, eventdata, handles) +% hObject handle to firing_frequency (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + current_sweepset=getappdata(handles.output,'paired_sweepset'); + test_type=whos('current_sweepset'); + + if strcmp(test_type.class,'sweepset') + if ishandle(current_sweepset.handles.firing_frequency) + else + current_sweepset.handles.firing_frequency=firing_frequency(current_sweepset); + notify(current_sweepset,'selection_change') %force update of firing frequency + end + end + +% --- Executes on button press in average_trace. +function average_trace_Callback(hObject, eventdata, handles) +% hObject handle to average_trace (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hint: get(hObject,'Value') returns toggle state of average_trace + + current_sweepset=getappdata(handles.output,'paired_sweepset'); + test_type=whos('current_sweepset'); + + if strcmp(test_type.class,'sweepset') + status=get(current_sweepset.handles.average_trace,'visible'); + if strcmp(status,'off') + set(current_sweepset.handles.average_trace,'visible','on') + else + set(current_sweepset.handles.average_trace,'visible','off') + end + notify(current_sweepset,'state_change') + end + +% --- Executes on button press in background. +function background_Callback(hObject, eventdata, handles) +% hObject handle to background (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hint: get(hObject,'Value') returns toggle state of background + current_sweepset=getappdata(handles.output,'paired_sweepset'); + test_type=whos('current_sweepset'); + + if strcmp(test_type.class,'sweepset') + status=get(current_sweepset.handles.all_sweeps(1),'visible'); + if strcmp(status,'off') + set(current_sweepset.handles.all_sweeps,'visible','on') + else + set(current_sweepset.handles.all_sweeps,'visible','off') + end + notify(current_sweepset,'state_change') + end + +function smooth_average_Callback(hObject, eventdata, handles) +% hObject handle to smooth_average (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 smooth_average as text +% str2double(get(hObject,'String')) returns contents of smooth_average as a double + current_sweepset=getappdata(handles.output,'paired_sweepset'); + test_type=whos('current_sweepset'); + + if strcmp(test_type.class,'sweepset') + SF=current_sweepset.sampling_frequency; + current_sweepset.settings.average_smooth=round(str2num(get(hObject,'String'))*SF); + set(current_sweepset.handles.average_trace,'YData',current_sweepset.average_trace); %force update + end + +% --- Executes during object creation, after setting all properties. +function smooth_average_CreateFcn(hObject, eventdata, handles) +% hObject handle to smooth_average (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 + +% --- Executes on selection change in baseline_method. +function baseline_method_Callback(hObject, eventdata, handles) +% hObject handle to baseline_method (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 baseline_method contents as cell array +% contents{get(hObject,'Value')} returns selected item from baseline_method + current_sweepset=getappdata(handles.output,'paired_sweepset'); + test_type=whos('current_sweepset'); + + if strcmp(test_type.class,'sweepset'); + switch get(hObject,'Value') + case 1 + current_sweepset.settings.baseline_info.method='standard'; + case 2 + current_sweepset.settings.baseline_info.method='whole_trace'; + case 3 + current_sweepset.settings.baseline_info.method='moving_average_1s'; + end + current_sweepset.settings.baseline_info.substracted=~current_sweepset.settings.baseline_info.substracted; + current_sweepset.substract_baseline + notify(current_sweepset,'state_change') + end + +% --- Executes during object creation, after setting all properties. +function baseline_method_CreateFcn(hObject, eventdata, handles) +% hObject handle to baseline_method (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 print_selection. +function print_selection_Callback(hObject, eventdata, handles) +% hObject handle to print_selection (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + current_sweepset=getappdata(handles.output,'paired_sweepset'); + test_type=whos('current_sweepset'); + + if strcmp(test_type.class,'sweepset') + current_sweepset.sweep_selection + end + +% --- Executes on button press in smooth_trace. +function smooth_trace_Callback(hObject, eventdata, handles) +% hObject handle to smooth_trace (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hint: get(hObject,'Value') returns toggle state of smooth_trace + current_sweepset=getappdata(handles.output,'paired_sweepset'); + +if get(hObject,'Value')==1; + current_sweepset.smooth_trace(str2num(get(handles.smooth_ms,'String'))); +else + current_sweepset.smooth_trace('undo'); +end + + + +function smooth_ms_Callback(hObject, eventdata, handles) +% hObject handle to smooth_ms (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 smooth_ms as text +% str2double(get(hObject,'String')) returns contents of smooth_ms as a double + + +% --- Executes during object creation, after setting all properties. +function smooth_ms_CreateFcn(hObject, eventdata, handles) +% hObject handle to smooth_ms (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 + +%%%%%%%%%%%%%%%%%%%%%%%%%%%% other functions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +function update_everything(scr,ev,handles) +% Update all aspects of this GUI + if strcmp(ev,'closed_sweepset') + %means a sweepset was just closed, find the NEXT one on top + list=get(0,'children'); + found_it=0; + i=1; + while found_it==0; + i=i+1; %NEXT sweepset + current_sweepset=getappdata(list(i),'object'); + test_type=whos('current_sweepset'); + if strcmp(test_type.class,'sweepset') + found_it=1; + figure(list(i)); + end + end + else + % figure out which figure is currently active and link this GUI + current_sweepset=getappdata(gcf,'object'); + test_type=whos('current_sweepset'); + end + + if strcmp(test_type.class,'sweepset') + set(handles.sweepset_name,'String',current_sweepset.filename) + set(handles.sweep_selector,... + 'Max',current_sweepset.number_of_sweeps,... + 'Value',current_sweepset.current_sweep,... + 'SliderStep', [1/current_sweepset.number_of_sweeps , 10/current_sweepset.number_of_sweeps]) + set(handles.sweep_number,'String',['sweep ' num2str(current_sweepset.current_sweep)]) + if current_sweepset.sweep_selection(current_sweepset.current_sweep)==true + set(handles.selected,'String','selected','ForegroundColor',[0 0 1]) + else + set(handles.selected,'String','rejected','ForegroundColor',[1 0 0]) + end + if strcmp(get(current_sweepset.handles.average_trace,'visible'),'on') + set(handles.average_trace,'Value',1) + else + set(handles.average_trace,'Value',0) + end + if current_sweepset.settings.baseline_info.substracted==true + set(handles.substract_baseline,'Value',1) + else + set(handles.substract_baseline,'Value',0) + end + if strcmp(get(current_sweepset.handles.all_sweeps(1),'visible'),'on') + set(handles.background,'Value',1) + else + set(handles.background,'Value',0) + end + + % store the figure handle of the selected figure + setappdata(handles.output,'paired_sweepset',current_sweepset); + else %the gcf was not a sweepset, but we have to update something... + update_everything(handles.output,'closed_sweepset',handles); + end + +function sweepset_closed(scr, ev, handles, SIN) + % Will update the selection of availble sweeps + + data=getappdata(handles.output,'data'); + data.sweepset_SIN=data.sweepset_SIN(data.sweepset_SIN~=SIN); + data.number_active=data.number_active-1; + data.sweepset_handles=data.sweepset_handles(isvalid(data.sweepset_handles)); + setappdata(handles.output,'data',data) + + if data.number_active>0 + update_everything(scr, 'closed_sweepset', handles); + else + buttons_visible(handles,'off') + end + +function buttons_visible(handles,input) +set(handles.substract_baseline,'Visible',input) +set(handles.sweep_selector,'Visible',input) +set(handles.average_trace,'Visible',input) +set(handles.background,'Visible',input) +set(handles.measure,'Visible',input) +set(handles.firing_frequency,'Visible',input) +set(handles.print_selection,'Visible',input) +set(handles.baseline_method,'Visible',input) +set(handles.smooth_average,'Visible',input) +set(handles.smooth_average_text,'Visible',input) +set(handles.text5,'Visible',input) +set(handles.sweep_number,'Visible',input) +set(handles.selected,'Visible',input) +set(handles.sweepset_name,'Visible',input) +set(handles.smooth_trace,'Visible',input) +set(handles.smooth_ms,'Visible',input) +set(handles.text6,'Visible',input) + +function close_req(scr, ev, handles) +% runs when Bearphys is asked to close, but leaves sweepsets open, therfore +% listeners have to be delted. + +listeners=getappdata(handles.output,'listeners'); + +for i=1:length(listeners) + delete(listeners(1,i)) +end + +delete(scr) +disp('bye') + + + diff --git a/firing_frequency.fig b/firing_frequency.fig new file mode 100644 index 0000000..fca0da7 Binary files /dev/null and b/firing_frequency.fig differ diff --git a/firing_frequency.m b/firing_frequency.m new file mode 100644 index 0000000..0004bc5 --- /dev/null +++ b/firing_frequency.m @@ -0,0 +1,486 @@ +function varargout = firing_frequency(varargin) +% FIRING_FREQUENCY MATLAB code for firing_frequency.fig +% FIRING_FREQUENCY, by itself, creates a new FIRING_FREQUENCY or raises the existing +% singleton*. +% +% H = FIRING_FREQUENCY returns the handle to a new FIRING_FREQUENCY or the handle to +% the existing singleton*. +% +% FIRING_FREQUENCY('CALLBACK',hObject,eventData,handles,...) calls the local +% function named CALLBACK in FIRING_FREQUENCY.M with the given input arguments. +% +% FIRING_FREQUENCY('Property','Value',...) creates a new FIRING_FREQUENCY or raises the +% existing singleton*. Starting from the left, property value pairs are +% applied to the GUI before firing_frequency_OpeningFcn gets called. An +% unrecognized property name or invalid value makes property application +% stop. All inputs are passed to firing_frequency_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 + +% Edit the above text to modify the response to help firing_frequency + +% Last Modified by GUIDE v2.5 23-Jan-2017 16:40:05 + +% Begin initialization code - DO NOT EDIT +gui_Singleton = 1; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @firing_frequency_OpeningFcn, ... + 'gui_OutputFcn', @firing_frequency_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 firing_frequency is made visible. +function firing_frequency_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 firing_frequency (see VARARGIN) + +% Choose default command line output for firing_frequency +handles.output = hObject; + +% UIWAIT makes firing_frequency wait for user response (see UIRESUME) +% uiwait(handles.figure1); + +% Get the handle of the associated sweepset +handles.paired_sweepset=varargin{1}; +figure(handles.paired_sweepset.handles.figure) + +% Drawing all things assocaited with firing frequency +x_values=xlim; +y_values=ylim; +handles.display_handles.threshold_line=line([x_values(1) x_values(2)],[-10 -10],'Visible','off','Color',[0 1 0],'LineStyle','--'); +handles.display_handles.time_window_lines(1)=line([1149 1149],[y_values(1) y_values(2)],'Visible','off'); +handles.display_handles.time_window_lines(2)=line([2149 2149],[y_values(1) y_values(2)],'Visible','off'); +handles.display_handles.event_markers=plot([1 2 3 4],[0 0 0 0],'visible','off','LineStyle','none','Marker','x','MarkerSize',15,'Color',[0 0 0]); + +% Add listener +handles.listener(1)=addlistener(handles.paired_sweepset,'state_change',@(scr, ev) update_sweep(scr, ev, handles)); +handles.listener(2)=addlistener(handles.paired_sweepset,'selection_change',@(scr, ev) update_everything(scr, ev, handles)); +handles.listener(3)=addlistener(handles.paired_sweepset,'baseline_change',@(scr, ev) update_everything(scr, ev, handles)); + +% Update handles structure +guidata(hObject, handles); + +% Setting a callback for then this GUI is closed +set(hObject,'CloseRequestFcn',{@close_req, handles}) + +% Populating some parts of the GUI +set(handles.filename,'String',handles.paired_sweepset.filename) + + +% --- Outputs from this function are returned to the command line. +function varargout = firing_frequency_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; + + +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 threshold_Callback(hObject, eventdata, handles) +% hObject handle to threshold (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 threshold as text +% str2double(get(hObject,'String')) returns contents of threshold as a double + +threshold_value=str2double(get(hObject,'String')); + +set(handles.display_handles.threshold_line,'YData',[threshold_value threshold_value]) +notify(handles.paired_sweepset,'baseline_change'); + + +% --- Executes during object creation, after setting all properties. +function threshold_CreateFcn(hObject, eventdata, handles) +% hObject handle to threshold (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 start_time_Callback(hObject, eventdata, handles) +% hObject handle to start_time (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 start_time as text +% str2double(get(hObject,'String')) returns contents of start_time as a double + +value=str2double(get(hObject,'String')); +set(handles.display_handles.time_window_lines(1),'XData',[value value]) +notify(handles.paired_sweepset,'baseline_change'); + + +% --- Executes during object creation, after setting all properties. +function start_time_CreateFcn(hObject, eventdata, handles) +% hObject handle to start_time (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 end_time_Callback(hObject, eventdata, handles) +% hObject handle to end_time (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 end_time as text +% str2double(get(hObject,'String')) returns contents of end_time as a double +value=str2double(get(hObject,'String')); +set(handles.display_handles.time_window_lines(2),'XData',[value value]) +notify(handles.paired_sweepset,'baseline_change'); + + +% --- Executes during object creation, after setting all properties. +function end_time_CreateFcn(hObject, eventdata, handles) +% hObject handle to end_time (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 + + +% --- Executes on button press in display_window. +function display_window_Callback(hObject, eventdata, handles) +% hObject handle to display_window (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hint: get(hObject,'Value') returns toggle state of display_window + + + +if get(hObject,'value')==1; + set(handles.display_handles.time_window_lines(1),'Visible','on') + set(handles.display_handles.time_window_lines(2),'Visible','on') +else + set(handles.display_handles.time_window_lines(1),'Visible','off') + set(handles.display_handles.time_window_lines(2),'Visible','off') +end + + +% --- Executes on button press in disp_threshold. +function disp_threshold_Callback(hObject, eventdata, handles) +% hObject handle to disp_threshold (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hint: get(hObject,'Value') returns toggle state of disp_threshold + +if get(hObject,'Value')==1 + set(handles.display_handles.threshold_line,'Visible','on') +else + set(handles.display_handles.threshold_line,'Visible','off') +end + + +% --- Executes on button press in disp_events. +function disp_events_Callback(hObject, eventdata, handles) +% hObject handle to disp_events (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hint: get(hObject,'Value') returns toggle state of disp_events + +if get(hObject,'Value')==1 + set(handles.display_handles.event_markers,'Visible','on') +else + set(handles.display_handles.event_markers,'Visible','off') +end + +% --- Executes on button press in get_events. +function get_events_Callback(hObject, eventdata, handles) +% hObject handle to get_events (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +events=nan(sum(handles.paired_sweepset.sweep_selection),1000); % max 1000 events per sweep +threshold=get(handles.threshold,'String'); +threshold=str2num(threshold); +direction=get(handles.event_direction,'Value'); + +% figure our if the direction of the events is up or down +if direction==0; + direction='down'; +else + direction='up'; +end + +max_events=1; +j=0; +for i=1:handles.paired_sweepset.number_of_sweeps + if handles.paired_sweepset.sweep_selection(i) + j=j+1; + [total_events, timestamps]=find_events(handles.paired_sweepset.data(:,1,i), handles.paired_sweepset.X_data, threshold, direction); + events(j,1:total_events)=timestamps; + if total_events>max_events + max_events=total_events; + end + end +end + +events=events(:,1:max_events); +assignin('base','events',events); +plot=timestamp_plot(events); + +% --- Executes on button press in event_direction. +function event_direction_Callback(hObject, eventdata, handles) +% hObject handle to event_direction (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hint: get(hObject,'Value') returns toggle state of event_direction +%disp('here'); +if get(hObject,'Value')==0 + set(hObject,'String','events go down'); +else + set(hObject,'String','events go up'); +end + +notify(handles.paired_sweepset,'baseline_change'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Callbacks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function close_req(src, callbackdata, handles) +% Delete all doodles from this window + +delete(handles.display_handles.threshold_line) +delete(handles.display_handles.time_window_lines) +delete(handles.display_handles.event_markers) +delete(handles.listener(1)) +delete(handles.listener(2)) +delete(handles.listener(3)) +delete(src) + + + +function update_everything(src, callbackdata, handles) + + +% Update current sweep firing frequency +current_sweep=handles.paired_sweepset.current_sweep; +sweepset=handles.paired_sweepset.data; +selection=handles.paired_sweepset.sweep_selection; +X_trace=handles.paired_sweepset.X_data; +threshold=get(handles.threshold,'String'); +threshold=str2num(threshold); +direction=get(handles.event_direction,'Value'); + +% figure our if the direction of the events is up or down +if direction==0; + direction='down'; +else + direction='up'; +end + +[total_events, timestamps]=find_events(sweepset(:,1,current_sweep),X_trace,threshold, direction); + +spike_frequency=total_events/((max(X_trace)-min(X_trace))/1000); %Timeline should always be in ms +disp_text=['Selected Sweep: ' num2str(spike_frequency) 'Hz']; +set(handles.selected_sweep,'String',disp_text); + +% For this sweep we'll also have the opportunity to indicate events +set(handles.display_handles.event_markers,'XData',timestamps,'YData',ones(1,length(timestamps))*threshold); + +% Update all SELECTED sweeps firing frequency +total_events=find_events(sweepset(:,1,selection),X_trace,threshold, direction); +spike_frequency=sum(total_events)/(((max(X_trace)-min(X_trace))/1000)*length(total_events)); %Length total events, is the number of selected sweeps +disp_text=['All Sweeps: ' num2str(spike_frequency) 'Hz']; +set(handles.all_sweeps,'String',disp_text); + +% Update current sweep within selected window frequency +start_time=str2double(get(handles.start_time,'String')); +end_time=str2double(get(handles.end_time,'String')); + +[total_events, timestamps]=find_events(sweepset(:,1,current_sweep),X_trace,threshold, direction); +spike_frequency=sum(timestamps>start_time & timestampsend_time)/(((max(X_trace)-min(X_trace))-(end_time-start_time))/1000); +disp_text=['Selected Sweep: ' num2str(spike_frequency) 'Hz']; +set(handles.csow,'String',disp_text); + +% Update all SELECTED sweeps within selected time window +[total_events, timestamps]=find_events(sweepset(:,1,selection),X_trace,threshold, direction); +spike_frequency=sum(timestamps>start_time & timestampsend_time)/((((max(X_trace)-min(X_trace))-(end_time-start_time))/1000)*length(total_events)); +disp_text=['All Sweeps: ' num2str(spike_frequency) 'Hz']; +set(handles.asow,'String',disp_text); + +function update_sweep(src, callbackdata, handles) + + +% Update current sweep firing frequency +current_sweep=handles.paired_sweepset.current_sweep; +sweepset=handles.paired_sweepset.data; +selection=handles.paired_sweepset.sweep_selection; +X_trace=handles.paired_sweepset.X_data; +threshold=get(handles.threshold,'String'); +threshold=str2num(threshold); +direction=get(handles.event_direction,'Value'); + +% figure our if the direction of the events is up or down +if direction==0; + direction='down'; +else + direction='up'; +end + +[total_events, timestamps]=find_events(sweepset(:,1,current_sweep),X_trace,threshold, direction); + +spike_frequency=total_events/((max(X_trace)-min(X_trace))/1000); %Timeline should always be in ms +disp_text=['Selected Sweep: ' num2str(spike_frequency) 'Hz']; +set(handles.selected_sweep,'String',disp_text); + +% For this sweep we'll also have the opportunity to indicate events +set(handles.display_handles.event_markers,'XData',timestamps,'YData',ones(1,length(timestamps))*threshold); + +% Update current sweep within selected window frequency +start_time=str2double(get(handles.start_time,'String')); +end_time=str2double(get(handles.end_time,'String')); + +[total_events, timestamps]=find_events(sweepset(:,1,current_sweep),X_trace,threshold, direction); +spike_frequency=sum(timestamps>start_time & timestampsend_time)/(((max(X_trace)-min(X_trace))-(end_time-start_time))/1000); +disp_text=['Selected Sweep: ' num2str(spike_frequency) 'Hz']; +set(handles.csow,'String',disp_text); + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Other %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function [total_events, timestamps]=find_events(Y_trace, X_trace, threshold, direction); +% will output timestamps (in one long array) and total events (per sweep). +% Note that there must be a minimum number of data points between events +% (see below). This is not based on sampling frequency. + + +timestamps=[]; +total_events=zeros(1,length(Y_trace(1,:))); +for i=1:length(Y_trace(1,:)); + + if strcmp(direction,'up') + above_threshold=Y_trace(:,i)'>=threshold; + else + above_threshold=Y_trace(:,i)'<=threshold; %should be called 'below_threshold' I guess. + end + + transpose(1,:)=[0 above_threshold(1:end-1)]; + for j=1:25 %must be 25 data points between events, can change here + transpose=[0 transpose(1:end-1)]+transpose; + end + timestamps_temp=above_threshold==1 & transpose==0; + + timestamps=[timestamps X_trace(timestamps_temp)]; + total_events(i)=sum(timestamps_temp); + +end + +function [ figure_handle ] = timestamp_plot( event_list ) +%TIMESTAMP_PLOT will plot events and average firing frequency +% Currently, this plot does not update after state change in the sweep +% set. + +% Variables +size_input=size(event_list); +max_events=size_input(2); +sweeps=size_input(1); + +% Figure +figure_handle=figure(); + +% Actual plot +Y_values=repmat([1:sweeps]',1,max_events); +subplot(2,1,1) +event_plot=plot(event_list',fliplr(Y_values'),... + 'LineStyle','none',... + 'Marker','x',... + 'MarkerFaceColor',[0 0 1],... + 'MarkerEdgeCOlor',[0 0 1]); +xlim([0 5000]) +xlabel('time (ms)') +ylabel('sweep #') + +% Figure out the distribution +i=1; +event_distribution=zeros(1,51); +binsize=0.2; +for t=0:binsize:10 + event_distribution(1,i)=(sum(sum((event_list/1000)>=t-(binsize/2) & (event_list/1000)0 && new_selected_sweep<=this_sweepset.number_of_sweeps + % simply won't do it if that sweep is not available + this_sweepset.current_sweep=new_selected_sweep; + set(this_sweepset.handles.current_sweep,'YData',this_sweepset.data(:,1,this_sweepset.current_sweep)); + notify(this_sweepset,'state_change') + end + end + + function substract_baseline(this_sweepset) + % substract baseline + % note: there are different baseline methods, see the baseline + % function. + figure(this_sweepset.handles.figure) + + this_sweepset.settings.baseline_info.substracted=~ this_sweepset.settings.baseline_info.substracted; + end + + function average_trace=get.average_trace(this_sweepset) + average_trace=mean(squeeze(this_sweepset.data(:,1,this_sweepset.sweep_selection)),2); + + if this_sweepset.settings.average_smooth>0 + average_trace=smooth(average_trace,this_sweepset.settings.average_smooth); + end + + end + + function smooth_trace(this_sweepset, input) + % function will smooth the traces (removed noise) using a sliding window based on input*sampling_frequency. + + if ischar(input) + if strcmp(input,'undo') + this_sweepset.settings.smoothed=false; + disp('smoothing undone') + else + disp('unrecognized input') + end + else + this_sweepset.settings.smoothed=true; + this_sweepset.settings.smooth_factor=input; + disp(['Data smoothed by ' num2str(input) 'ms']); + end + + end + + function baseline=get.baseline(this_sweepset) + + switch this_sweepset.settings.baseline_info.method + case 'standard' + % standard is substract value between start and end + start_point=this_sweepset.settings.baseline_info.start*this_sweepset.sampling_frequency; + end_point=this_sweepset.settings.baseline_info.end*this_sweepset.sampling_frequency; + baseline=mean(this_sweepset.original_data(start_point:end_point,1,:),1); + baseline=repmat(baseline,length(this_sweepset.data(:,1,1)),1); + baseline=reshape(baseline,size(this_sweepset.data)); + case 'whole_trace' + baseline=mean(this_sweepset.original_data(:,1,:),1); + baseline=repmat(baseline,length(this_sweepset.data(:,1,1)),1); + baseline=reshape(baseline,size(this_sweepset.data)); + case 'moving_average_1s' + baseline=zeros(size(this_sweepset.data)); + for i=1:length(this_sweepset.data(1,1,:)) + baseline(:,1,i)=smooth(this_sweepset.original_data(:,1,i),this_sweepset.sampling_frequency*10^3); %smooth over 1sec sliding window + end + otherwise + disp('Baseline substraction method not recognized.'); + baseline=0; + end + + end + + function base_data=get.base_data(this_sweepset) + % This getter function is run when settings about baseline + % substraction or other data manipulations are changed. It + % takes the original data and performs the requested + % manipulations. + + % first looking at the baseline: + switch this_sweepset.settings.baseline_info.substracted + case true + base_data=this_sweepset.original_data-this_sweepset.baseline; + case false + base_data=this_sweepset.original_data; %But this is wrong, because trace can be smoothed + end + + % now checking if the traces are suposed to be smooth + input=this_sweepset.settings.smooth_factor; + if this_sweepset.settings.smoothed==true + for i=1:length(this_sweepset.data(1,1,:)) + base_data(:,1,i)=smooth(base_data(:,1,i),this_sweepset.sampling_frequency*input); + end + end + + + end + + end + +%%%%%%%%%%%%%%%%%%%%%% Callbacks & other functions%%%%%%%%%%%%%%%%%%%%%%%%% + + methods (Access = private) + + function key_press(this_sweepset, scr, ~) + % controls user keyboard input + key=double(get(this_sweepset.handles.figure,'CurrentCharacter')); + + switch key + case 29 %Right arrow (next sweep) + move_sweep(this_sweepset,this_sweepset.current_sweep+1); + case 28 %Left arrow (previous sweep) + move_sweep(this_sweepset,this_sweepset.current_sweep-1); + case 115 %'S' (select sweep) + this_sweepset.sweep_selection(this_sweepset.current_sweep)=1; + case 114 %'R' (reject sweep) + this_sweepset.sweep_selection(this_sweepset.current_sweep)=0; + case 13 %ENTER print selection + disp_text=[get(this_sweepset.handles.figure,'Name') ,' current selection:']; + disp(disp_text); + disp(this_sweepset.sweep_selection); + case 97 %'A' plot average trace + status=get(this_sweepset.handles.average_trace,'visible'); + if strcmp(status,'off') + set(this_sweepset.handles.average_trace,'visible','on') + else + set(this_sweepset.handles.average_trace,'visible','off') + end + case 113 %'Q' substract baseline + this_sweepset.substract_baseline + case 122 %'Z' show all other sweeps in background + status=get(this_sweepset.handles.all_sweeps(1),'visible'); + if strcmp(status,'off') + set(this_sweepset.handles.all_sweeps,'visible','on') + else + set(this_sweepset.handles.all_sweeps,'visible','off') + end + case 109 %'M' measure + this_sweepset.handles.measurement=measure(this_sweepset); + case 102 %'F' firing frequency + this_sweepset.handles.firing_frequency=firing_frequency(this_sweepset); + case 27 % Esc, reset axis for complete overview + floor=min(min(this_sweepset.data))-10; + roof=max(max(this_sweepset.data))+10; + disp_right=round(length(this_sweepset.data(:,1,1))/this_sweepset.sampling_frequency); + axis([0 disp_right floor roof]) + end + + notify(this_sweepset,'state_change') + end + + function plot_update(this_sweepset, ev, ~) + % Will listen to changed variabled and update other accordingly + + switch ev.Name + case 'sweep_selection' + notify(this_sweepset,'selection_change') + % update all plots that are dependend on this variable + set(this_sweepset.handles.average_trace,'YData',this_sweepset.average_trace); + case 'settings' + notify(this_sweepset,'state_change') + this_sweepset.data=this_sweepset.base_data; + set(this_sweepset.handles.average_trace,'YData',this_sweepset.average_trace); + set(this_sweepset.handles.current_sweep,'YData',this_sweepset.data(:,1,this_sweepset.current_sweep)); + for i=1:length(this_sweepset.handles.all_sweeps) + set(this_sweepset.handles.all_sweeps(i),'YData',squeeze(this_sweepset.data(:,1,i))); + end + end + + + end + + function close_req(this_sweepset, scr, ev) + % just to make sure that not only this figure, but also it's associated + % windows are closed. + + notify(this_sweepset,'sweepset_closed') + + if ishandle(this_sweepset.handles.measurement) + delete(this_sweepset.handles.measurement); + end + + if ishandle(this_sweepset.handles.firing_frequency) + delete(this_sweepset.handles.firing_frequency); + end + + delete(this_sweepset.handles.figure) + delete(this_sweepset) + end + + end + + events + state_change % reports anything that changes (fires all the time, best not to use to often) + selection_change % only fires when selected sweep changes + baseline_change % only fires when the baseline changes + sweepset_closed % fires when this sweepset window is closed + end + + +end + + + + + + +