-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add & remove COBRA prefixes (#565)
* feat: dedicated funcs to add and rem ID prefixes * refactor: add and rem COBRA prefixes
- Loading branch information
Showing
12 changed files
with
1,563 additions
and
1,258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | ||
"http://www.w3.org/TR/REC-html40/loose.dtd"> | ||
<html> | ||
<head> | ||
<title>Description of addCOBRAstylePrefixes</title> | ||
<meta name="keywords" content="addCOBRAstylePrefixes"> | ||
<meta name="description" content="addCOBRAstylePrefixes"> | ||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> | ||
<meta name="generator" content="m2html v1.5 © 2003-2005 Guillaume Flandin"> | ||
<meta name="robots" content="index, follow"> | ||
<link type="text/css" rel="stylesheet" href="../m2html.css"> | ||
</head> | ||
<body> | ||
<a name="_top"></a> | ||
<div><a href="../index.html">Home</a> > <a href="index.html">struct_conversion</a> > addCOBRAstylePrefixes.m</div> | ||
|
||
<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png"> Master index</a></td> | ||
<td align="right"><a href="index.html">Index for struct_conversion <img alt=">" border="0" src="../right.png"></a></td></tr></table>--> | ||
|
||
<h1>addCOBRAstylePrefixes | ||
</h1> | ||
|
||
<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> | ||
<div class="box"><strong>addCOBRAstylePrefixes</strong></div> | ||
|
||
<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> | ||
<div class="box"><strong>function model=addCOBRAstylePrefixes(model,fields,printWarnings) </strong></div> | ||
|
||
<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> | ||
<div class="fragment"><pre class="comment"> addCOBRAstylePrefixes | ||
This function adds COBRA style identifier prefixes, which are: | ||
"R_" for model.rxns, | ||
"M_" for model.mets, | ||
"C_" for model.comps; | ||
"G_" for model.genes (and also represented in model.grRules). | ||
If all entries in a field already have the prefix, then no additional | ||
prefix will be added. | ||
|
||
Input: | ||
model model whose identifiers should be modified | ||
fields cell array with model field names to which the prefix | ||
should be added, possible values: {'rxns', 'mets', | ||
'comps', 'genes'} (optional, by default prefixes are | ||
added to all listed model fields will be checked). | ||
printWarnings if warnings should be shown (optional, default true). | ||
|
||
Output: | ||
model modified model | ||
|
||
Usage: model=addCOBRAstylePrefixes(model,fields,printWarnings)</pre></div> | ||
|
||
<!-- crossreference --> | ||
<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)"> | ||
</ul> | ||
This function is called by: | ||
<ul style="list-style-image:url(../matlabicon.gif)"> | ||
</ul> | ||
<!-- crossreference --> | ||
|
||
|
||
|
||
<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> | ||
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function model=addCOBRAstylePrefixes(model,fields,printWarnings)</a> | ||
0002 <span class="comment">% addCOBRAstylePrefixes</span> | ||
0003 <span class="comment">% This function adds COBRA style identifier prefixes, which are:</span> | ||
0004 <span class="comment">% "R_" for model.rxns,</span> | ||
0005 <span class="comment">% "M_" for model.mets,</span> | ||
0006 <span class="comment">% "C_" for model.comps;</span> | ||
0007 <span class="comment">% "G_" for model.genes (and also represented in model.grRules).</span> | ||
0008 <span class="comment">% If all entries in a field already have the prefix, then no additional</span> | ||
0009 <span class="comment">% prefix will be added.</span> | ||
0010 <span class="comment">%</span> | ||
0011 <span class="comment">% Input:</span> | ||
0012 <span class="comment">% model model whose identifiers should be modified</span> | ||
0013 <span class="comment">% fields cell array with model field names to which the prefix</span> | ||
0014 <span class="comment">% should be added, possible values: {'rxns', 'mets',</span> | ||
0015 <span class="comment">% 'comps', 'genes'} (optional, by default prefixes are</span> | ||
0016 <span class="comment">% added to all listed model fields will be checked).</span> | ||
0017 <span class="comment">% printWarnings if warnings should be shown (optional, default true).</span> | ||
0018 <span class="comment">%</span> | ||
0019 <span class="comment">% Output:</span> | ||
0020 <span class="comment">% model modified model</span> | ||
0021 <span class="comment">%</span> | ||
0022 <span class="comment">% Usage: model=addCOBRAstylePrefixes(model,fields,printWarnings)</span> | ||
0023 | ||
0024 <span class="keyword">if</span> nargin<2 || isempty(fields) | ||
0025 fields = {<span class="string">'rxns'</span>,<span class="string">'mets'</span>,<span class="string">'comps'</span>,<span class="string">'genes'</span>}; | ||
0026 <span class="keyword">end</span> | ||
0027 <span class="keyword">if</span> nargin<3 || isempty(printWarnings) | ||
0028 printWarnings = true; | ||
0029 <span class="keyword">end</span> | ||
0030 | ||
0031 modelFields = {<span class="string">'rxns'</span>,<span class="string">'R_'</span>; | ||
0032 <span class="string">'mets'</span>,<span class="string">'M_'</span>; | ||
0033 <span class="string">'comps'</span>,<span class="string">'C_'</span>; | ||
0034 <span class="string">'genes'</span>,<span class="string">'G_'</span>}; | ||
0035 | ||
0036 toChangeIdx = find(ismember(modelFields(:,1),fields)); | ||
0037 <span class="keyword">for</span> i=1:numel(toChangeIdx) | ||
0038 currName = modelFields{toChangeIdx(i),1}; | ||
0039 currPrefix = modelFields{toChangeIdx(i),2}; | ||
0040 <span class="keyword">if</span> isfield(model,currName) | ||
0041 currField = model.(currName); | ||
0042 <span class="keyword">else</span> | ||
0043 <span class="keyword">continue</span>; | ||
0044 <span class="keyword">end</span> | ||
0045 <span class="keyword">if</span> ~all(startsWith(currField,currPrefix)) | ||
0046 currField = strcat(currPrefix, currField); | ||
0047 <span class="keyword">if</span> strcmp(currName,<span class="string">'genes'</span>) | ||
0048 model.grRules = regexprep(model.grRules, <span class="string">'(\<[0-9_a-zA-Z])'</span>, <span class="string">'G_$1'</span>); | ||
0049 model.grRules = regexprep(model.grRules, <span class="string">' G_or '</span>, <span class="string">' or '</span>); | ||
0050 model.grRules = regexprep(model.grRules, <span class="string">' G_and '</span>, <span class="string">' and '</span>); | ||
0051 <span class="keyword">end</span> | ||
0052 model.(currName) = currField; | ||
0053 <span class="keyword">elseif</span> printWarnings | ||
0054 warning([<span class="string">'All identifiers in "model.'</span> currName <span class="string">'" already start '</span> <span class="keyword">...</span> | ||
0055 <span class="string">'with "'</span> currPrefix <span class="string">'", no additional prefix added.'</span>]) | ||
0056 <span class="keyword">end</span> | ||
0057 <span class="keyword">end</span> | ||
0058 <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> © 2005</address> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | ||
"http://www.w3.org/TR/REC-html40/loose.dtd"> | ||
<html> | ||
<head> | ||
<title>Description of removeCOBRAstylePrefixes</title> | ||
<meta name="keywords" content="removeCOBRAstylePrefixes"> | ||
<meta name="description" content="removeCOBRAstylePrefixes"> | ||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> | ||
<meta name="generator" content="m2html v1.5 © 2003-2005 Guillaume Flandin"> | ||
<meta name="robots" content="index, follow"> | ||
<link type="text/css" rel="stylesheet" href="../m2html.css"> | ||
</head> | ||
<body> | ||
<a name="_top"></a> | ||
<div><a href="../index.html">Home</a> > <a href="index.html">struct_conversion</a> > removeCOBRAstylePrefixes.m</div> | ||
|
||
<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png"> Master index</a></td> | ||
<td align="right"><a href="index.html">Index for struct_conversion <img alt=">" border="0" src="../right.png"></a></td></tr></table>--> | ||
|
||
<h1>removeCOBRAstylePrefixes | ||
</h1> | ||
|
||
<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> | ||
<div class="box"><strong>removeCOBRAstylePrefixes</strong></div> | ||
|
||
<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> | ||
<div class="box"><strong>function model=removeCOBRAstylePrefixes(model,fields,forceRemove) </strong></div> | ||
|
||
<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> | ||
<div class="fragment"><pre class="comment"> removeCOBRAstylePrefixes | ||
This function removes COBRA style identifier prefixes, which are: | ||
"R_" for model.rxns, model.rxnNames and model.id, | ||
"M_" for model.mets and model.metNames, | ||
"C_" for model.comps; | ||
"G_" for model.genes (and also represented in model.grRules). | ||
By default, the prefixes are only removed if all entries in a | ||
particular field has the prefix. | ||
|
||
Input: | ||
model model whose identifiers should be modified | ||
fields cell array with model field names from which the | ||
identifiers should be removed, possible values: | ||
'rxns', 'mets', 'comps', 'genes', 'metNames', | ||
'rxnNames', 'id'. (optional, by default all listed | ||
model fields will be checked). | ||
forceRemove if prefixes should be removed even if not all entries | ||
in a model field have the prefix (optional, default | ||
false) | ||
|
||
Output: | ||
model modified model | ||
|
||
Usage: model=removeCOBRAstylePrefixes(model,fields,forceRemove)</pre></div> | ||
|
||
<!-- crossreference --> | ||
<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)"> | ||
</ul> | ||
This function is called by: | ||
<ul style="list-style-image:url(../matlabicon.gif)"> | ||
</ul> | ||
<!-- crossreference --> | ||
|
||
|
||
|
||
<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> | ||
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function model=removeCOBRAstylePrefixes(model,fields,forceRemove)</a> | ||
0002 <span class="comment">% removeCOBRAstylePrefixes</span> | ||
0003 <span class="comment">% This function removes COBRA style identifier prefixes, which are:</span> | ||
0004 <span class="comment">% "R_" for model.rxns, model.rxnNames and model.id,</span> | ||
0005 <span class="comment">% "M_" for model.mets and model.metNames,</span> | ||
0006 <span class="comment">% "C_" for model.comps;</span> | ||
0007 <span class="comment">% "G_" for model.genes (and also represented in model.grRules).</span> | ||
0008 <span class="comment">% By default, the prefixes are only removed if all entries in a</span> | ||
0009 <span class="comment">% particular field has the prefix.</span> | ||
0010 <span class="comment">%</span> | ||
0011 <span class="comment">% Input:</span> | ||
0012 <span class="comment">% model model whose identifiers should be modified</span> | ||
0013 <span class="comment">% fields cell array with model field names from which the</span> | ||
0014 <span class="comment">% identifiers should be removed, possible values:</span> | ||
0015 <span class="comment">% 'rxns', 'mets', 'comps', 'genes', 'metNames',</span> | ||
0016 <span class="comment">% 'rxnNames', 'id'. (optional, by default all listed</span> | ||
0017 <span class="comment">% model fields will be checked).</span> | ||
0018 <span class="comment">% forceRemove if prefixes should be removed even if not all entries</span> | ||
0019 <span class="comment">% in a model field have the prefix (optional, default</span> | ||
0020 <span class="comment">% false)</span> | ||
0021 <span class="comment">%</span> | ||
0022 <span class="comment">% Output:</span> | ||
0023 <span class="comment">% model modified model</span> | ||
0024 <span class="comment">%</span> | ||
0025 <span class="comment">% Usage: model=removeCOBRAstylePrefixes(model,fields,forceRemove)</span> | ||
0026 | ||
0027 <span class="keyword">if</span> nargin<2 || isempty(fields) | ||
0028 fields = {<span class="string">'rxns'</span>,<span class="string">'mets'</span>,<span class="string">'comps'</span>,<span class="string">'genes'</span>,<span class="string">'metNames'</span>,<span class="string">'rxnNames'</span>,<span class="string">'id'</span>}; | ||
0029 <span class="keyword">end</span> | ||
0030 <span class="keyword">if</span> nargin<3 || isempty(forceRemove) | ||
0031 forceRemove = true; | ||
0032 <span class="keyword">end</span> | ||
0033 | ||
0034 modelFields = {<span class="string">'rxns'</span>, <span class="string">'R_'</span>; | ||
0035 <span class="string">'mets'</span>, <span class="string">'M_'</span>; | ||
0036 <span class="string">'comps'</span>, <span class="string">'C_'</span>; | ||
0037 <span class="string">'genes'</span>, <span class="string">'G_'</span>; | ||
0038 <span class="string">'metNames'</span>, <span class="string">'M_'</span>; | ||
0039 <span class="string">'rxnNames'</span>, <span class="string">'R_'</span>; | ||
0040 <span class="string">'id'</span>, <span class="string">'M_'</span>}; | ||
0041 | ||
0042 toChangeIdx = find(ismember(modelFields(:,1),fields)); | ||
0043 <span class="keyword">for</span> i=1:numel(toChangeIdx) | ||
0044 currName = modelFields{toChangeIdx(i),1}; | ||
0045 currPrefix = modelFields{toChangeIdx(i),2}; | ||
0046 currField = model.(currName); | ||
0047 | ||
0048 <span class="keyword">if</span> forceRemove | ||
0049 hasPrefix = true; | ||
0050 <span class="keyword">else</span> | ||
0051 hasPrefix = all(startsWith(currField,currPrefix)); | ||
0052 <span class="keyword">end</span> | ||
0053 <span class="keyword">if</span> hasPrefix | ||
0054 currField = regexprep(currField,[<span class="string">'^'</span> currPrefix],<span class="string">''</span>); | ||
0055 <span class="keyword">if</span> strcmp(currName,<span class="string">'genes'</span>) | ||
0056 model.grRules=regexprep(model.grRules,<span class="string">'^G_'</span>,<span class="string">''</span>); | ||
0057 model.grRules=regexprep(model.grRules,<span class="string">'\(G_'</span>,<span class="string">'('</span>); | ||
0058 model.grRules=regexprep(model.grRules,<span class="string">' G_'</span>,<span class="string">' '</span>); | ||
0059 <span class="keyword">end</span> | ||
0060 <span class="keyword">end</span> | ||
0061 model.(currName) = currField; | ||
0062 <span class="keyword">end</span> | ||
0063 <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> © 2005</address> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.