Attribute VB_Name = "ExtractMLData" '**************************************************************************************** ' ' File: ExtractMLData.BAS ' ' '**************************************************************************************** ' ' Purpose: Extract mass intensity pairs from MassLynx data files ' '**************************************************************************************** Sub Main() Dim ExMLDataParams As VGRAWFILE 'read the current file in the sample list from the MLCurSmp.txt file in the temp directory lRtn = GetSampleListFileVB(ExMLDataParams) 'output the masses and intensities of the current data file Call WriteMIPairsToTextFile(ExMLDataParams) 'output the chromatogram and integrated data for the file Call WriteChroAndIntegData(ExMLDataParams) End Sub '**************************************************************************************** ' ' Purpose: get the mass intensity pairs for all the data in the current file and dump it out to a text file of name: ' "raw data file".txt ' '**************************************************************************************** Sub WriteMIPairsToTextFile(DataFile As VGRAWFILE) Dim HeaderInfo As DMRAWHEADER Dim ScanStats As DMRAWSTATS Dim lScans As Long Dim fMass() As Single Dim fInten() As Single Dim lRtn As Long Dim nRtn As Integer Dim sTemp, sDir, sFile As String 'create an output file sDir = DataFile.lpVGFile.szDirectory nRtn = InStr(sDir, Chr(0)) sDir = Left(sDir, nRtn - 1) sFile = DataFile.lpVGFile.szName nRtn = InStr(sFile, Chr(0)) sFile = Left(sFile, nRtn - 1) sTemp = sDir & sFile & ".txt" Set ScriptObject = CreateObject("Scripting.FileSystemObject") Set fil = ScriptObject.CreateTextFile(sTemp, True) 'read the header information from the current file nRtn = DmRawReadHeaderVB(DataFile, HeaderInfo) 'loop through all the functions in the file For nFuncCount = 1 To HeaderInfo.wFuncsInFile DataFile.wFunc = nFuncCount lScans = DmRawScansInFunction(DataFile) For nScanCount = 1 To lScans nRtn = DmRawReadScanStatsVB(DataFile, nScanCount, True, ScanStats) ReDim fMass(0 To ScanStats.dwPeaksInScan) ReDim fInten(0 To ScanStats.dwPeaksInScan) lRtn = DmRawReadSpectrumVB(DataFile, nScanCount, True, 1, ScanStats.dwPeaksInScan, fMass(0), fInten(0)) Dim sOutLine As String sOutLine = "Function " & Format(nFuncCount, "0000") & " Scan " & Format(nScanCount, "000000") fil.WriteLine (sOutLine) For nPeakCount = 0 To (ScanStats.dwPeaksInScan - 1) sOutLine = Format(fMass(nPeakCount), "######0.0000") & " " & Format(fInten(nPeakCount), "######0.0000") fil.WriteLine (sOutLine) Next nPeakCount Next nScanCount Next nFuncCount fil.Close End Sub '**************************************************************************************** ' ' Purpose: get the chromatogram data and output the peak height, retention time and peak area to a file of name ' "raw data file"pkdet.txt ' '**************************************************************************************** Sub WriteChroAndIntegData(DataFile As VGRAWFILE) Dim HeaderInfo As DMRAWHEADER 'Dim ScanStats As DMRAWSTATS Dim lpIntParams As INTEGRATE_CHRO_PARAMS Dim ChroType As DMRAWCHRTYPE Dim lpIntResult As PKD_FULL_PEAK Dim lScans, lRtn, hWnd As Long, ResultHandle As Long, lNumOfPeaks As Long Dim lScanStart As Long, lScanEnd As Long, lChromHandle As Long Dim lpScan() As Single Dim lpTime() As Single Dim lpIntensity() As Single Dim nRtn, wBytes, wPeak As Integer Dim sTemp, sDir, sFile, sOutLine As String Dim sChroDesc(0 To 2) As String 'Integrate all scans lScanStart = 0 lScanEnd = 0 'create an output file sDir = DataFile.lpVGFile.szDirectory nRtn = InStr(sDir, Chr(0)) sDir = Left(sDir, nRtn - 1) sFile = DataFile.lpVGFile.szName nRtn = InStr(sFile, Chr(0)) sFile = Left(sFile, nRtn - 1) sTemp = sDir & sFile & "pkdet.txt" Set ScriptObject = CreateObject("Scripting.FileSystemObject") Set fil = ScriptObject.CreateTextFile(sTemp, True) 'read the header information from the current file nRtn = DmRawReadHeaderVB(DataFile, HeaderInfo) sChroDesc(0) = "TIC" sChroDesc(1) = "BPI" 'sChroDesc(2) = "734.46" sChroDesc(2) = "44" '''''''''''''''''''''''''''''''''''''''''''''''''''''''''' show chromatogram ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' For nDesc = 0 To 2 'show the chromatogram description sOutLine = sChroDesc(nDesc) fil.WriteLine (sOutLine) 'loop through all the functions in the file For nFuncCount = 1 To HeaderInfo.wFuncsInFile DataFile.wFunc = nFuncCount lScans = DmRawScansInFunction(DataFile) ReDim lpScan(0 To lScans) ReDim lpTime(0 To lScans) ReDim lpIntensity(0 To lScans) lRtn = DmRawReadChromatogramVB(DataFile, sChroDesc(nDesc), True, 1, lScans, lpScan(0), lpTime(0), lpIntensity(0)) sOutLine = "Function " & Format(nFuncCount, "0000") fil.WriteLine (sOutLine) For nScanCount = 0 To (lScans - 1) sOutLine = Format(lpScan(nScanCount), "##0.0000") & " " & Format(lpTime(nScanCount), "####0.0000") & " " & Format(lpIntensity(nScanCount), "#####0.0000") fil.WriteLine (sOutLine) Next nScanCount Next nFuncCount Next nDesc ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' show integrated data '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' hWnd = GetActiveWindow() For nDesc = 0 To 2 'show the chromatogram description sOutLine = sChroDesc(nDesc) fil.WriteLine (sOutLine) nRtn = IntegrateGetIniFile("ChrIntegrate", lpIntParams) nRtn = ChroDescToChroType(sChroDesc(nDesc), ChroType) 'loop through all the functions in the file For nFuncCount = 1 To HeaderInfo.wFuncsInFile DataFile.wFunc = nFuncCount lScans = DmRawScansInFunction(DataFile) nRtn = IntegrateChromatogramRange(hWnd, DataFile, ChroType, ResultHandle, _ lNumOfPeaks, lChromHandle, lpIntParams, lScanStart, lScanEnd, 0) dwStartOfResults = GlobalLock(ResultHandle) wBytes = Len(lpIntResult) sOutLine = "Function " & Format(nFuncCount, "0000") fil.WriteLine (sOutLine) For wPeak = 1 To lNumOfPeaks Call hmemcpyTolp(lpIntResult, dwStartOfResults + wBytes * (wPeak - 1), wBytes) sOutLine = "Peak # " & Format(wPeak, "000") & " Top " & Format(lpIntResult.fTop, "000.000") & " Height " & Format(lpIntResult.fHeight, "000.000") & " Area " & Format(lpIntResult.fArea, "000.000") fil.WriteLine (sOutLine) Next wPeak Next nFuncCount Next nDesc fil.Close End Sub