function plotflow(action) switch action case 'rename' rename; case 'prune' prune; case 'edit_pop_name' changePopNumber(0); case 'cancel_pop_name' closereq; case 'load_pop_names' loadPopNames; case 'ok_pop_name' okPopName; case 'five_back' changePopNumber(-5); case 'one_back' changePopNumber(-1); case 'one_ahead' changePopNumber(1); case 'five_ahead' changePopNumber(5); case 'help' openHelp; end return % ------------------------------------------------------------------------- function rename h0 = gcf; h1 = findobj(h0, 'Tag','attr_menu'); g = get(h1,'Userdata'); varnames = g.varnames; openInputPopNamesFigure(varnames); % rename clusters % ------------------------------------------------------------------------- function prune h0 = gcf; h1 = findobj(h0, 'Tag','attr_menu'); g = get(h1,'Userdata'); adjmat = g.adjmat; if isfield(g,'adjmat2') adjmat2 = g.adjmat2; min_strength = min(adjmat2(logical(adjmat2>0))); else min_strength = min(adjmat(logical(adjmat>0))); end %waitALittle; answer = inputdlg( ['Specify the minimal strength of the gene flow graph such that'... ' edges with lower weight will be pruned'],... 'Prune the graph',1, {num2str(min_strength)}); if isempty(answer) % cancel has been pressed return else min_strength = str2num(answer{1}); fprintf('Minimal flow strength: %4.5f\n', min_strength); adjmat(adjmat num_of_pops disable('five_ahead_button'); else enable('five_ahead_button'); end; if (num_of_curr + 1) > num_of_pops disable('one_ahead_button'); else enable('one_ahead_button'); end; function loadPopNames %Loads the population names to UserData of 'population_ %names_figure'. Gets the names from a file specified by %the user. [filename,pathname] = uigetfile('*.txt','Load Population Names'); if (filename == 0) & (pathname == 0) %Cancel was pushed. return, end; input_file = [pathname filename]; %Read population names from the file to a variable 'names': fid = fopen(input_file); if fid == -1 %File didn't exist msgbox('Loading of the population names was unsuccessful', ... 'Error', 'error'); return; end; line = fgetl(fid); counter = 1; while (line ~= -1) && ~isempty(line) names{counter} = line; line = fgetl(fid); counter = counter + 1; end; fclose(fid); %Check that the number of lines is the same as npops: h0 = findobj('Tag','data_info_button'); tiedot = get(h0,'UserData'); counts = tiedot.countsUD; sizc = size(counts); npops = sizc(3); length_names = length(names); if npops ~= length_names msgbox(['Loading of names was unsuccessful.' ... 'The number of lines in a file that contains the names ' ... 'must be same as the number of observed ' ... 'sampling units in the data.'] ,'Error', ... 'error'); return; end; %Save names to the UserData of the 'population_names_figure': h0 = findobj('Tag','population_names_figure'); tiedot = get(h0,'UserData'); tiedot.tempnamesUD = names; set(h0,'UserData',tiedot); %Update text-field to initial state: h0 = findobj('Tag','input_pop_name_text'); set(h0,'String','Name of Cluster 1:'); %Set the name of the first population to the screen: h0 = findobj('Tag','pop_name_edit'); set(h0,'String',names{1}); function okPopName %Saves the names of populations and closes %'population_names_figure'. h0 = findobj('Tag','population_names_figure'); tiedot = get(h0,'UserData'); names = tiedot.tempnamesUD; %Close the figure: % closereq; close(h0); handle = gcf; h0 = findobj(handle,'Tag','attr_menu'); g = get(h0,'Userdata'); g.varnames = names; set(h0,'UserData',g); % redraw the figure switch g.type case 'GENEFLOW' graphvizpath = g.graphvizpath; nodecolors = g.nodecolors; nodestyles = g.nodestyles; arccolors = g.arccolors; arcstyles = g.arcstyles; groupnames = g.varnames; d = cd; plotmodel(g.adjmat2,g.k,'graphvizpath', graphvizpath, ... 'nodecolors', nodecolors, ... 'nodestyles', nodestyles, ... 'arccolors',arccolors, ... 'arcstyles',arcstyles, ... 'varnames', groupnames, ... 'target', ['matlab:',num2str(handle)]); cd(d); case {'nj', 'upgma'} switch g.visualtype case {'square', 'angular'} viewDendrogram(g.visualtype) case {'radial', 'phylogram'} viewUnrooted(g.visualtype) end otherwise return end function enable(obj_tag) h0 = findobj('Tag',obj_tag); set(h0,'Enable','on'); function disable(obj_tag) h0 = findobj('Tag',obj_tag); set(h0,'Enable','off'); function openHelp info{1}='Gene Flow Between Populations'; info{2}=''; info{3}='Produced using GraphViz'; info{4}='Source: gene flow matrix produced by BAPS'; info{5}=''; info{6}='Author: Jing Tang'; info{7}=''; helpdlg(info,'Help');