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) Rasmus Agren, 2013-08-01
0001 function Z=getFluxZ(solutionsA, solutionsB) 0002 % getFluxZ 0003 % Calculates the Z scores between two sets of random flux distributions. 0004 % 0005 % solutionsA random solutions for the reference condition (as 0006 % generated by randomSampling) 0007 % solutionsB random solutions for the test condition (as generated 0008 % by randomSampling) 0009 % 0010 % Z a vector with Z-scores that tells you for each reaction 0011 % how likely it is for its flux to have increased (positive sign) 0012 % or decreased (negative sign) in the second condition with 0013 % respect to the first. 0014 % 0015 % Usage: Z=getFluxZ(solutionsA, solutionsB) 0016 % 0017 % Rasmus Agren, 2013-08-01 0018 % 0019 0020 nRxns=size(solutionsA,1); 0021 0022 %Check that the number of reactions is the same in both cases 0023 if nRxns~=size(solutionsB,1) 0024 dispEM('The number of reactions must be the same in solutionsA as in solutionsB'); 0025 end 0026 0027 Z=zeros(nRxns,1); 0028 0029 %Calculate the mean and standard deviation for the two cases 0030 mA=mean(solutionsA,2); 0031 mB=mean(solutionsB,2); 0032 0033 %This can lead to OUT OF MEMORY, so do it in segments of 500 reactions 0034 varA=zeros(size(solutionsA,1),1); 0035 for i=1:500:size(solutionsA,1) 0036 varA(i:min(i+499,size(solutionsA,1)))=var(solutionsA(i:min(i+499,size(solutionsA,1)),:),0,2); 0037 end 0038 varB=zeros(size(solutionsB,1),1); 0039 for i=1:500:size(solutionsB,1) 0040 varB(i:min(i+499,size(solutionsB,1)))=var(solutionsB(i:min(i+499,size(solutionsB,1)),:),0,2); 0041 end 0042 0043 %If the mean of both solutions are the same then the Z-score is zero 0044 toCheck=mA~=mB; 0045 0046 %If the variance is zero in both cases, then put a very large or very small 0047 %Z-score for the corresponding reactions 0048 I=find(varA==0 & varB==0 & toCheck==true); 0049 toCheck(I)=false; 0050 J=mA(I)>mB(I); 0051 Z(I(J))=100; 0052 Z(I(~J))=-100; 0053 toCheck=find(toCheck); 0054 0055 for i=1:numel(toCheck) 0056 Z(toCheck(i))=(mB(toCheck(i))-mA(toCheck(i)))/sqrt(varA(toCheck(i))+varB(toCheck(i))); 0057 end 0058 0059 %Shrink very large values 0060 Z=min(Z,100); 0061 Z=max(Z,-100); 0062 end