getColorCodes Calculates the coloring for a number of fluxes by comparing them to reference fluxes. referenceFluxes vector of reference fluxes fluxes vector of fluxes. The number of elements in fluxes and referenceFluxes must be equal maxChange the logfold increase or decrease that corresponds to full negative or full positive coloring. Must be a positive value (opt, default 1) defaultColor a color in Matlab format to be used if there are no changes between the fluxes. This color is also used to calculate the transition between the colors for up and down regulated fluxes (opt, default [1 1 1]) upColor a color in Matlab format to be used if the flux is larger than the reference flux (opt, default [0 1 0]) downColor a color in Matlab format to be used if the flux is smaller than the reference flux (opt, default [1 0 0])
0001 function [colorCodes signChange errorFlag]= getColorCodes(referenceFluxes, fluxes, maxChange, defaultColor, upColor, downColor) 0002 % getColorCodes 0003 % Calculates the coloring for a number of fluxes by comparing them to 0004 % reference fluxes. 0005 % 0006 % referenceFluxes vector of reference fluxes 0007 % fluxes vector of fluxes. The number of elements in fluxes 0008 % and referenceFluxes must be equal 0009 % maxChange the logfold increase or decrease that corresponds 0010 % to full negative or full positive coloring. Must 0011 % be a positive value (opt, default 1) 0012 % defaultColor a color in Matlab format to be used if there are no 0013 % changes between the fluxes. This color is also used to 0014 % calculate the transition between the colors for up and 0015 % down regulated fluxes (opt, default [1 1 1]) 0016 % upColor a color in Matlab format to be used if the flux is 0017 % larger than the reference flux (opt, default [0 1 0]) 0018 % downColor a color in Matlab format to be used if the flux is 0019 % smaller than the reference flux (opt, default [1 0 0]) 0020 0021 % colorCodes array list of colors in Matlab format in the same 0022 % order as the fluxes 0023 % signChange array list of boolean values where true indicates 0024 % that there has been a sign change between the 0025 % fluxes. Reactions with sign changes are not 0026 % colored, but rather marked in another way. The 0027 % order correspondes to the order of the fluxes 0028 % errorFlag true if there has been an error 0029 % 0030 % Usage: [colorCodes signChange errorFlag]=getColorCodes(referenceFluxes,... 0031 % fluxes, maxChange, defaultColor, upColor, downColor) 0032 % 0033 % Rasmus Agren, 2010-12-16 0034 % 0035 0036 if nargin<6 0037 downColor=[1 0 0]; 0038 end 0039 if nargin<5 0040 upColor=[0 1 0]; 0041 end 0042 if nargin<4 0043 defaultColor=[1 1 1]; 0044 end 0045 if nargin<3 0046 maxChange=1; 0047 end 0048 0049 %Checks that the flux vector and the reference flux vector have the same 0050 %number of elements 0051 if length(fluxes)~=length(referenceFluxes) 0052 colorCodes={}; 0053 signChange={}; 0054 errorFlag=1; 0055 fprintf('fluxes and referenceFluxes must have the same dimensions'); 0056 return; 0057 end 0058 0059 %Loops through the fluxes. If the reference flux is 0, then mark as 0060 %upColor, if the flux is 0 then mark as downColor, and if both fluxes are 0 0061 %then mark as defaultColor 0062 for i=1:length(fluxes) 0063 signChange{i}=false; 0064 0065 if referenceFluxes(i)==0 || fluxes(i)==0 0066 if referenceFluxes(i)==0 && fluxes(i)==0 0067 colorCodes{i}=defaultColor; 0068 else 0069 if referenceFluxes(i)==0 0070 colorCodes{i}=upColor; 0071 else 0072 colorCodes{i}=downColor; 0073 end 0074 end 0075 else 0076 %At the moment a negative flux that gets more negative is counted 0077 %as being upregulated. This might be counter intuitive. 0078 logvalue=log10(abs(fluxes(i))/abs(referenceFluxes(i))); 0079 0080 %If there is a sign change 0081 if fluxes(i)*referenceFluxes(i)<0 0082 colorCodes{i}=defaultColor; 0083 signChange{i}=true; 0084 else 0085 colorCodes{i}=getColor(logvalue, defaultColor, upColor, downColor, maxChange); 0086 end 0087 end 0088 end 0089 0090 function colorValue=getColor(logvalue, defaultColor, upColor, downColor, maxChange) 0091 % getColor 0092 % Calculates the color for a specified logvalue. 0093 % 0094 % logvalue the logfold increase or desrease of a flux compared to the 0095 % corresponding reference flux. Must be a positive 0096 % value 0097 % defaultColor a color in Matlab format to be used if there are no 0098 % changes between the fluxes. This color is also used to 0099 % calculate the transition between the colors for up and 0100 % down regulated fluxes 0101 % upColor a color in Matlab format to be used if the flux is 0102 % larger than the reference flux 0103 % downColor a color in Matlab format to be used if the flux is 0104 % smaller than the reference flux 0105 % maxChange the logfold increase or decrease that corresponds 0106 % to full negative or full positive coloring 0107 % 0108 % colorValue vector with the calculated color 0109 % 0110 % Usage: colorValue=getColor(logvalue, defaultColor, upColor, downColor, maxChange) 0111 % 0112 % Rasmus Ågren, 2010-12-16 0113 % 0114 0115 %If the flux has decreased 0116 if logvalue<0 0117 %If the flux is lower than 10^-maxChange of the original then color as 0118 %downColor 0119 if logvalue<-maxChange 0120 colorValue=downColor; 0121 else 0122 %The color is linear from defaultColor to downColor 0123 colorValue=[defaultColor(1)+(downColor(1)-defaultColor(1))*logvalue/(-maxChange)... 0124 defaultColor(2)+(downColor(2)-defaultColor(2))*logvalue/(-maxChange)... 0125 defaultColor(3)+(downColor(3)-defaultColor(3))*logvalue/(-maxChange)]; 0126 end 0127 %If it has increased 0128 else 0129 %If the flux is higher than 10^maxChange times the original then color green 0130 if logvalue>maxChange 0131 colorValue=upColor; 0132 else 0133 %The color is linear from defaultColor to upColor 0134 colorValue=[defaultColor(1)+(upColor(1)-defaultColor(1))*logvalue/(maxChange)... 0135 defaultColor(2)+(upColor(2)-defaultColor(2))*logvalue/(maxChange)... 0136 defaultColor(3)+(upColor(3)-defaultColor(3))*logvalue/(maxChange)]; 0137 end 0138 end