-
Notifications
You must be signed in to change notification settings - Fork 0
/
MSFileReader.py
2791 lines (2491 loc) · 131 KB
/
MSFileReader.py
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/env python2.7
# encoding: utf-8
#
# The MIT License (MIT)
#
# Copyright (c) 2016 François ALLAIN
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from __future__ import print_function
import sys
import os
import time
import logging
from collections import namedtuple
from ctypes import *
__version__ = "3.1.5.0"
# XRawfile2(_x64).dll 3.0.29.0
# fregistry(_x64).dll 3.0.0.0
# Fileio(_x64).dll 3.0.0.0
# cf.
# https://thermo.flexnetoperations.com/control/thmo/[email protected]&password=B8g-72&action=authenticate&nextURL=index
# -> Utility Software
# Related third party imports
if sys.version_info.major == 2 and sys.version_info.minor < 7:
OrderedDict = dict
else:
from collections import OrderedDict
try:
WindowsError
except NameError:
raise ImportError("Platform Not Supported")
try:
import comtypes
from comtypes.client import GetModule, CreateObject
except (ImportError, NameError) as e:
raise ImportError("Could not import comtypes")
log = logging.getLogger(os.path.basename(__file__))
try:
# Load previously built COM wrapper
from comtypes.gen import MSFileReaderLib
DLL_IS_LOADED = True
except ImportError:
DLL_IS_LOADED = False
_default_paths = [
# Theoretical Bundled 64 bit MSFileReader DLL
os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'XRawfile2_x64.dll'),
# Default Installation Path on 64 bit systems
u'C:\\Program Files\\Thermo\\MSFileReader\\XRawfile2_x64.dll',
u'C:\\Program Files (x86)\\Thermo\\MSFileReader\\XRawfile2.dll',
# Default Installation Path on 32 bit systems
u'C:\\Program Files\\Thermo\\MSFileReader\\XRawfile2.dll',
]
def _register_dll(search_paths=None):
global DLL_IS_LOADED
if DLL_IS_LOADED:
return True
if search_paths is None:
search_paths = []
search_paths = list(search_paths)
search_paths.extend(_default_paths)
paths_yet_to_search = list(search_paths)
for path in paths_yet_to_search:
try:
log.debug("Attempting to load DLL from %r" % (path,))
GetModule(path)
DLL_IS_LOADED = True
return True
except Exception:
continue
else:
return False
def register_dll(search_paths=None):
if search_paths is None:
search_paths = []
loaded = _register_dll(search_paths)
if not loaded:
log.debug("Could not resolve XRawfile-related DLL")
search_paths.extend(_default_paths)
msg = '''
1) The msFileReader DLL (XRawfile2.dll or XRawfile2_x64.dll) may not be installed and
therefore not registered to the COM server.
2) The msFileReader DLL may not be a these paths:
%s
''' % ('\n'.join(search_paths))
raise ImportError(msg)
GetLabelData_Labels = namedtuple(
'LabelData_Labels', 'mass intensity resolution baseline noise charge')
GetLabelData_Flags = namedtuple(
'LabelData_Flags', 'saturated fragmented merged exception reference modified')
GetAllMSOrderData_Labels = namedtuple(
'AllMSOrderData_Labels', 'mass intensity resolution baseline noise charge')
GetAllMSOrderData_Flags = namedtuple(
'AllMSOrderData_Flags', 'activation_type is_precursor_range_valid')
FullMSOrderPrecursorData = namedtuple(
'FullMSOrderPrecursorData',
['precursorMass',
'isolationWidth',
'collisionEnergy',
'collisionEnergyValid',
'rangeIsValid',
'firstPrecursorMass',
'lastPrecursorMass',
'isolationWidthOffset'])
GetPrecursorInfoFromScanNum_PrecursorInfo = namedtuple(
'PrecursorInfo', 'isolationMass monoIsoMass chargeState scanNumber')
def _to_float(x):
try:
out = float(x)
except ValueError:
out = str(x)
return out
try:
basestring
except NameError:
basestring = str
# noinspection PyPep8Naming
class ThermoRawfile(object):
# static class members
sampleType = {0: 'Unknown',
1: 'Blank',
2: 'QC',
3: 'Standard Clear (None)',
4: 'Standard Update (None)',
5: 'Standard Bracket (Open)',
6: 'Standard Bracket Start (multiple brackets)',
7: 'Standard Bracket End (multiple brackets)'}
controllerType = {-1: 'No device',
0: 'MS',
1: 'Analog',
2: 'A/D card',
3: 'PDA',
4: 'UV',
'No device': -1,
'MS': 0,
'Analog': 1,
'A/D card': 2,
'PDA': 3,
'UV': 4}
massAnalyzerType = {'ITMS': 0,
'TQMS': 1,
'SQMS': 2,
'TOFMS': 3,
'FTMS': 4,
'Sector': 5,
0: 'ITMS',
1: 'TQMS',
2: 'SQMS',
3: 'TOFMS',
4: 'FTMS',
5: 'Sector'}
activationType = {'CID': 0,
'MPD': 1,
'ECD': 2,
'PQD': 3,
'ETD': 4,
'HCD': 5,
'Any activation type': 6,
'SA': 7,
'PTR': 8,
'NETD': 9,
'NPTR': 10,
0: 'CID',
1: 'MPD',
2: 'ECD',
3: 'PQD',
4: 'ETD',
5: 'HCD',
6: 'Any activation type',
7: 'SA',
8: 'PTR',
9: 'NETD',
10: 'NPTR'}
detectorType = {'CID': 0,
'PQD': 1,
'ETD': 2,
'HCD': 3,
0: 'CID',
1: 'PQD',
2: 'ETD',
3: 'HCD'}
scanType = {'ScanTypeFull': 0,
'ScanTypeSIM': 1,
'ScanTypeZoom': 2,
'ScanTypeSRM': 3,
0: 'ScanTypeFull',
1: 'ScanTypeSIM',
2: 'ScanTypeZoom',
3: 'ScanTypeSRM'}
@staticmethod
def create_com_object():
try:
log.debug("obj = CreateObject('MSFileReader.XRawfile')")
obj = CreateObject('MSFileReader.XRawfile')
except Exception as exc:
log.debug(exc)
try:
log.debug("obj = CreateObject('XRawfile.XRawfile')")
obj = CreateObject('XRawfile.XRawfile')
except Exception as e:
log.debug(e)
raise ImportError(
('Please install the appropriate Thermo MSFileReader'
'version depending of your Python version (32bits or 64bits)\n%r') % e)
return obj
def __init__(self, filename, **kwargs):
self.filename = os.path.abspath(filename)
self.filename = os.path.normpath(self.filename)
self.source = None
if not DLL_IS_LOADED:
register_dll()
obj = self.create_com_object()
self.source = obj
try:
error = obj.Open(filename)
except WindowsError:
raise WindowsError(
("RAWfile {0} could not be opened, is the file accessible and\
not opened in Xcalibur/QualBrowser ?").format(self.filename))
if error:
raise IOError(
"RAWfile {0} could not be opened, is the file accessible ?".format(
self.filename))
error = obj.SetCurrentController(c_long(0), c_long(1))
if error:
obj.Close()
raise IOError("Open error {} : {}".format(self.filename, error))
self.StartTime = self.GetStartTime()
self.EndTime = self.GetEndTime()
self.FirstSpectrumNumber = self.GetFirstSpectrumNumber()
self.LastSpectrumNumber = self.GetLastSpectrumNumber()
self.LowMass = self.GetLowMass()
self.HighMass = self.GetHighMass()
self.MassResolution = self.GetMassResolution()
self.NumSpectra = self.GetNumSpectra()
try:
self.InstMethodNames = self.GetInstMethodNames()
self.NumInstMethods = self.GetNumInstMethods()
except IOError:
self.InstMethodNames = None
self.NumInstMethods = None
self.NumStatusLog = self.GetNumStatusLog()
self.NumErrorLog = self.GetNumErrorLog()
self.NumTuneData = self.GetNumTuneData()
self.NumTrailerExtra = self.GetNumTrailerExtra()
self.dll_version = self.Version()
self.FileName = self.GetFileName()
self.InstrumentDescription = self.GetInstrumentDescription()
self.AcquisitionDate = self.GetAcquisitionDate()
self.InstName = self.GetInstName()
self.InstModel = self.GetInstModel()
self.InstSoftwareVersion = self.GetInstSoftwareVersion()
self.InstHardwareVersion = self.GetInstHardwareVersion()
def Close(self):
"""Closes a raw file and frees the associated memory."""
self.source.Close()
def Version(self): # MSFileReader DLL version
"""This function returns the version number for the DLL."""
MajorVersion, MinorVersion, SubMinorVersion, BuildNumber = c_long(
), c_long(), c_long(), c_long()
error = self.source.Version(byref(MajorVersion), byref(
MinorVersion), byref(SubMinorVersion), byref(BuildNumber))
if error:
raise IOError("Version error :", error)
return '{}.{}.{}.{}'.format(
MajorVersion.value, MinorVersion.value, SubMinorVersion.value,
BuildNumber.value)
def GetFileName(self):
"""Returns the fully qualified path name of an open raw file."""
pbstrFileName = comtypes.automation.BSTR()
error = self.source.GetFileName(byref(pbstrFileName))
if error:
raise IOError("GetFileName error :", error)
return pbstrFileName.value
def GetCreatorID(self):
"""Returns the creator ID. The creator ID is the
logon name of the user when the raw file was acquired."""
pbstrCreatorID = comtypes.automation.BSTR()
error = self.source.GetCreatorID(byref(pbstrCreatorID))
if error:
raise IOError("GetCreatorID error :", error)
return pbstrCreatorID.value
def GetVersionNumber(self):
"""Returns the file format version number"""
versionNumber = c_long()
error = self.source.GetVersionNumber(byref(versionNumber))
if error:
raise IOError("GetVersionNumber error :", error)
return versionNumber.value
def GetCreationDate(self):
"""Returns the file creation date in DATE format."""
# https://msdn.microsoft.com/en-us/library/82ab7w69.aspx
# The DATE type is implemented using an 8-byte floating-point number
pCreationDate = c_double()
error = self.source.GetCreationDate(byref(pCreationDate))
if error:
raise IOError("GetCreationDate error :", error)
return time.gmtime(pCreationDate.value)
def IsError(self):
"""Returns the error state flag of the raw file. A return value of TRUE indicates that an error has
occurred. For information about the error, call the GetErrorCode or GetErrorMessage
functions."""
pbIsError = c_long()
error = self.source.IsError(byref(pbIsError))
if error:
raise IOError("IsError error :", error)
return bool(pbIsError.value)
def IsNewFile(self):
"""Returns the creation state flag of the raw file. A return value of TRUE indicates that the file
has not previously been saved."""
bNewFile = c_long()
error = self.source.IsNewFile(byref(bNewFile))
if error:
raise IOError("IsNewFile error :", error)
return bool(bNewFile.value)
def IsThereMSData(self):
"""This function checks to see if there is MS data in the raw file. A return value of TRUE means
that the raw file contains MS data. You must open the raw file before performing this check."""
pbMSData = c_long()
error = self.source.IsThereMSData(byref(pbMSData))
if error:
raise IOError("IsThereMSData error :", error)
return bool(pbMSData.value)
def HasExpMethod(self):
"""This function checks to see if the raw file contains an experimental method. A return value of
TRUE indicates that the raw file contains the method. You must open the raw file before
performing this check."""
bHasMethod = c_long()
error = self.source.HasExpMethod(byref(bHasMethod))
if error:
raise IOError("HasExpMethod error :", error)
return bool(bHasMethod.value)
def InAcquisition(self):
"""Returns the acquisition state flag of the raw file. A return value of TRUE indicates that the
raw file is being acquired or that all open handles to the file during acquisition have not been
closed."""
pbInAcquisition = c_long()
error = self.source.InAcquisition(byref(pbInAcquisition))
if error:
raise IOError("InAcquisition error :", error)
return bool(pbInAcquisition.value)
def GetErrorCode(self):
"""Returns the error code of the raw file. A return value of 0 indicates that there is no error."""
nErrorCode = c_long()
error = self.source.GetErrorCode(byref(nErrorCode))
if error:
raise IOError("GetErrorCode error :", error)
return nErrorCode.value
def GetErrorMessage(self):
"""Returns error information for the raw file as a descriptive string. If there is no error, the
returned string is empty."""
pbstrErrorMessage = comtypes.automation.BSTR()
error = self.source.GetErrorMessage(byref(pbstrErrorMessage))
if error:
raise IOError("GetErrorMessage error : ", error)
return pbstrErrorMessage.value
def GetWarningMessage(self):
"""Returns warning information for the raw file as a descriptive string. If there is no warning, the
returned string is empty."""
pbstrWarningMessage = comtypes.automation.BSTR()
error = self.source.GetWarningMessage(byref(pbstrWarningMessage))
if error:
raise IOError("GetWarningMessage error : ", error)
return pbstrWarningMessage.value
def RefreshViewOfFile(self):
"""Refreshes the view of a file currently being acquired. This function provides a more efficient
mechanism for gaining access to new data in a raw file during acquisition without closing and
reopening the raw file. This function has no effect with files that are not being acquired."""
error = self.source.RefreshViewOfFile()
if error:
raise IOError("RefreshViewOfFile error :", error)
return
def GetNumberOfControllers(self):
"""Returns the number of registered device controllers in the raw file. A device controller
represents an acquisition stream such as MS data, UV data, and so on. Devices that do not
acquire data, such as autosamplers, are not registered with the raw file during acquisition."""
pnNumControllers = c_long()
error = self.source.GetNumberOfControllers(byref(pnNumControllers))
if error:
raise IOError("GetNumberOfControllers error :", error)
return pnNumControllers.value
def GetNumberOfControllersOfType(self, controllerType='MS'):
"""Returns the number of registered device controllers of a particular type in the raw file. See
Controller Type in the Enumerated Types section for a list of the available controller types
and their respective values."""
if isinstance(controllerType, basestring):
controllerType = ThermoRawfile.controllerType[controllerType]
pnNumControllersOfType = c_long()
error = self.source.GetNumberOfControllersOfType(
c_long(controllerType), byref(pnNumControllersOfType))
if error:
raise IOError("GetNumberOfControllersOfType error :", error)
return pnNumControllersOfType.value
def GetControllerType(self, index):
"""Returns the type of the device controller registered at the specified index position in the raw
file. Index values start at 0. See Controller Type in the Enumerated Types section for a list of
the available controller types and their respective values."""
controllerType = c_long()
error = self.source.GetControllerType(index, byref(controllerType))
if error:
raise IOError("GetControllerType error :", error)
return ThermoRawfile.controllerType[controllerType.value]
def SetCurrentController(self, controllerType, controllerNumber):
"""Sets the current controller in the raw file. This function must be called before subsequent calls
to access data specific to a device controller (for example, MS or UV data) may be made. All
requests for data specific to a device controller are forwarded to the current controller until the
current controller is changed. The controller number is used to indicate which device
controller to use if there is more than one registered device controller of the same type (for
example, multiple UV detectors). Controller numbers for each type are numbered starting
at 1. See Controller Type in the Enumerated Types section for a list of the available controller
types and their respective values."""
if isinstance(controllerType, basestring):
controllerType = ThermoRawfile.controllerType[controllerType]
error = self.source.SetCurrentController(
c_long(controllerType), c_long(controllerNumber))
if error:
raise IOError("SetCurrentController error :", error)
return
def GetCurrentController(self):
"""Gets the current controller type and number for the raw file. The controller number is used to
indicate which device controller to use if there is more than one registered device controller of
the same type (for example, multiple UV detectors). Controller numbers for each type are
numbered starting at 1. See Controller Type in the Enumerated Types section for a list of the
available controller types and their respective values."""
pnControllerType = c_long()
pnControllerNumber = c_long()
error = self.source.GetCurrentController(
byref(pnControllerType), byref(pnControllerNumber))
if error:
raise IOError("GetCurrentController error :", error)
return pnControllerType.value, pnControllerNumber.value
def GetExpectedRunTime(self):
"""Gets the expected acquisition run time for the current controller. The actual acquisition may
be longer or shorter than this value. This value is intended to allow displays to show the
expected run time on chromatograms. To obtain an accurate run time value during or after
acquisition, use the GetEndTime function."""
pdExpectedRunTime = c_double()
error = self.source.GetExpectedRunTime(byref(pdExpectedRunTime))
if error:
raise IOError("GetExpectedRunTime error :", error)
return pdExpectedRunTime.value
def GetNumTrailerExtra(self):
"""Gets the trailer extra entries recorded for the current controller. Trailer extra entries are only
supported for MS device controllers and are used to store instrument specific information for
each scan if used."""
pnNumberOfTrailerExtraEntries = c_long()
error = self.source.GetNumTrailerExtra(
byref(pnNumberOfTrailerExtraEntries))
if error:
raise IOError("GetNumTrailerExtra error :", error)
return pnNumberOfTrailerExtraEntries.value
def GetMaxIntegratedIntensity(self):
"""Gets the highest integrated intensity of all the scans for the current controller. This value is
only relevant to MS device controllers."""
pdMaxIntegIntensity = c_double()
error = self.source.GetMaxIntegratedIntensity(
byref(pdMaxIntegIntensity))
if error:
raise IOError("GetMaxIntegratedIntensity error :", error)
return pdMaxIntegIntensity.value
def GetMaxIntensity(self):
"""Gets the highest base peak of all the scans for the current controller. This value is only relevant
to MS device controllers."""
dMaxInt = c_long()
error = self.source.GetMaxIntensity(byref(dMaxInt))
if error:
raise IOError("GetMaxIntensity error :", error)
return dMaxInt.value
def GetInletID(self):
"""Gets the inlet ID number for the current controller. This value is typically only set for raw
files converted from other file formats."""
nInletID = c_long()
error = self.source.GetInletID(byref(nInletID))
if error:
raise IOError("GetInletID error :", error)
return nInletID.value
def GetErrorFlag(self):
"""Gets the error flag value for the current controller. This value is typically only set for raw files
converted from other file formats."""
pnErrorFlag = c_long()
error = self.source.GetErrorFlag(byref(pnErrorFlag))
if error:
raise IOError("GetErrorFlag error :", error)
return pnErrorFlag.value
def GetFlags(self):
"""Returns the acquisition flags field for the current controller. This value is typically only set for
raw files converted from other file formats."""
pbstrFlags = comtypes.automation.BSTR(None)
error = self.source.GetFlags(byref(pbstrFlags))
if error:
raise IOError("GetFlags error :", error)
return pbstrFlags.value
def GetAcquisitionFileName(self):
"""Returns the acquisition file name for the current controller. This value is typically only set for
raw files converted from other file formats."""
pbstrFileName = comtypes.automation.BSTR(None)
error = self.source.GetAcquisitionFileName(byref(pbstrFileName))
if error:
raise IOError("GetAcquisitionFileName error :", error)
return pbstrFileName.value
def GetAcquisitionDate(self):
"""Returns the acquisition date for the current controller. This value is typically only set for raw
files converted from other file formats."""
pbstrAcquisitionDate = comtypes.automation.BSTR(None)
error = self.source.GetAcquisitionDate(byref(pbstrAcquisitionDate))
if error:
raise IOError("GetAcquisitionDate error :", error)
return pbstrAcquisitionDate.value
def GetOperator(self):
"""Returns the operator name for the current controller. This value is typically only set for raw
files converted from other file formats."""
pbstrOperator = comtypes.automation.BSTR(None)
error = self.source.GetOperator(byref(pbstrOperator))
if error:
raise IOError("GetOperator error :", error)
return pbstrOperator.value
def GetComment1(self):
"""Returns the first comment for the current controller. This value is typically only set for raw
files converted from other file formats."""
pbstrComment1 = comtypes.automation.BSTR(None)
error = self.source.GetComment1(byref(pbstrComment1))
if error:
raise IOError("GetComment1 error :", error)
return pbstrComment1.value
def GetComment2(self):
"""Returns the second comment for the current controller. This value is typically only set for raw
files converted from other file formats."""
pbstrComment2 = comtypes.automation.BSTR(None)
error = self.source.GetComment2(byref(pbstrComment2))
if error:
raise IOError("GetComment2 error :", error)
return pbstrComment2.value
def GetFilters(self):
"""Returns the list of unique scan filters for the raw file. This function is only supported for MS
device controllers. If the function succeeds, pvarFilterArray points to an array of BSTR fields,
each containing a unique scan filter, and pnArraySize contains the number of scan filters in the
pvarFilterArray."""
pvarFilterArray = comtypes.automation.VARIANT()
pnArraySize = c_long()
error = self.source.GetFilters(
byref(pvarFilterArray), byref(pnArraySize))
if error:
raise IOError("GetFilters error :", error)
return pvarFilterArray.value
def SetMassTolerance(self, userDefined=True, massTolerance=500.0, units=0):
"""This function sets the mass tolerance that will be used with the raw file.
userDefined A boolean indicating whether the mass tolerance is user-defined (True) or
based on the values in the raw file (False).
massTolerance The mass tolerance value.
units The type of tolerance value (amu = 2, mmu = 0, or ppm = 1).
"""
error = self.source.SetMassTolerance(
userDefined, c_double(massTolerance), c_long(units))
if error:
raise IOError("SetMassTolerance error :", error)
return
def GetMassTolerance(self):
"""This function gets the mass tolerance that is being used with the raw file. To set these values,
use the SetMassTolerance() function.
bUserDefined A flag indicating whether the mass tolerance is user-defined (TRUE) or
based on the values in the raw file (FALSE).
dMassTolerance The mass tolerance value.
nUnits The type of tolerance value (amu = 2, mmu = 0, or ppm = 1).
"""
bUserDefined = c_long()
dMassTolerance = c_double()
nUnits = c_long()
error = self.source.GetMassTolerance(
byref(bUserDefined), byref(dMassTolerance), byref(nUnits))
if error:
raise IOError("GetMassTolerance error :", error)
return bool(bUserDefined.value), dMassTolerance.value, nUnits.value
# INSTRUMENT BEGIN
def GetInstrumentDescription(self):
"""Returns the instrument description field for the current controller. This value is typically only
set for raw files converted from other file formats."""
pbstrInstrumentDescription = comtypes.automation.BSTR(None)
error = self.source.GetInstrumentDescription(
byref(pbstrInstrumentDescription))
if error:
raise IOError("GetInstrumentDescription error :", error)
return pbstrInstrumentDescription.value
def GetInstrumentID(self):
"""Gets the instrument ID number for the current controller. This value is typically only set for
raw files converted from other file formats."""
pnInstrumentID = c_long()
error = self.source.GetInstrumentID(byref(pnInstrumentID))
if error:
raise IOError("GetInstrumentID error :", error)
return pnInstrumentID.value
def GetInstName(self):
"""Returns the instrument name, if available, for the current controller."""
pbstrInstName = comtypes.automation.BSTR(None)
error = self.source.GetInstName(byref(pbstrInstName))
if error:
raise IOError("GetInstName error :", error)
return pbstrInstName.value
def GetInstModel(self):
"""Returns the instrument model, if available, for the current controller."""
pbstrInstModel = comtypes.automation.BSTR(None)
error = self.source.GetInstModel(byref(pbstrInstModel))
if error:
raise IOError("GetInstModel error :", error)
return pbstrInstModel.value
def GetInstSerialNumber(self):
"""Returns the serial number, if available, for the current controller."""
pbstrInstSerialNumber = comtypes.automation.BSTR(None)
error = self.source.GetInstSerialNumber(byref(pbstrInstSerialNumber))
if error:
raise IOError("GetInstSerialNumber error :", error)
return pbstrInstSerialNumber.value
def GetInstSoftwareVersion(self):
"""Returns revision information for the current controller software, if available."""
InstSoftwareVersion = comtypes.automation.BSTR()
error = self.source.GetInstSoftwareVersion(byref(InstSoftwareVersion))
if error:
raise IOError("GetInstSoftwareVersion error :", error)
return InstSoftwareVersion.value
def GetInstHardwareVersion(self):
"""Returns revision information for the current controller software, if available."""
InstHardwareVersion = comtypes.automation.BSTR()
error = self.source.GetInstHardwareVersion(byref(InstHardwareVersion))
if error:
raise IOError("GetInstHardwareVersion error :", error)
return InstHardwareVersion.value
def GetInstFlags(self):
"""Returns the experiment flags, if available, for the current controller. The returned string may
contain one or more fields denoting information about the type of experiment performed.
These are the currently defined experiment fields:
TIM - total ion map
NLM - neutral loss map
PIM - parent ion map
DDZMap - data-dependent ZoomScan map"""
pbstrInstFlags = comtypes.automation.BSTR()
error = self.source.GetInstFlags(byref(pbstrInstFlags))
if error:
raise IOError("GetInstFlags error :", error)
return pbstrInstFlags.value
def GetInstNumChannelLabels(self):
"""Returns the number of channel labels specified for the current controller. This field is only
relevant to channel devices such as UV detectors, A/D cards, and Analog inputs. Typically, the
number of channel labels, if labels are available, is the same as the number of configured
channels for the current controller."""
pnInstNumChannelLabels = c_long()
error = self.source.GetInstNumChannelLabels(
byref(pnInstNumChannelLabels))
if error:
raise IOError("GetInstNumChannelLabels error :", error)
return pnInstNumChannelLabels.value
def GetInstChannelLabel(self, channelLabelNumber=0):
"""Returns the channel label, if available, at the specified index for the current controller. This
field is only relevant to channel devices such as UV detectors, A/D cards, and Analog inputs.
Channel label indices are numbered starting at 0."""
pbstrFlags = comtypes.automation.BSTR()
error = self.source.GetInstChannelLabel(
c_long(channelLabelNumber), byref(pbstrFlags))
if error:
raise IOError("GetInstChannelLabel error :", error)
return pbstrFlags.value
# INSTRUMENT END
def GetScanEventForScanNum(self, scanNumber):
"""This function returns scan event information as a string for the specified scan number."""
pbstrScanEvent = comtypes.automation.BSTR()
error = self.source.GetScanEventForScanNum(
c_long(scanNumber), byref(pbstrScanEvent))
if error:
raise IOError("GetScanEventForScanNum error :", error)
return pbstrScanEvent.value
# NOT GetSegmentAndScanEventForScanNum
def GetSegmentAndEventForScanNum(self, scanNumber):
"""Returns the segment and scan event indexes for the specified scan."""
pbstrScanEvent = comtypes.automation.BSTR()
pnSegment = c_long(0)
pnScanEvent = c_long(0)
error = self.source.GetSegmentAndEventForScanNum(
c_long(scanNumber), byref(pnSegment), byref(pnScanEvent))
if error:
raise IOError("GetSegmentAndEventForScanNum error :", error)
return pbstrScanEvent.value
def GetSegmentAndScanEventForScanNum(self, scanNumber):
return self.GetSegmentAndEventForScanNum(scanNumber)
def GetCycleNumberFromScanNumber(self, scanNumber):
"""This function returns the cycle number for the scan specified by scanNumber from the scan
index structure in the raw file."""
pnCycleNumber = c_long()
error = self.source.GetCycleNumberFromScanNumber(
c_long(scanNumber), byref(pnCycleNumber))
if error:
raise IOError("GetCycleNumberFromScanNumber error :", error)
return pnCycleNumber.value
def GetAValueFromScanNum(self, scanNumber):
"""This function gets the A parameter value in the scan event. The value returned is either 0, 1,
or 2 for parameter A off, parameter A on, or accept any parameter A, respectively."""
pnXValue = c_long()
error = self.source.GetAValueFromScanNum(
c_long(scanNumber), byref(pnXValue))
if error:
raise IOError("GetAValueFromScanNum error :", error)
return pnXValue.value
def GetBValueFromScanNum(self, scanNumber):
"""This function gets the B parameter value in the scan event. The value returned will be either
0, 1, or 2 for parameter B off, parameter B on, or accept any parameter B, respectively."""
pnXValue = c_long()
error = self.source.GetBValueFromScanNum(
c_long(scanNumber), byref(pnXValue))
if error:
raise IOError("GetBValueFromScanNum error :", error)
return pnXValue.value
def GetFValueFromScanNum(self, scanNumber):
"""This function gets the F parameter value in the scan event. The value returned is either 0, 1,
or 2 for parameter F off, parameter F on, or accept any parameter F, respectively."""
pnXValue = c_long()
error = self.source.GetFValueFromScanNum(
c_long(scanNumber), byref(pnXValue))
if error:
raise IOError("GetFValueFromScanNum error :", error)
return pnXValue.value
def GetKValueFromScanNum(self, scanNumber):
"""This function gets the K parameter value in the scan event. The value returned is either 0, 1,
or 2 for parameter K off, parameter K on, or accept any parameter K, respectively."""
pnXValue = c_long()
error = self.source.GetKValueFromScanNum(
c_long(scanNumber), byref(pnXValue))
if error:
raise IOError("GetKValueFromScanNum error :", error)
return pnXValue.value
def GetRValueFromScanNum(self, scanNumber):
"""This function gets the R parameter value in the scan event. The value returned is either 0, 1,
or 2 for parameter R off, parameter R on, or accept any parameter R, respectively."""
pnXValue = c_long()
error = self.source.GetRValueFromScanNum(
c_long(scanNumber), byref(pnXValue))
if error:
raise IOError("GetRValueFromScanNum error :", error)
return pnXValue.value
def GetVValueFromScanNum(self, scanNumber):
"""This function gets the V parameter value in the scan event. The value returned is either 0, 1,
or 2 for parameter V off, parameter V on, or accept any parameter V, respectively."""
pnXValue = c_long()
error = self.source.GetVValueFromScanNum(
c_long(scanNumber), byref(pnXValue))
if error:
raise IOError("GetVValueFromScanNum error :", error)
return pnXValue.value
def GetMSXMultiplexValueFromScanNum(self, scanNumber):
"""This function gets the msx-multiplex parameter value in the scan event. The value returned is
either 0, 1, or 2 for multiplex off, multiplex on, or accept any multiplex, respectively."""
pnMSXValue = c_long()
error = self.source.GetMSXMultiplexValueFromScanNum(
c_long(scanNumber), byref(pnMSXValue))
if error:
raise IOError("GetMSXMultiplexValueFromScanNum error :", error)
return pnMSXValue.value
def GetNumberOfMassRangesFromScanNum(self, scanNumber):
"""This function gets the number of MassRange data items in the scan."""
result = c_long()
error = self.source.GetNumberOfMassRangesFromScanNum(
c_long(scanNumber), byref(result))
if error:
raise IOError("GetNumberOfMassRangesFromScanNum error :", error)
return result.value
def GetMassRangeFromScanNum(self, scanNumber, massRangeIndex):
"""This function retrieves information about the mass range data of a scan (high and low
masses). You can find the count of mass ranges for the scan by calling
GetNumberOfMassRangesFromScanNum()."""
pdMassRangeLowValue = c_double()
pdMassRangeHighValue = c_double()
error = self.source.GetMassRangeFromScanNum(c_long(scanNumber), c_long(
massRangeIndex), byref(pdMassRangeLowValue), byref(pdMassRangeHighValue))
if error:
raise IOError("GetMassRangeFromScanNum error :", error)
return pdMassRangeLowValue.value, pdMassRangeHighValue.value
def GetNumberOfSourceFragmentsFromScanNum(self, scanNumber):
"""This function gets the number of source fragments (or compensation voltages) in the scan."""
result = c_long()
error = self.source.GetNumberOfSourceFragmentsFromScanNum(
c_long(scanNumber), byref(result))
if error:
raise IOError(
"GetNumberOfSourceFragmentsFromScanNum error :", error)
return result.value
def GetSourceFragmentValueFromScanNum(self, scanNumber, sourceFragmentIndex):
"""This function retrieves information about one of the source fragment values of a scan. It is
also the same value as the compensation voltage. You can find the count of source fragments
for the scan by calling GetNumberOfSourceFragmentsFromScanNum ()."""
pdSourceFragmentValue = c_double()
error = self.source.GetSourceFragmentValueFromScanNum(
c_long(scanNumber), c_long(sourceFragmentIndex), byref(pdSourceFragmentValue))
if error:
raise IOError("GetSourceFragmentValueFromScanNum error :", error)
return pdSourceFragmentValue.value
def GetNumberOfSourceFragmentationMassRangesFromScanNum(self, scanNumber):
"""This function gets the number of source fragmentation mass ranges in the scan."""
result = c_long()
error = self.source.GetNumberOfSourceFragmentationMassRangesFromScanNum(
c_long(scanNumber), byref(result))
if error:
raise IOError(
"GetNumberOfSourceFragmentationMassRangesFromScanNum error :", error)
return result.value
def GetSourceFragmentationMassRangeFromScanNum(self, scanNumber, sourceFragmentIndex):
"""This function retrieves information about the source fragment mass range data of a scan (high
and low source fragment masses). You can find the count of mass ranges for the scan by calling
GetNumberOfSourceFragmentationMassRangesFromScanNum ()."""
pdSourceFragmentRangeLowValue = c_double()
pdSourceFragmentRangeHighValue = c_double()
error = self.source.GetSourceFragmentationMassRangeFromScanNum(c_long(scanNumber), c_long(
sourceFragmentIndex), byref(pdSourceFragmentRangeLowValue), byref(pdSourceFragmentRangeHighValue))
if error:
raise IOError(
"GetSourceFragmentationMassRangeFromScanNum error :", error)
return pdSourceFragmentRangeLowValue.value, pdSourceFragmentRangeHighValue.value
def GetIsolationWidthForScanNum(self, scanNumber, MSOrder):
"""This function returns the isolation width for the scan specified by scanNumber and the
transition specified by MSOrder from the scan event structure in the raw file."""
result = c_double()
error = self.source.GetIsolationWidthForScanNum(
c_long(scanNumber), c_long(MSOrder), byref(result))
if error:
raise IOError("GetIsolationWidthForScanNum error :", error)
return result.value
def GetCollisionEnergyForScanNum(self, scanNumber, MSOrder):
"""This function returns the collision energy for the scan specified by scanNumber and the
transition specified by MSOrder from the scan event structure in the raw file. """
result = c_double()
error = self.source.GetCollisionEnergyForScanNum(
c_long(scanNumber), c_long(MSOrder), byref(result))
if error:
raise IOError("GetCollisionEnergyForScanNum error :", error)
return result.value
def GetActivationTypeForScanNum(self, scanNumber, MSOrder):
"""This function returns the activation type for the scan specified by scanNumber and the
transition specified by MSOrder from the scan event structure in the RAW file.
The value returned in the pnActivationType variable is one of the following:
CID 0
MPD 1
ECD 2
PQD 3
ETD 4
HCD 5
Any activation type 6
SA 7
PTR 8
NETD 9
NPTR 10"""
result = c_long()
error = self.source.GetActivationTypeForScanNum(
c_long(scanNumber), c_long(MSOrder), byref(result))
if error:
raise IOError("GetActivationTypeForScanNum error :", error)
return ThermoRawfile.activationType[result.value]
def GetMassAnalyzerTypeForScanNum(self, scanNumber):
"""This function returns the mass analyzer type for the scan specified by scanNumber from the
scan event structure in the RAW file. The value of scanNumber must be within the range of
scans or readings for the current controller. The range of scans or readings for the current
controller may be obtained by calling GetFirstSpectrumNumber and
GetLastSpectrumNumber.
The value returned in the pnMassAnalyzerType variable is one of the following:
ITMS 0
TQMS 1
SQMS 2
TOFMS 3
FTMS 4
Sector 5"""
result = c_long()
error = self.source.GetMassAnalyzerTypeForScanNum(
c_long(scanNumber), byref(result))
if error:
raise IOError("GetMassAnalyzerTypeForScanNum error :", error)
try:
massAnalyzerType = ThermoRawfile.massAnalyzerType[result.value]
except KeyError:
massAnalyzerType = "Unknown"
return massAnalyzerType
def GetDetectorTypeForScanNum(self, scanNumber):
"""This function returns the detector type for the scan specified by scanNumber from the scan
event structure in the RAW file.