0001 function notShownMets = outputNetworkCytoscape(model,fileBase,rxnList,rxnData,metList,metData,metDegreeThr)
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
0036
0037
0038
0039
0040
0041
0042 if (nargin < 3)
0043 rxnInd = [1:length(model.rxns)];
0044 rxnList = model.rxns;
0045 else
0046 if (isempty(rxnList))
0047 rxnInd = [1:length(model.rxns)];
0048 rxnList = model.rxns;
0049 else
0050 [isInModel,rxnInd] = ismember(rxnList,model.rxns);
0051 rxnInd = rxnInd(isInModel);
0052 end
0053 end
0054
0055 if (nargin < 4)
0056 rxnData = [];
0057 end
0058
0059 if (nargin < 5)
0060 metInd = [1:length(model.mets)];
0061 metList = model.mets;
0062 selMet = true(length(model.mets),1);
0063 else
0064 if (isempty(metList))
0065 metInd = [1:length(model.mets)];
0066 metList = model.mets;
0067 selMet = true(length(model.mets),1);
0068 else
0069 [isInModel,metInd] = ismember(metList,model.mets);
0070 metList = metList(isInModel);
0071 selMet = ismember(model.mets,metList);
0072 end
0073 end
0074
0075 if (nargin < 6)
0076 metData = [];
0077 end
0078
0079 if (nargin < 7)
0080 allowedMet = true(length(model.mets),1);
0081 notShownMets = [];
0082 else
0083 nRxnsMet = sum(model.S' ~= 0)';
0084 allowedMet = nRxnsMet <= metDegreeThr;
0085 metsNotAllowed = model.mets(~allowedMet);
0086 baseMetNames = parseMetNames(model.mets);
0087 if (~isempty(metsNotAllowed))
0088 metsNotAllowedBase = parseMetNames(metsNotAllowed);
0089 allowedMet = ~ismember(baseMetNames,metsNotAllowedBase);
0090 notShownMets = model.mets(~allowedMet);
0091 else
0092 allowedMet = true(length(model.mets),1);
0093 notShownMets = [];
0094 end
0095 end
0096
0097
0098 fid = fopen([fileBase '.sif'],'w');
0099 fidNodeType = fopen([fileBase '_nodeType.noa'],'w');
0100 fprintf(fidNodeType,'NodeTypes\n');
0101 if (isfield(model,'subSystems'))
0102 fidSubSys = fopen([fileBase '_subSys.noa'],'w');
0103 fprintf(fidSubSys,'SubSystems\n');
0104 end
0105 fidEdgeType = fopen([fileBase '_edgeType.noa'],'w');
0106 fprintf(fidEdgeType,'EdgeType\n');
0107
0108
0109 if (isfield(model,'genes'))
0110 for geneNo = 1:length(model.genes)
0111 fprintf(fidNodeType,'%s = gene\n',model.genes{geneNo});
0112 end
0113 end
0114
0115 for i = 1:length(rxnList)
0116 rxnNo = rxnInd(i);
0117
0118 fprintf(fidNodeType,'%s = rxn\n',model.rxns{rxnNo});
0119
0120 if (isfield(model,'subSystems'))
0121 fprintf(fidSubSys,'%s = %s\n',model.rxns{rxnNo},model.subSystems{rxnNo});
0122 end
0123
0124 if (isfield(model,'genes'))
0125 geneInd = full(find(model.rxnGeneMat(rxnNo,:)));
0126 for geneNo = 1:length(geneInd)
0127 fprintf(fid,'%s gra %s\n',model.rxns{rxnNo},model.genes{geneInd(geneNo)});
0128 fprintf(fidEdgeType,'%s (gra) %s = gra\n',model.rxns{rxnNo},model.genes{geneInd(geneNo)});
0129 end
0130 end
0131
0132 if (model.rev(rxnNo))
0133 metInd = find(model.S(:,rxnNo) ~= 0 & allowedMet & selMet);
0134 for j = 1:length(metInd)
0135 metNo = metInd(j);
0136 fprintf(fid,'%s rev %s\n',model.rxns{rxnNo},model.mets{metNo});
0137 fprintf(fidEdgeType,'%s (rev) %s = rev\n',model.rxns{rxnNo},model.mets{metNo});
0138 end
0139 else
0140 metInd = find(model.S(:,rxnNo) < 0 & allowedMet & selMet);
0141 for j = 1:length(metInd)
0142 metNo = metInd(j);
0143 fprintf(fid,'%s dir %s\n',model.mets{metNo},model.rxns{rxnNo});
0144 fprintf(fidEdgeType,'%s (dir) %s = dir\n',model.mets{metNo},model.rxns{rxnNo});
0145 end
0146 metInd = find(model.S(:,rxnNo) > 0 & allowedMet & selMet);
0147 for j = 1:length(metInd)
0148 metNo = metInd(j);
0149 fprintf(fid,'%s dir %s\n',model.rxns{rxnNo},model.mets{metNo});
0150 fprintf(fidEdgeType,'%s (dir) %s = dir\n',model.rxns{rxnNo},model.mets{metNo});
0151 end
0152 end
0153 end
0154 fclose(fid);
0155 fclose(fidEdgeType);
0156 if (isfield(model,'subSystems'))
0157 if (isfield(model,'subSystemsMet'))
0158 for i = 1:length(model.mets)
0159 fprintf(fidSubSys,'%s = %s\n',model.mets{i},model.subSystemsMet{i});
0160 end
0161 end
0162 fclose(fidSubSys);
0163 end
0164
0165
0166 for metNo = 1:length(model.mets)
0167 fprintf(fidNodeType,'%s = met\n',model.mets{metNo});
0168 end
0169 fclose(fidNodeType);
0170
0171
0172 [baseMetNames,compSymbols] = parseMetNames(model.mets);
0173 fidComp = fopen([fileBase '_nodeComp.noa'],'w');
0174 fprintf(fidComp,'NodeComp\n');
0175 for i = 1:length(baseMetNames)
0176 fprintf(fidComp,'%s = %s\n',model.mets{i},compSymbols{i});
0177 end
0178 for i = 1:length(model.rxns)
0179 rxnCompSymbol = unique(compSymbols(full(model.S(:,i) ~= 0)));
0180 if (length(rxnCompSymbol) == 1)
0181 fprintf(fidComp,'%s = %s\n',model.rxns{i},rxnCompSymbol{1});
0182 else
0183 fprintf(fidComp,'%s = t\n',model.rxns{i});
0184 end
0185 end
0186 fclose(fidComp);
0187
0188
0189 if (~isempty(metData))
0190 fidData = fopen([fileBase '_rxnMetData.noa'],'w');
0191 [nMets,nSets] = size(metData);
0192 if (nSets == 1)
0193 fprintf(fidData,'rxnMetData\n');
0194 for i = 1:nMets
0195 if (iscell(metData))
0196 fprintf(fidData,'%s = %s\n',metList{i},metData{i});
0197 else
0198 fprintf(fidData,'%s = %f\n',metList{i},metData(i));
0199 end
0200 end
0201 else
0202 fprintf(fidData,'ID\tID\t');
0203 for j = 1:nSets
0204 fprintf(fidData,'set%d\t',j);
0205 end
0206 fprintf(fidData,'\n');
0207 for i = 1:nMets
0208 fprintf(fidData,'%s\t%s\t',metList{i},metList{i});
0209 for j = 1:nSets
0210 if (iscell(metData))
0211 fprintf(fidData,'%s\t',metData{i,j});
0212 else
0213 fprintf(fidData,'%f\t',metData(i,j));
0214 end
0215 end
0216 fprintf(fidData,'\n');
0217 end
0218 end
0219 if (isempty(rxnData))
0220 fclose(fidData);
0221 end
0222 end
0223
0224
0225 if (~isempty(rxnData))
0226 [nRxns,nSets] = size(rxnData);
0227 if (isempty(metData))
0228 fidData = fopen([fileBase '_rxnMetData.noa'],'w');
0229 if (nSets == 1)
0230 fprintf(fidData,'rxnMetData\n');
0231 else
0232 fprintf(fidData,'ID\tID\t');
0233 for j = 1:nSets
0234 fprintf(fidData,'set%d\t',j);
0235 end
0236 fprintf(fidData,'\n');
0237 end
0238 end
0239
0240 if (nSets == 1)
0241 for i = 1:nRxns
0242 if (iscell(rxnData))
0243 fprintf(fidData,'%s = %s\n',rxnList{i},rxnData{i});
0244 else
0245 fprintf(fidData,'%s = %f\n',rxnList{i},rxnData(i));
0246 end
0247 end
0248 else
0249 for i = 1:nRxns
0250 fprintf(fidData,'%s\t%s\t',rxnList{i},rxnList{i});
0251 for j = 1:nSets
0252 if (iscell(rxnData))
0253 fprintf(fidData,'%s\t',rxnData{i,j});
0254 else
0255 fprintf(fidData,'%f\t',rxnData(i,j));
0256 end
0257 end
0258 fprintf(fidData,'\n');
0259 end
0260 end
0261 fclose(fidData);
0262 end