Hi all,
I've been using findRxnsFromMets for a while but ran into an issue upon installing the latest version of COBRA on a new machine. Essentially, the function does not return the correct list of reactions when metList has length 1. Instead, it returns the first reaction in model.rxns.
I think this has to do with how the function gets the 'totals' in line 119 of the new version. When 'index' has length > 1, the sum is done over the rows and it returns the correct indices for the associated reactions. However when 'index' has length == 1, the sum now acts over the columns resulting in the wrong reaction (i.e., always model.rxns(1)) being returned. I see that the code was recently modified from:
totals = sum(model.S(index,:) ~= 0,1);
to
totals = sum(model.S(index,:) ~= 0);
which seems to have to do with correctly filtering for produced/consumed metabolites, but results in this new behavior. This unfortunately breaks aspects of our pipeline that we've built using findRxnsFromMets, so I wanted to flag it while finding a workaround. I've added a few cases below (with iAF1260, no varargin) and the relevant components of the function to illustrate the issue, and am happy to clarify further.
Thank you very much and best regards,
Alan
Case 1: 'old' version, metList length 1, correct output
clearvars
load iAF1260.mat
model = iAF1260;
metList = {'ala__L_e'};
index = ismember(model.mets,metList); % Line 71
totals = sum(model.S(index,:) ~= 0,1); % Line 119
rels = totals > 0; % Line 120
rxnList = model.rxns(totals > 0 & rels)% Line 135
rxnList =
2×1 cell array
{'ALAtex' }
{'EX_ala__L_e'}
Case 2, 'new' version, metList length > 1, correct output
clearvars
load iAF1260.mat
model = iAF1260;
metList = {'ala__L_e','cl_e'};
index = ismember(model.mets,metList);
totals = sum(model.S(index,:) ~= 0);
rels = totals > 0;
rxnList = model.rxns(totals > 0 & rels)
rxnList =
4×1 cell array
{'ALAtex' }
{'CLtex' }
{'EX_ala__L_e'}
{'EX_cl_e' }
Case 3, 'new' version, metList length 1, incorrect output
clearvars
load iAF1260.mat
model = iAF1260;
metList = {'ala__L_e'};
index = ismember(model.mets,metList);
totals = sum(model.S(index,:) ~= 0);
rels = totals > 0;
rxnList = model.rxns(totals > 0 & rels)
rxnList =
1×1 cell array
{'ACGAM1PPpp'}
Case 4, 'new' version, metList length > 1 but index length 1, incorrect output
clearvars
load iAF1260.mat
model = iAF1260;
metList = {'ala__L_e','pizza_e'};
index = ismember(model.mets,metList);
totals = sum(model.S(index,:) ~= 0);
rels = totals > 0;
rxnList = model.rxns(totals > 0 & rels)
rxnList =
1×1 cell array
{'ACGAM1PPpp'}