-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgetFluxes.m
46 lines (42 loc) · 1.11 KB
/
getFluxes.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
function [TableRes] = getFluxes(model, flux, rxn, hBins, exactMatch)
%User friendly function to visualize the fluxes of a FBA model or a
%population model
%flux could be either the struct result from optimizeCbModel or only a
%vector of fluxes
if ~isstruct(model)
reactions = model;
else
reactions = model.rxns;
end
if nargin < 4
hBins = 0;
end
if nargin < 5
exactMatch = false;
end
if strcmp(rxn, 'all reactions')
idx = [1:length(reactions)]';
else
if exactMatch
idx = find(strcmp(reactions, rxn)==1);
else
idxS = strfind(lower(reactions),lower(rxn));
idx = find(not(cellfun('isempty', idxS)));
end
end
TableRes = table();
if(isempty(idx))
disp(rxn);
disp('No reaction found');
return
else
if isstruct(flux)
TableRes = table(idx, reactions(idx), flux.x(idx), 'VariableNames', {'ID' 'Reaction', 'Flux',});
else
TableRes = table(idx, reactions(idx), flux(idx,:), 'VariableNames', {'ID' 'Reaction', 'Flux',});
end
if hBins > 0
hist(TableRes.Flux, hBins);
end
return
end