Skip to content

Commit 6c1ba69

Browse files
authored
Merge pull request #1761 from opencobra/develop
Develop
2 parents 9478adc + b74c212 commit 6c1ba69

File tree

801 files changed

+39053
-5901
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

801 files changed

+39053
-5901
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@
4646
path = external/base/samplers/looplessFluxSampler
4747
url = https://github.com/rmtfleming/looplessFluxSampler
4848
ignore = dirty
49+
[submodule "external/base/utilities/condalab"]
50+
path = external/base/utilities/condalab
51+
url = https://github.com/sg-s/condalab

external/base/utilities/condalab

Submodule condalab added at 95b33ce

external/dataIntegration/mCADRE/pruningModel.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,17 @@
6666
model_rem = removeRxns(tissueModel, r);
6767
end
6868
% Check for inactive reactions after removal of r
69-
[fluxConsistentMetBool,fluxConsistentRxnBool] = findFluxConsistentSubset(model_rem,paramConsistency);
69+
try
70+
[fluxConsistentMetBool,fluxConsistentRxnBool] = findFluxConsistentSubset(model_rem,paramConsistency);
71+
rStatus_and_not_error = true;
72+
catch
73+
rStatus_and_not_error = false;
74+
end
75+
else
76+
rStatus_and_not_error = false;
77+
end
78+
79+
if rStatus_and_not_error
7080
inactive_G= [ r; model_rem.rxns(fluxConsistentRxnBool==0)];
7181

7282
inactiveCore = intersect(inactive_G, coreRxn);

src/analysis/multiSpecies/microbiomeModelingToolbox/additionalAnalysis/analyzeMgPipeResults.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function analyzeMgPipeResults(infoFilePath,resPath,varargin)
113113
cd(violinPath)
114114

115115
% create violin plots for net uptake and secretion files
116-
if any(contains(fileList{i,1},{'net_uptake_fluxes.csv','net_secretion_fluxes.csv'}))
116+
if any(strcmp(fileList{i,1},{'net_uptake_fluxes.csv','net_secretion_fluxes.csv'}))
117117
makeViolinPlots(sampleData, infoFile, 'stratification',sampleGroupHeaders{j}, 'plottedFeature', filename, 'unit', 'mmol/person/day')
118118
end
119119
cd(currentDir)

src/analysis/multiSpecies/microbiomeModelingToolbox/additionalAnalysis/calculateReactionAbundance.m

100755100644
Lines changed: 357 additions & 438 deletions
Large diffs are not rendered by default.

src/analysis/multiSpecies/microbiomeModelingToolbox/additionalAnalysis/calculateSubsystemAbundance.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
% AUTHOR
1818
% - Almut Heinken, 08/2020
1919

20-
reactionDatabase = readtable('reactionDatabase.txt', 'Delimiter', 'tab','TreatAsEmpty',['UND. -60001','UND. -2011','UND. -62011'], 'ReadVariableNames', false);
20+
reactionDatabase = readtable('ReactionDatabase.txt', 'Delimiter', 'tab','TreatAsEmpty',['UND. -60001','UND. -2011','UND. -62011'], 'ReadVariableNames', false);
2121
reactionDatabase=table2cell(reactionDatabase);
2222

2323
reactionAbundance = readtable(reactionAbundancePath, 'ReadVariableNames', false);
@@ -54,6 +54,4 @@
5454
end
5555
end
5656

57-
writetable(cell2table(subsystemAbundance),'SubsystemAbundance.txt','FileType','text','WriteVariableNames',false,'Delimiter','\t');
58-
5957
end
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
function ReactionAbundance = fastCalculateReactionAbundance(abundancePath, modelPath, rxnsList, numWorkers)
2+
% Part of the Microbiome Modeling Toolbox. This function calculates and
3+
% plots the total abundance of reactions of interest in a given microbiome
4+
% sample based on the strain-level composition.
5+
% Reaction presence or absence in each strain is derived from the reaction content
6+
% of the respective AGORA model.
7+
%
8+
% USAGE
9+
%
10+
% ReactionAbundance = fastCalculateReactionAbundance(abundancePath, modelPath, rxnsList, numWorkers)
11+
%
12+
% INPUTS:
13+
% abundancePath: Path to the .csv file with the abundance data.
14+
% Example: 'cobratoolbox/papers/018_microbiomeModelingToolbox/examples/normCoverage.csv'
15+
% modelPath: Folder containing the strain-specific AGORA models
16+
% OPTIONAL INPUTS:
17+
% rxnsList: List of reactions for which the abundance
18+
% should be calculated (if left empty: all
19+
% reactions in all models)
20+
% numWorkers: Number of workers used for parallel pool. If
21+
% left empty, the parallel pool will not be
22+
% started. Parallellization is recommended if
23+
% all reactions are computed.
24+
%
25+
% OUTPUT:
26+
% ReactionAbundance Table with total abundance for each microbiome
27+
% and reaction
28+
%
29+
% .. Author: - Almut Heinken, 04/2021
30+
31+
% read the csv file with the abundance data
32+
abundance = readtable(abundancePath, 'ReadVariableNames', false);
33+
abundance = table2cell(abundance);
34+
if isnumeric(abundance{2, 1})
35+
abundance(:, 1) = [];
36+
end
37+
38+
% load the models
39+
for i = 2:size(abundance, 1)
40+
model = readCbModel([modelPath filesep abundance{i, 1} '.mat']);
41+
modelsList{i, 1} = model;
42+
end
43+
44+
if ~exist('rxnsList', 'var') || isempty(rxnsList) % define reaction list if not entered
45+
fprintf('No reaction list entered. Abundances will be calculated for all reactions in all models. \n')
46+
% get model list from abundance input file
47+
for i = 2:size(abundance, 1)
48+
model = modelsList{i, 1};
49+
rxnsList = vertcat(model.rxns, rxnsList);
50+
end
51+
rxnsList = unique(rxnsList);
52+
end
53+
54+
% load the models found in the individuals and extract which reactions are
55+
% in which model
56+
for i = 2:size(abundance, 1)
57+
model = modelsList{i, 1};
58+
ReactionPresence{i, 1} = abundance{i, 1};
59+
for j = 1:length(rxnsList)
60+
ReactionPresence{1, j + 1} = rxnsList{j};
61+
if ~isempty(find(ismember(model.rxns, rxnsList{j})))
62+
ReactionPresence{i, j + 1} = '1';
63+
else
64+
ReactionPresence{i, j + 1} = '0';
65+
end
66+
end
67+
end
68+
ReactionPresence{1,1}='Strains';
69+
70+
71+
% prepare table for the total abundance
72+
ReactionAbundance = {};
73+
for i = 1:length(rxnsList)
74+
ReactionAbundance{1, i + 1} = rxnsList{i};
75+
end
76+
for i = 2:size(abundance, 2)
77+
ReactionAbundance{i, 1} = abundance{1, i};
78+
end
79+
80+
% use parallel pool if workers specified as input
81+
if exist('numWorkers', 'var') && numWorkers > 0
82+
poolobj = gcp('nocreate');
83+
if isempty(poolobj)
84+
parpool(numWorkers)
85+
end
86+
end
87+
88+
clear abundance
89+
90+
totalAbun={};
91+
parfor i = 2:size(ReactionAbundance, 1)
92+
i
93+
% reload the file to avoid running out of memory
94+
abundance = readtable(abundancePath, 'ReadVariableNames', false);
95+
abundance = table2cell(abundance);
96+
if isnumeric(abundance{2, 1})
97+
abundance(:, 1) = [];
98+
end
99+
100+
% temporarily store reaction abundances
101+
totalAbun{i} = zeros(length(rxnsList), 1);
102+
103+
for j = 2:size(abundance, 1)
104+
% find all reactions present in the strain
105+
presentRxns = find(strcmp(ReactionPresence(j,2:end),'1'));
106+
107+
for k = 1:length(presentRxns)
108+
% summarize total abundance
109+
totalAbun{i}(presentRxns(k),1) = totalAbun{i}(presentRxns(k),1) + str2double(abundance{j,i});
110+
end
111+
end
112+
end
113+
114+
% collect the temporarily stored abundances to put together the table
115+
for i = 2:size(ReactionAbundance, 1)
116+
ReactionAbundance(i,2:end) = num2cell(totalAbun{i});
117+
end
118+
119+
end

src/analysis/multiSpecies/microbiomeModelingToolbox/mgPipe/adaptVMHDietToAGORA.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
% Define the list of metabolites required by at least one AGORA model for
5353
% growth
54-
essentialMetabolites = {'EX_12dgr180(e)'; 'EX_26dap_M(e)'; 'EX_2dmmq8(e)'; 'EX_2obut(e)'; 'EX_3mop(e)'; 'EX_4abz(e)'; 'EX_4hbz(e)'; 'EX_ac(e)'; 'EX_acgam(e)'; 'EX_acmana(e)'; 'EX_acnam(e)'; 'EX_ade(e)'; 'EX_adn(e)'; 'EX_adocbl(e)'; 'EX_adpcbl(e)'; 'EX_ala_D(e)'; 'EX_ala_L(e)'; 'EX_amet(e)'; 'EX_amp(e)'; 'EX_arab_D(e)'; 'EX_arab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ttdca(e)'; 'EX_tyr_L(e)'; 'EX_ura(e)'; 'EX_val_L(e)'; 'EX_xan(e)'; 'EX_xyl_D(e)'; 'EX_zn2(e)'; 'EX_glu_D(e)'; 'EX_melib(e)'; 'EX_chtbs(e)'; 'EX_metsox_S_L(e)'; 'EX_hdca(e)'; 'EX_gam(e)'; 'EX_indole(e)'; 'EX_glcn(e)'; 'EX_coa(e)'};
54+
essentialMetabolites = {'EX_12dgr180(e)'; 'EX_26dap_M(e)'; 'EX_2dmmq8(e)'; 'EX_2obut(e)'; 'EX_3mop(e)'; 'EX_4abz(e)'; 'EX_4hbz(e)'; 'EX_ac(e)'; 'EX_acgam(e)'; 'EX_acmana(e)'; 'EX_acnam(e)'; 'EX_ade(e)'; 'EX_adn(e)'; 'EX_adocbl(e)'; 'EX_ala_D(e)'; 'EX_ala_L(e)'; 'EX_amet(e)'; 'EX_amp(e)'; 'EX_arab_D(e)'; 'EX_arab_L(e)'; 'EX_arg_L(e)'; 'EX_asn_L(e)'; 'EX_btn(e)'; 'EX_ca2(e)'; 'EX_cbl1(e)'; 'EX_cgly(e)'; 'EX_chor(e)'; 'EX_chsterol(e)'; 'EX_cit(e)'; 'EX_cl(e)'; 'EX_cobalt2(e)'; 'EX_csn(e)'; 'EX_cu2(e)'; 'EX_cys_L(e)'; 'EX_cytd(e)'; 'EX_dad_2(e)'; 'EX_dcyt(e)'; 'EX_ddca(e)'; 'EX_dgsn(e)'; 'EX_fald(e)'; 'EX_fe2(e)'; 'EX_fe3(e)'; 'EX_fol(e)'; 'EX_for(e)'; 'EX_gal(e)'; 'EX_glc_D(e)'; 'EX_gln_L(e)'; 'EX_glu_L(e)'; 'EX_gly(e)'; 'EX_glyc(e)'; 'EX_glyc3p(e)'; 'EX_gsn(e)'; 'EX_gthox(e)'; 'EX_gthrd(e)'; 'EX_gua(e)'; 'EX_h(e)'; 'EX_h2o(e)'; 'EX_h2s(e)'; 'EX_his_L(e)'; 'EX_hxan(e)'; 'EX_ile_L(e)'; 'EX_k(e)'; 'EX_lanost(e)'; 'EX_leu_L(e)'; 'EX_lys_L(e)'; 'EX_malt(e)'; 'EX_met_L(e)'; 'EX_mg2(e)'; 'EX_mn2(e)'; 'EX_mqn7(e)'; 'EX_mqn8(e)'; 'EX_nac(e)'; 'EX_ncam(e)'; 'EX_nmn(e)'; 'EX_no2(e)'; 'EX_ocdca(e)'; 'EX_ocdcea(e)'; 'EX_orn(e)'; 'EX_phe_L(e)'; 'EX_pheme(e)'; 'EX_pi(e)'; 'EX_pnto_R(e)'; 'EX_pro_L(e)'; 'EX_ptrc(e)'; 'EX_pydx(e)'; 'EX_pydxn(e)'; 'EX_q8(e)'; 'EX_rib_D(e)'; 'EX_ribflv(e)'; 'EX_ser_L(e)'; 'EX_sheme(e)'; 'EX_so4(e)'; 'EX_spmd(e)'; 'EX_thm(e)'; 'EX_thr_L(e)'; 'EX_thymd(e)'; 'EX_trp_L(e)'; 'EX_ttdca(e)'; 'EX_tyr_L(e)'; 'EX_ura(e)'; 'EX_val_L(e)'; 'EX_xan(e)'; 'EX_xyl_D(e)'; 'EX_zn2(e)'; 'EX_glu_D(e)'; 'EX_melib(e)'; 'EX_chtbs(e)'; 'EX_metsox_S_L(e)'; 'EX_hdca(e)'; 'EX_gam(e)'; 'EX_indole(e)'; 'EX_glcn(e)'; 'EX_coa(e)'; 'EX_man(e)'; 'EX_fum(e)'; 'EX_succ(e)'; 'EX_no3(e)'; 'EX_ins(e)'; 'EX_uri(e)'; 'EX_drib(e)'; 'EX_pime(e)'; 'EX_lac_L(e)'; 'EX_glypro(e)'; 'EX_urea(e)'; 'EX_duri(e)'; 'EX_h2(e)'; 'EX_mal_L(e)'; 'EX_tre(e)'; 'EX_orot(e)'};
5555

5656
% fix any exchange nomenclature issues
5757
adaptedDietConstraints(:, 1) = strrep(adaptedDietConstraints(:, 1), '[e]', '(e)');
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
function [exch,modelStoragePath] = buildModelStorage(microbeNames,modPath)
2+
3+
currentDir=pwd;
4+
mkdir('modelStorage')
5+
cd('modelStorage')
6+
modelStoragePath = pwd;
7+
8+
exch = {};
9+
for j = 1:size(microbeNames, 1)
10+
model = readCbModel([modPath filesep microbeNames{j,1} '.mat']);
11+
%exch = union(exch, model.mets(find(sum(model.S(:, strncmp('EX_', model.rxns, 3)), 2) ~= 0)));
12+
exStruct = findSExRxnInd(model);
13+
new_exch = findMetsFromRxns(model,model.rxns(exStruct.ExchRxnBool & ~exStruct.biomassBool));
14+
exch = union(exch,new_exch);
15+
end
16+
17+
% get already built reconstructions
18+
dInfo = dir(modelStoragePath);
19+
modelList={dInfo.name};
20+
modelList=modelList';
21+
modelList=strrep(modelList,'.mat','');
22+
microbesNames=setdiff(microbeNames,modelList);
23+
24+
25+
if length(microbesNames)>0
26+
%% create a new extracellular space [u] for microbes
27+
for j = 1:size(microbeNames, 1)
28+
model = readCbModel([modPath filesep microbeNames{j,1} '.mat']);
29+
% temp fix
30+
if isfield(model,'C')
31+
model=rmfield(model,'C');
32+
model=rmfield(model,'d');
33+
end
34+
%
35+
36+
% removing possible constraints of the bacs
37+
selExc = findExcRxns(model);
38+
Reactions2 = model.rxns(find(selExc));
39+
allex = Reactions2(strmatch('EX', Reactions2));
40+
biomass = allex(find(strncmp(allex,'bio',3)));
41+
finrex = setdiff(allex, biomass);
42+
model = changeRxnBounds(model, finrex, -1000, 'l');
43+
model = changeRxnBounds(model, finrex, 1000, 'u');
44+
45+
% removing blocked reactions from the bacs
46+
%BlockedRxns = identifyFastBlockedRxns(model,model.rxns, printLevel);
47+
%model= removeRxns(model, BlockedRxns);
48+
%BlockedReaction = findBlockedReaction(model,'L2')
49+
50+
model = convertOldStyleModel(model);
51+
exmod = model.rxns(strncmp('EX_', model.rxns, 3)); % find exchange reactions
52+
eMets = model.mets(~cellfun(@isempty, strfind(model.mets, '[e]'))); % exchanged metabolites
53+
dummyMicEU = createModel();
54+
%dummyMicEU = makeDummyModel(2 * size(eMets, 1), size(eMets, 1));
55+
dummyMicEUmets = [strcat(strcat(microbeNames{j, 1}, '_'), regexprep(eMets, '\[e\]', '\[u\]')); regexprep(eMets, '\[e\]', '\[u\]')];
56+
dummyMicEU = addMultipleMetabolites(dummyMicEU,dummyMicEUmets);
57+
nMets = numel(eMets);
58+
S = [speye(nMets);-speye(nMets)];
59+
lbs = repmat(-1000,nMets,1);
60+
ubs = repmat(1000,nMets,1);
61+
names = strcat(strcat(microbeNames{j, 1}, '_'), 'IEX_', regexprep(eMets, '\[e\]', '\[u\]'), 'tr');
62+
dummyMicEU = addMultipleReactions(dummyMicEU,names,dummyMicEUmets,S,'lb',lbs,'ub',ubs);
63+
model = removeRxns(model, exmod);
64+
model.rxns = strcat(strcat(microbeNames{j, 1}, '_'), model.rxns);
65+
model.mets = strcat(strcat(microbeNames{j, 1}, '_'), regexprep(model.mets, '\[e\]', '\[u\]')); % replace [e] with [u]
66+
[model] = mergeTwoModels(dummyMicEU, model, 2, false, false);
67+
68+
%finish up by A: removing duplicate reactions
69+
%We will lose information here, but we will just remove the duplicates.
70+
[model,rxnToRemove,rxnToKeep]= checkDuplicateRxn(model,'S',1,0,1);
71+
72+
writeCbModel(model,'format','mat','fileName',[microbeNames{j,1} '.mat']); % store model
73+
end
74+
end
75+
76+
cd(currentDir)
77+
78+
end

src/analysis/multiSpecies/microbiomeModelingToolbox/mgPipe/createPersonalizedModel.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
createdModels = {};
2929

3030
% use the setup model containing every strain in every sample
31-
parfor k = 1:length(sampNames)
31+
for k = 1:length(sampNames)
3232
mgmodel = model;
3333
abunRed = abundance(:,k+1);
3434

@@ -64,7 +64,7 @@
6464
% Coupling constraints for bacteria
6565
for i = 1:length(presBac)
6666
IndRxns=find(strncmp(mgmodel.rxns,[presBac{i,1} '_'],length(presBac{i,1})+1));%finding indixes of specific reactions
67-
% find the name of biomass reacion in the microbe model
67+
% find the name of biomass reaction in the microbe model
6868
bioRxn=mgmodel.rxns{find(strncmp(mgmodel.rxns,strcat(presBac{i,1},'_bio'),length(char(strcat(presBac{i,1},'_bio')))))};
6969
mgmodel=coupleRxnList2Rxn(mgmodel,mgmodel.rxns(IndRxns(1:length(mgmodel.rxns(IndRxns(:,1)))-1,1)),bioRxn,400,0); %couple the specific reactions
7070
end

0 commit comments

Comments
 (0)