Home > data-utility > get_csv_data_v2.m

get_csv_data_v2

PURPOSE ^

e.g.

SYNOPSIS ^

function [out, headers] = get_csv_data_v2(csv, columns, IDs)

DESCRIPTION ^

 e.g.
 csv = '/bell/multiwork/data_vis/correlation/cevent_inhand-eye_child-child_prop_vs_age.csv';
 get_csv_data_v2(csv, [1 2 3], [3203, 3204]);

 csv: full or relative path to .csv file
 (optional) columns: array containing list of columns from which to grab data
 (optional) IDs: array of subject IDs or experiment IDs. If provided, only
 a subset of the data will return, matching the provided subject list.

 The order of the returned data is based on the order within the csv file, not
 the order of the IDs input. Meaning, IDs = [3202 3201] may return 3201,
 3202 if this is ordering within the csv file.

 This function assumes the csv follows a certain format. The first column should
 be a list of subjects. If not, it will ignore the IDs input and just
 output all of the data for the columns. The csv can contain header lines, but
 each header line must begin with a #
 e.g.
 #subject, proportion roi, age

 This function assumes a proper csv, meaning, there must be equal number
 of commas in each row, including the header lines.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [out, headers] = get_csv_data_v2(csv, columns, IDs)
0002 % e.g.
0003 % csv = '/bell/multiwork/data_vis/correlation/cevent_inhand-eye_child-child_prop_vs_age.csv';
0004 % get_csv_data_v2(csv, [1 2 3], [3203, 3204]);
0005 %
0006 % csv: full or relative path to .csv file
0007 % (optional) columns: array containing list of columns from which to grab data
0008 % (optional) IDs: array of subject IDs or experiment IDs. If provided, only
0009 % a subset of the data will return, matching the provided subject list.
0010 %
0011 % The order of the returned data is based on the order within the csv file, not
0012 % the order of the IDs input. Meaning, IDs = [3202 3201] may return 3201,
0013 % 3202 if this is ordering within the csv file.
0014 %
0015 % This function assumes the csv follows a certain format. The first column should
0016 % be a list of subjects. If not, it will ignore the IDs input and just
0017 % output all of the data for the columns. The csv can contain header lines, but
0018 % each header line must begin with a #
0019 % e.g.
0020 % #subject, proportion roi, age
0021 %
0022 % This function assumes a proper csv, meaning, there must be equal number
0023 % of commas in each row, including the header lines.
0024 %
0025 
0026 root = fullfile(get_multidir_root, 'data_vis', 'correlation');
0027 if exist(fullfile(root, csv), 'file')
0028     csv = fullfile(root, csv);
0029 end 
0030 
0031 [headers, i] = get_csv_headers(csv);
0032 
0033 data = dlmread(csv, ',', i-1, 0);
0034 
0035 if exist('columns', 'var') && ~isempty(columns)
0036     out = data(:, columns);
0037     headers = cellfun(@(a) strsplit(strrep(a, ',',', '), ','), headers, 'un', 0);
0038     headers = cellfun(@(a) a(:,columns), headers, 'un', 0);
0039     headers = cellfun(@(a) strjoin(a, ','), headers, 'un', 0);
0040 else
0041     out = data;
0042 end
0043 
0044 if exist('IDs', 'var')
0045     if all(ismember(data(:,1), list_subjects()))
0046         [list,~,~] = intersect_order(data(:,1), cIDs(IDs));
0047         log = ismember(data(:,1), list);
0048         out = out(log,:);
0049     end
0050 end
0051 
0052 end

Generated on Wed 24-May-2017 00:00:56 by m2html © 2005