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 (optional, 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 (optional, default [1 1 1]) upColor a color in Matlab format to be used if the flux is larger than the reference flux (optional, default [0 1 0]) downColor a color in Matlab format to be used if the flux is smaller than the reference flux (optional, 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 (optional, 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 (optional, default [1 1 1]) 0016 % upColor a color in Matlab format to be used if the flux is 0017 % larger than the reference flux (optional, default [0 1 0]) 0018 % downColor a color in Matlab format to be used if the flux is 0019 % smaller than the reference flux (optional, 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 if nargin<6 0034 downColor=[1 0 0]; 0035 end 0036 if nargin<5 0037 upColor=[0 1 0]; 0038 end 0039 if nargin<4 0040 defaultColor=[1 1 1]; 0041 end 0042 if nargin<3 0043 maxChange=1; 0044 end 0045 0046 %Checks that the flux vector and the reference flux vector have the same 0047 %number of elements 0048 if length(fluxes)~=length(referenceFluxes) 0049 colorCodes={}; 0050 signChange={}; 0051 errorFlag=1; 0052 fprintf('fluxes and referenceFluxes must have the same dimensions'); 0053 return; 0054 end 0055 0056 %Loops through the fluxes. If the reference flux is 0, then mark as 0057 %upColor, if the flux is 0 then mark as downColor, and if both fluxes are 0 0058 %then mark as defaultColor 0059 for i=1:length(fluxes) 0060 signChange{i}=false; 0061 0062 if referenceFluxes(i)==0 || fluxes(i)==0 0063 if referenceFluxes(i)==0 && fluxes(i)==0 0064 colorCodes{i}=defaultColor; 0065 else 0066 if referenceFluxes(i)==0 0067 colorCodes{i}=upColor; 0068 else 0069 colorCodes{i}=downColor; 0070 end 0071 end 0072 else 0073 %At the moment a negative flux that gets more negative is counted 0074 %as being upregulated. This might be counter intuitive. 0075 logvalue=log10(abs(fluxes(i))/abs(referenceFluxes(i))); 0076 0077 %If there is a sign change 0078 if fluxes(i)*referenceFluxes(i)<0 0079 colorCodes{i}=defaultColor; 0080 signChange{i}=true; 0081 else 0082 colorCodes{i}=getColor(logvalue, defaultColor, upColor, downColor, maxChange); 0083 end 0084 end 0085 end 0086 end 0087 0088 function colorValue=getColor(logvalue, defaultColor, upColor, downColor, maxChange) 0089 % getColor 0090 % Calculates the color for a specified logvalue. 0091 % 0092 % logvalue the logfold increase or desrease of a flux 0093 % compared to the 0094 % corresponding reference flux. Must be a 0095 % positive value 0096 % defaultColor a color in Matlab format to be used if 0097 % there are no 0098 % changes between the fluxes. This color is 0099 % also used to calculate the transition 0100 % between the colors for up and down 0101 % regulated fluxes 0102 % upColor a color in Matlab format to be used if the 0103 % flux is 0104 % larger than the reference flux 0105 % downColor a color in Matlab format to be used if the 0106 % flux is 0107 % smaller than the reference flux 0108 % maxChange the logfold increase or decrease that 0109 % corresponds 0110 % to full negative or full positive coloring 0111 % 0112 % colorValue vector with the calculated color 0113 % 0114 % Usage: colorValue=getColor(logvalue, defaultColor, upColor, 0115 % downColor, maxChange) 0116 0117 %If the flux has decreased 0118 if logvalue<0 0119 %If the flux is lower than 10^-maxChange of the original then 0120 %color as downColor 0121 if logvalue<-maxChange 0122 colorValue=downColor; 0123 else 0124 %The color is linear from defaultColor to downColor 0125 colorValue=[defaultColor(1)+(downColor(1)-defaultColor(1))*logvalue/(-maxChange)... 0126 defaultColor(2)+(downColor(2)-defaultColor(2))*logvalue/(-maxChange)... 0127 defaultColor(3)+(downColor(3)-defaultColor(3))*logvalue/(-maxChange)]; 0128 end 0129 %If it has increased 0130 else 0131 %If the flux is higher than 10^maxChange times the original 0132 %then color green 0133 if logvalue>maxChange 0134 colorValue=upColor; 0135 else 0136 %The color is linear from defaultColor to upColor 0137 colorValue=[defaultColor(1)+(upColor(1)-defaultColor(1))*logvalue/(maxChange)... 0138 defaultColor(2)+(upColor(2)-defaultColor(2))*logvalue/(maxChange)... 0139 defaultColor(3)+(upColor(3)-defaultColor(3))*logvalue/(maxChange)]; 0140 end 0141 end 0142 end