0001 function options = drawCbMap(map,options,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 global mapHandle
0036 global CB_MAP_OUTPUT
0037
0038
0039 if ~exist('CB_MAP_OUTPUT', 'var') || isempty(CB_MAP_OUTPUT)
0040 error('No render target specified. Call changeCbMapOutput(outputFormat)');
0041 end
0042
0043
0044 if (nargin < 2)
0045 options = [];
0046 end
0047
0048 if mod(length(varargin),2)==0
0049 for i=1:2:length(varargin)-1
0050 switch lower(varargin{i})
0051 case 'nodeweight', options.nodeWeight = cell2mat(varargin(i+1));
0052 case 'nodecolor', options.nodeColor = cell2mat(varargin(i+1));
0053 case 'edgeweight', options.edgeWeight = cell2mat(varargin(i+1));
0054 case 'edgecolor', options.edgeColor = cell2mat(varargin(i+1));
0055 case 'edgearrowcolor', options.edgeArrowColor = cell2mat(varargin(i+1));
0056 case 'textsize', options.textSize = cell2mat(varargin(i+1));
0057 case 'textcolor', options.textColor = cell2mat(varargin(i+1));
0058 case 'othertextsize', options.otherTextSize = cell2mat(varargin(i+1));
0059 case 'othertextcolor', options.otherTextColor = cell2mat(varargin(i+1));
0060 case 'filename', options.fileName = varargin{i+1};
0061 otherwise, options.(varargin{i}) = varargin{i+1};
0062 end
0063 end
0064 else
0065 error('Invalid number of parameters/values');
0066 end
0067
0068
0069 nNodes = size(map.molName,1);
0070 nEdges = size(map.connection,1);
0071
0072 if ~isfield(options,'nodeWeight')
0073 options.nodeWeight = ones(nNodes,1)*15;
0074 if strcmp(CB_MAP_OUTPUT,'svg')
0075 options.nodeWeight = ones(nNodes,1)*25;
0076 end
0077 end
0078
0079 if ~isfield(options,'nodeWeightSecondary')
0080 options.nodeWeightSecondary = ones(nNodes,1)*10;
0081 if strcmp(CB_MAP_OUTPUT,'svg')
0082 options.nodeWeightSecondary = ones(nNodes,1)*15;
0083 end
0084 end
0085
0086 if ~isfield(options,'nodeColor')
0087 options.nodeColor = repmat([255,160,128],nNodes,1);
0088 end
0089
0090 if ~isfield(options,'edgeColor')
0091 options.edgeColor = repmat([0,191,255],nEdges,1);
0092 end
0093
0094 if ~isfield(options,'edgeArrowColor')
0095 options.edgeArrowColor = repmat([0,0,255],nEdges,1);
0096 end
0097
0098 if ~isfield(options,'edgeWeight')
0099 options.edgeWeight = ones(nEdges,1)*2;
0100 if strcmp(CB_MAP_OUTPUT,'svg')
0101 options.edgeWeight = ones(nEdges,1)*4;
0102 end
0103 end
0104
0105 if ~isfield(options,'textSize')
0106 options.textSize = ones(max(nNodes,nEdges),1)*12;
0107 if strcmp(CB_MAP_OUTPUT,'svg')
0108 options.textSize = ones(max(nNodes,nEdges),1)*6;
0109 end
0110 end
0111
0112 if ~isfield(options,'textColor')
0113 options.textColor = zeros(nNodes,3);
0114 end
0115
0116
0117
0118
0119
0120
0121
0122
0123 if ~isfield(options,'otherTextColor')
0124 options.otherTextColor= zeros(size(map.text,1),3);
0125 end
0126
0127 nodeWeight = options.nodeWeightSecondary;
0128 nodeWeight(strcmp(map.molPrime,'Y')) = options.nodeWeight(strcmp(map.molPrime,'Y'));
0129
0130 if ~isfield(options,'fileName')
0131 options.fileName = 'target.svg';
0132 end
0133
0134 if ~isfield(options,'rxnDir')
0135 options.rxnDir = zeros(size(map.connectionAbb,1),1);
0136 end
0137
0138 if ~isfield(options,'rxnDirMultiplier')
0139 options.rxnDirMultiplier = 2;
0140 end
0141
0142
0143 if strcmp(CB_MAP_OUTPUT,'matlab')
0144 clf;
0145
0146 figure(1);colormap(cool(100))
0147 colorbar('location','southoutside');
0148 axis equal;
0149 hold on
0150 elseif strcmp(CB_MAP_OUTPUT, 'java')
0151
0152 plotcbmap;
0153
0154 R=map.molPosition';
0155 R=sort(R);
0156 a=max(R);
0157 b=min(R);
0158 xmax=a(1,1);
0159 xmin=b(1,1);
0160 ymax=a(1,2);
0161 ymin=b(1,2);
0162 settrans(mapHandle,xmax,xmin,ymax,ymin);
0163 elseif strcmp(CB_MAP_OUTPUT, 'svg')
0164
0165 if isempty(regexp(lower(options.fileName),'.svg$'))
0166 options.fileName = strcat(options.fileName,'.svg');
0167 end
0168 textPos = (map.textPos);
0169 x1 = min(map.molPosition(1,:));
0170 if min(textPos(:,1))<x1
0171 x1 = min(textPos(:,1));
0172 end
0173 y1 = min(map.molPosition(2,:));
0174 if min(textPos(:,2))<y1
0175 y1 = min(textPos(:,2));
0176 end
0177 x2 = max(map.molPosition(1,:));
0178 if max(textPos(:,1))>x2
0179 x2 = max(textPos(:,1));
0180 end
0181 y2 = max(map.molPosition(2,:));
0182 if max(textPos(:,2))>y2
0183 y2 = max(textPos(:,2));
0184 end
0185 if isfield(options,'colorScale')
0186 numColorBins = size(options.colorScale,1);
0187 colorScaleWidth = 0.25*(x2-x1);
0188 binWidth = colorScaleWidth/numColorBins;
0189 colorScaleHeight = 0.05*colorScaleWidth;
0190 colorScaleBuffer = colorScaleHeight*1.5;
0191 y2 = y2+colorScaleBuffer;
0192 end
0193 if isfield(options,'fluxVarColor')
0194 colorScaleHeight = 0.0125*(x2-x1);
0195 colorScaleBuffer = colorScaleHeight*1.5;
0196 colorWidth = 0.025*(x2-x1);
0197 y2 = y2+colorScaleBuffer;
0198 end
0199 [x1,y1,x2,y2] = deal(x1-200, y1-200, x2+200, y2+200);
0200 SF = .25;
0201 mapHandle = fopen(options.fileName, 'w');
0202 fprintf(mapHandle, '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n');
0203 fprintf(mapHandle,'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">\n');
0204 fprintf(mapHandle,'<svg height="%+.2f" width="%+.2f" viewBox="%+.2f %+.2f %+.2f %+.2f" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">\n',(y2-y1+20)*SF,(x2-x1+20)*SF,(x1-10)*SF,(y1-10)*SF,(x2-x1+0)*SF,(y2-y1+20)*SF);
0205 fprintf(mapHandle,'<g transform="scale(%5.3f)">\n',SF);
0206
0207
0208 if isfield(options,'overlayType')
0209 for i=1:numColorBins
0210 color = strcat('rgb(',num2str(options.colorScale(i,1)),',',num2str(options.colorScale(i,2)),',',num2str(options.colorScale(i,3)),')');
0211 fprintf(mapHandle,'<g style="stroke-linecap: round; stroke-linejoin: round; stroke-miterlimit: 20; fill: %s; ">\n',color);
0212 fprintf(mapHandle,'<rect x="%.2f" y="%.2f" width="%.2f" height="%.2f" />\n</g>\n',x2-colorScaleWidth-200*2+(binWidth*(i-1)),y2-colorScaleHeight*1.25,binWidth,colorScaleHeight);
0213 end
0214 fprintf(mapHandle, '<g style="font-family: sans; stroke: none; text-anchor:end">\n');
0215 fprintf(mapHandle,'<text style="fill: rgb(0,0,0); text-rendering: optimizeLegibility;" x="%.2f" y="%.2f" font-size="%dpx">%s</text>\n</g>\n',x2-colorScaleWidth-200*2-0.25*colorScaleHeight,y2-colorScaleHeight*.4,colorScaleHeight,['Scale: ' options.scaleTypeLabel ' ' options.overlayType ': ' options.overlayLB]);
0216 fprintf(mapHandle, '<g style="font-family: sans; stroke: none; text-anchor:start">\n');
0217 fprintf(mapHandle,'<text style="fill: rgb(0,0,0); text-rendering: optimizeLegibility;" x="%.2f" y="%.2f" font-size="%dpx">%s</text>\n</g>\n',x2-200*2+0.25*colorScaleHeight,y2-colorScaleHeight*.4,colorScaleHeight,[options.overlayUB]);
0218 end
0219 if isfield(options,'fluxVarColor')
0220 colorTextLabel = {'Bidirectional / reversible:', 'Unidirectional / reversible forward:', 'Unidirectional / reversible reverse:', 'Unidirectional / irreversible:'};
0221 color{1} = strcat('rgb(',num2str(options.fluxVarColor.biDirColor(1)),',',num2str(options.fluxVarColor.biDirColor(2)),',',num2str(options.fluxVarColor.biDirColor(3)),')');
0222 color{2} = strcat('rgb(',num2str(options.fluxVarColor.uniDirFwdColor(1)),',',num2str(options.fluxVarColor.uniDirFwdColor(2)),',',num2str(options.fluxVarColor.uniDirFwdColor(3)),')');
0223 color{3} = strcat('rgb(',num2str(options.fluxVarColor.uniDirRevColor(1)),',',num2str(options.fluxVarColor.uniDirRevColor(2)),',',num2str(options.fluxVarColor.uniDirRevColor(3)),')');
0224 color{4} = strcat('rgb(',num2str(options.fluxVarColor.uniDirIrrColor(1)),',',num2str(options.fluxVarColor.uniDirIrrColor(2)),',',num2str(options.fluxVarColor.uniDirIrrColor(3)),')');
0225 for i=2:3:11
0226 fprintf(mapHandle, '<g style="font-family: sans; stroke: none; text-anchor:end">\n');
0227 fprintf(mapHandle,'<text style="fill: rgb(0,0,0); text-rendering: optimizeLegibility;" x="%.2f" y="%.2f" font-size="%dpx">%s</text>\n</g>\n',i*(x2-x1)/12,y2-colorScaleHeight*.4,colorScaleHeight,colorTextLabel{ceil(i/3)});
0228 fprintf(mapHandle,'<g style="stroke-linecap: round; stroke-linejoin: round; stroke-miterlimit: 20; fill: %s; ">\n',color{ceil(i/3)});
0229 fprintf(mapHandle,'<rect x="%.2f" y="%.2f" width="%.2f" height="%.2f" />\n</g>\n',i*(x2-x1)/12,y2-colorScaleHeight*1.25,colorWidth,colorScaleHeight);
0230 end
0231 end
0232 end
0233
0234
0235
0236 if isfield(map,'shapeThickness')
0237 for i = 1:size((map.shapeThickness),1)
0238 drawShape(map.shapeType(i,1),map.shapePos(i,1:2),map.shapeSize(i,1:2),map.shapeColor(i,1:3),map.shapeThickness(i,1),map.shapeStyle(i,1));
0239 end
0240 end
0241
0242 for i = 1:(size((map.connection),1))
0243 drawLine(map.connection(i,1),map.connection(i,2),map,options.edgeColor(i,:),options.edgeArrowColor(i,:),options.edgeWeight(i),nodeWeight,options.rxnDir(i),options.rxnDirMultiplier);
0244 end
0245
0246 for i = 1:size((map.molPosition),2)
0247 drawCircle(map.molPosition(:,i),nodeWeight(i),options.nodeColor(i,:));
0248 end
0249
0250 for i = 1:length(map.text)
0251 textFont =map.textFont{i};
0252 if regexp(textFont,'@')
0253 [textFont, textSize] = strtok(textFont,'@');
0254 textSize = str2num(regexprep(textSize,'@',''));
0255 elseif(map.textSize(i) >= 60)
0256 textSize = 60;
0257 else
0258 textSize = map.textSize(i);
0259 end
0260 if find(regexp(textFont,'Italic'))
0261 textStyle = 'italic;';
0262 else
0263 textStyle = '';
0264 end
0265
0266
0267 if (find(regexp(textFont,'B')))
0268 textWeight = 'bold';
0269 textFont = regexprep(textFont,' B','');
0270 else
0271 textWeight = '';
0272 end
0273 if isfield(options,'otherTextSize'), textSize = options.otherTextSize(i); end
0274 drawText(map.textPos(i,1),map.textPos(i,2),map.text{i,1},textSize,textStyle,options.otherTextColor(i,:),lower(textFont),textWeight,true);
0275 end
0276
0277 for i = 1:size((map.molPosition),2)
0278
0279 if(options.textSize(i) ~= 0)
0280 drawText(map.molLabelPos(i,1),map.molLabelPos(i,2),map.molAbbreviation{i},options.textSize(i),'',options.textColor(i,:));
0281 end
0282 end
0283
0284 for i = 1:size(map.rxnLabelPosition,2)
0285 if ~any(isnan(map.rxnLabelPosition(:,i)))
0286 if isfield(options, 'rxnTextSize')
0287 drawText(map.rxnLabelPosition(1,i),map.rxnLabelPosition(2,i),map.connectionAbb{find(map.rxnIndex(i)==map.connection,1)},options.rxnTextSize(i),'italic');
0288 else
0289 drawText(map.rxnLabelPosition(1,i),map.rxnLabelPosition(2,i),map.connectionAbb{find(map.rxnIndex(i)==map.connection,1)},8,'italic');
0290 end
0291 end
0292 end
0293
0294 if strcmp(CB_MAP_OUTPUT,'matlab')
0295 hold off;
0296 elseif strcmp(CB_MAP_OUTPUT,'java')
0297
0298 elseif strcmp(CB_MAP_OUTPUT,'svg')
0299
0300 fprintf(mapHandle,'</g>\n');
0301 fprintf(mapHandle,'</svg>\n');
0302 fclose(mapHandle);
0303 display('Document Written')
0304 end