outputNetworkCytoscape

PURPOSE ^

outputNetworkCytoscape Output a metabolic network in Cytoscape format

SYNOPSIS ^

function notShownMets = outputNetworkCytoscape(model,fileBase,rxnList,rxnData,metList,metData,metDegreeThr)

DESCRIPTION ^

outputNetworkCytoscape Output a metabolic network in Cytoscape format

 notShownMets =
 outputNetworkCytoscape(model,fileBase,rxnList,rxnData,metList,metData,metDegreeThr)

INPUTS
 model         COBRA metabolic network model
 fileBase      Base file name (without extensions) for Cytoscape input
               files that are generated by the function

OPTIONAL INPUTS
 rxnList       List of reactions that will included in the output
               (Default = all reactions)
 rxnData       Vector or matrix of data or cell array of strings to output for each
               reaction in rxnList (Default = empty)
 metList       List of metabolites that will be included in the output
               (Default = all metabolites)
 metData       Vector or matrix of data or cell array of strings to output
               for each metabolite in metList (Default = empty)
 metDegreeThr  Maximum degree of metabolites that will be included in the
               output. Allows filtering out highly connected metabolites
               such as h2o or atp (Default = no filtering)

OUTPUT
 notShownMets  Metabolites that are not included in the output

 Outputs three to five files:

 [baseName].sif            Basic network structure file containing
                           reaction-metabolite and gene-reaction 
                           (if provided in model) associations
 [baseName]_nodeType.noa   Describes the node types (gene, rxn, met) in the
                           network
 [baseName]_nodeComp.noa   Describes the compartments for metabolites
 [baseName]_subSys.noa     Describes the subsystems for reactions (if
                           provided)
 [baseName]_rxnMetData.noa   Reaction and metabolite data (if provided)

 Markus Herrgard 9/21/06

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function notShownMets = outputNetworkCytoscape(model,fileBase,rxnList,rxnData,metList,metData,metDegreeThr)
0002 %outputNetworkCytoscape Output a metabolic network in Cytoscape format
0003 %
0004 % notShownMets =
0005 % outputNetworkCytoscape(model,fileBase,rxnList,rxnData,metList,metData,metDegreeThr)
0006 %
0007 %INPUTS
0008 % model         COBRA metabolic network model
0009 % fileBase      Base file name (without extensions) for Cytoscape input
0010 %               files that are generated by the function
0011 %
0012 %OPTIONAL INPUTS
0013 % rxnList       List of reactions that will included in the output
0014 %               (Default = all reactions)
0015 % rxnData       Vector or matrix of data or cell array of strings to output for each
0016 %               reaction in rxnList (Default = empty)
0017 % metList       List of metabolites that will be included in the output
0018 %               (Default = all metabolites)
0019 % metData       Vector or matrix of data or cell array of strings to output
0020 %               for each metabolite in metList (Default = empty)
0021 % metDegreeThr  Maximum degree of metabolites that will be included in the
0022 %               output. Allows filtering out highly connected metabolites
0023 %               such as h2o or atp (Default = no filtering)
0024 %
0025 %OUTPUT
0026 % notShownMets  Metabolites that are not included in the output
0027 %
0028 % Outputs three to five files:
0029 %
0030 % [baseName].sif            Basic network structure file containing
0031 %                           reaction-metabolite and gene-reaction
0032 %                           (if provided in model) associations
0033 % [baseName]_nodeType.noa   Describes the node types (gene, rxn, met) in the
0034 %                           network
0035 % [baseName]_nodeComp.noa   Describes the compartments for metabolites
0036 % [baseName]_subSys.noa     Describes the subsystems for reactions (if
0037 %                           provided)
0038 % [baseName]_rxnMetData.noa   Reaction and metabolite data (if provided)
0039 %
0040 % Markus Herrgard 9/21/06
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 % Open files
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 % Print out gene names
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     % Reaction names
0118     fprintf(fidNodeType,'%s = rxn\n',model.rxns{rxnNo});
0119     % Subsystems
0120     if (isfield(model,'subSystems'))
0121         fprintf(fidSubSys,'%s = %s\n',model.rxns{rxnNo},model.subSystems{rxnNo});
0122     end
0123     % Gene-reaction associations
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     % Reaction associations
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 % Metabolite names
0166 for metNo = 1:length(model.mets)
0167     fprintf(fidNodeType,'%s = met\n',model.mets{metNo});
0168 end
0169 fclose(fidNodeType);
0170 
0171 % Compartments
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 % Reaction data
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 % Reaction data
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

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