From b3492e45855e8dff4a8bcc4264e5c0f77f8d4557 Mon Sep 17 00:00:00 2001 From: Almut Heinken Date: Fri, 11 Oct 2024 00:38:00 +0200 Subject: [PATCH] Fixed some bugs in DEMETER/mgPipe --- .../additionalAnalysis/analyzeMgPipeResults.m | 8 ++++---- .../additionalAnalysis/makeViolinPlots.m | 13 +++++++++--- .../mgPipe/createPanModels.m | 20 +++++++++++++++---- .../testCreatePanModels.m | 6 ++++-- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/analysis/multiSpecies/microbiomeModelingToolbox/additionalAnalysis/analyzeMgPipeResults.m b/src/analysis/multiSpecies/microbiomeModelingToolbox/additionalAnalysis/analyzeMgPipeResults.m index 8bfadd3f13..6ccc05087c 100755 --- a/src/analysis/multiSpecies/microbiomeModelingToolbox/additionalAnalysis/analyzeMgPipeResults.m +++ b/src/analysis/multiSpecies/microbiomeModelingToolbox/additionalAnalysis/analyzeMgPipeResults.m @@ -112,9 +112,9 @@ function analyzeMgPipeResults(infoFilePath,resPath,varargin) % Print the results as a text file filename = strrep(fileList{i},'.csv',''); filename = strrep(filename,'.txt',''); - writetable(cell2table(Statistics),[statPath filesep filename '_' sampleGroupHeaders{j} '_Statistics'],'FileType','text','WriteVariableNames',false,'Delimiter','tab'); + writetable(cell2table(Statistics),[statPath filesep filename '_' sampleGroupHeaders{j} '_Statistics.csv'],'WriteVariableNames',false); if size(significantFeatures,2)>1 - writetable(cell2table(significantFeatures),[statPath filesep filename '_' sampleGroupHeaders{j} '_SignificantFeatures'],'FileType','text','WriteVariableNames',false,'Delimiter','tab'); + writetable(cell2table(significantFeatures),[statPath filesep filename '_' sampleGroupHeaders{j} '_SignificantFeatures.csv'],'WriteVariableNames',false); end % create plots @@ -133,9 +133,9 @@ function analyzeMgPipeResults(infoFilePath,resPath,varargin) % Print the results as a text file filename = strrep(fileList{i},'.csv',''); filename = strrep(filename,'.txt',''); - writetable(cell2table(Statistics),[statPath filesep filename '_Statistics'],'FileType','text','WriteVariableNames',false,'Delimiter','tab'); + writetable(cell2table(Statistics),[statPath filesep filename '_Statistics.csv'],'WriteVariableNames',false); if size(significantFeatures,2)>1 - writetable(cell2table(significantFeatures),[statPath filesep filename '_SignificantFeatures'],'FileType','text','WriteVariableNames',false,'Delimiter','tab'); + writetable(cell2table(significantFeatures),[statPath filesep filename '_SignificantFeatures.csv'],'WriteVariableNames',false); end % create violin plots diff --git a/src/analysis/multiSpecies/microbiomeModelingToolbox/additionalAnalysis/makeViolinPlots.m b/src/analysis/multiSpecies/microbiomeModelingToolbox/additionalAnalysis/makeViolinPlots.m index cd0094afa6..6c4db5c06a 100755 --- a/src/analysis/multiSpecies/microbiomeModelingToolbox/additionalAnalysis/makeViolinPlots.m +++ b/src/analysis/multiSpecies/microbiomeModelingToolbox/additionalAnalysis/makeViolinPlots.m @@ -54,9 +54,16 @@ function makeViolinPlots(sampleData, sampleInformation, varargin) cnt=1; delArray=[]; for i=2:size(sampleData,1) - if sum(str2double(sampleData(i,2:end)))<0.0001 - delArray(cnt,1)=i; - cnt=cnt+1; + if contains(version,'R202') % for MATLAB 2020a or newer + if sum(cell2mat(sampleData(i,2:end)))<0.0001 + delArray(cnt,1)=i; + cnt=cnt+1; + end + else + if sum(str2double(sampleData(i,2:end)))<0.0001 + delArray(cnt,1)=i; + cnt=cnt+1; + end end end sampleData(delArray,:)=[]; diff --git a/src/analysis/multiSpecies/microbiomeModelingToolbox/mgPipe/createPanModels.m b/src/analysis/multiSpecies/microbiomeModelingToolbox/mgPipe/createPanModels.m index 6740d11b88..a6810ac78a 100755 --- a/src/analysis/multiSpecies/microbiomeModelingToolbox/mgPipe/createPanModels.m +++ b/src/analysis/multiSpecies/microbiomeModelingToolbox/mgPipe/createPanModels.m @@ -1,4 +1,4 @@ -function createPanModels(agoraPath, panPath, taxonLevel, agoraVersion, numWorkers) +function createPanModels(agoraPath, panPath, taxonLevel, agoraVersion, numWorkers, builtTaxa) % This function creates pan-models for all unique taxa (e.g., species) % included in the AGORA resource. If reconstructions of multiple strains % in a given taxon are present, the reactions in these reconstructions will @@ -23,16 +23,22 @@ function createPanModels(agoraPath, panPath, taxonLevel, agoraVersion, numWorker % created pan-models will be stored in. Must end with a file separator. % taxonLevel String with desired taxonomical level of the pan-models. % Allowed inputs are 'Species','Genus','Family','Order', 'Class','Phylum'. -% agoraVersion Version of AGORA that will be used (allowed inputs: 'AGORA', 'AGORA2') +% agoraVersion Version of AGORA that will be used (allowed inputs: 'AGORA', 'AGORA2', +% alternatively: path to custom table with reconstruction information) % % OPTIONAL INPUTS % numWorkers Number of workers for parallel pool (default: no pool) +% builtTaxa Names of taxa in table that will be built (default: +% all). Need to be entered as a cell array of strings with names written +% exactly as in the corresponding column in the table. % % .. Authors % - Stefania Magnusdottir, 2016 % - Almut Heinken, 06/2018: adapted to function. % - Almut Heinken, 03/2021: enabled parallelization % - Almut Heinken, 05/2024: enforced specifying AGORA version +% - Almut Heinken, 10/2024: allowed specifying input table and taxa +% to create tol = 1e-5; @@ -58,13 +64,13 @@ function createPanModels(agoraPath, panPath, taxonLevel, agoraVersion, numWorker solver = CBT_LP_SOLVER; environment = getEnvironment(); -% load the file with information on AGORA/AGORA2 +% load the file with information on AGORA/AGORA2 or custom table if strcmp(agoraVersion,'AGORA') infoFile = readInputTableForPipeline('AGORA_infoFile.xlsx'); elseif strcmp(agoraVersion,'AGORA2') infoFile = readInputTableForPipeline('AGORA2_infoFile.xlsx'); else - error('Incorrect input for agoraVersion! Allowed inputs: AGORA, AGORA2') + infoFile = readInputTableForPipeline(agoraVersion); end % get the reaction and metabolite database @@ -78,6 +84,12 @@ function createPanModels(agoraPath, panPath, taxonLevel, agoraVersion, numWorker allTaxa(strncmp(allTaxa, 'unclassified', 12)) = []; allTaxa(strcmp(allTaxa, '')) = []; +% reduce to specified list of taxa to build if entered +if nargin >5 + [~,I] = setdiff(allTaxa,builtTaxa); + allTaxa(I,:) = []; +end + % Remove models that have already been assembled from the list of models to create dInfo = dir(panPath); dInfo = dInfo(~[dInfo.isdir]); diff --git a/test/verifiedTests/analysis/testMultiSpeciesModelling/testCreatePanModels.m b/test/verifiedTests/analysis/testMultiSpeciesModelling/testCreatePanModels.m index dfa0f901cb..852fddf93a 100644 --- a/test/verifiedTests/analysis/testMultiSpeciesModelling/testCreatePanModels.m +++ b/test/verifiedTests/analysis/testMultiSpeciesModelling/testCreatePanModels.m @@ -26,7 +26,8 @@ % create the pan-models on species level panPath=[pwd filesep 'panSpeciesModels']; -createPanModels(modPath,panPath,'Species','AGORA',numWorkers); +builtTaxa = {'Acinetobacter junii','Bacteroides ovatus','Enterobacter cloacae','Megasphaera elsdenii','Ruminococcus flavefaciens'}; +createPanModels(modPath,panPath,'Species','AGORA_infoFile.xlsx',numWorkers,builtTaxa) % test that pan-models can grow [notGrowing,Biomass_fluxes] = plotBiomassTestResults(panPath, 'pan-models','numWorkers',numWorkers); @@ -40,7 +41,8 @@ % create the pan-models on genus level panPath=[pwd filesep 'panGenusModels']; -createPanModels(modPath,panPath,'Genus','AGORA',numWorkers); +builtTaxa = {'Acinetobacter','Bacteroides','Megasphaera','Ruminococcus'}; +createPanModels(modPath,panPath,'Genus','AGORA_infoFile.xlsx',numWorkers,builtTaxa); % test that pan-models can grow [notGrowing,Biomass_fluxes] = plotBiomassTestResults(panPath, 'pan-models','numWorkers',numWorkers);