Attribute VB_Name = "INTEGRAT" '**************************************************************************************** ' ' File: INTEGRAT.BAS ' ' Author: Roberto Raso ' Date: 2nd February 1994 ' '**************************************************************************************** ' ' Purpose: Provide peak detection, integration and smooth functions. ' '**************************************************************************************** '**************************************************************************************** ' ' Constant/Global declarations. ' '**************************************************************************************** Global Const CHR_INT_PARA = "ChrIntegrate" 'Interference Peak flags Public Enum InterferenceFlags PKD_NONE PKD_POSITIVE PKD_NEGATIVE End Enum '**************************************************************************************** ' ' Data type declarations. ' '**************************************************************************************** '*** '*** SMO_PARAMS *** '*** Smoothing parameters *** '*** Type SMO_PARAMS nMethod As Long 'Smoothing method nSGPoly As Long 'Order of SG polynomial nSGDeriv As Long 'Order of SG derivative nWidth As Long 'Width of smoothing window nIterates As Long 'No of iterations bMedianConv As Long 'Median smooth to convergence ? bAllowMedian As Long 'Median smooth allowed ? fPeakWidth As Single 'Spectrum peak width fFactor As Single 'Chromatogram smooth factor bUsePeakWidth As Long 'Use peak width parameter End Type '*** '*** PKDSTATS '*** Peak statistics *** '*** Type PKDSTATS lfWidth As Double 'Width at 5% height lfMean As Double 'Mean lfSigma As Double 'Standard deviation lfSkew As Double 'Skewness lfKurtosis As Double 'Kurtosis End Type '*** '*** PKD_FULL_PEAK '*** Full peak structure *** '*** Type PKD_FULL_PEAK fStart As Single 'Baseline start X fStartHt As Single 'Baseline start Y nStartType As Long 'Baseline start type fEnd As Single 'Baseline end X fEndHt As Single 'Baseline end Y nEndType As Long 'Baseline end type fTop As Single 'Peaktop X fHeight As Single 'Peaktop Y fCent As Single 'Centroid X fCentHt As Single 'Centroid Y fArea As Single 'Peak area nFlags As Long 'Flags fPurityMean As Single 'Purity index fPuritySigma As Single 'Purity standard deviation nInterferenceFlag As Long 'Can be PKD_NONE, PKD_POSITIVE or PKD_NEGATIVE. nPack1 As Long 'Structure packing variable, not used dInterferencePercentage As Double 'Percentage difference between secondary traces. sStats As PKDSTATS 'Peak statistics End Type '*** '*** PKD_THRESH '*** Type PKD_THRESH nPack1 As Long 'Structure packing variable, not used wRespThreshold As Integer fRespAreaRel As Single fRespAreaAbs As Single fRespHeightRel As Single fRespHeightAbs As Single End Type '*** '*** PKD_PARAMS '*** Parameters for Peak Detection *** '*** Type PKD_PARAMS nPack1 As Long 'Structure packing variable, not used nMode As Long 'Standard centroid, fast centroid, QTOF centroid nHalfWidth As Long 'Min peak width at half height bShldrDetect As Long 'Detect shoulders (True/False) nShldrWidth As Long 'Min shoulder width fBalance As Single 'Min peak balance (percent) '100% = Not balanced fShldrThresh As Single 'Shoulder flatness threshold fSkim As Single 'Peak skim threshold (percent) '100% = All skimmed fMinEdge As Single 'Edge threshold fReduceTail As Single 'Reduce peak tailing by... fMaxReduceHt As Single 'Move baseline by no more than nCntrMethod As Long 'Centre method fCentTop As Single 'Topmost percentage of peak to 'use for centroid bMakeSticks As Long 'Centre only - make sticks? nSticks As Long 'Centre only - stick type nWindow As Long 'Centre only - add/replace/new fBaseWidth As Single 'Peak width at baseline (fast centroid only) fBaseThresh As Single 'Baseline threshold (fast centroid only) sWatParams As PKD_WAT_PARAMS 'Waters peak detection parameters sQTOFParams As PKD_QTOF_PARAMS bEnableTOFCentroid As Long 'Allow TOF centroid mode 'Accurate Mass bEnableAccMassCentroid As Long 'Use centroiding with uncertainty estimation bAccMassScan As Long 'OUTPUT: Accurate mass scan if true wAccMassDiagnostic As Integer 'OUTPUT: Bits set on accurate mass failure according to RawIntrf.h bDoAdaptiveSubtract As Long 'Do adaptive background subtract End Type '*** '*** INTEGRATE_CHRO_PARAMS *** '*** Chromatogram Integration parameters *** '*** Maps to INTEGRATE_PARAMS in VC++ *** '*** Type INTEGRATE_CHRO_PARAMS bSmooth As Long 'Smoothing on / off sSmoParams As SMO_PARAMS 'Smooth parameters sPkdParams As PKD_PARAMS 'Peak detect parameters sThreshold As PKD_THRESH 'Threshold parameters sChroStats As CHRO_STATS 'Chromatogram stats End Type '*** '*** INTEGRATE_SPEC_PARAMS *** '*** Spectrum Integration parameters *** '*** Maps to INTEGRATE_PARAMS in VC++ *** '*** Type INTEGRATE_SPEC_PARAMS bSmooth As Long 'Smoothing on / off sSmoParams As SMO_PARAMS 'Smooth parameters sPkdParams As PKD_PARAMS 'Peak detect parameters sThreshold As PKD_THRESH 'Threshold parameters sSpecStats As SPEC_STATS 'Spectrum stats End Type '**************************************************************************************** ' ' Function declarations. ' '**************************************************************************************** Declare Function IntegrateChromatogramRange Lib "integr32.dll" _ Alias "_IntegrateChromatogramRange@40" (ByVal hWnd As Long, lpRawFile As VGRAWFILE, _ lpChroType As DMRAWCHRTYPE, hPeaks As Long, wNumPeaks As Long, hDm As Long, _ lpIntParams As INTEGRATE_CHRO_PARAMS, ByVal dwScanStart As Long, _ ByVal dwScanEnd As Long, ByVal wTraceNumber As Integer) As Integer Declare Function IntegrateGetIniFile Lib "integr32.dll" Alias "_IntegrateGetIniFile@8" (ByVal lpName As String, lpIntParams As INTEGRATE_CHRO_PARAMS) As Integer Declare Sub IntegrateEditParams Lib "integr32.dll" Alias "_IntegrateEditParams@16" (ByVal hWnd As Long, sVGRawFile As Any, sDMRawChroType As Any, sIntegrateParams As INTEGRATE_CHRO_PARAMS) Declare Function IntegrateDialogClosed Lib "integr32.dll" Alias "_IntegrateDialogClosed@4" (sIntegrateParams As INTEGRATE_CHRO_PARAMS) As Integer '**************************************************************************************** ' ' Purpose: Integrate chromatogram over requested range. ' Prototype. ' '**************************************************************************************** Function IntegrateChro() As Integer Dim hWnd As Long Dim hResults As Long Dim wNumPeaks As Long Dim hDmRaw As Long Dim wBytes As Integer Dim wPeak As Integer Dim dwStartScan As Long Dim dwEndScan As Long Dim dwStartOfResults As Long Dim lpIniPara As String Dim lpRawFile As VGRAWFILE Dim lpChroType As DMRAWCHRTYPE Dim lpIntParams As INTEGRATE_CHRO_PARAMS Dim lpIntResult As PKD_FULL_PEAK lpIniPara = "ChrIntegrate" If IntegrateGetIniFile(lpIniPara, lpIntParams) Then Debug.Print ChroDescToChroType("91", lpChroType) 'lpChroType.nChroType = 1 'lpChroType.afMasses(0) = 91 'lpChroType.afMasses(32) = 0 If GetMLFileInfo("RAW", lpRawFile.lpVGFile) Then lpRawFile.wFunc = 1 hWnd = FindWindow(vbNullString, "OpenLynx MS Station") If IntegrateChromatogramRange(hWnd, lpRawFile, lpChroType, hResults, wNumPeaks, _ CLng(hDmRaw), lpIntParams, 1, 953, 0) Then dwStartOfResults = GlobalLock(hResults) wBytes = Len(lpIntResult) For wPeak = 1 To wNumPeaks Call hmemcpyTolp(lpIntResult, dwStartOfResults + wBytes * (wPeak - 1), wBytes) Debug.Print "Peak #"; wPeak; lpIntResult.fTop; lpIntResult.fHeight; lpIntResult.fArea; lpIntResult.fStart; lpIntResult.fEnd; lpIntResult.fStartHt; lpIntResult.fEndHt Next wPeak Debug.Print "Unlock"; GlobalUnlock(hResults) Debug.Print "Free"; GlobalFree(hResults) DmRawClose IntegrateChro = wNumPeaks Else IntegrateChro = False End If Else IntegrateChro = False End If Else IntegrateChro = False End If End Function '**************************************************************************************** ' ' Purpose: Integrate chromatogram over requested range. ' Returns the handle of the integrated trace ' Returns number of peaks and fills array of PKD_FULL_PEAK ' '**************************************************************************************** Function IntegrateChromatogramProcess(lpWindowCaption As String, sRawFile As VGRAWFILE, _ wFunc As Integer, lpChroDesc As String, fStart As Single, fEnd As Single, _ wScans As Integer, lpResults() As PKD_FULL_PEAK, sIntParams As INTEGRATE_CHRO_PARAMS, _ bUseIni As Integer, hDm As Long, Optional nrTraceNumber As Long = 0) As Integer Dim wFuncOK As Integer Dim hWnd As Long Dim hResults As Long Dim wNumPeaks As Long Dim hDmRaw As Long Dim wBytes As Integer Dim wPeak As Integer Dim dwStartScan As Long Dim dwEndScan As Long Dim dwStartOfResults As Long Dim lpIniPara As String Dim lpChroType As DMRAWCHRTYPE Dim lpIntParams As INTEGRATE_CHRO_PARAMS Dim lpIntResult As PKD_FULL_PEAK wFuncOK = True wFuncOK = ChroExit() lpIniPara = CHR_INT_PARA If Asc(lpWindowCaption) <> 0 Then hWnd = FindWindow(vbNullString, lpWindowCaption) Else hWnd = GetActiveWindow() End If lpIniPara = "ChrIntegrate" If bUseIni <> False Then wFuncOK = IntegrateGetIniFile(lpIniPara, lpIntParams) Else lpIntParams = sIntParams End If If DMCheckFunction(wFunc, sRawFile) Then If wScans Then dwStartScan = DMCheckScan(wFunc, CInt(fStart), sRawFile) dwEndScan = DMCheckScan(wFunc, CInt(fEnd), sRawFile) Else dwStartScan = DMCheckRT(wFunc, CInt(fStart), sRawFile) dwEndScan = DMCheckRT(wFunc, CInt(fEnd), sRawFile) End If If dwStartScan = False Or fStart = 0 Then dwStartScan = 1 End If If dwEndScan = False Or fEnd = 0 Then dwEndScan = DmRawScansInFunction(sRawFile) End If Else wFuncOK = False End If If Not ChroDescToChroType(lpChroDesc, lpChroType) Then wFuncOK = False End If If wFuncOK Then If IntegrateChromatogramRange(hWnd, sRawFile, lpChroType, hResults, wNumPeaks, hDm, _ lpIntParams, dwStartScan, dwEndScan, nrTraceNumber) Then dwStartOfResults = GlobalLock(hResults) wBytes = Len(lpIntResult) If wNumPeaks Then ReDim lpResults(wNumPeaks - 1) For wPeak = 1 To wNumPeaks Call hmemcpyTolp(lpIntResult, dwStartOfResults + wBytes * (wPeak - 1), wBytes) lpResults(wPeak - 1) = lpIntResult Next wPeak End If wFuncOK = GlobalUnlock(hResults) wFuncOK = GlobalFree(hResults) DmRawClose IntegrateChromatogramProcess = wNumPeaks Else IntegrateChromatogramProcess = False End If End If End Function '________________________________________________________________________________________ ' ' Process: IntegrateParsEdit ' ' Author: Roberto Raso ' Date: 21st June 1995 ' ' Purpose: Brings up the integrate editor and sets an INTEGRATE_CHRO_PARAMS structure. ' ' Parameters: hWnd is the window handle that will be used to position the ' editor dialogue box to. ' sIntegrateParams is the set of parameters that will be used by ' the dialogue box and set. ' ' Return: True if parameters have been changed. '________________________________________________________________________________________ Function IntegrateParsEdit(hWnd As Long, sIntegrateParams As INTEGRATE_CHRO_PARAMS) As Integer Dim strIntegrateParamsCur As String Dim strIntegrateParamsNew As String IntegrateParsEdit = False strIntegrateParamsCur = String$(Len(sIntegrateParams), 0) Call hmemcpy(ByVal strIntegrateParamsCur, sIntegrateParams, Len(sIntegrateParams)) If GetGlobalDialogWnd(GD_CHRO_INTEGRATE) Then Exit Function End If Call IntegrateEditParams(hWnd, 0&, 0&, sIntegrateParams) Do Until GetGlobalDialogWnd(GD_CHRO_INTEGRATE) DoEvents Loop Do While GetGlobalDialogWnd(GD_CHRO_INTEGRATE) DoEvents Loop If IntegrateDialogClosed(sIntegrateParams) = 0 Then Exit Function End If strIntegrateParamsNew = String$(Len(sIntegrateParams), 0) Call hmemcpy(ByVal strIntegrateParamsNew, sIntegrateParams, Len(sIntegrateParams)) If strIntegrateParamsNew <> strIntegrateParamsCur Then IntegrateParsEdit = True End If End Function