From 9f3342f00cc7aa7d95d2b417f6f120dda7e149a3 Mon Sep 17 00:00:00 2001 From: HandeJong Date: Sun, 19 Mar 2017 13:14:56 -0700 Subject: [PATCH] Add files via upload --- Bearphys.fig | Bin 0 -> 5750 bytes Bearphys.m | 447 +++++++++++++++++++++++++++++++++++++++ firing_frequency.fig | Bin 0 -> 5579 bytes firing_frequency.m | 486 +++++++++++++++++++++++++++++++++++++++++++ measure.fig | Bin 0 -> 3814 bytes measure.m | 240 +++++++++++++++++++++ sweepset.m | 342 ++++++++++++++++++++++++++++++ 7 files changed, 1515 insertions(+) create mode 100644 Bearphys.fig create mode 100644 Bearphys.m create mode 100644 firing_frequency.fig create mode 100644 firing_frequency.m create mode 100644 measure.fig create mode 100644 measure.m create mode 100644 sweepset.m diff --git a/Bearphys.fig b/Bearphys.fig new file mode 100644 index 0000000000000000000000000000000000000000..74741fc1510e1085f139d5e643fe2ecddd733276 GIT binary patch literal 5750 zcma)gXE+-U^sc>EOVu8wXzdw|RaHe%dzL7wsJ-_nwYL`4+Pl^A6E%v&re^Hen;-}= zLL%|+|K2b6<9)xJbKXzqdCqg*^PE>--BeHg8K1m_6raAjsrWlrcPBAELw9@scV508 zz<->Ej)I&RpN6lKy}#32J}=LIoR=rxOM6c~8CgDQ08r)$P)dfnMyD;0N6085oqf8g@GcP7K}M4zr3r&`(QJlZ_uCXclU%)Z1)1I!d8-_u}BT z6>T+79TuSL#)F!l9s8oKx|=oc+-Vxs6pC+#JJ@{2s86T+(<;TYQ>BMNCm>GCvBE-v{#yDn>?ep5+eQOM51knrX@UJx1)4 zX)l%)hCU=NQdH#bw+0wBq-lGQQ?$|Vhuv#>e`iu<)NH$3f+cG$fNgi4AEde7q6KH_ zZHa|kQP>R9-ET+>;ofF1bIa^~k>UhzYM^!kMB;hG5=KvUdx?$^ek>mmCd2Q@ja_`7 zTQwHbPeg(!)q_F8n%BE-I=2#dOuC9391pg+p& zCaC|`@W!B@SCo*qIhcG~e#P8h40X8C=^NileBT*X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Jh+eNijK`WV8?kayz61}7>!k560cnnFA9&O5Dqn6>@O$B zPWKo)kW{_4&6K}-B4fmZrn2;oP$YTv=wM(4-0E4lBt3+v@p1)hcEBTV$NbGJ8{lAN z{behSru)MhH+Tw&4BUi+iv4SCX0or{HnFmX!A zxUaN=G@~8R)Oty# zgddW(*c;$0)S21bs-L;??b!8&t$!pQxDja{FsW6Jfa}0&^FmY$2}gYx z|KwJ0ma8u69L=d3R>w`f~=VR^o?RCEHY7aq&e0 zhG0%u_E;}JAB{+0#pGF7(L%&RK=b^UL>`MIlBCj6njIsD6uZ$e+H8;2q_ECsJK^-< zHCXznQ&i;HF4A_6Wmth@B;3$Vm=I zN)j_h=Y2@%678z(a_d5N39L(>yqN4^M@HM!6VJ7lAe|ZgAxElvp>{7z^4LfxNC#y0 zoCcWAGaE?S2)VT-7VK^%a5iKKoLyi-V1VuXO9OG+YR0_@3$}0Pw*m?$Nvy@P*v_{_ zvh6P-$S#OyM4?4$&~;0Rj22BbC9lbh3orcZ+qusFH>_c9v2jrusyI6ZUh#ZXJr0#h eD8rR9jMe)%1J@5D|1Ni~Ei--(rX=5RWceQ-0h3+; literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..fca0da702a441a491d79bf9d7fadb46eef569580 GIT binary patch literal 5579 zcma)A`9Bnn^CnkrLT*bbDp^Xo7Abe`l)FvHZLQlb>&|_Ia<7WW5jo1a7VD^7$&qu{ zy>8aEthM{?{rda^-}zD>qMP8F5oj2me

rHvPliHqXBu38JTBfxK*%4KJ2ej&0cj zHu;SSk4BQ$v;D1DW>WuXzyiK1S)qY~A)3zvr7w$gyWSJ0-P~~P`Z{XXNk8}6Xl#A* z{e{!`FF}jnHHpq+6A}lr;-3AfMq0LtFFYq>5Mv|m6I?UBU0PzEnu4caA{-;>gaW#E zu9CQ*p7v1O2V_rje{f?kJ1PB>o! z1S!P}8p4#M1+)-lau3I*ai1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.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) zWFT*DIv`VFbRa}!V<0g%ATc&NGc-CfHXt%EF*YC|ARr(hARr(hARr(hARr(hARr(h zARr(hARr(hARr(hARr(hARr)U4FCWD000000ZB~{0002s3;+Oloa|Z8ZyQAvp4cW$ zT2c~D>4{t*iHKsSLMj)O&5xD@2#M;r5+`T8JGQ4;&#Y!XL=zWH`?6##Hh24Gz33E46r zl-IO97HOAdtJjLo7!QFZYm* zp&Q(BRkrs*JC9tKJjS(FGOg_@uK5gg`j4M74<(bjU&*yc$Ws1)zu6xSX5KT}o|b<~ z1Pcx#vO!(SIyxHAYjxbhF8UNUP^)8`2vkFCtA*P(Ig+StLFU-hYs!utMErFa2^;ed zI{Zcjv3)Ew@?Z~2+;EBUld$oW7oyL3}-xZPy`#wm^)x<7|P`*EI{`>pCmjS6?dmYc;7=yu$d& z@vJWKS~vag<(t(|f2Z{iTK}l^Pg+0L`WLN#)B1_lzia(e>p!%9ruCm%KiB%je@s75 z5X8WewngTck%WN8-7yjobYTq~pr|)Ms zL3}?`c3$nBJg>G?^bsYs{HCNr6?&X6+6;Sw=Zj6^)tfxOO&olL9Ur=7A$LHOZy?Ae zwON)7M~`3VF@82SeiqPbwJ*O+%r65JH|WPN7xT*jLJ8`J$6ZR`q-;Igq2{>9Hgw$zv=5Wx zcAF1~Xv2e*--Ano@#86N&&&2}aaXkSm`#!+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Rgbydiu!#{a)

dMyBQ2Sqs1^<-;k1`ypu)Gt!S!+!m*$b+_GO-DdBYbZRfJ{YBnZ)06L9Vx4XOo;dn)Pw9w^MjJ%qQ zNgsetW)?|=&EjZH1DF|ctY-br_UvSp10EP z5%iN-N`UBmr@a35)usLMyhQJxOA=j`mZI`^1wqR(Q3GlJ4}a%l(g&c^_J@nXEes8M(FbaS;6+fSRuDHgtz` zF9?6$L_1vXK+qfUtxI4_D}~h}k*|X@d06%k_Uye9><#+-Nc-YRK#kxch53KLNA4eym+={`!3Mfa|4~})qbBU5U48C{ zIQ{}C)^6Yr0001X0RRAaob6W4O2a@9o@{>F23qjeqfg+uXA2S!#e;&qg(a?SFmA%O zqP~HT;bZtRf=7=&g1g;avl&y1i1dAH1)*P6b3RYna?uEQt;tvL1G_X#+2SNK`+X(IHqDoIbART z3u$&sU>iq c-*#S`LvxSkn}PLt&3%7=Ij^bs1cG8i!9YTXH~;_u literal 0 HcmV?d00001 diff --git a/measure.m b/measure.m new file mode 100644 index 0000000..d3df5a2 --- /dev/null +++ b/measure.m @@ -0,0 +1,240 @@ +function varargout = measure(varargin) +% MEASURE MATLAB code for measure.fig +% MEASURE, by itself, creates a new MEASURE or raises the existing +% singleton*. +% +% H = MEASURE returns the handle to a new MEASURE or the handle to +% the existing singleton*. +% +% MEASURE('CALLBACK',hObject,eventData,handles,...) calls the local +% function named CALLBACK in MEASURE.M with the given input arguments. +% +% MEASURE('Property','Value',...) creates a new MEASURE or raises the +% existing singleton*. Starting from the left, property value pairs are +% applied to the GUI before measure_OpeningFcn gets called. An +% unrecognized property name or invalid value makes property application +% stop. All inputs are passed to measure_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 measure + +% Last Modified by GUIDE v2.5 17-Dec-2016 13:15:21 + +% Begin initialization code - DO NOT EDIT +gui_Singleton = 0; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @measure_OpeningFcn, ... + 'gui_OutputFcn', @measure_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 measure is made visible. +function measure_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 measure (see VARARGIN) + +% Choose default command line output for measure +handles.output = hObject; + +% Update handles structure +guidata(hObject, handles); + +% Storing the handle to the sweepset object +handles.paired_sweepset=varargin{1}; + +% Drawing all elements, but not making them visible +figure(handles.paired_sweepset.handles.figure) +handles.display_handles.peak_up=text(1,1,'empty','visible','off'); +handles.display_handles.peak_down=text(1,1,'empty','visible','off'); + +% Add listener +handles.listener=addlistener(handles.paired_sweepset,'state_change',@(scr, ev) update_everything(scr, ev, handles)); + +% Update handles structure +guidata(hObject, handles); + +% Filling variable in the GUI +set(handles.filename,'String',handles.paired_sweepset.filename) +if strcmp(handles.paired_sweepset.clamp_type,'Voltage (mV)') + set(handles.text3,'String','Maximum (mV)') + set(handles.text4,'String','Minimum (mV)') +end + +% Find peaks +find_peak(handles); + +% Setting a callback for then this GUI is closed and other callbacks +set(hObject,'CloseRequestFcn',{@close_req, handles}) + + +% --- Outputs from this function are returned to the command line. +function varargout = measure_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 measurement_start_Callback(hObject, eventdata, handles) +% hObject handle to measurement_start (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 measurement_start as text +% str2double(get(hObject,'String')) returns contents of measurement_start as a double + +find_peak(handles); + +% --- Executes during object creation, after setting all properties. +function measurement_start_CreateFcn(hObject, eventdata, handles) +% hObject handle to measurement_start (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 measurement_end_Callback(hObject, eventdata, handles) +% hObject handle to measurement_end (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 measurement_end as text +% str2double(get(hObject,'String')) returns contents of measurement_end as a double + +find_peak(handles); + +% --- Executes during object creation, after setting all properties. +function measurement_end_CreateFcn(hObject, eventdata, handles) +% hObject handle to measurement_end (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. +function display_Callback(hObject, eventdata, handles) +% hObject handle to display (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +if get(hObject,'value')==1; + set(handles.display_handles.peak_up,'visible','on') + set(handles.display_handles.peak_down,'visible','on') +else + set(handles.display_handles.peak_up,'visible','off') + set(handles.display_handles.peak_down,'visible','off') +end + +% --- Executes on button press in select_current. +function select_current_Callback(hObject, eventdata, handles) +% hObject handle to select_current (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 select_current + +if get(handles.select_average,'value')==1 + set(handles.select_average,'value',0) + find_peak(handles); +else + set(hObject,'value',1) +end + +% --- Executes on button press in select_average. +function select_average_Callback(hObject, eventdata, handles) +% hObject handle to select_average (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 select_average + +if get(handles.select_current,'value')==1 + set(handles.select_current,'value',0) + find_peak(handles); +else + set(hObject,'value',1) +end + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Callbacks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% just to make sure that not only this GUI, but also it's associated +% doodles are closed. + +function close_req(src,ev,handles) +delete(handles.display_handles.peak_up) +delete(handles.display_handles.peak_down) + + +delete(src) +delete(handles.listener) + + +function update_everything(scr,ev,handles) + +find_peak(handles); + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Other %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function find_peak(handles) +paired_sweepset=handles.paired_sweepset; + +if get(handles.select_average,'value')==1 + + average_trace_handle=paired_sweepset.handles.average_trace; + trace_to_analyse=get(average_trace_handle,'YData'); + +else + trace_to_analyse=paired_sweepset.data(:,1,paired_sweepset.current_sweep); +end + +SF=paired_sweepset.sampling_frequency; + +measurement_start=str2num(get(handles.measurement_start,'String'))*SF; +measurement_end=str2num(get(handles.measurement_end,'String'))*SF; + + +[peak.up, peak.location_up]=max(trace_to_analyse(measurement_start:measurement_end)); +[peak.down, peak.location_down]=min(trace_to_analyse(measurement_start:measurement_end)); + +peak.location_up=(peak.location_up+measurement_start)/SF; +peak.location_down=(peak.location_down+measurement_start)/SF; + +display_text_up= ['\leftarrow ',num2str(peak.up)]; +display_text_down= ['\leftarrow ',num2str(peak.down)]; + +set(handles.display_handles.peak_up,'Position',[peak.location_up,peak.up,0],'String',display_text_up); +set(handles.display_handles.peak_down,'Position',[peak.location_down,peak.down,0],'String',display_text_down); + +% updating displayed vallues +set(handles.maximum,'String',num2str(peak.up)) +set(handles.minimum,'String',num2str(peak.down)) diff --git a/sweepset.m b/sweepset.m new file mode 100644 index 0000000..b3fa5bc --- /dev/null +++ b/sweepset.m @@ -0,0 +1,342 @@ +classdef sweepset < handle + %SWEEPSET creates an object containing a set of sweeps + % This class uses abfload (by Harald Hentschke) to load a set of + % axonclamp sweeps into an object. The object creates a figure and is + % accesible either by keyboard (see keypress callback) or by a + % customized GUI. + % + % Current methods include 'average trace' and 'substract baseline'. + % New methods are easily added. If an opperation on the data requires + % that the figure is updated, call 'update_figure('event_type'). + % Update figure can be customized to only update specific parts of + % the figure. + % + % For GUI design: note that the object handle is stored in the + % appdata of the figure. Thus getappdata(gcf,'object') provides the + % handle of the object that controls the figure. + % + % INPUTS: + % - 'user_select', ('on'/'off') | UI for file selection + % - 'filename', 'path/filename' | open selected file + % + % Made by Johannes de Jong, j.w.dejong@berkeley.edu + + + properties (SetObservable) + filename % .abf file + file_header % provide by abfload + data % sweepset as it is currently used + original_data % sweepset as is was imported at startup + X_data % X_axis + clamp_type % Voltage or current clamp + sampling_frequency % in KHz + number_of_sweeps % number of sweeps in the set + handles % Of all aspects of the figure + sweep_selection % sweeps can be either rejected or selected by the user + current_sweep % the currently active sweep + outside_world % used when this objects thinks the outside world might want to update something. + settings % struct with settings, used for interaction with user and GUI + end + + properties (Dependent) + baseline % can be value or complex, depending on the baseline substraction method + average_trace % average trace is computed using only the selected sweeps + base_data % used for dynamic updating of the figure after settings change + end + + methods + + function this_sweepset = sweepset(varargin) + + % Deal with arguments + for i=1:2:nargin + % open input filename + if strcmp(varargin{i},'filename') + this_sweepset.filename=varargin{i+1}; + [this_sweepset.data, sampling_interval, this_sweepset.file_header]=abfload(this_sweepset.filename); + this_sweepset.sampling_frequency=10^3/sampling_interval; % The sampling frequency in kHz + end + + % allow the user to select file + if strcmp(varargin{i},'user_select') && strcmp(varargin{i+1},'on') + [temp_filename, path] = uigetfile({'*.abf'},'select files','MultiSelect','off'); + if temp_filename==0 + delete(this_sweepset) + disp('no file selected') + return + end + filename_path=fullfile(path, temp_filename); + [this_sweepset.data, sampling_interval, this_sweepset.file_header]=abfload(filename_path); + this_sweepset.sampling_frequency=10^3/sampling_interval; % The sampling frequency in kHz + this_sweepset.filename=temp_filename; + end + end + + % Current or voltage clamp + if strcmp(this_sweepset.file_header.recChUnits{1},'pA') + this_sweepset.clamp_type='Current (pA)'; + else + this_sweepset.clamp_type='Voltage (mV)'; + end + + % Setting other variables + this_sweepset.X_data=[0:1/this_sweepset.sampling_frequency:(length(this_sweepset.data)/this_sweepset.sampling_frequency)-(1/this_sweepset.sampling_frequency)]; + this_sweepset.current_sweep=1; + this_sweepset.number_of_sweeps=length(this_sweepset.data(1,1,:)); + this_sweepset.sweep_selection=true(1,this_sweepset.number_of_sweeps); + this_sweepset.settings.baseline_info.start=1; + this_sweepset.settings.baseline_info.end=100; + this_sweepset.settings.baseline_info.method='standard'; + this_sweepset.settings.baseline_info.substracted=false; + this_sweepset.settings.average_smooth=false; + this_sweepset.settings.smoothed=false; + this_sweepset.settings.smooth_factor=0; + + % Make a figure + this_sweepset.handles.figure=figure('position',[-1840,-137,700,500]); + set(this_sweepset.handles.figure,'name',char(this_sweepset.filename),'numbertitle','off'); + hold on + + % Add callbacks to the figure + set(this_sweepset.handles.figure,'keypressfcn',@this_sweepset.key_press); + + % Figure axis + xlabel('time (ms)') + ylabel(this_sweepset.clamp_type) + 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]) + + % Plot all the sweeps, but only the selected sweep is visible + this_sweepset.handles.all_sweeps=plot(this_sweepset.X_data,squeeze(this_sweepset.data(:,1,:)),'b','visible','off'); + this_sweepset.handles.current_sweep=plot(this_sweepset.X_data,this_sweepset.data(:,1,this_sweepset.current_sweep),'r'); + this_sweepset.handles.average_trace=plot(this_sweepset.X_data,this_sweepset.average_trace,'g','visible','off'); + + % Add listener + addlistener(this_sweepset,'sweep_selection','PostSet',@this_sweepset.plot_update); + addlistener(this_sweepset,'settings','PostSet',@this_sweepset.plot_update); + + % We will manipulate data, so storing the original data as well + this_sweepset.original_data=this_sweepset.data; + + % Put the handle to this object in the figure (for GUI use) + setappdata(this_sweepset.handles.figure,'object',this_sweepset) + + % Add a callback for a close request + set(this_sweepset.handles.figure,'CloseRequestFcn', @this_sweepset.close_req) + + % Final settings + this_sweepset.handles.measurement='not a handle'; % no measuremenet open + this_sweepset.handles.firing_frequency='not a handle'; % no FF measurement open + + end + + function move_sweep(this_sweepset, new_selected_sweep) + % will move the selected sweep to new_selected_sweep + + if new_selected_sweep>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 + + + + + + +