-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20211123-MSAlignOutput_AzoNM.vbs
175 lines (134 loc) · 5.85 KB
/
20211123-MSAlignOutput_AzoNM.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
SetLocale(1033) ' Localise for US (. instead , accepted as decimal separator for calculations)
Dim comp, spec, i, oPeak, prec, chargeState, PrecursorMZ, PrecursorMass, RTStart, RTEnd, bUseSNAP
Dim MSMSSpec, MSMSoutput(), FileName, sExtension, Factor, MSMSType, counter
Const Proton = 1.00727647
bUseSNAP = True
sExtension = ".msalign"
counter = 1
Const ETDData = "ETD"
'**************************************************************************************************
'*************************************************************************************************
Factor = 10
RTStart = 1
RTEnd = 80
'*************************************************************************************************
'************************************************************************************************
FileName = GetExportFileName(sExtension)
Dim objFSO, objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(FileName)
Call SetMethodParametersPeakfinder()
Analysis.ClearChromatogramRangeSelections
Analysis.AddChromatogramRangeSelection RTStart, RTEnd, 0, 0
Analysis.FindAutoMSn
On Error Resume Next
For Each comp In Analysis.compounds
MSMSType = "CID"
PrecursorMass = 0
chargeState = 0
PrecursorMZ = 0
chargeState = CInt(GetChargeState(comp))
If IsNumeric(comp.Precursor) Then
PrecursorMZ = Round(comp.precursor, 4)
Else
PrecursorMZ= GetPrecMassFromName(comp)
End If
PrecursorMass = Round(((PrecursorMZ*chargeState) - chargeState),4)
Set MSMSSpec = comp(2)
If IsETD(MSMSSpec) Then
MSMSType = "ETD"
End If
ReDim MSMSoutput(MSMSSpec.MSPeakList.Count, 2)
for i=1 to MSMSSpec.MSPeakList.Count
Set oPeak = MSMSSpec.MSPeakList(i)
MSMSoutput(i,0) = Round((oPeak.DeconvolutedMolweight - Proton),4)
MSMSoutput(i,1) = Round((oPeak.intensity * Factor),2)
MSMSoutput(i,2) = oPeak.chargestate
Next
objFile.WriteLine("BEGIN IONS")
objFile.WriteLine("ID=" & comp.CompoundNumber)
objFile.WriteLine("SCANS=" & GetScanNumbers(MSMSSpec))
objFile.WriteLine("ACTIVATION=" & MSMSType)
objFile.WriteLine("PRECURSOR_MZ=" & PrecursorMZ)
objFile.WriteLine("PRECURSOR_CHARGE=" & chargeState)
objFile.WriteLine("PRECURSOR_MASS=" & PrecursorMass)
Dim count, line
For count = 1 To UBound(MSMSOutput)
line = (MSMSoutput(count,0) & " " & MSMSoutput(count,1) & " " & MSMSoutput(count,2))
objFile.WriteLine(line)
Next
objFile.WriteLine("END IONS" & vbCrLf)
Next
Call ResetPeakfinder()
objFile.Close
Analysis.Save
Form.Close
'***********************************************************************
Public Function GetChargeState (comp)
GetChargeState = 1
mChargeState = 1
Dim mSpec, mPrec, mPeak, mChargeState, p, y
Set mSpec = comp(1)
If IsNumeric(comp.Precursor) Then 'get the precursor mass. This checks to make sure the compound has an assigned precursor. (A bug in DA 4.4 means this can be missing)
mPrec = Round(comp.precursor, 4)
Else
mPrec = GetPrecMassFromName(comp) 'if the precursor mass is missing then extract the information from the compound name
End If
for y=1 to mSpec.MSPeakList.Count 'As the charge state for the precursor is not included search through the MS spectrum to find the precursor mass and get the charge state from there
Set mPeak = mSpec.MSPeakList(y)
If Round(mPeak.m_over_z,4) = mPrec Then
mChargeState = mPeak.ChargeState
Exit For
End If
Next
GetChargeState = mChargeState 'return the chrage state (if for some reason the charge state can not be determined (SNAP was not able to deconvolute peak) then return "1" as charge state
End Function
Sub SetMethodParametersPeakfinder()
Dim oPeakFinderParameters
Set oPeakFinderParameters = Analysis.Method.MassListParameters()
If bUseSNAP = True Then
oPeakFinderParameters.DetectionAlgorithm = 2 ' 3 means Sum; 2 means SNAP; 0 means APEX
Else
oPeakFinderParameters.DetectionAlgorithm = 3 ' 3 means Sum; 2 means SNAP; 0 means APEX
End If
End Sub
Sub ResetPeakfinder
Dim oPeakFinderParameters
Set oPeakFinderParameters = Analysis.Method.MassListParameters()
oPeakFinderParameters.DetectionAlgorithm = 3 ' 3 means Sum; 2 means SNAP; 0 means APEX
End Sub
Function GetExportFileName(sExtension)
Dim aFileNames
aFileNames = split(Analysis.Name,".d",-1,1)
GetExportFileName = Analysis.Path & "\" & aFileNames(0) & sExtension
End Function
Function IsETD(comp)
Dim mComp, mCompName
IsETD = False
mCompName = comp.Name
If InStr(mCompName,ETDData) Then
IsETD= True
End If
End Function
Function GetScanNumbers(Spectrum)
Dim position, position2, initialScanPos
GetScanNumbers = ""
position = InStr(Spectrum.Name,"#")
position2 = InStrRev(Spectrum.Name,"-")
If position2 >0 Then
initialScanPos = position2-(position+1)
GetScanNumbers = (Mid(Spectrum.Name, position+1, initialScanPos))+1
Else
GetScanNumbers = (Mid(Spectrum.Name, position+1))+1
End If
End Function
Function GetPrecMassFromName(comp)
GetPrecMassFromName = 0
Dim compName
compName = comp.Name
Dim count, str, startPos, endPos
startPos = (InStr(compName,"(") + 1)
endPos = InStr(compName,")")
str = Mid(compName,(startPos),(endPos-startPos))
GetPrecMassFromName = CDbl(str)
End Function