function baseline_acquire (varargin) % % % BASELINE_ACQUIRE % % Acquires a baseline, stimulating the neurons in both % directions, once a minute, until the "Stop" button % is pressed. % global fig fighandles minute; % If we were called with no arguments means we were called straight % from matlab; so we will set up the figure. if nargin==0 % The amp specifics for voltage clamp. scaling = 100; % mV/V, the command sensitivity of the amplifier gain = 1; % V/nA, the output gain of the amplifier amplitude = 2; % mV, amplitude of test pulse nrepeat = 5; % number of times we want the testpulse repeated pulsewidth = 200; % actual array elements frequency = 10000; % in Hz % Plot specifics pre_x_begin = frequency * 0.2 - 50; pre_x_end = frequency * 0.2 + 150; post_x_begin = frequency * 0.2 - 50; post_x_end = frequency * 0.2 + 450; % These are guidelines: they get overruled if the actual numbers % fall outside these boundaries. psc_min = 0; % In pA access_min = 5; % In MegaOhms access_max = 50; leak_min = -50; % in pA; leak_max = 0; % in pA; % The length of time (minutes) we will record before quitting % (unless the user interrupts first) length = 80; % The variables PRE12 and POST12 will store the data outputted % when treating channel 1 as the presynaptic cell and channel 2 % as the postsynaptic cell. Ditto for PRE21 and POST21. pre12=zeros(frequency,1); post12=zeros(frequency,1); pre21=zeros(frequency,1); post21=zeros(frequency,1); % The HEALTH array will monitor the health of our two recordings. % The first two columns will record the access resistance of the % two channels, the third and fourth columns will record the % leak currents, and the fifth and sixth columns will record the % membrane capacitance. % We will also store a TESTPULSE_OUTPUT array, that will record % (in successive columns) the output of testpulse itself in case % we need to analyze it in some new way in the future. health = zeros(1,6); testpulse_output = zeros(1,2); % Make the figure now. fig=figure; set(fig, 'units', 'normalized', 'color', [.6 .6 .6], 'position', [0.45 0.1 0.55 0.8]); set(fig, 'NumberTitle', 'off', 'Name', 'Baseline acquisition'); % Here's where we specify the details of the figure. pre2 = subplot('Position', [0.1 0.7 0.1 0.2]); subplot(pre2); set(gca, 'tag', 'pre2'); post1 = subplot('Position', [0.25 0.7 0.2 0.2]); subplot(post1); set(gca, 'tag', 'post1'); pre1 = subplot('Position', [0.55 0.7 0.1 0.2]); subplot(pre1); set(gca, 'tag', 'pre1'); post2 = subplot('Position', [0.7 0.7 0.2 0.2]); subplot(post2); set(gca, 'tag', 'post2'); psc1 = subplot('Position', [0.1 0.4 0.35 0.2]); subplot(psc1); set(gca, 'tag', 'psc1'); psc2 = subplot('Position', [0.55 0.4 0.35 0.2]); subplot(psc2); set(gca, 'tag', 'psc2'); health1 = subplot('Position', [0.1 0.12 0.35 0.2]); subplot(health1); set(gca, 'tag', 'health1'); health2 = subplot('Position', [0.55 0.12 0.35 0.2]); subplot(health2); set(gca, 'tag', 'health2'); % And here are the buttons: stop_button=uicontrol('style','checkbox','units','normalized',... 'position',[0.45 .02 0.1 0.05],'backgroundcolor',[0.9 0 0],... 'FontUnits', 'normalized', 'FontSize', 0.4,... 'tag','stop_button','string','Stop'); psc_1_button=uicontrol('style','checkbox','units','normalized',... 'position',[0.35 .61 0.1 0.02],'backgroundcolor',[0.9 0.9 0],... 'tag','psc1_button','string','Get x values',... 'callback', 'baseline_acquire(''get_psc_x_1'')'); psc_2_button=uicontrol('style','checkbox','units','normalized',... 'position',[0.8 .61 0.1 0.02],'backgroundcolor',[0.9 0.9 0],... 'tag','psc2_button','string','Get x values',... 'callback', 'baseline_acquire(''get_psc_x_2'')'); % create structure of handles fighandles = guihandles(fig); % add the additional data for the x position to calculate pscs fighandles.psc_x_1 = [0 0]; fighandles.psc_x_2 = [0 0]; fighandles.psc_x_1_index = [0 0]; fighandles.psc_x_2_index = [0 0]; % The PSC1 and PSC2 arrays will monitor the PSC vales for the two % channels, based on the x values supplied by the user. fighandles.psc1_values = [0]; fighandles.psc2_values = [0]; % These are the x-axes for the current plots fighandles.pre_x_axis = [-5:0.1:15]; fighandles.post_x_axis = [-5:0.1:45]; % Add the plot specifics to the figure handle fighandles.psc_min = psc_min; fighandles.access_min = access_min; fighandles.access_max = access_max; fighandles.leak_min = leak_min; fighandles.leak_max = leak_max; minute = 1; while minute<=length % This will be the x-axis for this plot. if (minute >= 50) health_x_labels = [0:10:minute+9]; elseif (minute > 15) health_x_labels = [0:5:minute+4]; else health_x_labels = [0:minute]; end % The axis for the PSC plots fighandles.psc_x_axis = [0:1:minute]; [rtot,rseries,rmem,cmem,il,output] = ... testpulse(frequency, scaling, gain, amplitude, pulsewidth, nrepeat); current=vstimulate(1, frequency, gain, scaling); if minute == 1 pre12 = current(:,1); post12 = current(:,2); health = [rseries il cmem]; testpulse_output = output; else pre12=[pre12 current(:,1)]; post12=[post12 current(:,2)]; health=[health; rseries il cmem]; testpulse_output = [testpulse_output output]; end make_a_subplot('pre1', current(pre_x_begin:pre_x_end,1), 0, 1); make_a_subplot('post2', current(post_x_begin:post_x_end,2), 0, 1); make_a_subplot('health1', [health(:,1), health(:,3)], health_x_labels, 1); make_a_subplot('health2', [health(:,2), health(:,4)], health_x_labels, 1); pause(28); stop=get(stop_button,'Value'); if stop==1 break end current=vstimulate(2, frequency, gain, scaling); if minute == 1 pre21=current(:,2); post21=current(:,1); else pre21=[pre21 current(:,2)]; post21=[post21 current(:,1)]; end make_a_subplot('pre2', current(pre_x_begin:pre_x_end,2), 0, 1); make_a_subplot('post1', current(post_x_begin:post_x_end,1), 0, 1); stop=get(stop_button,'Value'); if stop==1 break end pause(28); stop=get(stop_button,'Value'); if stop==1 break end minute=minute+1; end disp('Saving temp_baseline.mat...'); save temp_baseline disp('done.'); % The elseif below goes with the "if nargin == 0" above % elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try if (nargout) [varargout{1:nargout}] = feval(varargin{:}); else feval(varargin{:}); % FEVAL switchyard end catch disp(lasterr); end end %%% % % End of the main baseline function % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Subplot making function function make_a_subplot(plot_string, y_axis, x_labels, not_from_callback) global fig fighandles minute; figure(fig); pre_x_lim = [fighandles.pre_x_axis(1)... fighandles.pre_x_axis(length(fighandles.pre_x_axis))]; post_x_lim = [fighandles.post_x_axis(1)... fighandles.post_x_axis(length(fighandles.post_x_axis))]; % We do different things depending on the plot name. switch plot_string case 'pre1' subplot(fighandles.pre1); x_axis = fighandles.pre_x_axis; plot(x_axis, y_axis); set(gca, 'XLim', pre_x_lim); ylabel('pA'); xlabel(sprintf('msec \n')); title(sprintf('min=%d \n #1 pre',minute), ... 'FontSize', 14, 'FontWeight', 'bold'); case 'pre2' subplot(fighandles.pre2); x_axis = fighandles.pre_x_axis; plot(x_axis, y_axis); set(gca, 'XLim', pre_x_lim); ylabel('pA'); xlabel(sprintf('msec \n')); title(sprintf('min=%d \n #2 pre',minute), ... 'FontSize', 14, 'FontWeight', 'bold'); case 'post1' subplot(fighandles.post1); x_axis = fighandles.post_x_axis; plot(x_axis, y_axis); set(gca, 'XLim', post_x_lim); xlabel(sprintf('msec \n')); title('#1 post', 'FontSize', 14, 'FontWeight', 'bold'); % And now see about making the lines at the right x positions if any(fighandles.psc_x_1) xtemp = fighandles.psc_x_1(1); xtemp2 = [xtemp xtemp]; ytemp2 = get(gca, 'YLim'); line(xtemp2, ytemp2, 'Color', 'r', 'LineStyle', '--'); xtemp = fighandles.psc_x_1(2); xtemp2 = [xtemp xtemp]; line(xtemp2, ytemp2, 'Color', 'r', 'LineStyle', '--'); if not_from_callback psc_x_axis = fighandles.psc_x_axis; % Assign psc1_values appropriately fighandles.psc1_values = [fighandles.psc1_values ... (y_axis(fighandles.psc_x_1_index(1)) -... y_axis(fighandles.psc_x_1_index(2)))]; % Replot psc1_values subplot(fighandles.psc1); xbegin = 2; while fighandles.psc1_values(xbegin) == 0 xbegin = xbegin + 1; end plot(psc_x_axis(xbegin:length(psc_x_axis)), ... fighandles.psc1_values(xbegin:length(fighandles.psc1_values)), 'o'); % Set the min psc limit ylim = get(gca, 'YLim'); if ylim(1) > fighandles.psc_min ylim(1) = fighandles.psc_min; % Round up the max psc limit to the next 100 r = rem(ylim(2), 100); if ylim(2) > 50 && r > 0 ylim(2) = (fix(ylim(2)/100) + 1) * 100; end end set(gca, 'YLim', ylim); set(gca, 'YTickMode', 'auto'); ylabel('pA'); xlabel('Minutes'); title('PSC #1', 'FontSize', 14, 'FontWeight', 'bold'); end else if not_from_callback fighandles.psc1_values = [fighandles.psc1_values 0]; end end case 'post2' subplot(fighandles.post2); x_axis = fighandles.post_x_axis; plot(x_axis, y_axis); set(gca, 'XLim', post_x_lim); xlabel(sprintf('msec \n')); title('#2 post', 'FontSize', 14, 'FontWeight', 'bold'); % And now see about making the lines at the right x positions if any(fighandles.psc_x_2) xtemp = fighandles.psc_x_2(1); xtemp2 = [xtemp xtemp]; ytemp2 = get(gca, 'YLim'); line(xtemp2, ytemp2, 'Color', 'r', 'LineStyle', '--'); xtemp = fighandles.psc_x_2(2); xtemp2 = [xtemp xtemp]; line(xtemp2, ytemp2, 'Color', 'r', 'LineStyle', '--'); if not_from_callback psc_x_axis = fighandles.psc_x_axis; % Assign psc2_values appropriately fighandles.psc2_values = [fighandles.psc2_values ... (y_axis(fighandles.psc_x_2_index(1)) -... y_axis(fighandles.psc_x_2_index(2)))]; % Replot psc2_values subplot(fighandles.psc2); xbegin = 2; while fighandles.psc2_values(xbegin) == 0 xbegin = xbegin + 1; end plot(psc_x_axis(xbegin:length(psc_x_axis)), ... fighandles.psc2_values(xbegin:length(fighandles.psc2_values)), 'o'); % Set the min psc limit ylim = get(gca, 'YLim'); if ylim(1) > fighandles.psc_min ylim(1) = fighandles.psc_min; % Round up the max psc limit to the next 100 r = rem(ylim(2), 100); if ylim(2) > 50 && r > 0 ylim(2) = (fix(ylim(2)/100) + 1) * 100; end end set(gca, 'YLim', ylim); set(gca, 'YTickMode', 'auto'); ylabel('pA'); xlabel('Minutes'); title('PSC #2', 'FontSize', 14, 'FontWeight', 'bold'); end else if not_from_callback fighandles.psc2_values = [fighandles.psc2_values 0]; end end case 'health1' subplot(fighandles.health1); x_axis = 1:1:size(y_axis, 1); [ax, h1, h2] = plotyy(x_axis, y_axis(:,1) * 10^-6,... x_axis, y_axis(:,2)); set(h1, 'Color', 'blue'); set(h2, 'Color', 'red'); set(h1, 'LineStyle', '-'); set(h2, 'LineStyle', '--'); set(ax(1), 'Ycolor', 'blue'); set(ax(2), 'Ycolor', 'red'); set(ax(1), 'XTick', x_labels); set(ax(2), 'XTick', x_labels); set(get(ax(1), 'Ylabel'), 'String', 'Access R, M\Omega'); set(get(ax(2), 'Ylabel'), 'String', 'Leak C, pA'); set(get(ax(1), 'Xlabel'), 'String', 'Minutes'); % Set the limits of the access resistance. ylim = get(ax(1), 'YLim'); if ylim(1) > fighandles.access_min && ylim(1) < fighandles.access_max ylim(1) = fighandles.access_min; end if ylim(2) < fighandles.access_max && ylim(2) > fighandles.access_min ylim(2) = fighandles.access_max; end set(ax(1), 'YLim', ylim); set(ax(1), 'YTickMode', 'auto'); % Set the limits of the leak current. ylim = get(ax(2), 'YLim'); if ylim(1) > fighandles.leak_min && ylim(1) < fighandles.leak_max ylim(1) = fighandles.leak_min; end if ylim(2) < fighandles.leak_max && ylim(2) > fighandles.leak_min ylim(2) = fighandles.leak_max; end set(ax(2), 'YLim', ylim); set(ax(2), 'YTickMode', 'auto'); title('Health #1', 'FontSize', 14, 'FontWeight', 'bold'); case 'health2' subplot(fighandles.health2); x_axis = 1:1:size(y_axis, 1); [ax, h1, h2] = plotyy(x_axis, y_axis(:,1) * 10^-6,... x_axis, y_axis(:,2)); set(h1, 'Color', 'blue'); set(h2, 'Color', 'red'); set(h1, 'LineStyle', '-'); set(h2, 'LineStyle', '--'); set(ax(1), 'Ycolor', 'blue'); set(ax(2), 'Ycolor', 'red'); set(ax(1), 'XTick', x_labels); set(ax(2), 'XTick', x_labels); set(get(ax(1), 'Ylabel'), 'String', 'Access R, M\Omega'); set(get(ax(2), 'Ylabel'), 'String', 'Leak C, pA'); set(get(ax(1), 'Xlabel'), 'String', 'Minutes'); % Set the limits of the access resistance. ylim = get(ax(1), 'YLim'); if ylim(1) > fighandles.access_min && ylim(1) < fighandles.access_max ylim(1) = fighandles.access_min; end if ylim(2) < fighandles.access_max && ylim(2) > fighandles.access_min ylim(2) = fighandles.access_max; end set(ax(1), 'YLim', ylim); set(ax(1), 'YTickMode', 'auto'); % Set the limits of the leak current. ylim = get(ax(2), 'YLim'); if ylim(1) > fighandles.leak_min && ylim(1) < fighandles.leak_max ylim(1) = fighandles.leak_min; end if ylim(2) < fighandles.leak_max && ylim(2) > fighandles.leak_min ylim(2) = fighandles.leak_max; end set(ax(2), 'YLim', ylim); set(ax(2), 'YTickMode', 'auto'); title('Health #2', 'FontSize', 14, 'FontWeight', 'bold'); end % %%%%%%%%%%%%%%% Beginning the callback functions %%%%%%%%%%% % % The first one is for the getting the x values for the PSC of channel 1 % function varargout = get_psc_x_1(varargin) global fig fighandles; figure(fig); % Declare the axes we'll be working with here subplot(fighandles.post1); y_axis = get(findobj(gca,'Type','line', 'Color', 'blue'), 'YData'); x_axis = get(findobj(gca,'Type','line', 'Color', 'blue'), 'XData'); % See if there are pre-existing markers already if any(fighandles.psc_x_1) pre_existing = 1; else pre_existing = 0; end % Get the first input from the post2 figure [xtemp, ytemp] = ginput(1); % We want to round xtemp to the nearest 0.1 xtemp = (round (xtemp * 10)) / 10; fighandles.psc_x_1(1) = xtemp; % Get the y values for the plot line ytemp2 = get(gca, 'YLim'); % Replot the graph to remove any existing marker lines if pre_existing make_a_subplot('post1', y_axis, 0, 0); xtemp2 = [fighandles.psc_x_1(2) fighandles.psc_x_1(2)]; line(xtemp2, ytemp2, 'Color', 'r', 'LineStyle', '--'); end % Make the first dotted line xtemp2 = [xtemp xtemp]; line(xtemp2, ytemp2, 'Color', 'r', 'LineStyle', '--'); % Get the second input from the post2 figure [xtemp, ytemp] = ginput(1); % We want to round xtemp to the nearest 0.1 xtemp = (round (xtemp * 10)) / 10; fighandles.psc_x_1(2) = xtemp; % Replot the graph to remove any existing marker lines if pre_existing make_a_subplot('post1', y_axis, 0, 0); xtemp2 = [fighandles.psc_x_1(1) fighandles.psc_x_1(1)]; line(xtemp2, ytemp2, 'Color', 'r', 'LineStyle', '--'); end % Make the second dotted line xtemp2 = [xtemp xtemp]; line(xtemp2, ytemp2, 'Color', 'r', 'LineStyle', '--'); % Calculate indexes for i = 1:2 fighandles.psc_x_1_index(i) = int16((fighandles.psc_x_1(i) - x_axis(1))/0.1 + 1); if fighandles.psc_x_1_index(i) < 1 fighandles.psc_x_1_index(i) = 1; elseif fighandles.psc_x_1_index(i) > length(x_axis) fighandles.psc_x_1_index(i) = length(x_axis); end end % Assign the last psc1_values appropriately fighandles.psc1_values(length(fighandles.psc1_values)) = ... (y_axis(fighandles.psc_x_1_index(1)) -... y_axis(fighandles.psc_x_1_index(2))); % Replot psc1_values subplot(fighandles.psc1); psc_x_axis = fighandles.psc_x_axis; xbegin = 2; while fighandles.psc1_values(xbegin) == 0 xbegin = xbegin + 1; end % There are intervals when minute has been incremented but % psc1_values has not increased. We account for that here. x_end = length(psc_x_axis); if x_end > length(fighandles.psc1_values) x_end = x_end - 1; end % Finally we are ready to plot plot(psc_x_axis(xbegin:x_end), fighandles.psc1_values(xbegin:x_end), 'o'); ylabel('pA'); xlabel('Minutes'); title('PSC #1', 'FontSize', 14, 'FontWeight', 'bold'); % Adjust y limits, if necessary ylim = get(gca, 'YLim'); if ylim(1) > fighandles.psc_min ylim(1) = fighandles.psc_min; % Round up the max psc limit to the next 100 r = rem(ylim(2), 100); if ylim(2) > 50 && r > 0 ylim(2) = (fix(ylim(2)/100) + 1) * 100; end end set(gca, 'YLim', ylim); % Turn the button off set(fighandles.psc1_button, 'value', 0); pause(0.5); return; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % The next function is for the getting the x values for the PSC of channel 2 % function varargout = get_psc_x_2(varargin) global fig fighandles; figure(fig); % Declare the axes we'll be working with here subplot(fighandles.post2); y_axis = get(findobj(gca,'Type','line', 'Color', 'blue'), 'YData'); x_axis = get(findobj(gca,'Type','line', 'Color', 'blue'), 'XData'); % See if there are pre-existing markers already if any(fighandles.psc_x_2) pre_existing = 1; else pre_existing = 0; end % Get the first input from the post2 figure [xtemp, ytemp] = ginput(1); % We want to round xtemp to the nearest 0.1 xtemp = (round (xtemp * 10)) / 10; fighandles.psc_x_2(1) = xtemp; % Get the y values for the plot line ytemp2 = get(gca, 'YLim'); % Replot the graph to remove any existing marker lines if pre_existing make_a_subplot('post2', y_axis, 0, 0); xtemp2 = [fighandles.psc_x_2(2) fighandles.psc_x_2(2)]; line(xtemp2, ytemp2, 'Color', 'r', 'LineStyle', '--'); end % Make the first dotted line xtemp2 = [xtemp xtemp]; line(xtemp2, ytemp2, 'Color', 'r', 'LineStyle', '--'); % Get the second input from the post2 figure [xtemp, ytemp] = ginput(1); % We want to round xtemp to the nearest 0.1 xtemp = (round (xtemp * 10)) / 10; fighandles.psc_x_2(2) = xtemp; % Replot the graph to remove any existing marker lines if pre_existing make_a_subplot('post2', y_axis, 0, 0); xtemp2 = [fighandles.psc_x_2(1) fighandles.psc_x_2(1)]; line(xtemp2, ytemp2, 'Color', 'r', 'LineStyle', '--'); end % Make the second dotted line xtemp2 = [xtemp xtemp]; line(xtemp2, ytemp2, 'Color', 'r', 'LineStyle', '--'); % Calculate indexes for i = 1:2 fighandles.psc_x_2_index(i) = int16((fighandles.psc_x_2(i) - x_axis(1))/0.1 + 1); if fighandles.psc_x_2_index(i) < 1 fighandles.psc_x_2_index(i) = 1; elseif fighandles.psc_x_2_index(i) > length(x_axis) fighandles.psc_x_2_index(i) = length(x_axis); end end % Assign the last psc2_values appropriately fighandles.psc2_values(length(fighandles.psc2_values)) = ... (y_axis(fighandles.psc_x_2_index(1)) -... y_axis(fighandles.psc_x_2_index(2))); % Replot psc2_values subplot(fighandles.psc2); psc_x_axis = fighandles.psc_x_axis; xbegin = 2; while fighandles.psc2_values(xbegin) == 0 xbegin = xbegin + 1; end x_end = length(psc_x_axis); % Finally we are ready to plot plot(psc_x_axis(xbegin:x_end), fighandles.psc2_values(xbegin:x_end), 'o'); ylabel('pA'); xlabel('Minutes'); title('PSC #2', 'FontSize', 14, 'FontWeight', 'bold'); % Adjust y limits, if necessary ylim = get(gca, 'YLim'); if ylim(1) > fighandles.psc_min ylim(1) = fighandles.psc_min; % Round up the max psc limit to the next 100 r = rem(ylim(2), 100); if ylim(2) > 50 && r > 0 ylim(2) = (fix(ylim(2)/100) + 1) * 100; end end set(gca, 'YLim', ylim); % Turn the button off set(fighandles.psc2_button, 'value', 0); pause(0.5); return; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%