readCbMap

PURPOSE ^

readCbMap reads in a map from a textfile and returns a map struct

SYNOPSIS ^

function map = readCbMap(fileName)

DESCRIPTION ^

 readCbMap reads in a map from a textfile and returns a map struct

 map = readCbMap(fileName)

INPUT
 fileName is the text file exported from BiGG database

OUTPUT
 map                   Map structure
   molPosition             the positions of the metabolite nodes
   molIndex                index for molecule node(same as connection index)
   molName                 full name of metabiolites
   molAbbreviation         The abbreviation formetabolites(labels)
   molLabelPos             The positions to display the metabolite's labels
   molPrime                Y if metabolite is primary and N if not
   rxnPosition             the positions of the reaction nodes
   rxnLabelPosition        the positions of the reaction nodes' labels if the
                           node is a midpoint
   rxnIndex                the index of reaction nodes used in connection
   connection              the node connection matrix
   connectionAbb           the reaction abbreviations assigned to each
                           segment
   connectionName          the name of reactions
   connectionRiversibile   1 if reaction is reversible and 0 otherwise

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function map = readCbMap(fileName)
0002 % readCbMap reads in a map from a textfile and returns a map struct
0003 %
0004 % map = readCbMap(fileName)
0005 %
0006 %INPUT
0007 % fileName is the text file exported from BiGG database
0008 %
0009 %OUTPUT
0010 % map                   Map structure
0011 %   molPosition             the positions of the metabolite nodes
0012 %   molIndex                index for molecule node(same as connection index)
0013 %   molName                 full name of metabiolites
0014 %   molAbbreviation         The abbreviation formetabolites(labels)
0015 %   molLabelPos             The positions to display the metabolite's labels
0016 %   molPrime                Y if metabolite is primary and N if not
0017 %   rxnPosition             the positions of the reaction nodes
0018 %   rxnLabelPosition        the positions of the reaction nodes' labels if the
0019 %                           node is a midpoint
0020 %   rxnIndex                the index of reaction nodes used in connection
0021 %   connection              the node connection matrix
0022 %   connectionAbb           the reaction abbreviations assigned to each
0023 %                           segment
0024 %   connectionName          the name of reactions
0025 %   connectionRiversibile   1 if reaction is reversible and 0 otherwise
0026 %
0027 
0028 
0029 % The general format of the import file in 9 cols
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 % s = size(molLabelx);            %lenght of a general column
0055 % i = 1;
0056 
0057 % while i<= s(1)
0058 %     if strcmp(molAbb(i),'Reactions Nodes')
0059 %         rxnN = i;               % number of molecules
0060 %     elseif strcmp(molAbb(i),'Reactions')
0061 %         rxnEnd = i;
0062 %     elseif strcmp(molAbb(i),'Texts')
0063 %         textBeg = i;
0064 %     end
0065 %     i= i+1;
0066 % end
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);       % number of rxn nodes
0078 connectionNum = textBeg-rxnEnd;    % number of connections: connectionNum
0079 
0080 % set up the position matrix for molecules
0081 molPos(:,1) = molPosx(indexMols);  
0082 molPos(:,2) = molPosy(indexMols);
0083 
0084 % set up the position matrix for molecules' labels
0085 molLabelPos = [molLabelx(indexMols) molLabely(indexMols)];
0086 
0087 % set up the position matrix for reactions
0088 %rxnPos = [molLabelx(indexRxnNodes) molLabely(indexRxnNodes)];
0089 %Updated BiGG to output files in a less disorganized fashion
0090 rxnPos = [molPosx(indexRxnNodes) molPosy(indexRxnNodes)];
0091 
0092 % set up the position matrix for reactions' labels
0093 %rxnLabelPos = [molPosx(indexRxnNodes) molPosy(indexRxnNodes)];
0094 %Updated BiGG to output files in a less disorganized fashion
0095 rxnLabelPos = [molLabelx(indexRxnNodes) molLabely(indexRxnNodes)];
0096 
0097 % reaction ids
0098 rxnId = molId(indexRxnNodes);
0099 
0100 % set up the connection matrix
0101 node = [molLabelx(indexRxnNames) molLabely(indexRxnNames)];
0102 
0103 
0104 % set up the reversibility for each connection
0105 r = zeros(connectionNum,1);
0106 r(strmatch('Reversible',molPrim(indexRxnNames),'exact'))=1;
0107 
0108 rxnAbb = molAbb(indexRxnNames);
0109 rxnName = molName(indexRxnNames);
0110 
0111 %% Handling other shapes and texts
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

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