0001 function map = readCbMap(fileName)
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 if nargin < 1
0031 [fileName,filePath] = uigetfile({'*.txt'});
0032 else
0033 filePath = '';
0034 if isempty(regexp(fileName,'.txt$', 'once'))
0035 fileName = strcat(fileName,'.txt');
0036 end
0037 end
0038
0039
0040 format = '%s %n %s %f %f %f %f %n %s';
0041 fid = fopen(strcat(filePath,fileName));
0042 molecules = textscan(fid, format,'delimiter', '\t','HeaderLines',1);
0043 fclose(fid);
0044
0045 molAbb = molecules{1,1};
0046 molComp = molecules{1,2};
0047 molPrim = molecules{1,3};
0048 molLabelx = molecules{1,4};
0049 molLabely = molecules{1,5};
0050 molPosx = molecules{1,6};
0051 molPosy = molecules{1,7};
0052 molName = molecules{1,9};
0053 molId = molecules{1,8};
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068 rxnN = (strmatch('Reactions Nodes',molAbb));
0069 rxnEnd = strmatch('Reactions',molAbb,'exact');
0070 textBeg = strmatch('Texts',molAbb);
0071
0072 indexMols = (1:(rxnN-1));
0073 indexRxnNodes = ((rxnN+1):(rxnEnd-1));
0074 indexRxnNames = ((rxnEnd+1):(textBeg-1));
0075 indexTexts = ((textBeg+1):length(molAbb));
0076
0077 rxnNum = (rxnEnd-rxnN-1);
0078 connectionNum = textBeg-rxnEnd;
0079
0080
0081 molPos(:,1) = molPosx(indexMols);
0082 molPos(:,2) = molPosy(indexMols);
0083
0084
0085 molLabelPos = [molLabelx(indexMols) molLabely(indexMols)];
0086
0087
0088
0089
0090 rxnPos = [molPosx(indexRxnNodes) molPosy(indexRxnNodes)];
0091
0092
0093
0094
0095 rxnLabelPos = [molLabelx(indexRxnNodes) molLabely(indexRxnNodes)];
0096
0097
0098 rxnId = molId(indexRxnNodes);
0099
0100
0101 node = [molLabelx(indexRxnNames) molLabely(indexRxnNames)];
0102
0103
0104
0105 r = zeros(connectionNum,1);
0106 r(strmatch('Reversible',molPrim(indexRxnNames),'exact'))=1;
0107
0108 rxnAbb = molAbb(indexRxnNames);
0109 rxnName = molName(indexRxnNames);
0110
0111
0112 shapeIDs = [strmatch('Circle',molAbb); strmatch('Rect',molAbb); strmatch('Line',molAbb)];
0113 indexShapes = logical(sparse(length(molAbb),1));
0114 indexShapes(shapeIDs) = 1;
0115 map.shapeType = molAbb(indexShapes);
0116 map.shapePos = [molLabelx(indexShapes) molLabely(indexShapes)];
0117 map.shapeSize = [molPosx(indexShapes) molPosy(indexShapes)];
0118 for i=1:length(shapeIDs)
0119 str = molName(shapeIDs(i));
0120 [colorStr, str] = strtok(str,':');
0121 [c1,c2] = strtok(colorStr,'/');
0122 [c2,c3] = strtok(c2,'/');
0123 c3 = regexprep(c3,'\/','');
0124 if isnan(str2double(c3))
0125 c3 = 0;
0126 end
0127 [thickness, style] = strtok(str,'@');
0128 thickness = regexprep(thickness,'(\w*):','');
0129 style = regexprep(style,'\@','');
0130 map.shapeStyle(i,1) = style;
0131 map.shapeThickness(i,1) = str2num(thickness{1,1});
0132 map.shapeColor(i,1:3) = [str2double(c1{1,1}) str2double(c2{1,1}) str2double(c3{1,1})];
0133 end
0134 indexShapes(1:textBeg) = 1;
0135 map.text = molName(~indexShapes);
0136 map.textFont = molAbb(~indexShapes);
0137 map.textPos = [molLabelx(~indexShapes) molLabely(~indexShapes)];
0138 map.textSize = molPosx(~indexShapes);
0139
0140 map.molPosition = molPos';
0141 map.molIndex = molId(1:(rxnN-1));
0142 map.molName = molName(1:(rxnN-1));
0143 map.molAbbreviation = molAbb(1:(rxnN-1));
0144 map.molLabelPos = molLabelPos;
0145 map.molPrime = molPrim(1:(rxnN-1));
0146 map.molCompartment = molComp(1:(rxnN-1));
0147 map.rxnPosition = rxnPos';
0148 map.rxnLabelPosition = rxnLabelPos';
0149 map.rxnIndex = rxnId;
0150 map.connection = node;
0151 map.connectionAbb = rxnAbb;
0152 map.connectionName = rxnName;
0153 map.connectionReversible = r;
0154 end