forked from SysBioChalmers/RAVEN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfollowChanged.m
executable file
·105 lines (94 loc) · 4.38 KB
/
followChanged.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
function followChanged(model,fluxesA,fluxesB, cutOffChange, cutOffFlux, cutOffDiff, metaboliteList)
% followChanged
% Prints fluxes and reactions for each of the reactions that results in
% different fluxes compared to the reference case.
%
% model a model structure
% fluxesA flux vector for the test case
% fluxesB flux vector for the reference test
% cutOffChange reactions where the fluxes differ by less than
% this many percent won't be printed (opt, default 10^-8)
% cutOffFlux reactions where the absolute value of both fluxes
% are below this value won't be printed (opt,
% default 10^-8)
% cutOffDiff reactions where the fluxes differ by less than
% cutOffDiff won't be printed (opt, default 10^-8)
% metaboliteList cell array of metabolite names. Only reactions
% involving any of these metabolites will be
% printed (opt)
%
% Usage: followChanged(model,fluxesA,fluxesB, cutOffChange, cutOffFlux,
% cutOffDiff, metaboliteList)
%
% Rasmus Agren, 2014-01-08
%
%Checks if a cut off flux has been set
if nargin<4
cutOffChange=10^-8;
end
if nargin<5
cutOffFlux=10^-8;
end
if nargin<6
cutOffDiff=10^-8;
end
if nargin<7
metaboliteList=[];
end
%If a metabolite list is to be used, then find all the reactions involving
%any of those metabolites Finds the metabolites
if nargin>6
reactionIndexes=[];
for i=1:length(metaboliteList)
metaboliteIndex=find(strcmpi(metaboliteList(i),model.metNames)); %Should use id maybe, setting
if ~isempty(metaboliteIndex)
[~, b]=find(model.S(metaboliteIndex,:));
reactionIndexes=[reactionIndexes; b(:)];
else
fprintf('Could not find any reactions with the metabolite %s\n\n',char(metaboliteList(i)))
end
end
reactionIndexes=unique(reactionIndexes);
else
reactionIndexes=(1:length(fluxesA))';
end
%Finds the reactions where either flux is at or above the cutOffFlux value
in1=find(abs(fluxesA(reactionIndexes))>=cutOffFlux)';
in2=find(abs(fluxesB(reactionIndexes))>=cutOffFlux)';
ineither=reactionIndexes(unique([in1 in2]));
%Keep only those solutions where the difference is larger than or equal to
%cutOffDiff
ineither=ineither(find(abs(fluxesA(ineither)-fluxesB(ineither))>=cutOffDiff));
%Finds the reactions where the fluxes differ more than cutOffChange percent
%First check those fluxes that are non-zero in solution1.x
nonZeroFluxes=ineither(find(fluxesA(ineither)));
quota=1+cutOffChange/100;
larger=nonZeroFluxes(find((fluxesB(nonZeroFluxes)./fluxesA(nonZeroFluxes))>=(quota)))';
smaller=nonZeroFluxes(find((fluxesB(nonZeroFluxes)./fluxesA(nonZeroFluxes))<(1/quota)))';
fluxIndexes=[larger smaller];
%Then add those where solution1 has a zero flux
zeroFluxes=ineither(find(fluxesA(ineither)==0));
fluxIndexes=unique([fluxIndexes zeroFluxes(find(abs(fluxesB(zeroFluxes))>=cutOffFlux))']);
formulas=constructEquations(model,model.rxns(fluxIndexes));
if nargin>4
if nargin>5
fprintf('These reactions have flux values that differ by more than %s percent, absolute values above %s, and a total difference above %s (%s reactions)\n\n',num2str(cutOffChange),num2str(cutOffFlux),num2str(cutOffDiff),num2str(length(formulas)));
else
fprintf('These reactions have flux values that differ by more than %s percent and absolute values above %s (%s reactions)\n\n',num2str(cutOffChange),num2str(cutOffFlux),num2str(length(formulas)));
end
else
fprintf('These reactions have flux values that differ by more than %s percent (%s reactions)\n\n',num2str(cutOffChange),num2str(length(formulas)));
end
metaboliteNames=[];
for i=1:length(metaboliteList)
metaboliteNames=[metaboliteNames char(metaboliteList(i)) ' '];
end
if ~isempty(metaboliteNames)
fprintf('Only prints reactions involving one or more of the following metabolites:\n%s\n\n',metaboliteNames)
end
for i=1:length(formulas)
fluxText=['Flux: ' num2str(fluxesA(fluxIndexes(i))) ' Reference flux: ' num2str(fluxesB(fluxIndexes(i))) ' Difference: ' num2str(fluxesA(fluxIndexes(i))-fluxesB(fluxIndexes(i)))];
fprintf('%s: %s\n\t%s\n\t%s\n\n', char(model.rxns(fluxIndexes(i))), char(formulas(i)),...
char(model.rxnNames(fluxIndexes(i))),fluxText);
end
end