Batch MultiPeak Fitting

@ Igor Exchange moderators or anyone that could help. I am trying to do some batch processing with the MPF2_AutoMPFit() function to fit chromatograms with 19 peaks. My approach has been to do a careful manual multi peak fit to develop the peak coefficients and constraints. I know the peak coefficients and constraints text waves are now listed under root:Packages:MultiPeakFit2:MPF_SetFolder_2 along with a number of back up coefficients and various strings/variables. I have gone through and figured out the inputs for the MPF2_AutoMPFit function (shown below).

MPF2_AutoMPFit(resultDFBase, peakType, PeakCoefWaveFormat, BLType, BLCoefWaveName, yWaveList, xWaveList, InitialGuessOptions [, noiseEst, smFact, noiseEstMult, smFactMult, minAutoFindFraction])

I believe I would like to use initialOptionsGuess 0 "Do not run the automatic peak picker. Initial guesses will be pre-loaded in coefficient waves in the data folder resultDFBase+"_0". Use those values for every data set." I just am a bit lost on how I should set up a data folder containing the required information, and then how to feed that to the function inputs.
You have posted your question in two places. Here is the answer I just posted in the thread http://www.igorexchange.com/node/5696#comment-9524


That means that the first of the result data folders must exist before you call MPF2_AutoMPFit(), and you need to copy the coefficient waves from your manual run into that data folder. You might have something like
    String resultDFBase = "MyResults"
    String newDFName = resultDFBase+"_0"
    String PeakCoefWaveFormat = "myPeak%d"
    DuplicateDataFolder root:Packages:MultiPeakFit2:MPF_SetFolder_1, $newDFName
    DFREF newdf = $newDFName
    Variable i
    for (i = 0; i < 19; i += 1)
        String wname
        sprintf(wname, "Peak %d Coefs", i)
        String newname
        sprintf(newname, PeakCoefWaveFormat, i)
        Rename newdf:$wname, $newname
    endfor
    MPF2_AutoMPFit(resultDFBase, ..., PeakCoefWaveFormat, ...)

In that code (which is completely untested!) the complete data folder for a manual multipeak fit is duplicated, giving the duplicate the appropriate name ending in "_0". The the looop renames the coefficients waves from the names used by the MPF2 user interface, to names corresponding to the names specified by the PeakCoefWaveFormat input string.

If you have a baseline as part of the fit, you need to do the same for the baseline coefficient wave. To avoid the loop and renaming waves, you could just use
    String resultDFBase = "MyResults"
    String newDFName = resultDFBase+"_0"
    DuplicateDataFolder root:Packages:MultiPeakFit2:MPF_SetFolder_1, $newDFName
    MPF2_AutoMPFit(resultDFBase, ..., "Peak %d Coefs", ..., "Baseline Coefs", ...)

This simplifies the problem by using the same names as the GUI for MPF2 uses, so you only need to duplicate the data folder, you don't need to rename the waves.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.comJohn Weeks
WaveMetrics, Inc.
support@wavemetrics.com
I thought I had it all working, but I noticed that when I ran the MPF2_autoMPFit the resultDFBase_n datafolders all contained the exact same information. I have attached a experiment file for reference. So in my experiment I loaded three waves called wave4, wave5, and wave 6. All three waves are chromatograms I generated by separating a hydrocarbon standard with 20 peaks. I ran a manual multi peak fit on the three chromatograms generating the following three folders MPF_SetFolder_1 MPf_SetFolder_2 and MPF_SetFolder_3 for wave4, wave 5, and wave 6 respectively (path --> root:Packages:MultiPeakFit2). Inside each of those folders is a wave titled MPF2_ResultsListWave, which contains all of the useful peak information such as location and peak area. The values contained in MPF2_ResultsListWave in each folder MPF_SetFolder_1 MPf_SetFolder_2 and MPF_SetFolder_3 are all slightly different, which is what I would expect since each chromatogram have slightly different peak locations and areas. After I reviewed that data I then called the following function I wrote to set up the correct data folders with the required waves, variables, and strings to run MPF2_AutoMPFit.

 function resultDFBaseCreator(UserInNumPeak)    //function will take the output folder of  the manual MPF and copy/rename it to resultsDFbase_0 for the MPF2_AutoMPFit function input.<br />
                                                                            <br />
variable UserInNumPeaks<br />
string/g ywavelist = wavelist("*",";","")           //creates a wavelist from the target waves in the selected data folder to be used as wavelist input in MPF2_auto function<br />
String newDFName = "resultDFBase"+"_0"                 //declares a string with the name resultDFBase_0 <br />
DuplicateDataFolder root:Packages:MultiPeakFit2:MPF_SetFolder_1, $newDFName         //duplicates the manual MPF output parameter/coef folder and assigns it the resultDFBase_0 name to be used by the MPF2_auto function                                                        <br />
setdatafolder $newDFname<br />
variable/g NumOfPeaks = UserInNumPeaks<br />
variable/G MPFError = 0<br />
<br />
setdatafolder root:<br />
<br />
MPF2_AutoMPFit("resultDFBase", "gauss", "Peak %d Coefs", "constant", "Baseline Coefs", ywavelist,"",  0)            //calls MPF2_auto function to fit the rest of the waves in the root data folder via ywavelist<br />
<br />
end


In the data browser of the attached experiment you will find resultDFBase_0, resultDFBase_1, and ResultDFbase_2 which should correspond to wave4, wave_5, and wave6 respectively. In each of those folders there is a wave titled MPF2_ResultsListWave that contains all of the useful results of the fit for the wave of interest. However, the results contained in MPF2_ResultsListWave for resultDFBase_0, resultDFBase_1, and ResultDFbase_2 are identical. I.E identical peak locations, peak areas etc. This should not be the case. The chromatograms are indeed very very similar, but there are small differences in peak location and peak area in each chromatogram as I mentioned earlier. So my question here is what am I doing wrong? Do I have some input parameters such as ywavelist (ie wave4;wave5;wave6) in the wrong data folder?
BatchMPFV9.pxp (1.21 MB)
Quote:
However, the results contained in MPF2_ResultsListWave for resultDFBase_0, resultDFBase_1, and ResultDFbase_2 are identical. I.E identical peak locations, peak areas etc. This should not be the case. The chromatograms are indeed very very similar, but there are small differences in peak location and peak area in each chromatogram as I mentioned earlier. So my question here is what am I doing wrong?

You are doing nothing wrong. The presence of MPF2_ResultsListWave in those data folders is an unfortunate consequence of the use of the DuplicateDataFolder operation to create the results data folders. The MPF2_ResultsListWave in the original manual-fit folder was used by the GUI to display the results in the peak list in the control panel. It is not involved in the fits in the automated batch fitting.

Your batch fit did the job- here is a listing from a table of the Peak 0 Coefs waves from each of the resultDFBase_n data folders:

213.177 215.414 214.598
3.07289 2.66981 3.16373
0.153097 0.141413 0.100335

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Hi John,

Thanks for the help and clarification. The issue with the data in the Peak Coef waves is that only location, peak width, and peak amplitude are displayed. The information that I really need is peak area. Do you have any suggestions on how to access that information?

Thanks
One quick thought I had was to then write a function to fit the waves Peak 0, Peak 1, Peak 2 individually in resultDFBase_n since the fitted peaks are saved in those waves, and a quick fit to those would yield. However, when you do a quick gauss fit the output parameters are y0, A, x0, and width. I believe that A refers to peak amplitude. I am sure I can write something to calculate the peak area from those parameters, but if there is a faster/easier way I would appreciate it.