0001 function exportModelToSIF(model,fileName,graphType,rxnLabels,metLabels)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 fileName=char(fileName);
0018 if nargin<3
0019 graphType='rc';
0020 else
0021 graphType=char(graphType);
0022 end
0023
0024 if nargin<4 || isempty(rxnLabels)
0025 rxnLabels=model.rxns;
0026 else
0027 rxnLabels=convertCharArray(rxnLabels);
0028 end
0029 if nargin<5 || isempty(metLabels)
0030 metLabels=model.mets;
0031 else
0032 metLabels=convertCharArray(metLabels);
0033 end
0034
0035 if ~strcmpi(graphType,'rc') && ~strcmpi(graphType,'rr') && ~strcmpi(graphType,'cc')
0036 EM='The graph type is incorrect';
0037 dispEM(EM);
0038 end
0039
0040 if numel(rxnLabels)~=numel(unique(rxnLabels))
0041 EM='Not all reaction labels are unique';
0042 dispEM(EM,false);
0043 end
0044 if numel(metLabels)~=numel(unique(metLabels))
0045 EM='Not all metabolite labels are unique';
0046 dispEM(EM,false);
0047 end
0048
0049 if strcmpi(graphType,'rc')
0050 G=model.S;
0051 A=rxnLabels;
0052 B=metLabels;
0053 end
0054 if strcmpi(graphType,'rr')
0055 G=model.S'*model.S;
0056 A=rxnLabels;
0057 B=rxnLabels;
0058 end
0059 if strcmpi(graphType,'cc')
0060
0061
0062
0063 irrevModel=convertToIrrev(model);
0064 G=sparse(numel(model.mets),numel(model.mets));
0065 for i=1:numel(model.mets)
0066 I=irrevModel.S(i,:)<0;
0067 [J, ~]=find(irrevModel.S(:,I)>0);
0068 G(J,i)=1;
0069 end
0070 A=metLabels;
0071 B=metLabels;
0072 end
0073
0074 fid=fopen(fileName,'w');
0075
0076 for i=1:size(G,2)
0077 I=G(:,i)~=0;
0078 nodes=setdiff(B(I),A(i));
0079 if ~isempty(nodes)
0080 nNodes=numel(nodes);
0081 nodes(1:nNodes-1)=strcat(nodes(1:nNodes-1),{'\t'});
0082 fullString=[nodes{:}];
0083 fprintf(fid,[A{i} '\t' graphType '\t' fullString '\n']);
0084 end
0085 end
0086 fclose(fid);
0087 end