Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getBlast, importModel, replaceMets, ravenCobraWrapper / feat: getIndexes #551

Merged
merged 15 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/constructS.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
coeff=1;
name=strtrim(metabolites{j});
else
name=strtrim(metabolites{j}(space+1:end));
name=strtrim(metabolites{j}(space(1)+1:end));
end
end

Expand Down
2 changes: 1 addition & 1 deletion core/contractModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
% NOTE: This code might not work for advanced grRules strings
% that involve nested expressions of 'and' and 'or'.
%
% Usage: [reducedModel, removedRxns, indexedDuplicateRxns]=contractModel(model,distReverse)
% Usage: [reducedModel, removedRxns, indexedDuplicateRxns]=contractModel(model,distReverse,mets)

if nargin<2
distReverse=true;
Expand Down
40 changes: 32 additions & 8 deletions core/getIndexes.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@
% getIndexes
% Retrieves the indexes for a list of reactions or metabolites
%
% Input:
% Input:
% model a model structure
% objects either a cell array of IDs, a logical vector with the
% same number of elements as metabolites in the model,
% of a vector of indexes
% type 'rxns', 'mets', or 'genes' depending on what to retrieve
% 'metnames' queries metabolite names, while 'metcomps'
% allows to provide specific metabolites and their
% compartments in the format metaboliteName[comp]
% compartments in the format metaboliteName[comp]. If a
% model.ec structure exists (GECKO 3), then also
% 'ecenzymes', 'ecrxns' and 'ecgenes' are allowed
% returnLogical Sets whether to return a logical array or an array with
% the indexes (optional, default false)
%
% Output:
% Output:
% indexes can be a logical array or a double array depending on
% the value of returnLogical
%
% Usage: indexes=getIndexes(model, objects, type, returnLogical)
% Note: If 'ecenzymes', 'ecrxns' or 'ecgenes' are used with a GECKO 3
% model, then the indexes are from the model.ec.enzymes, model.ec.rxns or
% model.ec.genes fields, respectively.
%
% Usage: indexes=getIndexes(model, objects, type, returnLogical)

if nargin<4
returnLogical=false;
Expand Down Expand Up @@ -62,12 +68,27 @@
indexes=tempIndexes;
end
return %None of the remaining function needs to run if metcomps
case 'ecrxns'
if ~isfield(model,'ec')
error('Type %s cannot be used if no model.ec structure is present.',type)
end
searchIn=model.ec.rxns;
case 'ecenzymes'
if ~isfield(model,'ec')
error('Type %s cannot be used if no model.ec structure is present.',type)
end
searchIn=model.ec.enzymes;
case 'ecgenes'
if ~isfield(model,'ec')
error('Type %s cannot be used if no model.ec structure is present.',type)
end
searchIn=model.ec.genes;
otherwise
if contains(objects,{'rxns','mets','metnames','metcomps','genes'})
error('The second and third parameter provided to run getIndexes are likely switched. Note that the second parameter is the object to find the index for, while the third parameter is the object type (''rxns'', ''mets'', ''metnames'', ''metcomps'' or ''genes'').')
if contains(objects,{'rxns','mets','metnames','metcomps','genes','ecgenes','ecenzymes','ecrxns'})
error('The second and third parameter provided to run getIndexes are likely switched. Note that the second parameter is the object to find the index for, while the third parameter is the object type (''rxns'', ''mets'', ''metnames'', ''metcomps'', ''genes'', ''ecgenes'', ''ecenzymes'' or ''ecrxns'').')
else
error('Incorrect value of the ''type'' parameter. Allowed values are ''rxns'', ''mets'', ''metnames'', ''metcomps'' or ''genes''.');
end
error('Incorrect value of the ''type'' parameter. Allowed values are ''rxns'', ''mets'', ''metnames'', ''metcomps'', ''genes'', ''ecgenes'', ''ecenzymes'' or ''ecrxns''.');
end
end

if iscell(objects)
Expand All @@ -76,6 +97,9 @@
if strcmpi(type,'metnames')
indexes{i}=index;
elseif ~isempty(index)
if length(index) > 1
error('There are multiple instances of object "%s" in the model, while "%s" type should be unique', objects{i}, type)
end
indexes(i)=index;
else
error(['Could not find object ''' objects{i} ''' in the model']);
Expand Down
1 change: 0 additions & 1 deletion core/randomSampling.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
[~, I]=ismember(model.rxns,originalRxns);
solutions=zeros(numel(originalRxns),nSamples);
solutions(I,:)=sols;
solutions=sparse(solutions);
else
solutions=[];
end
Expand Down
31 changes: 19 additions & 12 deletions core/replaceMets.m
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
function model=replaceMets(model,metabolite,replacement,verbose)
function [model, removedRxns, idxDuplRxns]=replaceMets(model,metabolite,replacement,verbose)
% replaceMets
% Replaces metabolite names and annotation with replacement metabolite
% that is already in the model. If this results in duplicate metabolites,
% the replacement metabolite will be kept, while the S matrix is updated
% to use the replacement metabolite instead.
% to use the replacement metabolite instead. At the end, contractModel is
% run to remove any duplicate reactions that might have occured.
%
% model a model structure
% metabolite string with name of metabolite to be replace
% replacement string with name of replacement metabolite
% verbose logical whether to print the ids of reactions that
% involve the replaced metabolite (optional, default
% false)
% Input:
% model a model structure
% metabolite string with name of metabolite to be replace
% replacement string with name of replacement metabolite
% verbose logical whether to print the ids of reactions that
% involve the replaced metabolite (optional, default
% false)
%
% Output:
% model model structure with selected metabolites replaced
% removedRxns identifiers of duplicate reactions that were removed
% idxDuplRxns index of removedRxns in original model
%
% This function is useful when the model contains both 'oxygen' and 'o2'
% as metabolites.
% Note: This function is useful when the model contains both 'oxygen' and
% 'o2' as metabolites.
%
% Usage: model=replaceMets(model,metabolite,replacement,verbose)
% Usage: [model, removedRxns, idxDuplRxns] = replaceMets(model, metabolite, replacement, verbose)

metabolite=char(metabolite);
replacement=char(replacement);
Expand Down Expand Up @@ -116,5 +123,5 @@
end

% This could now have created duplicate reactions. Contract model.
model=contractModel(model);
model=contractModel(model,[],repIdx);
end
2 changes: 1 addition & 1 deletion doc/core/constructS.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" sr
0120 coeff=1;
0121 name=strtrim(metabolites{j});
0122 <span class="keyword">else</span>
0123 name=strtrim(metabolites{j}(space+1:end));
0123 name=strtrim(metabolites{j}(space(1)+1:end));
0124 <span class="keyword">end</span>
0125 <span class="keyword">end</span>
0126
Expand Down
6 changes: 3 additions & 3 deletions doc/core/contractModel.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="
NOTE: This code might not work for advanced grRules strings
that involve nested expressions of 'and' and 'or'.

Usage: [reducedModel, removedRxns, indexedDuplicateRxns]=contractModel(model,distReverse)</pre></div>
Usage: [reducedModel, removedRxns, indexedDuplicateRxns]=contractModel(model,distReverse,mets)</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
Expand All @@ -62,7 +62,7 @@ <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^
<li><a href="dispEM.html" class="code" title="function dispEM(string,throwErrors,toList,trimWarnings)">dispEM</a> dispEM</li><li><a href="getIndexes.html" class="code" title="function indexes=getIndexes(model, objects, type, returnLogical)">getIndexes</a> getIndexes</li><li><a href="removeReactions.html" class="code" title="function reducedModel=removeReactions(model,rxnsToRemove,removeUnusedMets,removeUnusedGenes,removeUnusedComps)">removeReactions</a> removeReactions</li><li><a href="sortModel.html" class="code" title="function model=sortModel(model,sortReversible,sortMetName,sortReactionOrder)">sortModel</a> sortModel</li><li><a href="standardizeGrRules.html" class="code" title="function [grRules,rxnGeneMat,indexes2check] = standardizeGrRules(model,embedded)">standardizeGrRules</a> standardizeGrRules</li></ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="mergeCompartments.html" class="code" title="function [model, deletedRxns, duplicateRxns]=mergeCompartments(model,keepUnconstrained,deleteRxnsWithOneMet,distReverse)">mergeCompartments</a> mergeCompartments</li><li><a href="replaceMets.html" class="code" title="function model=replaceMets(model,metabolite,replacement,verbose)">replaceMets</a> replaceMets</li><li><a href="simplifyModel.html" class="code" title="function [reducedModel, deletedReactions, deletedMetabolites]=simplifyModel(model,deleteUnconstrained, deleteDuplicates, deleteZeroInterval, deleteInaccessible, deleteMinMax, groupLinear, constrainReversible, reservedRxns, suppressWarnings)">simplifyModel</a> simplifyModel</li></ul>
<li><a href="mergeCompartments.html" class="code" title="function [model, deletedRxns, duplicateRxns]=mergeCompartments(model,keepUnconstrained,deleteRxnsWithOneMet,distReverse)">mergeCompartments</a> mergeCompartments</li><li><a href="replaceMets.html" class="code" title="function [model, removedRxns, idxDuplRxns]=replaceMets(model,metabolite,replacement,verbose)">replaceMets</a> replaceMets</li><li><a href="simplifyModel.html" class="code" title="function [reducedModel, deletedReactions, deletedMetabolites]=simplifyModel(model,deleteUnconstrained, deleteDuplicates, deleteZeroInterval, deleteInaccessible, deleteMinMax, groupLinear, constrainReversible, reservedRxns, suppressWarnings)">simplifyModel</a> simplifyModel</li></ul>
<!-- crossreference -->

<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
Expand Down Expand Up @@ -97,7 +97,7 @@ <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" sr
0025 <span class="comment">% NOTE: This code might not work for advanced grRules strings</span>
0026 <span class="comment">% that involve nested expressions of 'and' and 'or'.</span>
0027 <span class="comment">%</span>
0028 <span class="comment">% Usage: [reducedModel, removedRxns, indexedDuplicateRxns]=contractModel(model,distReverse)</span>
0028 <span class="comment">% Usage: [reducedModel, removedRxns, indexedDuplicateRxns]=contractModel(model,distReverse,mets)</span>
0029
0030 <span class="keyword">if</span> nargin&lt;2
0031 distReverse=true;
Expand Down
Loading
Loading