Home > data-vis > draw_correlation_plots.m

draw_correlation_plots

PURPOSE ^

SYNOPSIS ^

function draw_correlation_plots(subexpIDs, varname, measures, directory, nametag, args, modes)

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function draw_correlation_plots(subexpIDs, varname, measures, directory, nametag, args, modes)
0002 try
0003     if ~exist(directory, 'dir')
0004         error('%s does not exist, please create it first\n', directory);
0005     end
0006 
0007     if ~exist('modes', 'var') || isempty(modes)
0008         modes = [1 2 3];
0009     end
0010     
0011     [~,allsubs] = cIDs('all');
0012     
0013     % make multilong experiments have equal number of subjects
0014     log = ismember(allsubs(:,2), [70 71 72 73 74 75]);
0015     partsubs = allsubs(log,:);
0016     maxsub = max(partsubs(:,1) - partsubs(:,2)*100);
0017     longsubs = (1:maxsub)';
0018     uexp = [70 71 72 73 74 75];
0019     uallsubs = cell(numel(uexp),1);
0020     for u = 1:numel(uexp)
0021         uallsubs{u,1} = longsubs + uexp(u)*100;
0022     end
0023     uallsubs = vertcat(uallsubs{:});
0024     allsubs = allsubs(:,1);
0025     allsubs = cat(1, allsubs, uallsubs);
0026     allsubs = sort(unique(allsubs));
0027     
0028     nanmat = allsubs;
0029     nanmat(:,[2 3]) = NaN;
0030     
0031     subs = cIDs(subexpIDs);
0032     
0033     args.persubject = 1;
0034     if ~iscell(measures)
0035         measures = {measures};
0036     end
0037     args.measures = {measures};
0038     
0039     [age, ~, log] = get_age_at_exp(subs);
0040     
0041     subs = subs(log);
0042     [d,~] = extract_multi_measures(varname, subs, [], args);
0043     
0044     if ~isempty(d)
0045         [~, idx, log] = intersect_order(d(:,1), subs);
0046         
0047         d = d(idx,:);
0048         age = age(log);
0049         
0050         % all without text
0051         if ismember(1, modes)
0052             for m = 1:numel(measures)
0053                 measure = measures{m};
0054                 figure;
0055                 gscatter(age, d(:,m+3), d(:,2));% get_colors_v2(unique(d(:,2))));
0056                 set(gcf, 'position', [100 100 1280 720]);
0057                 title(strfix(nametag));
0058                 ylabel(strfix(measure));
0059                 xlabel('age');
0060                 legend('location', 'northeastoutside');
0061                 
0062                 figname = fullfile(directory, sprintf('%s_%s_vs_age_all', nametag, measure));
0063                 export_fig(gcf, figname, '-png', '-a1', '-r90', '-nocrop');
0064                 close gcf;
0065                 
0066                 [~, idx, log] = intersect_order(d(:,1), allsubs);
0067                 nanmat(log,2) = d(idx, m+3);
0068                 nanmat(log,3) = age(idx);
0069                 
0070                 headers = sprintf('subject,%s:%s,age', nametag, measure);
0071                 write2csv(nanmat, fullfile(directory, sprintf('%s_%s_vs_age_all.csv', nametag, measure)), headers);
0072             end
0073         end
0074         
0075         log = ~ismember(d(:,2), [70 71 72 73 74 75 76]);
0076         if sum(log) > 0
0077             if ismember(2, modes)
0078                 tage = age(log);
0079                 td = d(log,:);
0080                 % non-multilong with text
0081                 for m = 1:numel(measures)
0082                     measure = measures{m};
0083                     figure;
0084                     gscatter(tage, td(:,m+3), td(:,2));
0085                     set(gcf, 'position', [100 100 1280 720]);
0086                     title(strfix(nametag));
0087                     ylabel(strfix(measure));
0088                     xlabel('age');
0089                     legend('location', 'northeastoutside');
0090                     
0091                     
0092                     for t = 1:size(td,1)
0093                         text(tage(t), td(t,m+3), sprintf('%d', td(t,1)), 'HorizontalAlignment', 'right', 'VerticalAlignment', 'bottom');
0094                     end
0095                     
0096                     figname = fullfile(directory, sprintf('%s_%s_vs_age_reg', nametag, measure));
0097                     export_fig(gcf, figname, '-png', '-a1', '-r90', '-nocrop');
0098                     close gcf;
0099                 end
0100             end
0101         end
0102         
0103         if sum(~log) > 0
0104             if ismember(3, modes)
0105                 md = d(~log,:);
0106                 uexp = unique(md(:,2));
0107                 [~,idx] = ismember(md(:,2), uexp);
0108                 longid = md(:,1) - md(:,2)*100;
0109                 ulongid = unique(longid);
0110                 % multilong without text
0111                 for m = 1:numel(measures)
0112                     measure = measures{m};
0113                     figure;
0114                     gscatter(idx, md(:,m+3), md(:,2));
0115                     set(gcf, 'position', [100 100 1280 720]);
0116                     title(strfix(nametag));
0117                     ylabel(strfix(measure));
0118                     xlabel('age');
0119                     hold on;
0120                     
0121                     plothandles = cell(length(ulongid),1);
0122                     lulongsubs = plothandles;
0123                     i = 1;
0124                     for u = 1:length(ulongid)
0125                         log = ismember(longid, ulongid(u));
0126                         if sum(log) > 1
0127                             plothandles{i,1} = plot(idx(log), md(log,m+3));
0128                             lulongsubs{i,1} = ulongid(u);
0129                             i = i + 1;
0130                         end
0131                     end
0132                     
0133                     %                 for t = 1:size(idx,1)
0134                     %                     text(idx(t), md(t,m+3), sprintf('%d', md(t,1)), 'HorizontalAlignment', 'right', 'VerticalAlignment', 'bottom');
0135                     %                 end
0136                     
0137                     plothandles = vertcat(plothandles{:});
0138                     lulongsubs = vertcat(lulongsubs{:});
0139                     
0140                     legendarray = arrayfun(@(a) sprintf('%02d', a), lulongsubs, 'un', 0);
0141                     legend(plothandles, legendarray, 'location', 'northeastoutside');
0142                     
0143                     set(gca, 'xtick', 1:length(uexp));
0144                     set(gca, 'xticklabel', uexp);
0145                     
0146                     figname = fullfile(directory, sprintf('%s_%s_vs_age_multilong', nametag, measure));
0147                     export_fig(gcf, figname, '-png', '-a2', '-r90', '-nocrop');
0148                     close gcf;
0149                 end
0150             end
0151         end
0152     end
0153 catch ME
0154     disp(ME.message);
0155 end
0156     function strfixout = strfix(string)
0157         strfixout = strrep(string, '_', '\_');
0158     end
0159 
0160 end

Generated on Tue 23-May-2017 03:00:58 by m2html © 2005