groupRxnScores This function sums up the reaction scores for all reactions that were merged into one by the linear merge. model The model with linearly merged rxns. origRxnScores The rxnScores from the model before the linear merge. origRxnIds The rxn ids of the model before the linear merge. groupIds The groupIds vector output from linearMerge. There is one integer for each rxn in origRxnIds. 0 means the reaction was merged. A non-zero integer means that the reaction was merged with all other rxns having the same integer. origRxnsToZero A logical vector saying which of the original rxns that should not be part of the problem. The way this is solved is that all such reactions have a rxnScore of 0. If any original rxnScore value should be zero (which is very unlikely) it is changed to 0.01. If the sum of the rxnScores for a merged rxn becomes zero while some of them are nonzero, the new value will also be 0.01, to distinguish the rxn from rxns with only rxns to zero. There are two reasons why we don't want zeros in the reaction scores unless these reactions should be ignored: 1) we want to be able to separate those 2) it is difficult to handle a zero value in the MILP - the on/off of such a reaction can be random, so better to fix it in one direction.
0001 function newRxnScores = groupRxnScores(model, origRxnScores, origRxnIds, groupIds, origRxnsToZero) 0002 % groupRxnScores 0003 % This function sums up the reaction scores for all reactions that were merged 0004 % into one by the linear merge. 0005 % 0006 % model The model with linearly merged rxns. 0007 % origRxnScores The rxnScores from the model before the linear merge. 0008 % origRxnIds The rxn ids of the model before the linear merge. 0009 % groupIds The groupIds vector output from linearMerge. 0010 % There is one integer for each rxn in origRxnIds. 0 means 0011 % the reaction was merged. A non-zero integer means that the 0012 % reaction was merged with all other rxns having the same integer. 0013 % origRxnsToZero A logical vector saying which of the original rxns that should not 0014 % be part of the problem. The way this is solved is that all 0015 % such reactions have a rxnScore of 0. If any original rxnScore 0016 % value should be zero (which is very unlikely) it is changed to 0.01. 0017 % If the sum of the rxnScores for a merged rxn becomes zero 0018 % while some of them are nonzero, the new value will also be 0.01, 0019 % to distinguish the rxn from rxns with only rxns to zero. 0020 % There are two reasons why we don't want zeros in the reaction 0021 % scores unless these reactions should be ignored: 0022 % 1) we want to be able to separate those 0023 % 2) it is difficult to handle a zero value in the MILP - 0024 % the on/off of such a reaction can be random, so better 0025 % to fix it in one direction. 0026 0027 0028 newRxnScores = zeros(length(model.rxns),1); 0029 [~,ia,ib] = intersect(model.rxns,origRxnIds); 0030 grpIdsMerged = nan(length(model.rxns),1); 0031 grpIdsMerged(ia) = groupIds(ib); 0032 %check if any of the original scores are 0, in that case change them to 0.01 (unlikely) 0033 origRxnScores(origRxnScores == 0) = 0.01; 0034 %Then set the rxn scores for rxns to zero to 0 0035 origRxnScores(origRxnsToZero) = 0; 0036 0037 %fill in original scores 0038 newRxnScores(ia) = origRxnScores(ib); 0039 0040 for i = 1:length(model.rxns) 0041 %for reactions that are not merged with anything, just keep score as it is 0042 if grpIdsMerged(i) ~= 0 0043 %find all original rxns in the group 0044 sel = groupIds == grpIdsMerged(i); 0045 newRxnScores(i) = sum(origRxnScores(sel)); 0046 if (newRxnScores(i) == 0 && any(origRxnScores(sel) ~= 0)) 0047 %special unfortunate case, where the reactions happen to sum to 0 while some of them are nonzero 0048 %set to 0.01 in this case (proabably pretty unusual) 0049 newRxnScores(i) = 0.01; 0050 end 0051 end 0052 end 0053 0054 end