-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathgetFluxZ.m
More file actions
executable file
·60 lines (51 loc) · 1.91 KB
/
Copy pathgetFluxZ.m
File metadata and controls
executable file
·60 lines (51 loc) · 1.91 KB
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
function Z=getFluxZ(solutionsA, solutionsB)
% getFluxZ
% Calculates the Z scores between two sets of random flux distributions.
%
% solutionsA random solutions for the reference condition (as
% generated by randomSampling)
% solutionsB random solutions for the test condition (as generated
% by randomSampling)
%
% Z a vector with Z-scores that tells you for each reaction
% how likely it is for its flux to have increased (positive sign)
% or decreased (negative sign) in the second condition with
% respect to the first.
%
% Usage: Z=getFluxZ(solutionsA, solutionsB)
nRxns=size(solutionsA,1);
%Check that the number of reactions is the same in both cases
if nRxns~=size(solutionsB,1)
EM='The number of reactions must be the same in solutionsA as in solutionsB';
dispEM(EM);
end
Z=zeros(nRxns,1);
%Calculate the mean and standard deviation for the two cases
mA=mean(solutionsA,2);
mB=mean(solutionsB,2);
%This can lead to OUT OF MEMORY, so do it in segments of 500 reactions
varA=zeros(size(solutionsA,1),1);
for i=1:500:size(solutionsA,1)
varA(i:min(i+499,size(solutionsA,1)))=var(solutionsA(i:min(i+499,size(solutionsA,1)),:),0,2);
end
varB=zeros(size(solutionsB,1),1);
for i=1:500:size(solutionsB,1)
varB(i:min(i+499,size(solutionsB,1)))=var(solutionsB(i:min(i+499,size(solutionsB,1)),:),0,2);
end
%If the mean of both solutions are the same then the Z-score is zero
toCheck=mA~=mB;
%If the variance is zero in both cases, then put a very large or very small
%Z-score for the corresponding reactions
I=find(varA==0 & varB==0 & toCheck==true);
toCheck(I)=false;
J=mA(I)>mB(I);
Z(I(J))=100;
Z(I(~J))=-100;
toCheck=find(toCheck);
for i=1:numel(toCheck)
Z(toCheck(i))=(mB(toCheck(i))-mA(toCheck(i)))/sqrt(varA(toCheck(i))+varB(toCheck(i)));
end
%Shrink very large values
Z=min(Z,100);
Z=max(Z,-100);
end