drawLine

PURPOSE ^

drawLine

SYNOPSIS ^

function drawLine(node1,node2,map,edgeColor,edgeArrowColor,edgeWeight,nodeWeight,rxnDir,rxnDirMultiplier)

DESCRIPTION ^

drawLine

 drawLine(node1,node2,map,edgeColor,edgeArrowColor,edgeWeight,nodeWeight)

INPUTS
 node1             start node
 node2             end node
 map               COBRA map structure
 edgeColor         Line color
 edgeArrowColor    Arrowhead color
 edgeWeight        Line width

OPTIONAL INPUT
 nodeWeight        Node size

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function drawLine(node1,node2,map,edgeColor,edgeArrowColor,edgeWeight,nodeWeight,rxnDir,rxnDirMultiplier)
0002 %drawLine
0003 %
0004 % drawLine(node1,node2,map,edgeColor,edgeArrowColor,edgeWeight,nodeWeight)
0005 %
0006 %INPUTS
0007 % node1             start node
0008 % node2             end node
0009 % map               COBRA map structure
0010 % edgeColor         Line color
0011 % edgeArrowColor    Arrowhead color
0012 % edgeWeight        Line width
0013 %
0014 %OPTIONAL INPUT
0015 % nodeWeight        Node size
0016 %
0017 %
0018 
0019 if nargin < 9
0020     rxnDirMultipler = 2;
0021 end
0022 
0023 if nargin < 8
0024     rxnDir = 0;
0025 end
0026 
0027 if (nargin < 7)
0028     rad = 20;
0029 else
0030     index1 = find(map.molIndex(:) == node1);
0031     index2 = find(map.molIndex(:) == node2);
0032     if length(index1) == 1
0033         rad = nodeWeight(index1);
0034     elseif length(index2) == 1
0035         rad = nodeWeight(index2);
0036     else
0037         rad = 20;
0038     end
0039 end
0040 
0041 if isnan(node1) || isnan(node2)
0042     return;
0043 end
0044 
0045 [type1, nodePos(:,1)] = getType(node1, map);
0046 [type2, nodePos(:,2)] = getType(node2, map);
0047 p1 = nodePos(:,1);
0048 p2 = nodePos(:,2);
0049 
0050 if type1 == 1 && type2 == 1
0051     drawVector(nodePos(:,1),nodePos(:,2),edgeColor,edgeWeight);
0052     
0053 elseif type1 == 1 && type2 == 2
0054     %drawCircle(p2, 3, 'r');
0055     index1 = find(map.connection(:,1) == node2);
0056     index2 = find(map.connection(:,2) == node2);
0057     isend = 0;
0058     if map.connectionReversible(index1) == 1
0059         isend = 1;
0060     end
0061     if length(index1) == 1 && length(index2) == 1 % case metabolite to center reaction.
0062         [point1,dir] = c2p(nodePos(:,1),nodePos(:,2),rad);
0063         drawVector(point1, nodePos(:,2),edgeColor,edgeWeight);
0064         if isend
0065             if rxnDir < 0, rad = rad*rxnDirMultiplier; end
0066             drawArrowhead(point1,dir,rad,edgeArrowColor);
0067         end
0068     elseif length(index1) > 1 && length(index2) == 1
0069         display('blah'); % for some reason this doesn't happen. (metabolite node cannot have more than one point)
0070     elseif length(index1) == 1 && length(index2) > 1
0071         othernode = map.connection(index1,2);
0072         [t3,p3] = getType(othernode, map);
0073         %%%p3 = p3';
0074         direction = p2-p3;
0075         %direction = p3-p2;
0076         if any(direction~=0)
0077             dirnorm = direction/(norm(direction));
0078         else
0079             dirnorm = zeros(size(direction));
0080         end
0081         multiplier = dirnorm' * (p1-p2);
0082         multiplier = max([.3*norm(p2-p1), multiplier]);
0083         ptemp = p2 + multiplier*dirnorm;
0084         distance = norm(ptemp-p1);
0085         if distance < multiplier
0086             multiplier = mean([multiplier, distance]);
0087         end
0088         ptemp = p2 + multiplier*dirnorm;
0089         %drawCircle(ptemp,5,'m');
0090         %drawCircle(p3,5,'g');
0091         [p1,dir] = c2p(p1,ptemp,rad);
0092         drawBezier([p2,ptemp,p1],edgeColor,edgeWeight);
0093         if isend
0094             if rxnDir < 0, rad = rad*rxnDirMultiplier; end
0095             drawArrowhead(p1,dir,rad,edgeArrowColor)
0096         end
0097     else
0098         display('oops');
0099     end
0100     
0101 elseif type1 == 2 && type2 == 1
0102     %drawCircle(p1, 3, 'y');
0103     index1 = find(map.connection(:,1) == node1);
0104     index2 = find(map.connection(:,2) == node1);
0105     %         if length(index1) == 1 && length(index2) == 1 % case metabolite to center reaction.
0106     %             [point2,dir] = c2p(nodePos(:,2),nodePos(:,1),rad);
0107     %             drawVector(nodePos(:,1), point2,edgeColor,edgeWeight);
0108     %             drawArrowhead(point2,dir,rad,edgeArrowColor);
0109     %         elseif length(index1) > 1 && length(index2) == 1
0110     othernode = map.connection(index2,1);
0111     [t3,p3] = getType(othernode, map);
0112     %%%p3 = p3';
0113     direction = p1-p3;
0114     if any(direction~=0)
0115         dirnorm = direction/(norm(direction));
0116     else
0117         dirnorm = zeros(size(direction));
0118     end
0119     multiplier = dirnorm' * (p2-p1);
0120     multiplier = max([ .3*norm(p2-p1), multiplier]);
0121     ptemp = p1 + multiplier*dirnorm;
0122     distance = norm(ptemp-p2);
0123     if distance < multiplier
0124         multiplier = mean([multiplier, distance]);
0125     end
0126     ptemp = p1 + multiplier*dirnorm;
0127     %drawCircle(ptemp,5,'m');
0128     %drawCircle(p3,5,'g');
0129     [p2,dir] = c2p(p2,ptemp,rad);
0130     drawBezier([p1,ptemp,p2],edgeColor,edgeWeight);
0131     if rxnDir > 0, rad = rad*rxnDirMultiplier; end
0132     drawArrowhead(p2,dir,rad,edgeArrowColor);
0133     %         elseif length(index1) == 1 && length(index2) > 1
0134     %             display('blah2');% for some reason this doesn't happen.
0135     %         else
0136     %             display('oops');
0137     %         end
0138     
0139 elseif type1 ==2 && type2 == 2
0140     drawVector(nodePos(:,1),nodePos(:,2),edgeColor,edgeWeight);
0141 else
0142     display('oops');
0143     pause;
0144 end
0145 %         % display the reaction label in case of a midpoint
0146 %     if rxnTextWeight ~= 0
0147 %         if type1 == 2
0148 %             index1 = find(map.rxnIndex == node1);
0149 %             if map.rxnLabelPosition(1,index1)~= 0
0150 %                 index2 = find(map.connection(:,1) == node1);
0151 %                 drawText(map.rxnLabelPosition(1,index1),map.rxnLabelPosition(2,index1),map.connectionAbb(index2),rxnTextWeight,'italic;');
0152 %             end
0153 %         end
0154 %         if type2 == 2
0155 %             index1 = find(map.rxnIndex == node1);
0156 %             if map.rxnLabelPosition(1,index1)~= 0
0157 %                 index2 = find(map.connection(:,2) == node2);
0158 %                 drawText(map.rxnLabelPosition(1,index1),map.rxnLabelPosition(2,index1),map.connectionAbb(index2),rxnTextWeight,'italic');
0159 %             end
0160 %         end
0161 %     end
0162 
0163 end
0164 
0165 
0166 function [type, position] = getType(node, map) % you could also have it output a third value which could be the index of the preceding node.
0167 molIndex = find(map.molIndex == node);
0168 rxnIndex = find(map.rxnIndex == node);
0169 if ~isempty(molIndex)
0170     type = 1; %molecule
0171     position = map.molPosition(:,molIndex);
0172 elseif ~isempty(rxnIndex)
0173     type = 2; % reaction.
0174     position = map.rxnPosition(:,rxnIndex);
0175     %Add more code here to figure out subtype of reaction node.
0176 else % should never get here, but go ahead and scan for errors.
0177     display('errorXYZ in drawLine.m');
0178     %         pause;
0179 end
0180 if numel(molIndex) > 1 || numel(rxnIndex) > 1 % this means that it is not unique.
0181     display('error2');
0182     %         pause;
0183 end
0184 end
0185 % move p1 from the center of the circle to the pyrimid of the circle in the
0186 % direction of p2
0187 function [point,dir] = c2p(p1,p2,rad)
0188 dir = p2-p1;
0189 point = p1+rad*(dir/sqrt(dir(1)^2+dir(2)^2));
0190 
0191 end
0192

Generated on Thu 21-Jun-2012 15:39:23 by m2html © 2003