Skip to content

Commit

Permalink
Added getElementalMatrix function
Browse files Browse the repository at this point in the history
  • Loading branch information
Anand committed Mar 25, 2015
1 parent 65b137e commit 519527e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
34 changes: 24 additions & 10 deletions Toolbox/Core.m
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
9 changes: 7 additions & 2 deletions Toolbox/UsageStrings.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(*Usage strings*)


(* ::Subsection:: *)
(* ::Subsection::Closed:: *)
(*Options*)


Expand Down Expand Up @@ -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*)


Expand All @@ -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*)

Expand Down

0 comments on commit 519527e

Please sign in to comment.