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

refactor: char, string and cell array input #415

Merged
merged 23 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1ad1109
refactor: convert string input to char
edkerk Apr 30, 2022
ff462fd
feat: convertCharArray function
edkerk Apr 30, 2022
5a65fe0
feat: convertCharArray without tests
edkerk May 1, 2022
d4c0176
chore: updateDocumentation
edkerk May 2, 2022
9647845
fix: remove dependency on stats toolbox
edkerk May 4, 2022
c413c02
fix: setExchangeBounds not dependent on stats tlbx
edkerk May 4, 2022
93db92e
fix: allow tolerance in modelAbilitiesTests
edkerk May 4, 2022
c37be5a
chore: updateDocumentation
edkerk May 4, 2022
a49a911
fix: extractMiriam consistent output as cell array
edkerk May 6, 2022
4162a63
refactor: more appropriate folder
edkerk May 9, 2022
07d7419
doc: informative error compareMultipleModels
edkerk May 9, 2022
acc644c
feat: exportForGit has optional cobra output
edkerk May 9, 2022
ad2d43b
chore: updateDocumentation
edkerk May 9, 2022
8aae3b8
fix: exportForGit text format write grRules
edkerk May 9, 2022
0f97b0a
doc: informative error with txt analytics toolbox
edkerk May 12, 2022
2bfff07
refactor: correct permissions
edkerk May 12, 2022
ce19ef1
Merge branch 'fix/small-fixes' into refactor/charAndStringInput
edkerk May 12, 2022
c532eb4
chore: updateDocumentation
edkerk May 12, 2022
22e8bc7
doc: more informative error solver tests
edkerk May 12, 2022
d6e0d6e
fix: cdhitTests on mac
edkerk May 12, 2022
5f69c40
fix: prevent unnecessary output modelAbilitiesTest
edkerk May 13, 2022
cbc33c9
feat: remove dependency for COBRA
edkerk May 13, 2022
4d6cc4b
fix: add missing end
edkerk May 13, 2022
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
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# Use MATLAB style diff
*.m text diff=matlab
# Mark as binary to prevent EOL changes. Also no need to track
mafft-linux*/* binary
mafft.bat binary
mafft/ binary
# Files/folders that should not be included when downloading repo as ZIP
.gitattributes export-ignore
.gitignore export-ignore
Expand Down
4 changes: 4 additions & 0 deletions INIT/getINITModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@

if nargin<3
celltype=[];
else
celltype=char(celltype);
end
if nargin<4
hpaData=[];
Expand All @@ -121,6 +123,8 @@
end
if nargin<7
taskFile=[];
else
taskFile=char(taskFile);
end
if nargin<8 || isempty(useScoresForTasks)
useScoresForTasks=true;
Expand Down
21 changes: 7 additions & 14 deletions INIT/runINIT.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,17 @@
if isempty(rxnScores)
rxnScores=zeros(numel(model.rxns),1);
end
if nargin<3
if nargin<3 || isempty(presentMets)
presentMets={};
else
presentMets=convertCharArray(presentMets);
end
if isempty(presentMets)
presentMets={};
end
presentMets=presentMets(:);
if nargin<4
essentialRxns={};
end
if isempty(essentialRxns)
if nargin<4 || isempty(essentialRxns)
essentialRxns={};
else
essentialRxns=convertCharArray(essentialRxns);
end
essentialRxns=essentialRxns(:);
if nargin<5
prodWeight=0.5;
end
if isempty(prodWeight)
if nargin<5 || isempty(prodWeight)
prodWeight=0.5;
end
if nargin<6
Expand Down
4 changes: 4 additions & 0 deletions core/FSEOF.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
%
% Usage: targets=FSEOF(model,biomassRxn,targetRxn,iterations,coefficient,outputFile)

biomassRxn=char(biomassRxn);
targetRxn=char(targetRxn);

if nargin<4
iterations=10;
coefficient=0.9;
Expand Down Expand Up @@ -96,6 +99,7 @@
%Generating output
formatSpec='%s\t%s\t%s\t%s\t%s\t%s\t%s\n';
if output == 1 %Output to a file
outputFile=char(outputFile);
fid=fopen(outputFile,'w');
fprintf(fid,formatSpec,'Slope','rowID','Enzyme ID','Enzyme Name','Subsystems','Direction','Gr Rule');
else %Output to screen
Expand Down
5 changes: 4 additions & 1 deletion core/addExchangeRxns.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@

if nargin<3
mets=model.mets;
elseif ~islogical(mets) && ~isnumeric(mets)
mets=convertCharArray(mets);
end
reactionType=upper(reactionType);
J=getIndexes(model,mets,'mets',false);
mets=model.mets(J);

reactionType=char(upper(reactionType));

%Production is positive for OUT and BOTH
if strcmp(reactionType,'IN')
I=speye(numel(model.mets));
Expand Down
12 changes: 3 additions & 9 deletions core/addGenesRaven.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@
if ~isfield(genesToAdd,'genes')
EM='genes is a required field in genesToAdd';
dispEM(EM);
end

if ~iscellstr(genesToAdd.genes)
EM='genesToAdd.genes must be a cell array of strings';
dispEM(EM);
else
genesToAdd.genes=convertCharArray(genesToAdd.genes);
end

%Number of genes
Expand Down Expand Up @@ -68,14 +65,11 @@

%Some more checks and if they pass then add each field to the structure
if isfield(genesToAdd,'geneShortNames')
genesToAdd.geneShortNames=convertCharArray(genesToAdd.geneShortNames);
if numel(genesToAdd.geneShortNames)~=nGenes
EM='genesToAdd.geneShortNames must have the same number of elements as genesToAdd.genes';
dispEM(EM);
end
if ~iscellstr(genesToAdd.geneShortNames)
EM='genesToAdd.geneShortNames must be a cell array of strings';
dispEM(EM);
end
%Add empty field if it doesn't exist
if ~isfield(newModel,'geneShortNames')
newModel.geneShortNames=largeFiller;
Expand Down
45 changes: 11 additions & 34 deletions core/addMets.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
end
if nargin<4
prefix='m_';
else
prefix=char(prefix);
end

newModel=model;
Expand All @@ -69,35 +71,19 @@
%Check some stuff regarding the required fields
if ~isfield(metsToAdd,'mets')
metsToAdd.mets=generateNewIds(newModel,'mets',prefix,numel(metsToAdd.metNames));
else
metsToAdd.mets=convertCharArray(metsToAdd.mets);
end
if ~isfield(metsToAdd,'metNames')
metsToAdd.metNames=metsToAdd.mets;
else
metsToAdd.metNames=convertCharArray(metsToAdd.metNames);
end
if ~isfield(metsToAdd,'compartments')
EM='compartments is a required field in metsToAdd';
dispEM(EM);
end
if ischar(metsToAdd.mets)
metsToAdd.mets={metsToAdd.mets};
elseif ~iscellstr(metsToAdd.mets)
EM='metsToAdd.mets must be a cell array of strings';
dispEM(EM);
end
if ischar(metsToAdd.metNames)
metsToAdd.metNames={metsToAdd.metNames};
elseif ~iscellstr(metsToAdd.metNames)
EM='metsToAdd.metNames must be a cell array of strings';
dispEM(EM);
end
if ~iscellstr(metsToAdd.compartments)
if ischar(metsToAdd.compartments)
temp=cell(numel(metsToAdd.mets),1);
temp(:)={metsToAdd.compartments};
metsToAdd.compartments=temp;
else
EM='metsToAdd.compartments must be a cell array of strings';
dispEM(EM);
end
else
metsToAdd.compartments=convertCharArray(metsToAdd.compartments);
end

%Number of metabolites
Expand Down Expand Up @@ -193,14 +179,11 @@
end

if isfield(metsToAdd,'inchis')
metsToAdd.inchis=convertCharArray(metsToAdd.inchis);
if numel(metsToAdd.inchis)~=nMets
EM='metsToAdd.inchis must have the same number of elements as metsToAdd.mets';
dispEM(EM);
end
if ~iscellstr(metsToAdd.inchis)
EM='metsToAdd.inchis must be a cell array of strings';
dispEM(EM);
end
%Add empty field if it doesn't exist
if ~isfield(newModel,'inchis')
newModel.inchis=largeFiller;
Expand All @@ -214,14 +197,11 @@
end

if isfield(metsToAdd,'metFormulas')
metsToAdd.metFormulas=convertCharArray(metsToAdd.metFormulas);
if numel(metsToAdd.metFormulas)~=nMets
EM='metsToAdd.metFormulas must have the same number of elements as metsToAdd.mets';
dispEM(EM);
end
if ~iscellstr(metsToAdd.metFormulas)
EM='metsToAdd.metFormulas must be a cell array of strings';
dispEM(EM);
end
%Add empty field if it doesn't exist
if ~isfield(newModel,'metFormulas')
newModel.metFormulas=largeFiller;
Expand Down Expand Up @@ -255,14 +235,11 @@
end

if isfield(metsToAdd,'metNotes')
metsToAdd.metNotes=convertCharArray(metsToAdd.metNotes);
if numel(metsToAdd.metNotes)~=nMets
EM='metsToAdd.metNotes must have the same number of elements as metsToAdd.mets';
dispEM(EM);
end
if ~iscellstr(metsToAdd.metNotes)
EM='metsToAdd.metNotes must be a cell array of strings';
dispEM(EM);
end
%Add empty field if it doesn't exist
if ~isfield(newModel,'metNotes')
newModel.metNotes=largeFiller;
Expand Down
41 changes: 18 additions & 23 deletions core/addRxns.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,20 @@

if nargin<4
compartment=[];
else
compartment=char(compartment);
end
if nargin<5
allowNewMets=false;
elseif ~islogical(allowNewMets)
allowNewMets=char(allowNewMets);
end
if nargin<6
allowNewGenes=false;
end

if allowNewGenes & isfield(rxnsToAdd,'grRules')
genesToAdd.genes = strjoin(rxnsToAdd.grRules);
genesToAdd.genes = strjoin(convertCharArray(rxnsToAdd.grRules));
genesToAdd.genes = regexp(genesToAdd.genes,' |)|(|and|or','split'); % Remove all grRule punctuation
genesToAdd.genes = genesToAdd.genes(~cellfun(@isempty,genesToAdd.genes)); % Remove spaces and empty genes
genesToAdd.genes = setdiff(unique(genesToAdd.genes),model.genes); % Only keep new genes
Expand Down Expand Up @@ -147,10 +151,7 @@
end

if eqnType==2 || (eqnType==1 && allowNewMets==true)
if ~ischar(compartment)
EM='compartment must be a string';
dispEM(EM);
end
compartment=char(compartment);
if ~ismember(compartment,model.comps)
EM='compartment must match one of the compartments in model.comps';
dispEM(EM);
Expand All @@ -160,7 +161,8 @@
if ~isfield(rxnsToAdd,'rxns')
EM='rxns is a required field in rxnsToAdd';
dispEM(EM);
elseif iscell(rxnsToAdd.rxns)
else
rxnsToAdd.rxns=convertCharArray(rxnsToAdd.rxns);
%To fit with some later printing
rxnsToAdd.rxns=rxnsToAdd.rxns(:);
end
Expand All @@ -174,30 +176,16 @@
dispEM(EM);
end

if ~iscellstr(rxnsToAdd.rxns) && ~ischar(rxnsToAdd.rxns)
%It could also be a string, but it's not encouraged
EM='rxnsToAdd.rxns must be a cell array of strings';
dispEM(EM);
else
rxnsToAdd.rxns=cellstr(rxnsToAdd.rxns);
end

%Normal case: equations provided
if isfield(rxnsToAdd,'equations')
if ~iscellstr(rxnsToAdd.equations) && ~ischar(rxnsToAdd.equations)
%It could also be a string, but it's not encouraged
EM='rxnsToAdd.equations must be a cell array of strings';
dispEM(EM);
else
rxnsToAdd.equations=cellstr(rxnsToAdd.equations);
end

rxnsToAdd.equations=convertCharArray(rxnsToAdd.equations);

%Alternative case: mets+stoichiometry provided
else
%In the case of 1 rxn added (array of strings + vector), transform to
%cells of length=1:
if iscellstr(rxnsToAdd.mets)
rxnsToAdd.mets = {rxnsToAdd.mets};
rxnsToAdd.mets={rxnsToAdd.mets};
end
if isnumeric(rxnsToAdd.stoichCoeffs)
rxnsToAdd.stoichCoeffs = {rxnsToAdd.stoichCoeffs};
Expand Down Expand Up @@ -257,6 +245,7 @@
newModel.rxns=[newModel.rxns;rxnsToAdd.rxns(:)];

if isfield(rxnsToAdd,'rxnNames')
rxnsToAdd.rxnNames=convertCharArray(rxnsToAdd.rxnNames);
if numel(rxnsToAdd.rxnNames)~=nRxns
EM='rxnsToAdd.rxnNames must have the same number of elements as rxnsToAdd.rxns';
dispEM(EM);
Expand Down Expand Up @@ -340,6 +329,7 @@
end

if isfield(rxnsToAdd,'eccodes')
rxnsToAdd.eccodes=convertCharArray(rxnsToAdd.eccodes);
if numel(rxnsToAdd.eccodes)~=nRxns
EM='rxnsToAdd.eccodes must have the same number of elements as rxnsToAdd.rxns';
dispEM(EM);
Expand Down Expand Up @@ -414,6 +404,7 @@
end
end
if isfield(rxnsToAdd,'grRules')
rxnsToAdd.grRules=convertCharArray(rxnsToAdd.grRules);
if numel(rxnsToAdd.grRules)~=nRxns
EM='rxnsToAdd.grRules must have the same number of elements as rxnsToAdd.rxns';
dispEM(EM);
Expand All @@ -431,6 +422,7 @@
end

if isfield(rxnsToAdd,'rxnFrom')
rxnsToAdd.rxnFrom=convertCharArray(rxnsToAdd.rxnFrom);
if numel(rxnsToAdd.rxnFrom)~=nRxns
EM='rxnsToAdd.rxnFrom must have the same number of elements as rxnsToAdd.rxns';
dispEM(EM);
Expand All @@ -448,6 +440,7 @@
end

if isfield(rxnsToAdd,'rxnNotes')
rxnsToAdd.rxnNotes=convertCharArray(rxnsToAdd.rxnNotes);
if numel(rxnsToAdd.rxnNotes)~=nRxns
EM='rxnsToAdd.rxnNotes must have the same number of elements as rxnsToAdd.rxns';
dispEM(EM);
Expand All @@ -465,6 +458,7 @@
end

if isfield(rxnsToAdd,'rxnReferences')
rxnsToAdd.rxnReferences=convertCharArray(rxnsToAdd.rxnReferences);
if numel(rxnsToAdd.rxnReferences)~=nRxns
EM='rxnsToAdd.rxnReferences must have the same number of elements as rxnsToAdd.rxns';
dispEM(EM);
Expand All @@ -482,6 +476,7 @@
end

if isfield(rxnsToAdd,'pwys')
rxnsToAdd.pwys=convertCharArray(rxnsToAdd.pwys);
if numel(rxnsToAdd.pwys)~=nRxns
EM='rxnsToAdd.pwys must have the same number of elements as rxnsToAdd.rxns';
dispEM(EM);
Expand Down
Loading