function disp_mcomposites2(emesh, panels, m_ref, m_res, varargin) % disp_mcomposites(emesh, m_ref, m_res, panels, conn, m_res_mesh, m_res_mesh_idx) % displays composites of reference (m_ref) with others (m_res) % emesh is standard emesh struct % m_ref and m_res are indices for emesh % m_ref must have size of 1, m_res is an array % m_ref can be also logical, then a synthetic mesh is constructed % conn is optional, if given will query the gene symbols, can be empty % m_res_mesh contains the result meshes if emesh should not be used % m_res_mesh_idx contains the indices of result meshes in case there is no % 1:1 correspondence between m_res and m_res_mesh conn = []; % Initialize counter counter = 1; sym_all = []; mesh_src = []; if ~isempty(varargin) i = 1; while i <= length(varargin), switch(varargin{i}), case 'db' i = i+1; conn = varargin{i}; case 'source' i = i+1; mesh_src = varargin{i}; case 'symbols' i = i+1; sym_all = varargin{i}; if length(sym_all) == 1, sym_name = sym_all; sym_idx = 1:length(sym_all); else sym_name = sym_all{1}; sym_idx = sym_all{2}; end otherwise error('Argument %s not known', varargin{i}); end i = i+1; end end m_resfiles = cell(length(m_res), 1); % If m_res is a vector, assume it's an index for emesh entries if isvector(m_res) if isempty(mesh_src), for i=1:length(m_res), % Test if we query DB for symbols if isempty(conn), m_resfiles{i} = emesh.files{m_res(i)}; elseif isempty(sym_all) fn = emesh.files{m_res(i)}; sym = pg_query(conn,0, pg_insitus('symbol'),myinsitu2fn(fn)); m_resfiles{i} = sprintf('%s (%s)', sym{1}, fn); end end resmesh = emesh.stain(:, m_res); else resmesh = mesh_src(:, m_res); sym_idx = sym_idx(m_res); end else resmesh = m_res; end if ~isempty(sym_all), if length(sym_idx) ~= size(resmesh, 2), error('Symbol idx has different size'); end for i=1:length(m_res), if isempty(m_resfiles{i}), m_resfiles{i} = sprintf('%s', sym_name{sym_idx(i)}); else m_resfiles{i} = sprintf('%s (%s)', sym_name{sym_idx(i)}, m_resfiles{i}); end end end if panels == 1, ysize = 0; elseif panels == 2, ysize = 200; elseif panels == 3, ysize = 400; else error('panels=%d but should be 1, 2 or 3', panels); end if isempty(m_ref), refstain = zeros(size(emesh.stain(:,1),1), 1); refstain(1:end) = 255; elseif islogical(m_ref), refstain = zeros(size(emesh.stain(:,1),1), 1); refstain(m_ref == 0) = 255; else refstain = emesh.stain(:, m_ref); end % Create and then hide the GUI as it is being constructed. % minimum [360,500,600,300] w/o list f = figure('Visible','off','Position',[360,500,700,260+ysize]); % Construct the components hforw = uicontrol('Style','pushbutton','String','Forward >',... 'Position',[380,15,70,25],... 'Callback',{@forwardbutton_Callback}); hback = uicontrol('Style','pushbutton','String','< Back',... 'Position',[50,15,70,25],... 'Callback',{@backbutton_Callback}); htext = uicontrol('Style','text','String', m_resfiles{counter},... 'Position',[500,15,120,15]); hlist = uicontrol('Style', 'listbox', 'String', m_resfiles,... 'Min', 1, 'Max', 1, 'Position',[500, 50, 150, 200+ysize],... 'Callback',{@listbox_Callback}); hp = uipanel('Units','Pixels','Position',[50,50,400,200+ysize]); ha = axes('Parent', hp, 'Units','Pixels','Position',[0,0,400,200+ysize]); % align([hforw,hback,htext],'Center','None'); % Initialize the GUI. %Change units to normalized so components resize automatically. set([f,ha,hp,hforw, hback, htext, hlist],... 'Units','normalized'); %Create a plot in the axes. displaypanels(panels, refstain, resmesh(:, counter), emesh.p_scale, emesh.t); % Assign the GUI a name to appear in the window title. set(f,'Name','Composite insitus') % Move the GUI to the center of the screen. movegui(f,'center') % Make the GUI visible. set(f,'Visible','on'); % Callbacks for simple_gui. These callbacks automatically have % access to component handles and initialized data because % they are nested at a lower level. function listbox_Callback(source, eventdata) % Determine the selected data set. str = get(source, 'String'); val = get(source,'Value'); % Set current data to the selected data set. counter = val; set(htext, 'String', m_resfiles{counter}); displaypanels(panels, refstain, resmesh(:, counter), emesh.p_scale, emesh.t); end % Push button callbacks. Each callback plots current_data in the % specified plot type. function forwardbutton_Callback(source,eventdata) % Display surf plot of the currently selected data. if counter < length(m_res), counter = counter + 1; set(htext, 'String', m_resfiles{counter}); set(hlist, 'Value', counter); displaypanels(panels, refstain, resmesh(:, counter), emesh.p_scale, emesh.t); end end function backbutton_Callback(source,eventdata) % Display mesh plot of the currently selected data. if counter > 1, counter = counter - 1; set(htext, 'String', m_resfiles{counter}); set(hlist, 'Value', counter); displaypanels(panels, refstain, resmesh(:, counter), emesh.p_scale, emesh.t); end end end function displaypanels(panels, refmesh, compmesh, p_scale,t) subplot(panels,1,panels); displaydmesh(refmesh, compmesh, p_scale, t); if panels > 1, subplot(panels,1,panels-1); displaycmesh(compmesh, p_scale, t, 1); if panels > 2, subplot(panels,1,panels-2); displaycmesh(refmesh, p_scale, t, 0); end end end function displaydmesh(refmesh, compmesh, p_scale,t) axis ij; axis off; hold on; cmesh = zeros(length(refmesh), 3); cmesh(:,1) = (255 - refmesh) ./ 255; cmesh(:,2) = (255 - compmesh) ./ 255; for i = 1:size(t,1) roic = fix(p_scale(t(i,:),1)'); roir = fix(p_scale(t(i,:),2)'); fill(roic,roir,cmesh(i,:), 'EdgeColor', cmesh(i,:)); end; end function displaycmesh(stain, p_scale, t, green) axis ij; axis off; hold on; cmesh = zeros(length(stain), 3); if green == 0, cmesh(:,1) = (255 - stain) ./ 255; else cmesh(:,2) = (255 - stain) ./ 255; end for i = 1:size(t,1) roic = fix(p_scale(t(i,:),1)'); roir = fix(p_scale(t(i,:),2)'); fill(roic,roir,cmesh(i,:),'EdgeColor', cmesh(i,:)); end; hold off; end