Skip to content

Commit 68d9461

Browse files
authored
Merge pull request #1813 from opencobra/develop
Develop
2 parents 8e09472 + 94b7757 commit 68d9461

File tree

75 files changed

+969
-729
lines changed

Some content is hidden

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

75 files changed

+969
-729
lines changed

initCobraToolbox.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ function initCobraToolbox(updateToolbox)
219219
% Update/initialize submodules
220220
%By default your submodules repository is in a state called 'detached HEAD'.
221221
%This means that the checked-out commit -- which is the one that the super-project (core) needs -- is not associated with a local branch name.
222-
[status_gitSubmodule, result_gitSubmodule] = system(['git submodule update --init --remote --no-fetch ' depthFlag]);
222+
%[status_gitSubmodule, result_gitSubmodule] = system(['git submodule update --init --remote --no-fetch ' depthFlag]);%old
223+
[status_gitSubmodule, result_gitSubmodule] = system(['git submodule foreach git submodule update --init --recursive']);% 23/9/21 RF submodules point to master
223224

224225
if status_gitSubmodule ~= 0
225226
fprintf(strrep(result_gitSubmodule, '\', '\\'));

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
%
2323
% OPTIONAL INPUTS:
2424
% resultsFolder char with path of directory where results are saved
25-
% (default: current folder)
2625
% osenseStr String indicating whether objective function(s)
2726
% should be maximized or minimized. Allowed inputs:
2827
% 'min','max', default:'max'.
@@ -50,7 +49,7 @@
5049
parser = inputParser(); % Define default input parameters if not specified
5150
parser.addRequired('modelFolder', @ischar);
5251
parser.addRequired('objectiveList', @iscell);
53-
parser.addParameter('resultsFolder',pwd, @ischar);
52+
parser.addParameter('resultsFolder',[pwd filesep 'ShadowPrices'], @ischar);
5453
parser.addParameter('osenseStr','max', @ischar);
5554
parser.addParameter('SPDef','Nonzero', @ischar);
5655
parser.addParameter('numWorkers', 0, @(x) isnumeric(x))
@@ -144,7 +143,7 @@
144143
% % store computed objective values
145144
for j=1:length(objectiveList)
146145
if ~isempty(FBAsolution{j,1})
147-
objectives{j+1,3+i} = FBAsolution{j,1}.obj;
146+
objectives{j+1,2+i} = FBAsolution{j,1}.obj;
148147
else
149148
objectives{j+1,3+i} = 0;
150149
end

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function analyzeMgPipeResults(infoFilePath,resPath,varargin)
22
% This function takes simulation results generated by mgPipe as the input
3-
% and determines which computed fluxes and reaction abundances are
3+
% and determines which computed fluxes and reaction infoFiles are
44
% significantly different between groups. Also creates violin plots of the
55
% simulation results. Requires a file with sample information (e.g.,
66
% disease group, age) for the microbiome models that were generated and
@@ -49,19 +49,20 @@ function analyzeMgPipeResults(infoFilePath,resPath,varargin)
4949
mkdir(violinPath)
5050

5151
% Read in the file with sample information
52-
infoFile = readtable(infoFilePath, 'ReadVariableNames', false);
53-
infoFile = table2cell(infoFile);
52+
infoFile = readtable(infoFilePath);
53+
infoFile = [infoFile.Properties.VariableNames;table2cell(infoFile)];
5454

5555
% get all spreadsheet files in results folder
5656
dInfo = dir(resPath);
5757
fileList={dInfo.name};
5858
fileList=fileList';
5959
fileList(~contains(fileList(:,1),{'.csv','.txt'}))=[];
60+
fileList(contains(fileList(:,1),{'ModelStat'}))=[];
6061

6162
% analyze data in spreadsheets
6263
for i=1:length(fileList)
63-
sampleData = readtable([resPath filesep fileList{i}], 'ReadVariableNames', false);
64-
sampleData = table2cell(sampleData);
64+
sampleData = readtable([resPath filesep fileList{i}]);
65+
sampleData = [sampleData.Properties.VariableNames;table2cell(sampleData)];
6566

6667
% merge columns for shadow price results
6768
if strcmp(sampleData{1,2},'Source')

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function [ReactionAbundance,TaxonomyInfo] = calculateReactionAbundance(abundancePath, modelPath, infoFilePath, rxnsList, numWorkers)
1+
function [ReactionAbundance,TaxonomyInfo] = calculateReactionAbundance(abundancePath, modelPath, taxonomyPath, rxnsList, numWorkers)
22
% Part of the Microbiome Modeling Toolbox. This function calculates and
33
% plots the total abundance of reactions of interest in a given microbiome
44
% sample based on the strain-level composition.
@@ -8,14 +8,14 @@
88
%
99
% USAGE
1010
%
11-
% [ReactionAbundance,TaxonomyInfo] = calculateReactionAbundance(abundancePath, modelPath, infoFilePath, rxnsList, numWorkers)
11+
% [ReactionAbundance,TaxonomyInfo] = calculateReactionAbundance(abundancePath, modelPath, taxonomyPath, rxnsList, numWorkers)
1212
%
1313
% INPUTS:
1414
% abundancePath: Path to the .csv file with the abundance data.
1515
% Example: 'cobratoolbox/papers/018_microbiomeModelingToolbox/examples/normCoverage.csv'
1616
% modelPath: Folder containing the strain-specific AGORA models
1717
% OPTIONAL INPUTS:
18-
% infoFilePath: Path to the spreadsheet with the taxonomy
18+
% taxonomyPath: Path to the spreadsheet with the taxonomy
1919
% information on organisms (default:
2020
% AGORA_infoFile.xlsx)
2121
% rxnsList: List of reactions for which the abundance
@@ -37,8 +37,8 @@
3737
% 01/2020: adapted to be suitable for pan-models
3838

3939
% read the csv file with the abundance data
40-
abundance = readtable(abundancePath, 'ReadVariableNames', false);
41-
abundance = table2cell(abundance);
40+
abundance = readtable(abundancePath);
41+
abundance = [abundance.Properties.VariableNames;table2cell(abundance)];
4242
if isnumeric(abundance{2, 1})
4343
abundance(:, 1) = [];
4444
end
@@ -62,13 +62,12 @@
6262
end
6363

6464
% Get the taxonomy information
65-
if exist('infoFilePath','var') && ~isempty(infoFilePath)
66-
taxonomy = readtable(infoFilePath, 'ReadVariableNames', false);
67-
taxonomy = table2cell(taxonomy);
65+
if exist('taxonomyPath','var') && ~isempty(taxonomyPath)
66+
taxonomy = readtable(taxonomyPath);
6867
else
69-
taxonomy = readtable('AGORA_infoFile.xlsx', 'ReadVariableNames', false);
70-
taxonomy = table2cell(taxonomy);
68+
taxonomy = readtable('AGORA_infoFile.xlsx');
7169
end
70+
taxonomy = [taxonomy.Properties.VariableNames;table2cell(taxonomy)];
7271

7372
% load the models found in the individuals and extract which reactions are
7473
% in which model
@@ -186,48 +185,48 @@
186185
% check if the reaction is present in the strain
187186
if ReactionPresence{k, j + 1} == 1
188187
% calculate total abundance
189-
totalAbun(j) = totalAbun(j) + str2double(abundance{k, i});
188+
totalAbun(j) = totalAbun(j) + abundance{k, i};
190189
% calculate phylum abundance
191190
t = 1;
192191
findTax = taxonomy(find(strcmp(abundance{k, 1}, inputTaxa)), TaxonomyLevels{t, 3});
193192
if any(strcmp(findTax{1}, TaxonomyLevels{t, 2}))
194193
taxonCol = find(strcmp(findTax{1}, TaxonomyLevels{t, 2}));
195-
tmpPhyl(1, taxonCol) = tmpPhyl(1, taxonCol) + str2double(abundance{k, i});
194+
tmpPhyl(1, taxonCol) = tmpPhyl(1, taxonCol) + abundance{k, i};
196195
end
197196
% calculate class abundance
198197
t = 2;
199198
findTax = taxonomy(find(strcmp(abundance{k, 1}, inputTaxa)), TaxonomyLevels{t, 3});
200199
if any(strcmp(findTax{1}, TaxonomyLevels{t, 2}))
201200
taxonCol = find(strcmp(findTax{1}, TaxonomyLevels{t, 2}));
202-
tmpClass(1, taxonCol) = tmpClass(1, taxonCol) + str2double(abundance{k, i});
201+
tmpClass(1, taxonCol) = tmpClass(1, taxonCol) + abundance{k, i};
203202
end
204203
% calculate order abundance
205204
t = 3;
206205
findTax = taxonomy(find(strcmp(abundance{k, 1}, inputTaxa)), TaxonomyLevels{t, 3});
207206
if any(strcmp(findTax{1}, TaxonomyLevels{t, 2}))
208207
taxonCol = find(strcmp(findTax{1}, TaxonomyLevels{t, 2}));
209-
tmpOrder(1, taxonCol) = tmpOrder(1, taxonCol) + str2double(abundance{k, i});
208+
tmpOrder(1, taxonCol) = tmpOrder(1, taxonCol) + abundance{k, i};
210209
end
211210
% calculate family abundance
212211
t = 4;
213212
findTax = taxonomy(find(strcmp(abundance{k, 1}, inputTaxa)), TaxonomyLevels{t, 3});
214213
if any(strcmp(findTax{1}, TaxonomyLevels{t, 2}))
215214
taxonCol = find(strcmp(findTax{1}, TaxonomyLevels{t, 2}));
216-
tmpFamily(1, taxonCol) = tmpFamily(1, taxonCol) + str2double(abundance{k, i});
215+
tmpFamily(1, taxonCol) = tmpFamily(1, taxonCol) + abundance{k, i};
217216
end
218217
% calculate genus abundance
219218
t = 5;
220219
findTax = taxonomy(find(strcmp(abundance{k, 1}, inputTaxa)), TaxonomyLevels{t, 3});
221220
if any(strcmp(findTax{1}, TaxonomyLevels{t, 2}))
222221
taxonCol = find(strcmp(findTax{1}, TaxonomyLevels{t, 2}));
223-
tmpGenus(1, taxonCol) = tmpGenus(1, taxonCol) + str2double(abundance{k, i});
222+
tmpGenus(1, taxonCol) = tmpGenus(1, taxonCol) + abundance{k, i};
224223
end
225224
% calculate species abundance
226225
t = 6;
227226
findTax = taxonomy(find(strcmp(abundance{k, 1}, inputTaxa)), TaxonomyLevels{t, 3});
228227
if any(strcmp(findTax{1}, TaxonomyLevels{t, 2}))
229228
taxonCol = find(strcmp(findTax{1}, TaxonomyLevels{t, 2}));
230-
tmpSpecies(1, taxonCol) = tmpSpecies(1, taxonCol) + str2double(abundance{k, i});
229+
tmpSpecies(1, taxonCol) = tmpSpecies(1, taxonCol) + abundance{k, i};
231230
end
232231
end
233232
end

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
% .. Author: - Almut Heinken, 01/2021
3030

3131
% read the file with the abundance data
32-
abundance = readtable(abundancePath, 'ReadVariableNames', false);
33-
abundance = table2cell(abundance);
32+
abundance = readtable(abundancePath);
33+
abundance = [abundance.Properties.VariableNames;table2cell(abundance)];
3434
if isnumeric(abundance{2, 1})
3535
abundance(:, 1) = [];
3636
end
@@ -68,7 +68,7 @@
6868
microbes=abundance(2:end,1);
6969
for i=2:size(abundance,2)
7070
ReactionPresence{1,i}=abundance{1,i};
71-
microbesInModels=microbes(find(str2double(abundance(2:end,i))>0),1);
71+
microbesInModels=microbes(find(cell2mat(abundance(2:end,i))>0),1);
7272
for j=2:size(reactionInModels,1)
7373
ReactionPresence{j,1}=reactionInModels{j,1};
7474
microbesWithReaction=microbes(find(cell2mat(reactionInModels(j,2:end))==1),1);

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,36 @@
1717
% AUTHOR
1818
% - Almut Heinken, 08/2020
1919

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

23-
reactionAbundance = readtable(reactionAbundancePath, 'ReadVariableNames', false);
24-
reactionAbundance = table2cell(reactionAbundance);
23+
reactionAbundance = readtable(reactionAbundancePath);
24+
reactionAbundance = [reactionAbundance.Properties.VariableNames;table2cell(reactionAbundance)];
2525

2626
% remove biomass reaction
2727
reactionAbundance(find(strncmp(reactionAbundance(:,1),'bio',3)),:)=[];
2828

2929
% remove reactions not in dataset
30-
[C,IA]=setdiff(reactionDatabase(:,1),reactionAbundance(:,1));
31-
reactionDatabase(IA,:)=[];
30+
[C,IA]=setdiff(database.reactions(:,1),reactionAbundance(:,1));
31+
database.reactions(IA,:)=[];
3232

3333
% get and calculate all subsystems
34-
subs=unique(reactionDatabase(:,11));
34+
subs=unique(database.reactions(:,11));
3535
subs(find(strcmp(subs(:,1),'')),:)=[];
3636

3737
subsystemAbundance(1,:)=reactionAbundance(1,:);
3838
subsystemAbundance{1,1}='Subsystems';
3939

4040
for i=1:length(subs)
4141
subsystemAbundance{i+1,1}=subs{i};
42-
rxns=reactionDatabase(find(strcmp(reactionDatabase(:,11),subs{i})),1);
42+
rxns=database.reactions(find(strcmp(database.reactions(:,11),subs{i})),1);
4343
% use the fraction of abundance for all reactions in this subsystem
4444
% taken together
4545
abunTmp=zeros(1,size(reactionAbundance,2));
4646
for j=1:length(rxns)
4747
rxnInd=find(strcmp(reactionAbundance(:,1),rxns{j}));
4848
for k=2:size(reactionAbundance,2)
49-
abunTmp(k)=abunTmp(k) + str2double(reactionAbundance{rxnInd,k});
49+
abunTmp(k)=abunTmp(k) + reactionAbundance{rxnInd,k};
5050
end
5151
end
5252
for k=2:size(reactionAbundance,2)

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,37 @@
3939
% changed flux input to a csv file.
4040

4141
% read the csv file with the abundance data
42-
abundance = table2cell(readtable(abundancePath, 'ReadVariableNames', false));
42+
abundance = readtable(abundancePath);
43+
abundance = [abundance.Properties.VariableNames;table2cell(abundance)];
4344
if isnumeric(abundance{2, 1})
4445
abundance(:, 1) = [];
4546
end
4647

47-
fluxes = table2cell(readtable(fluxPath, 'ReadVariableNames', false));
48+
fluxes = readtable(fluxPath);
49+
fluxes = [fluxes.Properties.VariableNames;table2cell(fluxes)];
4850

49-
metaboliteDatabase = readtable('MetaboliteDatabase.txt', 'Delimiter', 'tab','TreatAsEmpty',['UND. -60001','UND. -2011','UND. -62011'], 'ReadVariableNames', false);
50-
metaboliteDatabase=table2cell(metaboliteDatabase);
51+
% check if data is from same samples
52+
if ~isempty(setdiff(fluxes(1,2:end),abundance(1,2:end)))
53+
error('Sample IDs in abundance and flux files do not agree!')
54+
end
55+
56+
% load database
57+
database=loadVMHDatabase;
5158

5259
fluxes(:,1)=strrep(fluxes(:,1),'EX_','');
5360
fluxes(:,1)=strrep(fluxes(:,1),'(e)','');
5461
fluxes(:,1)=strrep(fluxes(:,1),'[fe]','');
5562
% for i=2:size(fluxes,1)
56-
% fluxes{i,1}=metaboliteDatabase{find(strcmp(metaboliteDatabase(:,1),fluxes{i,1})),2};
63+
% fluxes{i,1}=database.metabolites{find(strcmp(database.metabolites(:,1),fluxes{i,1})),2};
5764
% end
5865

5966
% Get the taxonomy information
6067
if exist('infoFilePath','var')
61-
taxonomy = readtable(infoFilePath, 'ReadVariableNames', false);
62-
taxonomy = table2cell(taxonomy);
68+
taxonomy = readtable(infoFilePath);
6369
else
64-
taxonomy = readtable('AGORA_infoFile.xlsx', 'ReadVariableNames', false);
65-
taxonomy = table2cell(taxonomy);
70+
taxonomy = readtable('AGORA_infoFile.xlsx');
6671
end
72+
taxonomy = [taxonomy.Properties.VariableNames;table2cell(taxonomy)];
6773

6874
if ~exist('corrMethod', 'var') % Define correlation coefficient method if not entered
6975
corrMethod = 'Pearson';
@@ -135,7 +141,7 @@
135141
% variable
136142
findinSampleAbun = find(strcmp(findTax{1}, SampleAbundance.(TaxonomyLevels{t})(1, :)));
137143
% sum up the relative abundance
138-
SampleAbundance.(TaxonomyLevels{t}){i, findinSampleAbun} = SampleAbundance.(TaxonomyLevels{t}){i, findinSampleAbun} + str2double(abundance{j, i});
144+
SampleAbundance.(TaxonomyLevels{t}){i, findinSampleAbun} = SampleAbundance.(TaxonomyLevels{t}){i, findinSampleAbun} + abundance{j, i};
139145
end
140146
end
141147
end
@@ -217,7 +223,7 @@
217223
% translate to metabolite descriptions
218224
for t = 2:size(TaxonomyLevels, 1)
219225
for i=2:size(FluxCorrelations.(TaxonomyLevels{t}),2)
220-
FluxCorrelations.(TaxonomyLevels{t}){1,i}=metaboliteDatabase{find(strcmp(metaboliteDatabase(:,1),FluxCorrelations.(TaxonomyLevels{t}){1,i})),2};
226+
FluxCorrelations.(TaxonomyLevels{t}){1,i}=database.metabolites{find(strcmp(database.metabolites(:,1),FluxCorrelations.(TaxonomyLevels{t}){1,i})),2};
221227
end
222228
end
223229

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
% .. Author: - Almut Heinken, 04/2021
3030

3131
% read the csv file with the abundance data
32-
abundance = readtable(abundancePath, 'ReadVariableNames', false);
33-
abundance = table2cell(abundance);
32+
abundance = readtable(abundancePath);
33+
abundance = [abundance.Properties.VariableNames;table2cell(abundance)];
3434
if isnumeric(abundance{2, 1})
3535
abundance(:, 1) = [];
3636
end
@@ -106,7 +106,7 @@
106106

107107
for k = 1:length(presentRxns)
108108
% summarize total abundance
109-
totalAbun{i}(presentRxns(k),1) = totalAbun{i}(presentRxns(k),1) + str2double(abundance{j,i});
109+
totalAbun{i}(presentRxns(k),1) = totalAbun{i}(presentRxns(k),1) + abundance{j,i};
110110
end
111111
end
112112
end

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ function makeViolinPlots(sampleData, sampleInformation, varargin)
3737
unit = parser.Results.unit;
3838

3939
% read metabolite database
40-
metaboliteDatabase = readtable('MetaboliteDatabase.txt', 'Delimiter', 'tab','TreatAsEmpty',['UND. -60001','UND. -2011','UND. -62011'], 'ReadVariableNames', false);
41-
metaboliteDatabase=table2cell(metaboliteDatabase);
40+
database = loadVMHDatabase;
4241

4342
% find the column with the sample information to split the samples by
4443
if ~isempty(stratification)
@@ -66,15 +65,15 @@ function makeViolinPlots(sampleData, sampleInformation, varargin)
6665
% get the predicted metabolite
6766
varname=strrep(sampleData{i,1},'EX_','');
6867
varname=strrep(varname,'[fe]','');
69-
if ~isempty(find(strcmp(metaboliteDatabase(:,1),varname)))
70-
varname=metaboliteDatabase{find(strcmp(metaboliteDatabase(:,1),varname)),2};
68+
if ~isempty(find(strcmp(database.metabolites(:,1),varname)))
69+
varname=database.metabolites{find(strcmp(database.metabolites(:,1),varname)),2};
7170
end
7271
figure;
7372
% plot the violins
7473
% if there are nonzero values in each stratification group and the
7574
% values aren't all the same
7675
strats=unique(sampleStratification);
77-
plotdata=str2double(sampleData(i,2:end))';
76+
plotdata=cell2mat(sampleData(i,2:end))';
7877
for j=1:length(strats)
7978
valsinstrat(j)=sum(plotdata(find(strcmp(sampleStratification,strats{j}))));
8079
uniquevals(j)=numel(unique(plotdata(find(strcmp(sampleStratification,strats{j})))));
@@ -83,20 +82,19 @@ function makeViolinPlots(sampleData, sampleInformation, varargin)
8382
hold on
8483
violinplot(plotdata,sampleStratification);
8584
if length(strats) > 3
86-
set(gca, 'FontSize', 14)
85+
set(gca, 'FontSize', 12)
8786
else
88-
set(gca, 'FontSize', 18)
87+
set(gca, 'FontSize', 14)
8988
end
9089
if length(strats) > 6
9190
xtickangle(45)
9291
end
93-
box on
94-
ylim([0 max(max(str2double(sampleData(i,2:end))))])
92+
ylim([0 max(max(cell2mat(sampleData(i,2:end))))])
9593
if ~isempty(unit)
9694
h=ylabel(unit);
9795
set(h,'interpreter','none')
9896
end
99-
h=title(varname,'FontSize',24);
97+
h=title(varname,'FontSize',14);
10098
set(h,'interpreter','none')
10199
if ~isempty(plottedFeature)
102100
h=suptitle(plottedFeature);

0 commit comments

Comments
 (0)