forked from BIMIB-DISCo/scFBA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditBoundaries.m
97 lines (94 loc) · 3.3 KB
/
EditBoundaries.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
function [modelOut, TableRes] = EditBoundaries(model,rxn, newLb, newUb, NotSure, exactMatch)
% Divide the popFBA flux solution in a matrix nReaction x nPop
%
% USAGE:
%
% [modelOut, TableRes] = EditBoundaries(model,rxn, newLb, newUb, NotSure, exactMatch)
%
% INPUT:
% model: metabolic model in COBRA format
% rxn: sub string to search in model.rxns field
%
% OPTIONAL INPUTS:
% newLb: new lower bound for the reactions founded, if empy values ([]) is
% passed no change occours for this bound
% newUb: new upper bound for the reactions founded, if empy values ([]) is
% passed no change occours for this bound
% NotSure: if TRUE a message box appeare before change anything (Default = TRUE)
% exactMatch: if TRUE the string rxn is compeared with the complete model.rxns strings
% with FALSE the match is made between rxn and any model.rxns substrings
% (Default = FALSE)
%
%
% OUTPUTS:
% modelOut: New model in COBRA format with boundaries changed.
% TableRes: A table with id, reaction identifier and boundaries
% founded. Usefull to keep the vector position of the
% model.rxns founded.
%
%
% .. Author:
% - Davide Maspero 30/01/2018
if nargin < 6
exactMatch = false;
end
if exactMatch
idx = find(strcmp(model.rxns, rxn)==1);
else
idxS = strfind(lower(model.rxns),lower(rxn));
idx = find(not(cellfun('isempty', idxS)));
end
%TableRes = table();
if nargin < 3
if(isempty(idx))
disp(rxn);
disp('No reaction found');
modelOut = model;
return
else
TableRes = table(idx, model.rxns(idx), model.lb(idx), model.ub(idx), 'VariableNames', {'ID', 'Reaction', 'LowerBound', 'UpperBound'})
disp('No change was made');
modelOut = model;
return
end
elseif nargin < 5
NotSure = true;
end
if(isempty(idx))
disp(rxn);
disp('No reaction found');
modelOut = model;
elseif(NotSure)
TableRes = table(idx, model.rxns(idx), model.lb(idx), model.ub(idx), 'VariableNames', {'ID', 'Reaction', 'LowerBound', 'UpperBound'})
choice = questdlg('Would you like to edit these boundaries?', 'Edit Boundaries', 'Yes','No','No');
switch choice
case 'Yes'
if ~isempty(newLb)
model.lb(idx) = newLb;
end
if ~isempty(newUb)
model.ub(idx) = newUb;
end
VetRev = zeros(length(idx), 1); %change the reversibility of the reactions
VetRev(model.lb(idx) < 0 & model.ub(idx) > 0) = 1;
model.rev(idx) = VetRev;
modelOut = model;
case 'No'
modelOut = model;
end
else
if nargout > 1
TableRes = table(idx, model.rxns(idx), model.lb(idx), model.ub(idx), 'VariableNames', {'ID', 'Reaction', 'LowerBound', 'UpperBound'});
end
if ~isempty(newLb)
model.lb(idx) = newLb;
end
if ~isempty(newUb)
model.ub(idx) = newUb;
end
VetRev = zeros(length(idx), 1); %change the reversibility of the reactions
VetRev(model.lb(idx) < 0 & model.ub(idx) > 0) = 1;
model.rev(idx) = VetRev;
modelOut = model;
end
end