Home > RAVEN > exportToTabDelimited.m

exportToTabDelimited

PURPOSE ^

exportToTabDelimited

SYNOPSIS ^

function exportToTabDelimited(model,path)

DESCRIPTION ^

 exportToTabDelimited
   Exports a model structure to a set of tab-delimited text files

   model    a model structure
   path    the path to export to. The resulting text files will be saved
           under the names excelRxns.txt, excelMets.txt, excelGenes.txt,
           excelModel.txt, and excelComps.txt

   NOTE: This functionality was previously a part of exportToExcelFormat.
         The naming of the resulting text files is to preserve backward
         compatibility

   NOTE: No checks are made regarding the correctness of the model. Use
         checkModelStruct to identify problems in the model structure

   Usage: exportToTabDelimited(model,path)

   Rasmus Agren, 2013-10-09

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function exportToTabDelimited(model,path)
0002 % exportToTabDelimited
0003 %   Exports a model structure to a set of tab-delimited text files
0004 %
0005 %   model    a model structure
0006 %   path    the path to export to. The resulting text files will be saved
0007 %           under the names excelRxns.txt, excelMets.txt, excelGenes.txt,
0008 %           excelModel.txt, and excelComps.txt
0009 %
0010 %   NOTE: This functionality was previously a part of exportToExcelFormat.
0011 %         The naming of the resulting text files is to preserve backward
0012 %         compatibility
0013 %
0014 %   NOTE: No checks are made regarding the correctness of the model. Use
0015 %         checkModelStruct to identify problems in the model structure
0016 %
0017 %   Usage: exportToTabDelimited(model,path)
0018 %
0019 %   Rasmus Agren, 2013-10-09
0020 %
0021 
0022 %If the folder doesn't exist then create it
0023 if ~exist(path,'dir')
0024     mkdir(path);
0025 end
0026 
0027 %Remove the files if they already exist
0028 if exist(fullfile(path,'excelRxns.txt'),'file')
0029     delete(fullfile(path,'excelRxns.txt'));
0030 end
0031 if exist(fullfile(path,'excelMets.txt'),'file')
0032     delete(fullfile(path,'excelMets.txt'));
0033 end
0034 if exist(fullfile(path,'excelGenes.txt'),'file')
0035     delete(fullfile(path,'excelGenes.txt'));
0036 end
0037 if exist(fullfile(path,'excelModel.txt'),'file')
0038     delete(fullfile(path,'excelModel.txt'));
0039 end
0040 if exist(fullfile(path,'excelComps.txt'),'file')
0041     delete(fullfile(path,'excelComps.txt'));
0042 end
0043 
0044 %Construct equations
0045 model.equations=constructEquations(model,model.rxns,true);
0046 
0047 %Check if it should print genes
0048 if isfield(model,'grRules');    
0049     %Also do some parsing here
0050     rules=model.grRules;
0051     rules=strrep(rules,'(','');
0052     rules=strrep(rules,')','');
0053     rules=strrep(rules,' and ',':');
0054     rules=strrep(rules,' or ',';');
0055 end
0056 
0057 %Open for printing the rxn sheet
0058 rxnFile=fopen(fullfile(path,'excelRxns.txt'),'wt');
0059 
0060 %Print header
0061 fprintf(rxnFile,'#\tID\tNAME\tEQUATION\tEC-NUMBER\tGENE ASSOCIATION\tLOWER BOUND\tUPPER BOUND\tOBJECTIVE\tCOMPARTMENT\tSUBSYSTEM\tMIRIAM\tREPLACEMENT ID\n');
0062 
0063 %Loop through the reactions
0064 for i=1:numel(model.rxns)
0065    fprintf(rxnFile,['\t' model.rxns{i} '\t' model.rxnNames{i} '\t' model.equations{i} '\t']);
0066    
0067    if isfield(model,'eccodes')
0068         fprintf(rxnFile,[model.eccodes{i} '\t']);
0069    else
0070         fprintf(rxnFile,'\t');
0071    end
0072    
0073    if isfield(model,'grRules')
0074         fprintf(rxnFile,[rules{i} '\t']);
0075    else
0076         fprintf(rxnFile,'\t');
0077    end
0078    
0079    %Print bounds and objectives
0080    fprintf(rxnFile,[num2str(model.lb(i)) '\t' num2str(model.ub(i)) '\t']);
0081    
0082    if model.c(i)~=0
0083         fprintf(rxnFile,[num2str(model.c(i)) '\t' ]);
0084    else
0085         fprintf(rxnFile,'\t');
0086    end
0087    
0088    if isfield(model,'rxnComps')
0089         fprintf(rxnFile,[model.comps{model.rxnComps(i)} '\t']);
0090    else
0091         fprintf(rxnFile,'\t');
0092    end   
0093    
0094    if isfield(model,'subSystems')
0095         fprintf(rxnFile,[model.subSystems{i} '\t']);
0096    else
0097         fprintf(rxnFile,'\t');
0098    end
0099    
0100    if isfield(model,'rxnMiriams')
0101        if ~isempty(model.rxnMiriams{i})
0102            toPrint=[];
0103            for j=1:numel(model.rxnMiriams{i}.name)
0104                toPrint=[toPrint strtrim(model.rxnMiriams{i}.name{j}) ':' strtrim(model.rxnMiriams{i}.value{j}) ';']; 
0105            end
0106            fprintf(rxnFile,[toPrint(1:end-1) '\t']);
0107        else
0108            fprintf(rxnFile,'\t');
0109        end
0110    else
0111         fprintf(rxnFile,'\t');
0112    end
0113    
0114    %Print replacement IDs
0115    fprintf(rxnFile,'\t');
0116    
0117    fprintf(rxnFile,'\n');
0118 end
0119 
0120 fclose(rxnFile);
0121 
0122 %Open for printing the metabolites sheet
0123 metFile=fopen(fullfile(path,'excelMets.txt'),'wt');
0124 
0125 %Print header
0126 fprintf(metFile,'#\tID\tNAME\tUNCONSTRAINED\tMIRIAM\tCOMPOSITION\tINCHI\tCOMPARTMENT\tREPLACEMENT ID\tMETS FIELD\n');
0127 
0128 %Loop through the metabolites
0129 for i=1:numel(model.mets)
0130    fprintf(metFile,['\t' model.metNames{i} '[' model.comps{model.metComps(i)} ']\t' model.metNames{i} '\t']);
0131    
0132    if isfield(model,'unconstrained')
0133        if model.unconstrained(i)~=0
0134             fprintf(metFile,'true\t');
0135        else
0136             fprintf(metFile,'\t');
0137        end
0138    else
0139        fprintf(metFile,'\t');
0140    end
0141    
0142    if isfield(model,'metMiriams')
0143        if ~isempty(model.metMiriams{i})
0144            toPrint=[];
0145            for j=1:numel(model.metMiriams{i}.name)
0146                toPrint=[toPrint strtrim(model.metMiriams{i}.name{j}) ':' strtrim(model.metMiriams{i}.value{j}) ';']; 
0147            end
0148            fprintf(rxnFile,[toPrint(1:end-1) '\t']);
0149        else
0150            fprintf(metFile,'\t');
0151        end
0152    else
0153         fprintf(metFile,'\t');
0154    end
0155    
0156    if isfield(model,'metFormulas')
0157        fprintf(metFile,[model.metFormulas{i} '\t']);
0158    else
0159        fprintf(metFile,'\t');
0160    end
0161    
0162    if isfield(model,'inchis')
0163        fprintf(metFile,[model.inchis{i} '\t']);
0164    else
0165        fprintf(metFile,'\t');
0166    end
0167    
0168    fprintf(metFile,[model.comps{model.metComps(i)} '\t']);
0169    
0170    %There can be no replacement IDs in the structure, but it has to be
0171    %something to give working met IDs.
0172    fprintf(metFile,['m' int2str(i) '\t']);
0173    
0174    %Print the model.mets field. The reason for not putting this as
0175    %replacement ID is that it's not guaranteed to be a valid SBML id.
0176    fprintf(metFile,[model.mets{i} '\t']);
0177    
0178    fprintf(metFile,'\n');
0179 end
0180 
0181 fclose(metFile);
0182 
0183 if isfield(model,'genes')
0184     %Open for printing the genes sheet
0185     geneFile=fopen(fullfile(path,'excelGenes.txt'),'wt');
0186 
0187     %Print header
0188     fprintf(geneFile,'#\tNAME\tMIRIAM\tCOMPARTMENT\n');
0189 
0190     %Loop through the genes
0191     for i=1:numel(model.genes)
0192        fprintf(geneFile,['\t' model.genes{i} '\t']);
0193 
0194        if isfield(model,'geneMiriams')
0195            if ~isempty(model.geneMiriams{i})
0196                toPrint=[];
0197                for j=1:numel(model.geneMiriams{i}.name)
0198                    toPrint=[toPrint strtrim(model.geneMiriams{i}.name{j}) ':' strtrim(model.geneMiriams{i}.value{j}) ';']; 
0199                end
0200                fprintf(geneFile,[toPrint(1:end-1) '\t']);
0201            else
0202                fprintf(geneFile,'\t');
0203            end
0204        else
0205             fprintf(geneFile,'\t');
0206        end
0207        
0208        if isfield(model,'geneComps')
0209             fprintf(geneFile,[model.comps{model.geneComps(i)} '\t']);
0210        else
0211             fprintf(geneFile,'\t');
0212        end 
0213 
0214         fprintf(geneFile,'\n');
0215     end
0216     fclose(geneFile);
0217 end
0218 
0219 if isfield(model,'id')
0220     %Open for printing the model sheet
0221     modelFile=fopen(fullfile(path,'excelModel.txt'),'wt');
0222 
0223     %Print header
0224     fprintf(geneFile,'#\tID\tDESCRIPTION\tDEFAULT LOWER\tDEFAULT UPPER\tCONTACT GIVEN NAME\tCONTACT FAMILY NAME\tCONTACT EMAIL\tORGANIZATION\tTAXONOMY\tNOTES\n');
0225     
0226     %Print model ID and name. It is assumed that the default lower/upper
0227     %bound correspond to min/max of the bounds
0228     toPrint=['\t' model.id '\t' model.description '\t'];
0229     if isfield(model,'annotation')
0230         if isfield(model.annotation,'defaultLB')
0231             toPrint=[toPrint num2str(model.annotation.defaultLB) '\t'];
0232         else
0233             toPrint=[toPrint num2str(min(model.lb)) '\t'];
0234         end
0235         if isfield(model.annotation,'defaultUB')
0236             toPrint=[toPrint num2str(model.annotation.defaultUB) '\t'];
0237         else
0238             toPrint=[toPrint num2str(max(model.ub)) '\t'];
0239         end
0240         if isfield(model.annotation,'givenName')
0241             toPrint=[toPrint model.annotation.givenName '\t'];
0242         else
0243             toPrint=[toPrint '\t'];
0244         end
0245         if isfield(model.annotation,'familyName')
0246             toPrint=[toPrint model.annotation.familyName '\t'];
0247         else
0248             toPrint=[toPrint '\t'];
0249         end
0250         if isfield(model.annotation,'email')
0251             toPrint=[toPrint model.annotation.email '\t'];
0252         else
0253             toPrint=[toPrint '\t'];
0254         end
0255         if isfield(model.annotation,'organization')
0256             toPrint=[toPrint model.annotation.organization '\t'];
0257         else
0258             toPrint=[toPrint '\t'];
0259         end
0260         if isfield(model.annotation,'taxonomy')
0261             toPrint=[toPrint model.annotation.taxonomy '\t'];
0262         else
0263             toPrint=[toPrint '\t'];
0264         end
0265         if isfield(model.annotation,'note')
0266             toPrint=[toPrint model.annotation.note '\t'];
0267         else
0268             toPrint=[toPrint '\t'];
0269         end
0270     else
0271         toPrint=[toPrint num2str(min(model.lb)) '\t' num2str(max(model.ub)) '\tRasmus\tAgren\trasmus.j.agren@gmail.com\tChalmers University of Technology\t\t\n'];
0272     end
0273     fprintf(modelFile,toPrint);
0274     fclose(modelFile);
0275 end
0276 
0277 if isfield(model,'comps')
0278     %Open for printing the model sheet
0279     compsFile=fopen(fullfile(path,'excelComps.txt'),'wt');
0280 
0281     %Print header
0282     fprintf(compsFile,'#\tABBREVIATION\tNAME\tINSIDE\tMIRIAM\n');
0283     
0284     for i=1:numel(model.comps)
0285         toPrint=['\t' model.comps{i} '\t' model.compNames{i} '\t'];
0286         if isfield(model,'compOutside')
0287             toPrint=[toPrint model.compOutside{i} '\t'];
0288         else
0289             toPrint=[toPrint '\t'];
0290         end
0291         if isfield(model,'compMiriams')
0292             if ~isempty(model.compMiriams{i})
0293                for j=1:numel(model.compMiriams{i}.name)
0294                    toPrint=[toPrint strtrim(model.compMiriams{i}.name{j}) ':' strtrim(model.compMiriams{i}.value{j}) ';']; 
0295                end
0296                toPrint(end)=[];
0297                toPrint=[toPrint '\t'];
0298             else
0299                 toPrint=[toPrint '\t'];
0300             end
0301         else
0302             toPrint=[toPrint '\t'];
0303         end
0304         toPrint=[toPrint '\n'];
0305         fprintf(compsFile,toPrint);
0306     end
0307     fclose(compsFile);
0308 end
0309 end

Generated on Mon 06-Jan-2014 14:58:12 by m2html © 2005