forked from opencobra/cobratoolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extractMetModel.m
77 lines (68 loc) · 2.09 KB
/
extractMetModel.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
function metabModel = extractMetModel(model,metabNames,nLayers,allCompFlag,nRxnsMetThr)
%extractMetModel Create a subnetwork model around one or more metabolites
%
% metabModel = extractMetModel(model,metabNames,nLayers,allCompFlag,nRxnsMetThr)
%
%INPUTS
% model COBRA model structure
% metabNames Metabolites to build subnetwork model around
% nLayers
% allCompFlag Use all metabolites regardless of compartment
%
%OPTIONAL INPUT
% nRxnsMetThr Ignore metabolites which appear in more than nRxnMetThr
% (Default = 100)
%
%OUTPUT
% metabModel COBRA model around one or more metabolites
%
% Markus Herrgard 3/1/06
if (nargin < 5)
nRxnsMetThr = 100;
end
% Filter out high degree metabolites
nRxnsMet = full(sum(model.S~=0,2));
baseMetNames = parseMetNames(model.mets);
for i = 1:length(baseMetNames)
nRxnsMetComp(i) = sum(nRxnsMet(strcmp(baseMetNames,baseMetNames{i})));
end
nRxnsMetComp = nRxnsMetComp';
selLowDegMet = nRxnsMetComp < nRxnsMetThr;
model.S = model.S(selLowDegMet,:);
model.mets = model.mets(selLowDegMet);
if (~iscell(metabNames))
tmpMetName = metabNames;
clear metabNames;
metabNames{1} = tmpMetName;
end
if (allCompFlag)
allMetNames = parseMetNames(model.mets);
metabNames = parseMetNames(metabNames);
else
allMetNames = model.mets;
end
selMets = find(ismember(allMetNames,metabNames));
metS = model.S(selMets,:);
[nMet,tmp] = size(metS);
if (nMet > 1)
selRxns = any(full(metS) ~= 0)';
else
selRxns = (full(metS) ~= 0)';
end
for i = 1:nLayers+1
metS = model.S(selMets,:);
[nMet,tmp] = size(metS);
if (nMet > 1)
selRxns = any(full(metS) ~= 0)';
else
selRxns = (full(metS) ~= 0)';
end
if (isfield(model,'c'))
selRxns = selRxns & ~ (model.c == 1);
end
nextLayerMets = find(any(model.S(:,selRxns) ~= 0,2));
selMets = union(selMets,nextLayerMets);
end
rxnNames = model.rxns(selRxns);
metNames = model.mets(selMets);
metabModel = extractSubNetwork(model,rxnNames,metNames);