一个在质谱和蛋白里面潜泳的家伙,痴人梦想让中国蛋白质组“更广、更深、更强”,质谱和蛋白质组学愿意就来找我!蛋白质与多肽药物结构分析网 www.tofms.org

源代码分享:DE自动保存peaklist文件

上一篇 / 下一篇  2011-06-03 12:28:53 / 个人分类:争鸣与商榷

文章来源
  • 文章来源:原创
Data Explorer 处理数据时,每次都是读取原始文件和参数,然后实时显示峰值,及时你进行了各种图谱处理,中间过程很难保存,每次打开数据时还得重新处理一遍。不知道软件开发人员怎么想的。

峰值文件是数据库查询、各种统计再分析必须要的,可是DE每个图谱都要人工copy,并不能直接保存为text文件,数据少的时候,没问题。

昨天,学生们已经无可奈何了,因为有数百张图谱要处理,每个都process一下和copy的话,确实工作量巨大。为此,本人研究了一下那个 Automation Macro,写了以下代码,与大家分享。

源代码功能说明:

1   如果引用,请保留wkh的declare以及存盘文件后缀“wkh.txt“ ,以示对本人的尊重。
2  自动基线处理主要适合我们的大样本血清线型模式的数据,如果你是别的检测模式,要选择其它baseline校正。
3  降噪和平滑主要针对线型方式,反射条件下,不推荐。
4  此代码只输出 m/z, Area, Normalized Intensity,如果需要输出别的信息(如电荷、s/n,分辨率等),自己添加进去。
5  自动保存的文件路径显示在result窗口,跟你的原始文件在一起。

==========================================

'Written by Kaihua Wei 06/02/2011

Sub SavePeaklist()
    'Get most intensive peaks every defined increment and sorted by mass from low to high

    Dim PeakRange As Integer
    Dim PeakNumber As Integer
    Dim FirstMass As Double
    Dim LastMass As Double
    Dim dStart As Double
    Dim dEnd As Double
    Dim SpecPeakArray As Variant
    Dim nIncrementer As Long
    Dim nSpecPeak As Long
    Dim LastIncrement As Integer
    Dim iPeak As Integer
    Dim nPeakEnd As Integer
    Dim TempPeakArray1() As Double
    Dim TempPeakArray2() As Double
    Dim TempPeakArray3() As Double
    Dim lmassPeak As Double
    Dim dMass As Double
    Dim dIntensity As Double
    Dim K As Long
    Dim I As Long
    Dim J As Long
    Dim tmpBasePeak As Variant
    
    ' Correct the spec baseline
    ActiveDocument.SpecSetup.BaselineFitPeakWidth = 32
    ActiveDocument.SpecSetup.BaselineFitFlexibility = 0.5
    ActiveDocument.SpecSetup.BaselineFitDegree = 0.1
    ActiveDocument.SpecView.CorrectBaseline2
    ' Smooth spectrum trace
    ActiveDocument.SpecSetup.SmoothFilterWidth = 5
    ActiveDocument.SpecView.SmoothTrace
       
   'Clear the output window

    Application.OutputWindowClear (deOutputResult)
   
   
    'Define increment and number of peaks for peak list
    PeakNumber = 10
    PeakRange = 50
   
    'Define mass range
    FirstMass = ActiveDocument.SpecView.DisplayMinX
    LastMass = ActiveDocument.SpecView.DisplayMaxX

    'Calculate the last increment for looping
    If (((LastMass - FirstMass) Mod PeakRange) = 0) Then
        LastIncrement = (LastMass - FirstMass) / PeakRange - 1
    Else
        LastIncrement = Int((LastMass - FirstMass) / PeakRange)
    End If
  
  
    ReDim TempPeakArray1(PeakNumber * (LastIncrement + 1))
    ReDim TempPeakArray2(PeakNumber * (LastIncrement + 1))
    ReDim TempPeakArray3(PeakNumber * (LastIncrement + 1))
      
   'Increment PEAKRANGE to higher mass
    N = 0
    For nIncrementer = 0 To LastIncrement
   
        'Set starting point
        dStart = FirstMass + nIncrementer * PeakRange
      
        'Choose right ending point
        If ((FirstMass + (nIncrementer + 1) * PeakRange) < LastMass) Then
            dEnd = FirstMass + (nIncrementer + 1) * PeakRange
        Else
            dEnd = LastMass
        End If
   
        'Get all peaks sorted by intensity (from low to high)
        nSpecPeak = ActiveDocument.SpecView.GetPeakData(deSpecPeakAll, deSpecPeakSortMass, dStart, dEnd, SpecPeakArray)
          
        'Get GetBasePeak
        tmpBasePeak = ActiveDocument.SpecView.GetBasePeak(dMass, dIntensity)
       
        'Write 1-PEAKNUMBER most intensive peaks (if has)per PEAKRANGE amu to output list
        If (nSpecPeak > 0) Then
       
            nPeakEnd = nSpecPeak - PeakNumber + 1
           
            If (nPeakEnd <= 0) Then
                nPeakEnd = 1
            End If
           
            For iPeak = nSpecPeak To nPeakEnd Step -1
                ' Add peak to the temporary array
                TempPeakArray1(N) = (SpecPeakArray(iPeak - 1, deSpecPeakCentroidMass))
                TempPeakArray2(N) = (SpecPeakArray(iPeak - 1, deSpecPeakArea))
                TempPeakArray3(N) = 100 * (SpecPeakArray(iPeak - 1, deSpecPeakPeakHeight)) / dIntensity
                N = N + 1
            'Go to next item
            Next iPeak
           
        End If
           
    Next nIncrementer
       
           
    'Sort from low to high mass in the TempPeakArray
    For I = 0 To PeakNumber * (LastIncrement + 1)
   
        For J = I To PeakNumber * (LastIncrement + 1)
       
            If TempPeakArray1(I) > TempPeakArray1(J) Then
           
                lmassPeak = TempPeakArray1(J)
                TempPeakArray1(J) = TempPeakArray1(I)
                TempPeakArray1(I) = lmassPeak
              
                lmassPeak = TempPeakArray2(J)
                TempPeakArray2(J) = TempPeakArray2(I)
                TempPeakArray2(I) = lmassPeak
               
                lmassPeak = TempPeakArray3(J)
                TempPeakArray3(J) = TempPeakArray3(I)
                TempPeakArray3(I) = lmassPeak
               
            End If
           
        Next J
       
    Next I
         
         
    'Put peaks in the output window
    For K = 0 To PeakNumber * (LastIncrement + 1)
   
        If TempPeakArray1(K) > 0 Then
       
        Application.OutputWindowWrite deOutputResult, (Format(TempPeakArray1(K), "######.0000") & "   " & Format(TempPeakArray2(K), "######.0000") & "   " & Format(TempPeakArray3(K), "######.0000"))
           
        End If
       
    Next K
   
    ' Save to file with the extension name .wkh.txt
   
    Dim strFilename As String
    strFilename = ActiveDocument.FullName

    strFilename = strFilename + ".wkh.txt"

       If (strFilename <> "") Then
        Dim File As Integer
        File = FreeFile
        Open strFilename For Output As #File
        For K = 0 To PeakNumber * (LastIncrement + 1)
            If TempPeakArray1(K) > 0 Then
              Print #File, Format(TempPeakArray1(K), "######.0000") & "," & Format(TempPeakArray2(K), "######.0000") & "," & Format(TempPeakArray3(K), "######.0000")
            End If
        Next K
            Application.OutputWindowWrite deOutputResult, strFilename
        Close #File
       End If
'     End If
              
End Sub

TAG: peaklist 文件 源代码

学海无涯乐作舟 引用 删除 zzl   /   2011-06-20 18:27:21
5
 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar