Nutrition_modelling_toolbox¶
- calculateFoodScore(originalFood, vmhLabelMacros, vmhMetaboliteMacros, translation)[source]¶
Calculates a score based on how similar the macros of the original food are with its VMH alternative. The score is added to the vmhFood structure. The user can add on weights in the template file to prioritise or deprioritise certain macros. It is suggested to have the weight for fiber, starch and minerals always set to 0. :Usage: [vmhFood] = calculateFoodScore (originalFood, vmhFood, translation)
- Inputs:
originalFood – The filled in template file with the original food items
vmhFoodMacros – A structure with each field a food item that contain a table with their macros
- Optional input:
translation – A cell with a translation of food items to a alias. The alias is the name of the fields in vmhFoodMacros. Used to obtain the correct original food item values
- Output:
vmhFoodMacros – An updated vmhFoodMacro structure where the original food item macros and the calculated scores are added to each fields macro table
Example
[vmhFood] = calculateFoodScore(originalFood, vmhFood, translation)
Note
It is important that the template file is used as otherwise issues could arise with finding the values (starting in the 6th column), the weights (the 2nd row) and calculating the differences between the original and VMH macros.
- calculateMacroOriginalDiet(diet, originalMacroTable)[source]¶
- Calucalte the macro composition of the diet based on the original macros
given in the template file used to choose VMH food item alternatives.
- Usage:
macroDiet = calculateMacroOriginalDiet (diet, originalMacroTable)
- Inputs:
diet – A nx2 cell array. Column one has to original food names, column 2 has the respective amounts eaten
originalMacroTable – A table. The filled in template file
- Output:
macroDiet – A cell array with the total macro composition of the the given diet based on the original food item macros
Example
macroDiet = calculateMacroOriginalDiet(diet, originalMacroTable)
Note
It is important that the template file base structure is not altered as we assume the basic structure here to perform calculations
- Authors
- collectFoodItemInfo(foods2Check, foodNames, varargin)[source]¶
Function that collects the macros and flux values for VMH food suggestions found in vmhFoodFinder
- Usage:
[allFluxes, allMacros] = collectFoodItemInfo (foods2Check, varargin)
- Inputs:
foods2Check – Structure where each field for a food item contains a table with in column 1 suggested VMH food items and in column 2 the amount of food eaten
- Optional inputs
- addStarch: Boolean indicating if additional starch should be
added based on the VMH food macros. Defaults to false
- macroType: Character, stating if macros should be calculated
from ‘metabolites’ calculated flux vectors or from ‘usda’ the USDA FoodData database. Defaults to ‘metabolites’
- databaseType: Character, which database should be used currently
only USDA 2024 compatibility for USDA FoodData database. Defaults to usda
- Outputs:
allFluxes – Structure where each field is a food item containing an table with flux values for each suggested VMH food item
allMacros – Structure where each field is a food item containing an table with macros for each suggested VMH food item
- Usage:
[allFluxes, allMacros] = collectFoodItemInfo (foods2Check, foodNames, “addStarch”, true)
- compareDietPerformance(model, diets, rois, varargin)[source]¶
Function to check the effect of different diets on the possible flux range for specified reactions.
[dietPerformance] = compareDietPerformance(model, diets, rois, varargin)
Example: [dietPerformance] = compareDietPerformance(model, diets, rois, ‘optPercentage’, 0.95, ‘microbiotaExcretionBound’, 0.5)
- INPUTS:
model – COBRA model where the rois are present
diets – Cell array where each cell contains an cell array with The metabolite composition of the diet {‘met’, value}
rois – Cell array with reactions to investigate under different diets
- OPTIONAL INPUTS:
optPercentage – Integer, used in fluxVariability to indicate the percentage of the objective for which FVA is solved. Defaults to 99
microbiotaExretionBound – Integer, used to constrain both bounds of Excretion_EX_microbiota_LI_biomass. Defaults to 1
dietNames – Cell array with names for diets in that will be used in the output. Defaults to Diet1, Diet2 etcetc.
- OUTPUT:
dietPerformance – Table for each given diet, the min and max flux for each roi.
- compareDiets(diet1, diet2, one2Two)[source]¶
Calculates the changes in metabolite flux composition between two diets. It also calculates unique metabolites in each diets. It defaults to calculating the differences in diet2 from diet1
[fluxChanges, uniqueDiet1, uniqueDiet2] = compareDiets(diet1,diet2,one2Two)
Example: compareDiets(diet1,diet2,false)
- INPUTS:
diet1 – A cell array with the first column the metabolite identifiers and the second with flux values as doubles or strings
diet2 – A cell array with the first column the metabolite identifiers and the second with flux values as doubles or strings
- OPTIONAL INPUTS:
one2Two – true(0) or false(1) to state if the default of calculating the differences in diet2 from diet1 should be used. If false(0) differences in diet1 from diet2 will be calculated.
- OUTPUT:
fluxChanges – Cell array with the first column the metabolite identifier and the second column the changed flux value
uniqueDiet1 – Cell array with unique metabolites in diet1 compared to diet2
uniqueDiet2 – Cell array with unique metabolites in diet2 compared to diet1
- createFridaDatabase(path2Files, varargin)[source]¶
Creation of flux tables and macro tables to be used in the nutrition toolbox for the Frida database. Food data (frida.fooddata.dk), National Food Institute, Technical University of Denmark.
- Usage:
createUSDAdatabase (path2Files, varargin)
- Inputs
path2Files: Character array; The directory where the the required input files for Frida are stored
- Optional inputs:
outputDir – Character array; THe directory where the results should be
saved
Example
createUSDAdatabase(path2Files)
- createUSDAdatabase(path2Files, varargin)[source]¶
Creates the files used in the nutrition toolbox from the USDA fooddata central database. This can be downloaded from https://fdc.nal.usda.gov/download-datasets.html This function was created based on the april 2024 Full Download of All Data Types
- Usage:
createUSDAdatabase (path2Files, varargin)
- Inputs
- path2Files: Path to the directory where all the USDA fooddata
files are stored. As well as the usdaNutrientVmhTransl file found in the cobra toolbox
- Optional inputs:
brandedFoods – Boolean, if the food source table of the branded foods should be created. Defaults to false. Warning putting this to true could take days of running the code as it will have to convert almost 2 million items
outputDir – Path to the directory where the individual food source databases should be stored. Defaults to [path2files , filesep, foodSourceNutrientTables]
finalDatabaseDir – Path to the directory where the final flux and macro databases should be stored. Defaults to [path2files, filesep, fluxMacroTables]
foodSource2Use – Cell array of with food source tables are to be used to create the final flux and macro databases. Defaults to {‘sr_legacy_food’;’foundation_food’;’survey_fndds_food’}
Example
createUSDAdatabase(path2Files)
- extractDietFromModel(model)[source]¶
This function analysis an VMH model and extracts the diet based on the lower bound constraints.
- USAGE:
[foodMenu] = extractDietFromModel(model)
- INPUT:
model: A human model (WBM)
- OUTPUT:
- foodMenu: A nx2 cell array containing n dietary metabolites and their
corresponding flux
- Authors:
Bronson R. Weston, 2022
- findViableDiet(model, targetString, varargin)[source]¶
Identifies changes to the diet that must be made for viability. If no solution is possible for viability, returns NaN.
[viableModel,pointsModel,pointsSln,dietChanges] = findViableDiet(model,targetString,varargin)
Example: findViableDiet(modelHM,’Diet_EX_’,’supplyScalar’,100,’lbValues’,-5)
- INPUTS:
model – COBRA model to make viable
targetString – String identifier for targeted reactions (e.g., ‘EX_’)
- generateInSilicoDiet(toCreateDiet, varargin)[source]¶
Code to take the input and creates a in silico diet. It calculates the metabolite flux vector that can be set as dietary constraints on the WBMs. Additionaly it calculates the macros from the metabolite flux vector and retrieves the macros as reported for the various food items. This way a comparison can be made to see how much of measured metabolites reflect the reported macros. If the macros for the original diets are given, they are taken along in the comparison. A calculation on the % of how much carbohydrates/lipids/proteins are contributing to the total energy of the diet. :Usage: [dietFlux] = generateInSilicoDiet (toCreateDiet, varargin)
- Inputs:
toCreateDiet – Path to the file with the diets that need to be created. consist of column “originalName” where the orignal food names are set. “databaseID” the ID of the fooditem in their database. “databaseUsed” which database was used to find that database alternative. Each column after is a diet where the values in gram show the food items consumed for each diet.
- Optional input:
outputDir – Path to the directory where the results should be stored. Defaults to ‘’.
originalDietMacros – Path to the file with the original macros for each diet. Should contain the rows lipids, carbohydrate, protein and energy. Defaults to ‘’.
analyseMacros – Boolean, indicates if analysis on macros should be performed. Defaults to true.
addStarch – Boolean, indicates if additional starch should be added based on the reported macros. Defaults to false.
- Output:
dietFlux – Table, contains the dietary flux in mmol/person/day for each diet and the dietary reactions that have to be set.
Example
[vmhFood] = calculateFoodScore(originalFood, ‘outputDir’, outputDir)
Note
The tutorial folder on the COBRA toolbox provides various template files with the structure of how the data should be formatted. Please look there for guidance.
- getDietComposition(input, varargin)[source]¶
This function takes a diet (or a model) and identifies the food macros
- USAGE:
[Macros,Categories] = getDietComposition (input)
- INPUT:
input – either a whole-body metabolic model or a diet
- OPTIONAL INPUT
- macroType: Which type of data is used to calculate macros. Currently
accepted is fdtable, metabolites and usda
- OUTPUT:
dietComposition – A table containing the breakdown of the diet macros
AUTHORS
Bronson R. Weston 2021-2022 Bram Nap 05-2024 - added additional functionilty for getting composition when the input are metabolites and when the USDA fooddata central database reported macros are wanting to be used. Removed fdTable functionality.
- getDietEnergy(diet, varargin)[source]¶
Given a nx2 cell array of diet components and serving sizes or metabolite list, computes how many calories are in the diet.
- Usage:
[calories] = getDietEnergy (diet, varargin)
- Inputs:
diet – A nx2 array of diet components and the grams of food eaten or the dietary flux names with the flux values
- Optional inputs:
databaseType – Character or cell array. Which method should be used to obtain calories. Options are metabolite (based on flux values) or database (cell array with ‘usda’ or ‘frida’ for each food item to be checked)
- Output:
calories – Amount of calories from the input
Example:
- getMetaboliteFlux(diet, varargin)[source]¶
This function takes a diet consisting of food items and returns the associated flux of metabolites.
- USAGE:
[metFlux] = getMetaboliteFlux (diet)
- INPUT:
diet – an nx2 cell array consisting of n dietary/food components and their corresponding flux in grams (for food items) or mmol (for individual metabolites) per day.
- Optional input:
databaseType – Which database should be used, either fdtable or usda. Corresponds to an inhouse table or the USDA foodData database. Defaults to usda
addStarch – Boolean wether or not additional starch should be added to the flux vector when it is not measured in the macros
- OUTPUT:
metFlux – returns an nx2 cell array containing a list of all n metabolites within the diet and the corresponding flux.
AUTHORS
Bronson R. Weston 2022 Bram Nap, 05-2024 - Added on functionality to work with the FoodData central database and add on missing starch functionalities. Removed FdTable functionality. 02-2025 added Frida database functionality and mixed database calculations
- makeDietFormatConsistant(model, diet)[source]¶
This function takes a diet input and checks it for formatting consisteny for input into setFoodConstraints
- USAGE:
[diet] = makeDietFormatConsistant (model,diet)
- INPUTS
model: A COBRA model
- diet: A nx2 cell array containing n dietary components and
the corresponding flux
- OUTPUT
diet: A diet of consistent format for setFoodConstraints
Authors
Bronson R. Weston 2022
- normalizeDiet(foodMenu, calories, exceptions)[source]¶
This function normalizes a diet to meet caloric specifications.
- USAGE:
[foodMenu] = normalizeDiet (foodMenu,calories,exceptions)
- INPUTS
- foodMenu: An nx2 cell array containing the food items and the
corresponding flux (n= number of food items)
- calories The number of calories the diet should be
renormalized to
- exceptions: A cell array containing any specific food items that
should be excluded from the renormalization step. This maintains the flux for the specefied food items.
- OUTPUT
foodMenu: An re-normalized version of the original foodMenu
Authors
Bronson R. Weston 2022
- nutritionAlgorithmWBM(model, obj, objMinMax, rois, roisMinMax, options)[source]¶
Identifies the minimal changes to a diet necessary to get a desired change in one or more reactions of interest. One may enter a metabolite of the pointsModel instead of a reaction and the algorithm will optimize the diet with a sink or demand reaction for the corresponding metabolite of interest.
- USAGE:
[newDietModel,pointsModel,slnMin,slnMax,pointsModelSln,itemsRemoved,itemsAdded] = nutritionAlgorithmWBM (pointsModel,obj,objMinMax,rois,roisMinMax,options) – Example: [newDietModel,pointsModel,roiFlux,pointsModelSln,itemsRemoved,itemsAdded] = nutritionAlgorithmWBM(WBmodel,’Whole_body_objective_rxn’,’max’,{},{})
- INPUTS:
- pointsModel – COBRA pointsModel structure with the fields:
.S
.b
.ub
.ub
.mets (required if pointsModel.SIntRxnBool absent)
.rxns (required if pointsModel.SIntRxnBool absent)
obj: organism’s objective function
objMinMax: minimize (‘min’) or maximize (‘max’) objective function
rois: cell array of all reactions of interest
roisMinMax: cell array of ‘min’/’max’ entries for rois
- OPTIONAL INPUTS:
options – Structure containing the optional specifications:
.foodOrMets: dictates if the algorithm adds individual
metabolites to the diet or food items. Default is food items. “Food Cat” adjust algorithm to identify categories of food rather than specific items.”AllMets” allows any dietary metabolite into the solution and “FoodMets” only allows metabolites that are in the fdTable spreadsheet into the solution. Possible inputs are: “Food”, “AllMets”, “FoodMets”.
.roiWeights: a vector of weights for each reaction of interest
default is equal to 1
.weightedFoodItems: A cell vector that specifies any food items
or metabolites that should be weighted and the corresponding weight.
.initObjSln: provide an initial solution for the objective
function. Output from optimizeWBmodel.
.caloricRange: 1x2 vector defining boundries for diet calories
- .slnType: Specify if solution should be ‘Detailed’ or ‘Quick’.
Default setting is ‘Detailed’
.roiBound: ‘Unbounded’ or ‘Bounded’. Default is ‘Bounded’.
- .foodAddedLimit: Specify a limit for the units of food that can
be added to the diet
- .foodRemovedLimit: Specify a limit for the units of food that can
be removed from the diet
.freeMets: Specifies any metabolites that should be freely
available to the model.
.graphicalAnalysis: set to ‘True’ include graphical analysis and
‘False’ to not include. Default is ‘False’ if .slnType is set to ‘Quick but is ‘True; if .slnType is ‘Detailed’.
.removeFoodItem: A nx2 cell array with the first column the food
item ID and the second column the name of the database of the food items that should be removed from the analysis
.addPrice: a nx3 cell array with the first column the food item
ID, the second column the name of the database, and in the third column the price (any currency) associated with that food item. Allows for optimizing the price of a diet, but only if enough information is available.
- OUTPUT:
newDietModel
pointsModel
roiFlux
pointsModelSln
menuChanges
macroChanges
roiChanges
usda and frida database. Enabled options for constraints with various macronutrients. Removed old/not used code. Added additional outputs for the user to better store and interpret the results. Set up the options and initialise variables
- searcher(keyWords, database, varargin)[source]¶
Function that searches a database based on keywords with one of two search strategies
- Usage:
[output] = searcher (keyWords, database, varargin)
- Inputs:
keyWords – Array of string that are to be used to search with
database – Table of a database that has to be searched
- Optional inputs:
searchType – Method of searching keywords in the food database. Either iterative or cumulative. Defaults to iterative
notInclude – Key words that exclude items. Defaults to an empty cell array.
- Output:
output – A cell array with the matches found in the database
Example
[output] = searcher(keyWords, database, “searchType”, ‘cumulative’)
- setFoodRxnsWbm(wbm, database, resetDietBounds, addPrice)[source]¶
Adjusts a WBM so that it can exchange food items and break them down into their respective metabolite components. Used to prepare WBMs to accept fooditem consumed weights as dietary input. :Usage: [wbm] = setFoodRxnsWbm (diet, wbm)
- Inputs:
diet – cell array with the databases where food items originated from. the USDA, FRIDA or both databases should be used to add food items on
wbm – A WBM model
resetDietBounds – Boolean, indicate if all Diet_EX_ reactions are set to 0, defaults to true.
addPrice
- Output:
wbm – An updated WBM model with food exchange and breakdown reactions.
Example
[wbm] = setFoodRxnsWbm(diet, wbm)
- setInSilicoDiet(dietToSet, varargin)[source]¶
Code to set either the dietary flux vector as a diet or the food items themselves on WBMs. The WBMs can either be the default Harvey/Harvetta or custom ones. The models are saved in specific folders and there is possibility to test the feasibility on the given diets for these models.
- Usage:
setInSilicoDiet (dietToSet, varargin)
- Inputs:
dietToSet – Path to the file with the diets that need to be created. consist of column “originalName” where the orignal food names are set. “foodName” the name of the database alternatives. “databaseID” the ID of the fooditem in their database. “databaseUsed” which database was used to find that database alternative. Each column after is a diet where the values in gram show the food items consumed for each diet.
- Optional input:
metadataPath – Path to the metadata file path. Should contain the columns “ID”, “sex” and “Diet”. Defaults to ‘’.
outputDir – Path to the directory where the results should be stored. Defaults to ‘’.
constrainFoodWBM – Boolean, indicates if food item exchange reactions and food item breakdown reactions should be added to the WBMs. The grams of food item consumed are then used as exchange flux of the food items. This should only be used to make queries on the composition of food items on the diet as the models become bulky. Works well with the nutrition algorithm. Defaults to false.
constrainFluxWBM – Boolean, indicates if the the diet flux vector should be set on the WBMs. Defaults to true.
checkFeasibility – Boolean, indicates if WBMs should be checked for feasibility. Defaults to true.
wbmVersion – The version of a specific WBM to use. Do not start with ‘_’. Defaults to ‘’ and thus latest version is loaded.
pathToWbms – If non standard Harvey Harvetta models are used indicate where they are stored. If there is a changed general female and male model ensure that _male and _female are present in the filename. Otherwise ensure that sample ID is present in the name that corresponds with the metadata.
Example
setInSilicoDiet(dietToSet, ‘checkFeasibility’, false)
Note
The tutorial folder on the COBRA toolbox provides various template files with the structure of how the data should be formatted. Please look there for guidance.
- vmhFoodFinder(templateFilePath, varargin)[source]¶
Finding VMH food alternatives to original food items based on key words or pre-selected VMH food items.
- Usage:
[output, fluxValues] = vmhFoodFinder (templateFilePath, varargin)
- Inputs:
templateFilePath – Path to the filled in template file
- Optional Inputs:
searchType – Method of searching keywords in the food database. Either iterative or cumulative. Defaults to iterative
addStarch – Boolean indicating if additional starch should be added based on the VMH food macros. Defaults to false
databaseType – Character, which database should be used either ‘usda’ for USDA FoodData database or ‘frida’ for the Danish food institute database. Can be ‘mixed’ if both databases should be used.
maxItems – Numeric, value indicating what the max amount of VMH food alternatives will be analysed for macros. Defaults to 50
outputDir – Path to where the output file will be stored. Defaults to [pwd filesep ‘NT_Result’]
foodSources2Use – Cell of strings, dictates which food sources from the USDA database will be used to find food items. Defaults to {‘sr_legacy_food’; ‘foundation_food’; ‘survey_fndds_food’};
- Output:
scoredFoods – A structure where each field is a fooditem and contains a table with the macro values of the original food items and the VMH alternatives. The score calculate based on similarity witht the original food item is present as well.
fluxValues – A structure where each field is a fooditem containing the calculated flux vector based on the amount eaten
Example
[output, fluxValues] = vmhFoodFinder(templateFilePath, ‘addStarch’, true)