mergeTwoModels

PURPOSE ^

function [modelNew] = MergeTwoModels(model1,model2,objrxnmodel)

SYNOPSIS ^

function [modelNew] = mergeTwoModels(model1,model2,objrxnmodel)

DESCRIPTION ^

 function [modelNew] = MergeTwoModels(model1,model2,objrxnmodel)

 Inputs
   model1          model 1
   model2          model 2
   objrxnmodel     Set as 1 or 2 to set objective reaction from
                   desired model

 based on[model_metE] = CreateMetE(model_E,model_M)) (Aarash Bordbar,
 07/06/07);
 11/10/2007 IT

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [modelNew] = mergeTwoModels(model1,model2,objrxnmodel)
0002 % function [modelNew] = MergeTwoModels(model1,model2,objrxnmodel)
0003 %
0004 % Inputs
0005 %   model1          model 1
0006 %   model2          model 2
0007 %   objrxnmodel     Set as 1 or 2 to set objective reaction from
0008 %                   desired model
0009 %
0010 % based on[model_metE] = CreateMetE(model_E,model_M)) (Aarash Bordbar,
0011 % 07/06/07);
0012 % 11/10/2007 IT
0013 
0014 
0015  
0016 if nargin < 3
0017     objrxnmodel =1;
0018 end
0019 
0020 % Creating Universal Metabolite Names
0021 
0022 % Only needed if metabolite names vary, in the specific instance of iAF1260
0023 % the metabolites vary by a [c] at the end, which is removed by the script
0024 % fprintf('Fixing metabolite names: ');
0025 % for i = 1:size(model2.mets,1)
0026 %     model2.mets(i,1) = strrep(model2.mets(i,1), '[c]' ,'');
0027 % end
0028 % fprintf('Finished\n');
0029 
0030 % Combining Reaction List
0031 fprintf('Combining reaction lists: ');
0032 modelNew.rxns = model1.rxns;
0033 modelNew.rxns(size(model1.rxns,1)+1:size(model1.rxns,1)+size(model2.rxns,1),1) = model2.rxns;
0034 lengthreaction = size(modelNew.rxns,1);
0035 fprintf('Finished, %i Distinct Reactions\n',lengthreaction);
0036 
0037 % Combining Metabolite List
0038 fprintf('Combining metabolite lists: ');
0039 h = waitbar(0, 'Combining Metabolites in Progress ...');
0040 modelNew.mets = model1.mets;
0041 
0042 sizemets = size(modelNew.mets,1)+1;
0043 HTABLE = java.util.Hashtable;
0044 for i = 1:length(model1.mets)
0045     HTABLE.put(model1.mets{i}, i);
0046 end
0047 for i = 1:size(model2.mets,1)
0048     %tmp2 = strmatch(model2.mets(i,1),model1.mets,'exact')
0049     tmp = HTABLE.get(model2.mets{i,1});
0050 %     if ~isempty(tmp) || ~isempty(tmp2)
0051 %         if any(tmp2 ~= tmp)
0052 %             pause;
0053 %         end
0054 %     end
0055     if isempty(tmp) == 1
0056         modelNew.mets(sizemets,1) = model2.mets(i,1);
0057         sizemets = sizemets+1;
0058     end
0059     if(mod(i,40) == 0),waitbar(i/size(model2.mets,1),h);end
0060 end
0061 
0062 lengthmet = size(modelNew.mets,1);
0063 close(h);
0064 fprintf('Finished, %i Distinct Metabolites\n',lengthmet);
0065 
0066 
0067 % Combining lb List
0068 fprintf('Combining LB list: ');
0069 modelNew.lb = model1.lb;
0070 floatingmodel = model2.lb;
0071 modelNew.lb(size(model1.lb,1)+1:size(model1.lb,1)+size(model2.lb,1),1) = floatingmodel;
0072 fprintf('Finished\n');
0073 
0074 % Combining ub List
0075 fprintf('Combining UB list: ');
0076 modelNew.ub = model1.ub;
0077 modelNew2.ub = model2.ub;
0078 modelNew.ub(size(model1.ub,1)+1:size(model1.ub,1)+size(model2.ub,1),1) = modelNew2.ub;
0079 fprintf('Finished\n');
0080 
0081 % Combining subsystem List
0082 % fprintf('Combining Subsystem List: ');
0083 % modelNew.subSystems = model1.RxnSubsystem;
0084 % modelNew.subSystems(size(model1.RxnSubsystem,1)+1:size(model1.RxnSubsystem,1)+size(model2.subSystems)) = model2.subSystems;
0085 % modelNew.rxnNames = model1.rxnNames;
0086 % modelNew.rxnNames(size(model1.rxnNames,1)+1:size(model1.rxnNames,1)+size(model2.rxnNames)) = model2.rxnNames;
0087 % fprintf('Finished\n');
0088 
0089 % Combining S Matrices (using sparse allocation)
0090 fprintf('Combining S matrices: ');
0091 [a1,b1] = find(model1.S);
0092 [a2,b2] = find(model2.S);
0093 model1_num = length(a1);
0094 model2_num = length(a2);
0095 modelNew.S = spalloc(size(modelNew.mets,1),size(modelNew.rxns,1),model1_num+model2_num);
0096 
0097 h = waitbar(0, 'Adding Matrix 1 in Progress ...');
0098 for i = 1:size(a1,1)
0099     modelNew.S(a1(i),b1(i)) = model1.S(a1(i),b1(i));
0100     if mod(i,40) == 0,waitbar(i/size(a1,1),h);end
0101 end
0102 close(h);
0103 
0104 
0105 
0106 HTABLE = java.util.Hashtable;
0107 for i = 1:length(modelNew.mets)
0108     HTABLE.put(modelNew.mets{i}, i);
0109 end
0110 h = waitbar(0, 'Adding Matrix 2 in Progress ...');
0111 for i = 1:size(model2.S,2)
0112     compounds = find(model2.S(:,i));
0113     for j = 1:size(compounds,1)
0114         metnames(j,1) = model2.mets(compounds(j));
0115         
0116         %tmp2 = strmatch(metnames(j,1),modelNew.mets,'exact');
0117         %metnames(j,1)
0118         tmp = HTABLE.get(metnames{j,1});
0119         %if any(tmp2 ~= tmp)
0120         %    pause;
0121         %end
0122         modelNew.S(tmp,i+size(model1.S,2)) = model2.S(compounds(j),i);
0123     end
0124     if mod(i,40) == 0,waitbar(i/size(model2.S,2),h);end
0125 end
0126 close(h);
0127 fprintf('Finished\n');
0128 
0129 % Creating b
0130 fprintf('Combining b lists: ');
0131 modelNew.b = zeros(size(modelNew.mets,1),1);
0132 fprintf('Finished\n');
0133 
0134 % Creating c (no objective function optimization)
0135 fprintf('Combining c lists: ');
0136 modelNew.c = zeros(size(modelNew.rxns,1),1);
0137 fprintf('Finished\n');
0138 
0139 % Optimization Parameters in modelNew.c
0140 fprintf('Setting up optimization parameters: ');
0141 switch objrxnmodel
0142     case 1
0143         modelNew.c(find(model1.c),1) = 1;
0144     case 2
0145         modelNew.c(find(model2.c)+size(model1.c,1),1) = 1;
0146 end
0147 fprintf('Finished\n');
0148 
0149 % Creating rev
0150 fprintf('Combining rev lists: ');
0151 modelNew.rev = model1.rev;
0152 modelNew.rev(size(model1.rev,1)+1:size(model1.rev,1)+size(model2.rev,1),1) = model2.rev;
0153 fprintf('Finished\n');
0154 
0155 % % Creating GPR Rules
0156 fprintf('Combining Genes: ');
0157 modelNew.genes = model1.genes;
0158 for i = 1:length(model2.genes)
0159     if isempty(strmatch(model2.genes{i},modelNew.genes,'exact')) == 1
0160         modelNew.genes(size(model.genes,1)+i) = model2.genes{i};
0161     end
0162 end
0163 fprintf('Finished\n');
0164 
0165 fprintf('Combining Remaining Genetic Information: ');
0166 h = waitbar(0, 'Combining Genetic Info ...');
0167 modelNew.rxnGeneMat = model1.rxnGeneMat;
0168 for i = 1:size(model2.rxnGeneMat,1)
0169     for j = 1:size(model2.rxnGeneMat,2)
0170         if model2.rxnGeneMat(i,j) ~= 0
0171             geneLoc = strmatch(model2.genes{j},modelNew.genes,'exact');
0172             modelNew.rxnGeneMat(length(model1.lb)+i,j) = 1;
0173         end
0174     end
0175     if(mod(i, 40) == 0),waitbar(i/size(model2.rxnGeneMat,1),h);end
0176 end
0177 close(h);
0178 
0179 modelNew.grRules = model1.grRules;
0180 modelNew.grRules(size(model1.grRules,1)+1:size(model1.grRules,1)+size(model2.grRules,1)) = model2.grRules;
0181 modelNew.rules = model1.rules;
0182 modelNew.rules(size(model1.rules,1)+1:size(model1.rules,1)+size(model2.rules,1)) = model2.rules;
0183 fprintf('Finished\n');

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