diff --git a/Toolbox/Core.m b/Toolbox/Core.m index a051070..412d150 100644 --- a/Toolbox/Core.m +++ b/Toolbox/Core.m @@ -1366,21 +1366,35 @@ Options[elementallyBalancedQ]={"ElementalComposition"->{},"RemoveExchanges"->True}; elementallyBalancedQ::notBalanced="The following reactions are not balanced: `1`."; elementallyBalancedQ[model_MASSmodel,opts:OptionsPattern[]]:=Module[{balancing,exclude}, -If[OptionValue["RemoveExchanges"], -exclude=model["Exchanges"];, -exclude={}; -]; -balancing=Thread[Rule[model["Reactions"],Expand/@((model["Species"]/.Dispatch[updateRules[model["ElementalComposition"],OptionValue["ElementalComposition"]]]).model["Stoichiometry"])]]; -balancing=DeleteCases[balancing,r_Rule/;MemberQ[exclude,r[[1]]]]; -If[ -(Round[Total[balancing[[All,2]]]]==0.), -True, -Message[elementallyBalancedQ::notBalanced,SlideView[Rule@@@Cases[balancing,r_Rule/;Round[r[[2]]]=!=0],AppearanceElements->All]];False] + If[OptionValue["RemoveExchanges"], + exclude=model["Exchanges"];, + exclude={}; + ]; + balancing=Thread[Rule[model["Reactions"],Expand/@((model["Species"]/.Dispatch[updateRules[model["ElementalComposition"],OptionValue["ElementalComposition"]]]).model["Stoichiometry"])]]; + balancing=DeleteCases[balancing,r_Rule/;MemberQ[exclude,r[[1]]]]; + If[ + (Round[Total[balancing[[All,2]]]]==0.), + True, + Message[elementallyBalancedQ::notBalanced,SlideView[Rule@@@Cases[balancing,r_Rule/;Round[r[[2]]]=!=0],AppearanceElements->All]]; + False + ] ]; +Options[getElementalMatrix]={"TableForm"->True}; +getElementalMatrix[model_MASSmodel,opts:OptionsPattern[]]:=Module[{elemList,elements,matrix}, + elemList=List/@(model["Species"]/.model["ElementalComposition"])/.Plus->Sequence; + elements=DeleteDuplicates@Flatten[elemList/._?NumericQ->1]; + matrix=Flatten/@Table[Cases[#,(x_*elem|elem)]&/@elemList/.{}->{0},{elem,elements}]/._String->1; + If[OptionValue[TableForm]==True, + Framed@TableForm[matrix,TableHeadings->{elements,model["Species"]}], + {elements,matrix} + ] +]; + + (*Gevorgyan,A.,Poolman,M.G.,& Fell,D.A.(2008).Detection of stoichiometric inconsistencies in biomolecular models Bioinformatics (Oxford,England),24(19),2245\[Dash]2251. doi:10.1093/bioinformatics/btn425*) Options[stoichiometricallyConsistentQ]={"Solver"->LinearProgramming}; diff --git a/Toolbox/UsageStrings.m b/Toolbox/UsageStrings.m index c1de5cb..c941d66 100644 --- a/Toolbox/UsageStrings.m +++ b/Toolbox/UsageStrings.m @@ -4,7 +4,7 @@ (*Usage strings*) -(* ::Subsection:: *) +(* ::Subsection::Closed:: *) (*Options*) @@ -368,7 +368,7 @@ subModel::usage="subModel[model, {rxn1, rxn2, ...}] will extract a sub-model consisting of the specified reactions."; -(* ::Subsection::Closed:: *) +(* ::Subsection:: *) (*QC/QA*) @@ -378,9 +378,14 @@ elementallyBalancedQ::usage="Checks if provided model is elementally balanced."; +getElementalMatrix::usage="getElementalMatrix[model] displays a formatted elemental matrix for the model. Use TableForm->False for the raw matrix."; + + stoichiometricallyConsistentQ::usage="Checks the stochiometric consistency of provide matrix or model (see Gevorgyan, A., Poolman, M. G., & Fell, D. A. (2008). Detection of stoichiometric inconsistencies in biomolecular models Bioinformatics (Oxford, England), 24(19), 2245\[Dash]2251. doi:10.1093/bioinformatics/btn425)."; + + (* ::Subsection::Closed:: *) (*Chemoinformatics*)