Skip to content

Commit

Permalink
refactor: use getGenesFromGrRules
Browse files Browse the repository at this point in the history
  • Loading branch information
edkerk committed Oct 29, 2024
1 parent b548aa5 commit 015bc18
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 205 deletions.
19 changes: 8 additions & 11 deletions core/changeGrRules.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,15 @@
error('Number of rxns and grRules should be identical')
end

for i=1:length(rxns)
% Add genes to model
geneList=transpose(cell(unique(regexp(grRules{i},'[)(]*|( and )*|( or )*','split')))); % Extract individual, unique genes from the geneAssoc provided
geneList=geneList(~cellfun(@isempty, geneList));
genesToAdd.genes=setdiff(geneList,model.genes); % Only keep the genes that are not yet part of the model.genes.
if ~isempty(genesToAdd.genes)
model=addGenesRaven(model,genesToAdd); % Add genes
end

% Find reaction and gene indices
idx=getIndexes(model,rxns,'rxns');
% Add genes to model
geneList = getGenesFromGrRules(grRules);
genesToAdd.genes=setdiff(geneList,model.genes); % Only keep the genes that are not yet part of the model.genes.
if ~isempty(genesToAdd.genes)
model=addGenesRaven(model,genesToAdd); % Add genes
end

% Find reaction and gene indices
idx=getIndexes(model,rxns,'rxns');

% Change gene associations
if replace==true % Replace old gene associations
Expand Down
49 changes: 23 additions & 26 deletions doc/core/changeGrRules.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="addGenesRaven.html" class="code" title="function newModel=addGenesRaven(model,genesToAdd)">addGenesRaven</a> addGenesRaven</li><li><a href="convertCharArray.html" class="code" title="function inputConverted = convertCharArray(funcInput)">convertCharArray</a> convertCharArray</li><li><a href="getIndexes.html" class="code" title="function indexes=getIndexes(model, objects, type, returnLogical)">getIndexes</a> getIndexes</li><li><a href="standardizeGrRules.html" class="code" title="function [grRules,rxnGeneMat,indexes2check] = standardizeGrRules(model,embedded)">standardizeGrRules</a> standardizeGrRules</li></ul>
<li><a href="addGenesRaven.html" class="code" title="function newModel=addGenesRaven(model,genesToAdd)">addGenesRaven</a> addGenesRaven</li><li><a href="convertCharArray.html" class="code" title="function inputConverted = convertCharArray(funcInput)">convertCharArray</a> convertCharArray</li><li><a href="getGenesFromGrRules.html" class="code" title="function [genes,rxnGeneMat] = getGenesFromGrRules(grRules, originalGenes)">getGenesFromGrRules</a> getGenesFromGrRules Extract gene list and rxnGeneMat from grRules array.</li><li><a href="getIndexes.html" class="code" title="function indexes=getIndexes(model, objects, type, returnLogical)">getIndexes</a> getIndexes</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)">
</ul>
Expand Down Expand Up @@ -89,31 +89,28 @@ <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" sr
0030 error(<span class="string">'Number of rxns and grRules should be identical'</span>)
0031 <span class="keyword">end</span>
0032
0033 <span class="keyword">for</span> i=1:length(rxns)
0034 <span class="comment">% Add genes to model</span>
0035 geneList=transpose(cell(unique(regexp(grRules{i},<span class="string">'[)(]*|( and )*|( or )*'</span>,<span class="string">'split'</span>)))); <span class="comment">% Extract individual, unique genes from the geneAssoc provided</span>
0036 geneList=geneList(~cellfun(@isempty, geneList));
0037 genesToAdd.genes=setdiff(geneList,model.genes); <span class="comment">% Only keep the genes that are not yet part of the model.genes.</span>
0038 <span class="keyword">if</span> ~isempty(genesToAdd.genes)
0039 model=<a href="addGenesRaven.html" class="code" title="function newModel=addGenesRaven(model,genesToAdd)">addGenesRaven</a>(model,genesToAdd); <span class="comment">% Add genes</span>
0040 <span class="keyword">end</span>
0041
0042 <span class="comment">% Find reaction and gene indices</span>
0043 idx=<a href="getIndexes.html" class="code" title="function indexes=getIndexes(model, objects, type, returnLogical)">getIndexes</a>(model,rxns,<span class="string">'rxns'</span>);
0044 <span class="keyword">end</span>
0045
0046 <span class="comment">% Change gene associations</span>
0047 <span class="keyword">if</span> replace==true <span class="comment">% Replace old gene associations</span>
0048 model.grRules(idx)=grRules;
0049 <span class="keyword">else</span> <span class="comment">% Add gene associations, add new gene rules after 'OR'.</span>
0050 model.grRules(idx)=strcat(<span class="string">'('</span>,model.grRules(idx),<span class="string">') or ('</span>,grRules,<span class="string">')'</span>);
0051 <span class="keyword">end</span>
0052
0053 <span class="comment">%Fix grRules and reconstruct rxnGeneMat</span>
0054 [grRules,rxnGeneMat] = <a href="standardizeGrRules.html" class="code" title="function [grRules,rxnGeneMat,indexes2check] = standardizeGrRules(model,embedded)">standardizeGrRules</a>(model,true);
0055 model.grRules = grRules;
0056 model.rxnGeneMat = rxnGeneMat;
0057 <span class="keyword">end</span></pre></div>
0033 <span class="comment">% Add genes to model</span>
0034 geneList = <a href="getGenesFromGrRules.html" class="code" title="function [genes,rxnGeneMat] = getGenesFromGrRules(grRules, originalGenes)">getGenesFromGrRules</a>(grRules);
0035 genesToAdd.genes=setdiff(geneList,model.genes); <span class="comment">% Only keep the genes that are not yet part of the model.genes.</span>
0036 <span class="keyword">if</span> ~isempty(genesToAdd.genes)
0037 model=<a href="addGenesRaven.html" class="code" title="function newModel=addGenesRaven(model,genesToAdd)">addGenesRaven</a>(model,genesToAdd); <span class="comment">% Add genes</span>
0038 <span class="keyword">end</span>
0039
0040 <span class="comment">% Find reaction and gene indices</span>
0041 idx=<a href="getIndexes.html" class="code" title="function indexes=getIndexes(model, objects, type, returnLogical)">getIndexes</a>(model,rxns,<span class="string">'rxns'</span>);
0042
0043 <span class="comment">% Change gene associations</span>
0044 <span class="keyword">if</span> replace==true <span class="comment">% Replace old gene associations</span>
0045 model.grRules(idx)=grRules;
0046 <span class="keyword">else</span> <span class="comment">% Add gene associations, add new gene rules after 'OR'.</span>
0047 model.grRules(idx)=strcat(<span class="string">'('</span>,model.grRules(idx),<span class="string">') or ('</span>,grRules,<span class="string">')'</span>);
0048 <span class="keyword">end</span>
0049
0050 <span class="comment">%Fix grRules and reconstruct rxnGeneMat</span>
0051 [grRules,rxnGeneMat] = <a href="standardizeGrRules.html" class="code" title="function [grRules,rxnGeneMat,indexes2check] = standardizeGrRules(model,embedded)">standardizeGrRules</a>(model,true);
0052 model.grRules = grRules;
0053 model.rxnGeneMat = rxnGeneMat;
0054 <span class="keyword">end</span></pre></div>
<hr><address>Generated by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>
2 changes: 1 addition & 1 deletion doc/core/getGenesFromGrRules.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^
</ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="checkModelStruct.html" class="code" title="function checkModelStruct(model,throwErrors,trimWarnings)">checkModelStruct</a> checkModelStruct</li></ul>
<li><a href="changeGrRules.html" class="code" title="function model = changeGrRules(model,rxns,grRules,replace)">changeGrRules</a> changeGrRules</li><li><a href="checkModelStruct.html" class="code" title="function checkModelStruct(model,throwErrors,trimWarnings)">checkModelStruct</a> checkModelStruct</li></ul>
<!-- crossreference -->


Expand Down
Loading

0 comments on commit 015bc18

Please sign in to comment.