Institute for Advanced Biosciences Keio University
MathDAMP Mathematica package for differential analysis of metabolite profiles
Home Overview Examples Downloads TriDAMP References Contact
MathDAMP > Examples > 05-MathDAMP-TwoGroups


This notebook provides a template for the comparison two groups of replicate datasets with the MathDAMP package. First, the respective group's datasets are averaged and compared in a similar way as demonstrated for two datasets in the 03-MathDAMP-TwoDatasets notebook. Additionally, t-test is performed for the groups of corresponding signal intensities from all datasets to locate statistically significant differences.
Additional notebooks from the MathDAMP package (04-MathDAMP-Outliers.nb and 06-MathDAMP-MultipleGroups.nb) provide templates for identifying outliers in a group of datasets and for the comparison of multiple groups of replicate datasets. The notebook 02-MathDAMP-Elements.nb demonstrates the basic functionality of the MathDAMP package.

Step 1 : Loading the Data

First, the MathDAMP package has to be loaded. Please assign the path leading to MathDAMP files to the MathDAMPPath variable. Due to the size of the datasets and results the global variable $HistoryLength is set to 1 to save memory. 1GB of physical memory may be necessary to execute this notebook.

$HistoryLength = 1 ;

MathDAMPPath = "/home/baran/math/ms/MathDAMP.1.0.0/" ;

<< (MathDAMPPath<>"MathDAMP.m")

MathDAMP version 1.0.0 loaded (2006/04/26)

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Datasets acquired by capillary electrophoresis coupled to a time-of-flight mass spectrometer (CE-TOFMS) will be used for the demonstration in this notebook. The *.bdt datafiles were generated using a separate in house software from *.csv datafiles exported by the Analyst QS software (for Agilent TOFMS). The csv data were binned to a 0.02 m/z units resolution along the m/z axis, baselines were subtracted from the individual electropherograms (as by the DAMPSubtractBaselines function with default options), noise was removed (as with the DAMPRemoveNoise function with default options), the data were binned to 1 m/z units resolution and saved in a binary format as *.bdt datafiles.

fnames = FileNames["/home2/baran/data/examples/"<>#<>"/*.bdt"] &/@{"1h", "4h"} ;

{ctrl, smpl} = DAMPImportBDT[#, StringReplace[#, __ ~~ "/" ~~ str__ ~~ "/" ~~ __str]] &/@#&/@fnames ;

NumberForm[MemoryInUse[], DigitBlock3]


Optional : Exploring the data, locating the peak of the internal standard in the reference dataset

Step 2 : Performing the Differential Analysis

The function DAMPTwoGoups performs the comparison of two groups of replicate datasets. DAMPNormalizeGroup function is used internally to align and normalize the datasets along with the annotation tables. Please refer to the MathDAMP.nb notebook for more details about the implementation of functions DAMPNormalizeGroup and DAMPTwoGroups. Execute ?FunctionName to list a brief description of the respective function's available options.

? DAMPNormalizeGroup

? DAMPTwoGroups

Most of the options for the DAMPTwoGroups and DAMPNormalizeGroup functions are specified explicitly in the command below to allow easy editing of the options. The annotation table for the cation mode CE-MS analysis is used. This table was assembled according to the CE-TOFMS analysis of a mixture of standard compounds. Methioninesulfone is used as the internal standard. Its short name (in the annotation table) 363 is passed to the DAMPNormalizeGroup function via the InternalStandard option. The location of the peak of the internal standard will be extrapolated from the aligned annotation table. Overlaid electropherograms of the vicinities of the expected peaks of the internal standard are plotted along with indicators of the beginning and the end of blindly integrated regions for visual confirmation. To specify the location of the peak explicitly, use the notation {mz,{starttime,endtime}} instead of the short name. In this case it would be {182,{14,14.6}} (according to the electropherogram at the end of the optional section).
The first dataset from the ctrl list will be used as the reference dataset (as specified by the options Reference->1).
The DAMPTwoGroups function returns the absolute, relative, and absolute×relative difference between the averages of the datasets of both groups. Additionally, a t-score map is generated by performing a t-test for the groups of corresponding signal intensities. In the case below, only peaks picked in the migration time range 8 - 23 min in the reference sample are used for the alignment. This leads to a better alignment of the peaks in this range at the expense of the alignment of the stack of peaks with migration times around 25 min.

Clear[rslt] ;

rslt = DAMPTwoGroups[ctrl, smpl, NormalizeGroupOptions {Reference1, Alignmen ... None}, ThresholdForRelative0, GroupNamesAutomatic, AbsRelTrendFilter2] ;






IS normalization coefficients : {1., 1.10901, 1.02771, 1.04268, 1.16882, 1.18705, 1.15713, 1.24596}

Step 3 : Exploring the Results, Listing the Candidates

The normalized datasets may be explored on density plots (annotated). The averaged normalized datasets from the first group are shown on the plot below.

DAMPDensityPlot[AveragedGroup1/.rslt, MaxScale20000, AnnotationTables (AlignedAnnotationTables/.rslt), Sequence @@ DAMPCETOFMSDensityPlotOptions] ;


The t-score map or any of the result datasets calculated using the averages of the groups may be plotted to show differences between the groups. Additionally, the result datasets may be combined or used as filters against each other. For example, the absolute×relative difference (of the averages) result may be filtered to allow only those signals for which the t-score is above certain threshold.

filtset = DAMPFilter[AbsRel/.rslt, DAMPSmooth[TScores/.rslt], 5] ;

DAMPDensityPlot[filtset, MaxScale20000, AnnotationTables (AlignedAnnotationTables/.rslt), Sequence @@ DAMPCETOFMSDensityPlotOptions] ;


Overlaid electropherograms in the vicinities of the most significant differences (according to a particular result) may be plotted in descending order of significance for visual confirmation (and for the rejection of false positives). Below are the electropherograms of the top 50 candidates from the filtered absolute×relative difference result. The vertical dashed line indicates the position of the most significant difference according to the result dataset. (Further below are the top 50 candidates from the t-test result).

plotcolors = Transpose[{DAMPGenColors[2], GroupCounts/.rslt}] ;

DAMPPlotCandidates[NormalizedDatasets/.rslt, filtset, PlotCount50, PlotChromatogramO ... #12315;, LegendDataTranspose[{plotcolors〚All, 1〛, (GroupNames/.rslt)}]}] ;



















































Different results datasets provide different ranking. For example, differences in small peaks usually do not score high in the absolute×relative difference result. On the other hand, presence of an outlying peak (in terms of signal intensities) in one dataset causes the drop of the difference in t-score ranking. Since different results have their strengths and weaknesses, it may prove beneficial to generate the lists of candidates based on multiple results. Below are electropherograms of candidate differences ranked according to the t-test result. Apart from the different ranking, smaller peaks achieve higher ranking in the list below when compared to ranking according to the absolute×relative result. However, the difference for L-Alanine (ranked second according to the absolute×relative result) is not among the first 50 candidates from the t-test result. Also note, that the vertical dashed line indicating the most significant difference often does not correspond to the peak top for the t-test result.

plotcolors = Transpose[{DAMPGenColors[2], GroupCounts/.rslt}] ;

DAMPPlotCandidates[NormalizedDatasets/.rslt, DAMPSmooth[TScores/.rslt], PlotCount50, ... #12315;, LegendDataTranspose[{plotcolors〚All, 1〛, (GroupNames/.rslt)}]}] ;