forked from opencobra/cobratoolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
identifyCorrelSets.m
76 lines (68 loc) · 2.11 KB
/
identifyCorrelSets.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
function [setsSorted,setNoSorted,setSize] = identifyCorrelSets(model,samples,corrThr,R)
%identifyCorrelSets Identify correlated reaction sets from sampling data
%
% [sets,setNumber,setSize] = identifyCorrelSets(model,samples,corrThr,R)
%
%INPUTS
% model COBRA model structure
% samples Samples to be used to identify correlated sets
%
%OPTIONAL INPUTS
% corrThr Minimum correlation (R^2) threshold (Default = 1-1e-8)
% R Correlation coefficient
%
%OUTPUTS
% sets Sorted cell array of sets (largest first)
% setNumber List of set numbers for each reaction in model (0 indicates
% that there is no set)
% setSize List of set sizes
%
% Markus Herrgard 9/15/06
if (nargin < 3)
corrThr = 1-1e-8;
end
nRxns = length(model.rxns);
% Calculate correlation coefficients
if (nargin < 4)
R = corrcoef(samples');
R = R - eye(nRxns);
end
% Define adjacency matrix
adjMatrix = (abs(R) >= corrThr);
% Only work with reactions that are correlated with others
selCorrelRxns = any(adjMatrix)';
rxnList = model.rxns(selCorrelRxns);
adjMatrix = adjMatrix(selCorrelRxns,selCorrelRxns);
% Construct set number index
hasSet = false(size(rxnList));
currSetNo = 0;
setNoTmp = zeros(size(rxnList));
for i = 1:length(rxnList)
if (~hasSet(i))
currSetNo = currSetNo+1;
setMembers = find(adjMatrix(i,:));
hasSet(setMembers) = true;
hasSet(i) = true;
setNoTmp(setMembers) = currSetNo;
setNoTmp(i) = currSetNo;
end
end
setNo = zeros(size(model.rxns));
[tmp,index1,index2] = intersect(model.rxns,rxnList);
setNo(index1) = setNoTmp(index2);
% Construct list of sets
for i = 1:max(setNo)
sets{i}.set = find(setNo == i);
sets{i}.names = model.rxns(sets{i}.set);
setSize(i) = length(sets{i}.set);
end
% Sort everything
[setSize,sortInd] = sort(setSize');
sortInd = flipud(sortInd);
setsSorted = sets(sortInd);
setNoSorted = zeros(size(setNo));
for i = 1:length(sortInd)
setNoSorted(setNo == sortInd(i)) = i;
end
setSize = flipud(setSize);
setsSorted = setsSorted';