The moiety_modeling API Reference¶
Routines for working with moiety modeling.
This package includes the following modules:
modeling
- This module provides the
Dataset
class to organize a single mass spectroscopy profile dataset into a dictionary-based data structure, theModelOptimization
and derived classes for performing a single model optimization, and theOptimizationManager
class to manage the optimization process of moiety modeling. model
- This module provides the
Moiety
,Molecule
,Relationship
, andModel
classes for representing a moiety model. analysis
- This module provides several classes to analyze the optimization results, select the optimal model, and visualize the
results. The
ResultAnalysis
class is responsible for generating general statistics from the optimization results. TheModelRank
class selects the model that best reflects the observed isotopologue profile. TheComparisonTable
class compares the optimal model selected under different optimization settings. ThePlotMoietyDistribution
class plots the distribution of moiety value of the moiety model. ThePlotIsotopologueIntensity
class plots comparison of the observed and the calculated isotopologue intensity. cli
- This module provides a command-line interface for the
moiety_modeling
package.
moiety_modeling.modeling¶
This module provides the Dataset
class to organize a single mass spectroscopy isotopologue
profile dataset into a dictionary-based data structure, the ModelOptimization
and derived
classes for performing a single model optimization, and the OptimizationManager
class
to manage the optimization process of moiety modeling.
The optimization results are stored in the JSON file. A txt file containing all the paths to the generated JSON
files is
created to facilitate further model analysis.
-
class
moiety_modeling.modeling.
Dataset
(datasetName, *args, **kwargs)[source]¶ Dataset class that stores a single mass spectroscopy isotopologue profile in the form of
UserDict
.
-
class
moiety_modeling.modeling.
ModelOptimization
(model, datasets, path, methodParameters, optimizationSetting, energyFunction)[source]¶ The abstract
ModelOptimization
class.-
__init__
(model, datasets, path, methodParameters, optimizationSetting, energyFunction)[source]¶ ModelOptimization initializer.
Parameters: - model (
Model
) – aModel
instance. - datasets (list) – a list of
Dataset
instances. - path (str) – the subdirectory path to save the optimization results.
- methodParameters (dict) – the parameters for optimization method.
- optimizationSetting (str) – abbreviated name for the optimization.
- energyFunction (str) – the energy function used in the optimization.
- model (
-
energyCalculation
(vector)[source]¶ Calculate the energy of the model.
Parameters: vector (list) – a list of model parameter values. Return double: the energy.
-
absDifferenceEnergyFunction
(moietyStateValue, dataset)[source]¶ The absolute difference energy function. The absolute value between the observed and the calculated isotopologues: energy = sum(|I<cal> - I<obs>|).
Parameters: Returns: the energy of the model.
Return type: double
-
logDifferenceEnergyFunction
(moietyStateValue, dataset)[source]¶ The log difference energy function. The difference between the log of observed and the calculated isotopologues: energy = sum(|log(I<cal>) - log(I<obs>)|)
Parameters: Returns: the energy of the model.
Return type: double
-
squareDifferenceEnergyFunction
(moietyStateValue, dataset)[source]¶ The absolute difference energy function. The absolute value between the observed and the calculated isotopologues: energy = sum(|I<cal> - I<obs>|).
Parameters: Returns: the energy of the model.
Return type: double
-
AICDifferenceEnergyFunction
(moietyStateValue, dataset)[source]¶ The absolute difference energy function. The absolute value between the observed and the calculated isotopologues: energy = sum(|I<cal> - I<obs>|).
Parameters: Returns: the energy of the model.
Return type: double
-
-
class
moiety_modeling.modeling.
SAGAoptimization
(model, datasets, path, methodParameters, optimizationSetting, energyFunction, noPrintBestResults, noPrintAllResults)[source]¶ The
SAGAoptimization
class (for combined datasets) inherited fromModelOptimization
.-
__init__
(model, datasets, path, methodParameters, optimizationSetting, energyFunction, noPrintBestResults, noPrintAllResults)[source]¶ SAGAoptimization initializer.
Parameters: - model (
Model
) – aModel
instance. - datasets (list) – a list of
Dataset
instances. - path (str) – the path to save the optimization results.
- methodParameters (dict) – the parameters for optimization method.
- optimizationSetting (str) – abbreviated name for the optimization.
- energyFunction (str) – the energy function used in the optimization.
- noPrintBestResults (int) – not to save the all the best results of the optimization process.
- noPrintAllResults (int) – not to save the all the results of the optimization process.
- model (
-
bestResultsFile
(i)[source]¶ Open the file to record the best results during the optimization process.
Parameters: i (int) – the ith optimization. Returns: the file handler. Return type: TextIOWrapper
-
allResultsFile
(i)[source]¶ Open the file to record the all optimization results.
Parameters: i (int) – the ith optimization. Returns: the file handler. Return type: TextIOWrapper
.
-
-
class
moiety_modeling.modeling.
SAGAseparateOptimization
(model, datasets, path, methodParameters, optimizationSetting, energyFunction, noPrintBestResults, noPrintAllResults)[source]¶ The
SAGAseparateOptimization
class (for split dataset) inherited fromSAGAoptimization
.-
__init__
(model, datasets, path, methodParameters, optimizationSetting, energyFunction, noPrintBestResults, noPrintAllResults)[source]¶ SAGAseparateOptimization initializer.
Parameters: - model (
Model
) – aModel
instance. - datasets (list) – a list of
Dataset
instances. - path (str) – the path to save the optimization results.
- methodParameters (dict) – the parameters for optimization method.
- optimizationSetting (str) – abbreviated name for the optimization.
- energyFunction (str) – the energy function used in the optimization.
- noPrintBestResults (int) – not to save the all the best results of the optimization process.
- noPrintAllResults (int) – not to save the all the results of the optimization process.
- model (
-
-
class
moiety_modeling.modeling.
ScipyGuess
(elements, energy)[source]¶ To convert optimization results to
Guess
instance.
-
class
moiety_modeling.modeling.
ScipyOptimization
(model, datasets, path, methodParameters, optimizationSetting, energyFunction, method)[source]¶ The
ScipyOptimization
class (for combined datasets) inherited fromModelOptimization
.-
__init__
(model, datasets, path, methodParameters, optimizationSetting, energyFunction, method)[source]¶ ScipyOptimization initializer.
Parameters: - model (
Model
) – theModel
instance. - datasets (list) – a list of
Dataset
instances. - path (str) – the path to save the optimization results.
- methodParameters (dict) – the parameters for optimization method.
- optimizationSetting (str) – abbreviated name for the optimization.
- energyFunction (str) – the energy function used in the optimization.
- method (str) – the scipy optimization method.
- model (
-
optimizeSingle
(i)[source]¶ To perform one optimization.
Parameters: i – the ith optimization. Returns: the best ScipyGuess
from the optimization process.Return type: ScipyGuess
.
-
-
class
moiety_modeling.modeling.
ScipySeparateOptimization
(model, datasets, path, methodParameters, energyFunction, optimizationSetting, method)[source]¶ The
ScipySeparateOptimization
class (for split dataset) inherited fromScipyOptimization
.-
__init__
(model, datasets, path, methodParameters, energyFunction, optimizationSetting, method)[source]¶ ScipySeparateOptimization initializer.
Parameters: - model (
Model
) – theModel
instance. - datasets (list) – a list of
Dataset
instances. - path (str) – the path to save the optimization results.
- methodParameters (dict) – the parameters for optimization method.
- energyFunction (str) – the energy function used in the optimization.
- optimizationSetting (str) – abbreviated name for the optimization.
- method (str) – the scipy optimization method.
- model (
-
optimizeSingle
(i)[source]¶ To perform single optimization.
Parameters: i (int) – the ith optimization. Returns: the best ScipyGuess
from the optimization process.Return type: ScipyGuess
.
-
-
class
moiety_modeling.modeling.
OptimizationManager
(models, datasets, optimizations, path, split=True, multiprocess=True, force=True, times=100, energyFunction='logDifference', printOptimizationScript=True)[source]¶ OptimizationManager class manage the optimization process based on the optimization settings.
-
__init__
(models, datasets, optimizations, path, split=True, multiprocess=True, force=True, times=100, energyFunction='logDifference', printOptimizationScript=True)[source]¶ OptimizationManager initializer.
Parameters: - models (list) – a list of
Moiety
instances. - datasets (list) – a list of
Dataset
instances. - optimizations (dict) – a list of optimization settings.
- path (str) – the path to store the optimization results.
- split (True) – to split the dataset or not.
- multiprocess (True) – to apply multiprocess or not.
- force (True) – to force optimization process or not.
- times (int) – the times of optimization for each moiety model.
- energyFunction (str) – the energy function used for optimization.
- printOptimizationScript (True) – to print out the optimization script or not.
- models (list) – a list of
-
moiety_modeling.model¶
This module provides the Moiety
class, the Molecule
class, the Relationship
class, and the Model
class to construct moiety model.
-
class
moiety_modeling.model.
Moiety
(name, maxIsotopeNum, states=None, isotopeStates=None, nickname=' ', ranking=0)[source]¶ Moiety class describes the
Moiety
entity in the moiety model.-
__init__
(name, maxIsotopeNum, states=None, isotopeStates=None, nickname=' ', ranking=0)[source]¶ Moiety initializer.
Parameters: - name (str) – the name of the moiety.
- maxIsotopeNum (dict) – the dictionary of the labeling isotopes and the corresponding number in the moiety. eg: {‘13C’: 5, ‘15N’: 3}.
- states (list) – the list of states of the moiety.
- isotopeStates (dict) – the dictionary of the labeling isotopes and the corresponding states in the moiety. eg: {‘13C’: [0, 2, 5], ‘15N’: [2, 3]}.
- nickname (str) – the nickname of the moiety.
- ranking (int) – the ranking of the moiety.
-
-
class
moiety_modeling.model.
Relationship
(moiety, moietyState, equivalentMoiety, equivalentMoietyState, operator=None, coefficient=None)[source]¶ Relationship class describes the relationship between moiety states in the moiety model.
-
__init__
(moiety, moietyState, equivalentMoiety, equivalentMoietyState, operator=None, coefficient=None)[source]¶ Relationship initializer.
Parameters: - moiety (
Moiety
) – theMoiety
in the relationship. - moietyState (str) – the state of the moiety (eg: ‘13C_0.15N_1’).
- equivalentMoiety (
Moiety
) –Moiety
in the relationship. - equivalentMoietyState (str) – the state of the equivalentMoiety (eg: ‘13C_0.15N_1’).
- operator (str) – the operator of the relationship (‘*’, ‘/’).
- coefficient (double) – the coefficient of the relationship.
- moiety (
-
-
class
moiety_modeling.model.
Molecule
(name, moieties)[source]¶ Molecule class describes the
Molecule
entity in the moiety model
-
class
moiety_modeling.model.
Model
(name, moieties, molecules, relationships=None)[source]¶ Model class describes the moiety
Model
entity.-
__init__
(name, moieties, molecules, relationships=None)[source]¶ Model initializer.
Parameters: - name (str) – the name of the model.
- moieties (list) – a list of
Moiety
instances. - molecules (list) – a list of
Molecule
instances. - relationships (list) – a list of
Relationship
instances.
-
moiety_modeling.analysis¶
This module provides several classes to analyze the optimization results, select the optimal model, and visualize the
results. The ResultAnalysis
class is responsible for generating general statistics
from the optimization results. The ModelRank
class selects the model that best
reflects the observed isotopologue profile. The ComparisonTable
class compares
the optimal model selected under different optimization settings. The PlotMoietyDistribution
class plots the distribution of moiety value of the moiety model. The PlotIsotopologueIntensity
class plots comparison of the observed and the calculated isotopologue intensity.
-
class
moiety_modeling.analysis.
ResultsAnalysis
(filename, path=None)[source]¶ ResultsAnalysis class performs the analysis of moiety model optimization results.
-
class
moiety_modeling.analysis.
ModelRank
(pathFile, path, selectionCriterion)[source]¶ ModelRank class ranks the models according to the selection criteria.
-
class
moiety_modeling.analysis.
ComparisonTable
(pathFile, path)[source]¶ ComparisonTable class collects the best and second best models under different optimization settings.
-
class
moiety_modeling.analysis.
PlotMoietyDistribution
(filename, path)[source]¶ PlotMoietyDistribution class plots the moiety state distribution of the optimization results.
-
class
moiety_modeling.analysis.
PlotIsotopologueIntensity
(filename, path)[source]¶ PlotIsotopologueIntensity class plots the comparison of calculated and observed isotoplogue intensity.
The moiety_modeling command-line interface option¶
- Usage:
- moiety_modeling -h | –help moiety_modeling –version moiety_modeling modeling [–combinedData=<combined_jsonfile>] [–models=<models_jsonfile] [–datasets=<datasets_jsonfile>] [–optimizations=<optimizations_jsonfile>] [–working=<working_dir>] [–repetition=<optim_count>] [–split] [–force] [–multiprocess] [–energyFunction=<function>] [–printOptimizationScripts] moiety_modeling analyze optimizations –a <optimizationPaths_txtfile> [–working=<working_dir>] moiety_modeling analyze optimizations –s <optimizationResults_jsonfile> [–working=<working_dir>] moiety_modeling analyze rank <analysisPaths_txtfile> [–working=<working_dir>] [–rankCriteria=<rankCriteria>] moiety_modeling analyze table <rankPaths_txtfile> [–working=<working_dir>] moiety_modeling plot moiety <analysisResults_jsonfile> [–working=<working_dir>] moiety_modeling plot isotopologue <analysisResults_jsonfile> [–working=<working_dir>]
- Options:
-h, --help Show this screen. --version Show version. --combinedData=<combined_jsonfile> JSON description file of the combined data (eg: models, datasets, optimization settings) --models=<models_jsonfile> JSON description file of the moiety models. --datasets=<datasets_jsonfile> JSON description file of the datasets. --optimizations=<optimizations_jsonfile> JSON description file of the optimization setting. --working=<working_dir> Alternative path to save the results. --repetition=<optim_count> The number of optimization repetitions to perform [default: 100]. --split To split the datasets or not. --force To force optimization process if error occurs. --multiprocess To perform with multiprocessing or not. --printOptimizationScripts To print the optimization script or not. --a To analyze a bunch of optimization results together with the path file. --s To analyze a single moiety model optimization results. --energyFunction=<enegyFunction> The energyFunction of the moiety modeling optimization. --optimizationSetting=<optimizationSetting> The optimization setting of the moiety modeling optimization. --rankCriteria=<rankCriteria> The criteria for model ranking [default: AICc].