Skip to content

Commit

Permalink
Merge pull request #67 from SysBioChalmers/curation/metabolites
Browse files Browse the repository at this point in the history
Curation/metabolites
  • Loading branch information
BenjaSanchez authored Feb 28, 2018
2 parents 1c84a9f + b677363 commit 7495053
Show file tree
Hide file tree
Showing 13 changed files with 304 additions and 89 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
84 changes: 84 additions & 0 deletions ComplementaryScripts/modelCuration/checkMetBalance.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% checkMetBalance(model,metName,flux,show_all)
% Shows for a given metabolite all involved reactions on all compartments.
%
% INPUT: model A GEM as a structure object
% metName The name of the desired metabolite (e.g. 'NADH')
% flux (OPTIONAL) A solution of the model (nx1 vector)
% show_all (OPTIONAL) If false, only non-zero fluxes will be
% displayed (default = false; if no flux is given as
% input then default = true)
%
% OUTPUT: On the command window displays all involved reactions,
% including the flux value, the reaction ID and the formula.
% Results are displayed by compartment, and separated depending
% if the metabolite is being consumed, produced or transported
% in each rxn. If no flux was given as input, a zero will appear
% instead.
%
% Benjamín J. Sánchez
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function checkMetBalance(model,metName,flux,show_all)

lb = model.lb;
ub = model.ub;

if nargin < 4
show_all = false;
if nargin < 3
flux = zeros(size(model.rxns));
show_all = true;
end
end

pos = zeros(size(model.mets));
for i = 1:length(model.metNames)
if strcmp(model.metNames{i},metName)
pos(i) = 1;
end
end
pos = find(pos);

for i = 1:length(pos)
rxns_cons = {};
rxns_prod = {};
for j = 1:length(model.rxns)
if model.S(pos(i),j) ~= 0 && (show_all || abs(flux(j)) > 1e-10)
rxn = model.rxns{j};
rxn_formula = printRxnFormula(model,model.rxns(j),false,false,true);
rxn_formula = rxn_formula{1};
if model.S(pos(i),j) < 0
rxns_cons = [rxns_cons;{lb(j) flux(j) ub(j) rxn rxn_formula}];
else
rxns_prod = [rxns_prod;{lb(j) flux(j) ub(j) rxn rxn_formula}];
end
end
end
if ~isempty(rxns_cons) || ~isempty(rxns_prod)
print_group(rxns_cons,'Consumption')
print_group(rxns_prod,'Production')
end
end

fprintf('\n')

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function print_group(rxns,name)

if ~isempty(rxns)
fprintf([name ':\n'])
[~,order] = sort(cell2mat(rxns(:,1)),'descend');
rxns = rxns(order,:);
for i = 1:length(order)
fprintf([sprintf('%6.2e',rxns{i,1}) '\t' sprintf('%6.2e',rxns{i,2}) ...
'\t' sprintf('%6.2e',rxns{i,3}) '\t' rxns{i,4} '\t\t' rxns{i,5} '\n'])
end
end

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 changes: 71 additions & 0 deletions ComplementaryScripts/modelCuration/makeFormulasCompliant.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% makeFormulasCompliant.m
% Corrects SBML-incompatible metabolite formulas.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%aa codes:
aas = {'s_0955[c]' 'ala' % A Alanine
's_0981[c]' 'cys' % C Cysteine
's_0973[c]' 'asp' % D Aspartic acid
's_0991[c]' 'glu' % E Glutamic acid
's_1032[c]' 'phe' % F Phenylalanine
's_1003[c]' 'gly' % G Glycine
's_1006[c]' 'his' % H Histidine
's_1016[c]' 'ile' % I Isoleucine
's_1025[c]' 'lys' % K Lysine
's_1021[c]' 'leu' % L Leucine
's_1029[c]' 'met' % M Methionine
's_0969[c]' 'asn' % N Asparagine
's_1035[c]' 'pro' % P Proline
's_0999[c]' 'gln' % Q Glutamine
's_0965[c]' 'arg' % R Arginine
's_1039[c]' 'ser' % S Serine
's_1045[c]' 'thr' % T Threonine
's_1056[c]' 'val' % V Valine
's_1048[c]' 'trp' % W Tryptophan
's_1051[c]' 'tyr'}; % Y Tyrosine

%tRNA's are just produced and consumed in single loops, so we can just
%replace the radical part with an "R" and still maintain mass balances,
%i.e. aa-tRNA(aa) will have "R" + the formula of the corresponding aa and
%tRNA(aa) will just have an "R". Example:
% tRNA(Ala): C10H17 O10PR2(C5H8O6PR)n -> R
% Ala-tRNA(Ala): C13H22NO11PR2(C5H8O6PR)n -> C3H6NOR (ala-R without an -OH)
% Cycle in which the 2 are involved:
% r_4047: 0.4193 Ala-tRNA(Ala) + ... -> 0.4193 tRNA(Ala) + ... + protein (growth)
% r_0157: ATP + L-alanine + tRNA(Ala) -> Ala-tRNA(Ala) + AMP + diphosphate
% C10H12N5O13P3 C3H7NO2 R C3H6NOR C10H12N5O7P HO7P2

for i = 1:length(model.mets)
name = model.metNames{i};
formula = model.metFormulas{i};
if contains(model.metNames{i},'-tRNA(')
%Correct metabolite:
try
aaName = lower(name(1:strfind(name,'-')-1));
aaID = aas{strcmp(aas(:,2),aaName),1};
aaPos = strcmp(model.mets,aaID);
model.metFormulas{i} = [model.metFormulas{aaPos} 'R'];
model.metFormulas{i} = takeOutFromFormula(model.metFormulas{i},'OH');
catch
%formyl-met: C6H11NO3S
model.metFormulas{i} = 'C6H10NO2SR';
end

%Correct associated tRNA pair:
pairName = name(strfind(name,'-')+1:end);
pairPos = strcmp(model.metNames,pairName);
if sum(pairPos) > 0
model.metFormulas{pairPos} = 'R';
end
end
end

%Display the remaining problems:
for i = 1:length(model.mets)
if contains(model.metFormulas{i},')n')
disp([model.metNames{i} ': ' model.metFormulas{i}]);
end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
File renamed without changes.
50 changes: 50 additions & 0 deletions ComplementaryScripts/modelCuration/takeOutFromFormula.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% formula = takeOutFromFormula(formula,elements)
% Takes away from formula each of the elements specified.
%
% Benjamín J. Sánchez
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function formula = takeOutFromFormula(formula,elements)

for i = 1:length(elements)
posInFormula = strfind(formula,elements(i));
if posInFormula == length(formula)
formula = strrep(formula,elements(i),''); %only 1 element at the end of the formula
else
for j = posInFormula+1:length(formula)
if isletter(formula(j))
if j == posInFormula+1
formula = strrep(formula,elements(i),''); %only 1 element in the middle of the formula
else
formula = goDown(formula,posInFormula,j); %more than 1 element in the formula
end
break
elseif j == length(formula)
formula = goDown(formula,posInFormula,j+1); %more than 1 element at the end of the formula
end
end
end
end

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function formula = goDown(formula,startPos,endPos)

numbElem = str2double(formula(startPos+1:endPos-1));
if numbElem == 2
numbElem = '';
else
numbElem = num2str(numbElem - 1);
end
if endPos == length(formula)+1
formula = [formula(1:startPos) numbElem];
else
formula = [formula(1:startPos) numbElem formula(endPos:end)];
end

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
GAM = 30.49; %Data from Nissen et al. 1997
P = 0.461; %Data from Nissen et al. 1997
NGAM = 0; %Refit done in Jouthen et al. 2012
cd ../modelCuration
model = changeBiomass(model,P,GAM,NGAM);
cd ../otherChanges

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 7495053

Please sign in to comment.