-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathload_gwas.m
54 lines (44 loc) · 1.59 KB
/
load_gwas.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function [logpmat,zmat]=load_gwas(traitfiles, nsnps, dummy_zscore)
%% LOAD_GWAS Load logpvec* and zvec* from MAT files
if iscell(traitfiles), nfiles = length(traitfiles); else nfiles = 1; end;
for i=1:nfiles
% Load file
if iscell(traitfiles), file = traitfiles{i};
else file = traitfiles;
end
fprintf('\n %s... ',file)
% Get all field names
traits = load(file);
if isempty(traits),
error( sprintf('Data file %s does not exist\n',file) );
end
fields = fieldnames(traits);
% Find which contains single log p
id = find(strncmpi(fields,'logp',4));
lpfield = fields( id );
if isempty(lpfield),
error( sprintf('Data file %s must contain variable logp*\n',file) );
end
fprintf('%s... ',lpfield{1})
lp = traits.(lpfield{1});
% Find which field contains z
id = find(strncmpi(fields,'z',1));
zfield = fields( id );
if isempty(zfield) && ~dummy_zscore
error( sprintf('Data file %s must contain variable z*\n',file) );
end
if isempty(zfield)
z = abs(norminv(1/2*10 .^ -lp));
else
fprintf('%s... ',zfield{1})
z = traits.(zfield{1});
end
if ~isvector(lp) || ~isvector(z)
error( sprintf('logp and z must be vectors, not matrices') );
end
if length(lp) ~= nsnps, error('%s logpvec has %i snps - expected %i snps', file, length(lp), nsnps); end
if length(z) ~= nsnps, error('%s zvec has %i snps - expected %i snps', file, length(z), nsnps); end
% Assign to logpmat
logpmat(:,i) = lp;
zmat(:,i) = z;
end