forked from MSELab/EpiscaleAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyzeT1Transitions.m
More file actions
85 lines (74 loc) · 2.8 KB
/
analyzeT1Transitions.m
File metadata and controls
85 lines (74 loc) · 2.8 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
% This function is meant to be run on a cluster to convert the output of
% the Epi-Scale simulation into a matlab-interpretable format.
% Flags
% 1: Made datafile for label
% 2: Datafile already exists
% -1: Did not find raw data
% Usage:
% analyzeT1Transitions(coreNumber [uint8 = 1], settings [struct = getSettings],
% path [string = pwd], analysis [uint8 = 2])
% where:
% coreNumber [uint8] indicates the number of cores to be used
% settings [struct] indicates the settings object for the analysis. This
% defaults to the object generated by getSettings. Empty set means
% default settings are used.
% path [string] indicates the path for the analysis. This defaults to the
% current directory.
% analysis [uint8] indicates the type of analysis to be conducted. This
% defaults to a full analysis (2). The following are the types:
% 1: Convert data into .mat files
% 2: Extract T1 transition frequency (requires 1)
% force [logical] determines whether to force recalculation of quantities.
% empty: Default to settings
% 0: Do not force anything
% 1: Force T1 transition analysis
% 2: Force T1 transition analysis and data processing
function flag = analyzeT1Transitions(varargin)
%% Input parsing
% Define the input parser
p = inputParser;
addOptional(p,'coreNumber', 1, @(x) validateattributes(x, {'numeric'}, {'>=',1,'<=',12}));
addOptional(p,'path', pwd, @ischar);
addOptional(p,'settings', [], @(x) isempty(x) || isstruct(x));
addOptional(p,'analysis', 2, @(x) any(x==[1,2]));
addOptional(p,'force', [], @(x) any(x==[0,1,2]));
% Parse inputs
parse(p,varargin{:});
coreNumber = p.Results.coreNumber;
settings = p.Results.settings;
path = p.Results.path;
analysis = p.Results.analysis;
% Prepare workspace
delete(gcp('nocreate'))
cd(path);
if isempty(settings)
settings = prepareWorkspace;
else
settings = prepareWorkspace(settings);
end
% Override force
if ~isempty(p.Results.force)
settings.force = p.Results.force;
end
labels = importData(settings);
%% Processes all files listed in the spreadsheet
flag_convert = zeros(length(labels), 1);
flag_analyze = zeros(length(labels), 1);
if coreNumber == 1
for k = 1:length(labels) %randperm(length(labels))
flag_convert(k) = saveSimulation(labels{k}, settings);
if analysis == 2
flag_analyze(k) = extractT1Transitions(labels{k}, settings);
end
end
else
parpool(coreNumber)
parfor k = 1:length(labels)
flag_convert(k) = saveSimulation(labels{k}, settings);
if analysis == 2
flag_analyze(k) = extractT1Transitions(labels{k}, settings);
end
end
delete(gcp('nocreate'))
end
flag = [flag_convert, flag_analyze];