-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeRandomGeneList.m
More file actions
32 lines (29 loc) · 998 Bytes
/
makeRandomGeneList.m
File metadata and controls
32 lines (29 loc) · 998 Bytes
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
function geneList = makeRandomGeneList(N,fn)
% geneList = makeRandomGeneList(N,fn) returns a struct array of N random genes
% from the Allen Database. fn is the text file save path for the list. If empty
% list is not saved, if omitted save file is requested.
if ~exist('fn','var')
[fn,fd] = uiputfile('*.txt','Save List As...');
if ~isempty(fn)
fn = [fd fn];
end
end
load('AllenAPI_Paths.mat')
load([GeneListDir filesep 'AllenAtlasGenes.mat'])
M = numel(AllGeneList);
idx = randsample(M,N);
outList = AllGeneList(idx);
while any(cellfun(@(x) any(isstrprop(x,'punct')),outList))
idx2 = find((cellfun(@(x) any(isstrprop(x,'punct')),outList)));
fprintf('Replacing %i genes due to punctuation\n',numel(idx2));
idx(idx2) = randsample(setdiff(1:M,idx2),numel(idx2),false);
outList = AllGeneList(idx);
end
geneList = AllGenes(idx);
if ~isempty(fn)
fid = fopen(fn,'w');
for i=1:N,
fprintf(fid,'%s\n',upper(outList{i}));
end
fclose(fid);
end