Skip to main content

Thermo MSFileReader Python 绑定,用于与 Thermo 串联质谱仪生成的 .raw 文件进行交互。

项目描述

Thermo MSFileReader Python 绑定

Thermo MSFileReader 是 ThermoFisher Scientific(在https://thermo.flexnetoperations.com/control/thmo/product?plneID=632401上)提供的 C++ 动态链接库 (.dll),可与由其范围生成的 .raw 文件进行交互串联质谱仪。

在这里,我提供了一些 Python 绑定,使 Thermo MSFileReader C++ 动态链接库可在 Python 中使用。

在 3.0SP2(2014 年 8 月)和 3.0SP3(2015 年 4 月)版本上进行了测试。150 / 171 个函数已绑定,21 / 171 个已被认为与已绑定函数冗余(参见 REDUNDANT 标志)。

注意:3.1 SP4 安装程序无法正确注册XRawfile2_x64.dll. 因此,要使其工作:

  1. 安装 MSFileReader 3.1 SP4,
  2. 在某处备份 3.1 SP4XRawfile2_x64.dll文件,C:\Program Files\Thermo\MSFileReader\
  3. 卸载 MSFileReader 3.1 SP4,然后安装 MSFileReader 3.1 SP2,
  4. 用之前备份的 3.1 SP4覆盖 3.1 SP2XRawfile2_x64.dll文件。C:\Program Files\Thermo\MSFileReader\XRawfile2_x64.dll

注意:函数 IsQExactive 仅适用于 3.0SP3 及更高版本。

注意:官方文档在 3.0SP2 版本中似乎比在 3.0SP3 版本中更新...

要求

请注意,这些绑定要求您根据您的 Python 架构(32 位或 64 位)安装适当的 Thermo MSFileReader 版本,以便将 .dll 注册到正确的 Windows COM 服务器(32 位或 64 位)。

单元测试

单元测试是用 pytest 完成的。只需在项目的根目录下pip install pytest运行即可。pytest

例子

为方便起见,下面的示例可以通过运行在任何原始文件上运行python MSFileReader.py myfile.raw.

 pymsfilereader 导入 MSFileReader

rawfile  =  MSFileReader ( "myfile.raw" )

print ( 'Version' ,  rawfile . Version ()) 
print ( 'GetFileName' ,  rawfile . GetFileName ()) 
print ( 'GetCreatorID' ,  rawfile . GetCreatorID ()) 
print ( 'GetVersionNumber' ,  rawfile . GetVersionNumber ()) 
print ( 'GetCreationDate' ,  rawfile .GetCreationDate ()) print ( ' IsError ' , rawfile .
 IsError ()) 
print ( 'IsNewFile' ,  rawfile . IsNewFile ()) 
print ( 'IsThereMSData' ,  rawfile . IsThereMSData ()) 
print ( 'HasExpMethod' ,  rawfile . HasExpMethod ()) 
print ( 'InAcquisition' ,  rawfile . InAcquisition ( )) 
print ( ' GetErrorCode ' ,  rawfile .GetErrorCode ( )) print ( 'GetErrorMessage' ,
 原始文件GetErrorMessage ()) 
print ( 'GetWarningMessage' ,  rawfile .GetWarningMessage ()) print ( 'RefreshViewOfFile' , rawfile . RefreshViewOfFile ()) print ( 'GetNumberOfControllers' , rawfile .GetNumberOfControllers ( ) )
 
 

print ( " GetNumberOfControllersOfType('No device')" ,  rawfile.GetNumberOfControllersOfType ( 'No device' )) print ( " GetNumberOfControllersOfType ('MS')" , rawfile.GetNumberOfControllersOfType ( 'MS' )) print ( " GetNumberOfControllersOfType ('Analog' )" , rawfile . GetNumberOfControllersOfType ( 'Analog' )) print ( "GetNumberOfControllersOfType('A/D card')" , rawfile .GetNumberOfControllersOfType (
 
 
 'A/D 卡' )) 
print ( " GetNumberOfControllersOfType('PDA')" ,  rawfile.GetNumberOfControllersOfType ( 'PDA' )) print ( " GetNumberOfControllersOfType ( 'UV')" , rawfile.GetNumberOfControllersOfType ( 'UV' )) print ( " GetControllerType('MS')" , rawfile .GetControllerType ( ' MS' )) # print( 'GetControllerType(1)', rawfile.GetControllerType(1) )
 
 


# print('GetControllerType(2)', rawfile.GetControllerType(2)) 
# print('GetControllerType(3)', rawfile.GetControllerType(3)) 
# print('GetControllerType(4)', rawfile.GetControllerType(4) ) 
print ( 'GetCurrentController()' , rawfile  .GetCurrentController ( )) # print( 'SetCurrentController(4,1)', rawfile.SetCurrentController(4,1) )


print ( 'GetCurrentController()' ,  rawfile . GetCurrentController ()) 
# print( 'SetCurrentController(0,1)', rawfile.SetCurrentController(0,1) )

print ( 'GetCurrentController()' ,  rawfile . GetCurrentController ()) 
print ( 'GetExpectedRunTime()' ,  rawfile . GetExpectedRunTime ()) 
print ( 'GetMaxIntegratedIntensity()' ,  rawfile . GetMaxIntegratedIntensity ()) 
print ( 'GetMaxIntensity()' ,  rawfile.GetMaxIntensity ( ) ) print ( ' GetInletID ()' , rawfile.GetInletID ( ) ) print (
 
'GetErrorFlag()'  原始文件GetErrorFlag ()) 
print ( 'GetFlags()' ,  rawfile .GetFlags ()) print ( 'GetAcquisitionFileName()' , rawfile .GetAcquisitionFileName ( ) ) print ( ' GetOperator ()' , rawfile .GetOperator ( ) ) print ( 'GetComment1 ()' , rawfile .GetComment1 ()) print ( 'GetComment2( ) ' , rawfile .GetComment2
 
 
 
 ())
打印( 'GetFilters()' , rawfile  .GetFilters ( ))打印( ' GetMassTolerance ()' , rawfile .GetMassTolerance ())
 

print ( 'rawfile.SetMassTolerance(userDefined=True, massTolerance=555.0, units=2)' , rawfile.SetMassTolerance ( 
        userDefined = True , massTolerance = 555.0 , units = 2 ) ) print ( ' GetMassTolerance ( )' , rawfile.GetMassTolerance ( )) print ( 'rawfile.SetMassTolerance ( userDefined=False, massTolerance =500.0, units=0)' , rawfile.SetMassTolerance ( userDefined = False ,  
 

         massTolerance = 500.0 ,  units = 0 )) 
print ( 'GetMassResolution' ,  rawfile.GetMassResolution ()) print ( 'GetNumTrailerExtra' , rawfile.GetNumTrailerExtra ( ) ) print ( ' GetLowMass ' , rawfile.GetLowMass ( ) ) print ( ' GetHighMass ' , rawfile .GetHighMass ()) print ( ' GetStartTime ' , rawfile .
 
 
 
 GetStartTime ()) 
print ( 'GetEndTime' , rawfile.GetEndTime  ( ) ) print ( 'GetNumSpectra' , rawfile.GetNumSpectra ( ) ) print ( ' GetFirstSpectrumNumber' , rawfile.GetFirstSpectrumNumber ( )) print ( ' GetLastSpectrumNumber ' , rawfile.GetLastSpectrumNumber ( ))打印( ' GetAcquisitionDate ' , rawfile .GetAcquisitionDate ())打印
 
 
 
 
( 'GetUniqueCompoundNames' , rawfile.GetUniqueCompoundNames  ( ) )

print ( '############################################# 仪器BEGIN' 
打印'GetInstrumentDescription'  rawfile.GetInstrumentDescription ())打印'GetInstrumentID' ,rawfile.GetInstrumentID 打印' GetInstSerialNumber ' rawfile.GetInstSerialNumber 打印' GetInstName ' rawfile.GetInstName )打印( 'GetInstModel' , 原始文件
 
 
 
 . GetInstModel ()) 
print ( 'GetInstSoftwareVersion' ,  rawfile.GetInstSoftwareVersion ()) print ( 'GetInstHardwareVersion' , rawfile.GetInstHardwareVersion ( ) ) print ( ' GetInstFlags ' , rawfile.GetInstFlags ( ) ) print ( ' GetInstNumChannelLabels ' , rawfile.GetInstNumChannelLabels ( )) # print('GetInstChannelLabel(0)', rawfile.GetInstChannelLabel(0)) print ( 'IsQExactive'
 
 
 

 原始文件IsQExactive ())   # 在 MSFileReader 3.0.29.0 中未实现
print ( '################################## ########### 仪器结束' )

scan_number  =  1
打印( '########################################### ## XCALIBUR INTERFACE BEGIN' ) 
print ( 'GetScanHeaderInfoForScanNum' , 
        rawfile . GetScanHeaderInfoForScanNum ( scan_number ))   # "View/Scan header", 上半部分
print ( 'GetTrailerExtraForScanNum' ,  rawfile . GetTrailerExtraForScanNum ( scan_number ))   # "View/Scan header" , 下部
打印( ' GetNumTuneData ' ,  rawfile .GetNumTuneData ())
print ( 'GetTuneData(0)' ,  rawfile . GetTuneData ( 0 ))   # "View/Report/Tune Method" 
print ( 'GetNumInstMethods' ,  rawfile . GetNumInstMethods ()) 
print ( 'GetInstMethodNames' ,  rawfile . GetInstMethodNames ()) 
for   范围内( rawfile . GetNumInstMethods ()): 
    print ( '------------------------------------ --------------------------------------------' )
    打印( rawfile . GetInstMethod ( i ))   # "View/Report/Instrument Method" 
    print ( '----------------------------- --------------------------------------------------' ) 
print ( 'rawfile.ExtractInstMethodFromRaw ' ,  rawfile.ExtractInstMethodFromRaw ( rawfile.filename + ' .meth ' ) )  


###### “查看/报告/样品信息” BEGIN print ( 'GetVialNumber' ,  rawfile.GetVialNumber ()) print ( 'GetInjectionVolume' , rawfile.GetInjectionVolume ( ) ) print ( ' GetInjectionAmountUnits ' , rawfile.GetInjectionAmountUnits ( ) ) print ( 'GetSampleVolume' , rawfile .GetSampleVolume ( )) print ( 'GetSampleVolumeUnits ' , rawfile .GetSampleVolumeUnits
 
 
 
 ()) 
print ( 'GetSampleWeight' , rawfile.GetSampleWeight  ( ) ) print ( 'GetSampleAmountUnits' , rawfile.GetSampleAmountUnits ( ) ) print ( 'GetSeqRowNumber' , rawfile.GetSeqRowNumber ( ) ) print ( 'GetSeqRowSampleType ' , rawfile.GetSeqRowSampleType ( ) 打印'GetSeqRowDataPath' 原始文件。GetSeqRowDataPath ( 打印
 
 
 
 
'GetSeqRowRawFileName' ,原始文件 GetSeqRowRawFileName ()) print ( 'GetSeqRowSampleName' , rawfile . GetSeqRowSampleName ()) print ( 'GetSeqRowSampleID' , rawfile . GetSeqRowSampleID ()) print ( 'GetSeqRowComment' , rawfile . GetSeqRowComment ()) print ( ' GetSeqRowLevelName ' ( Level ) ))打印( 'GetSeqRowUserText' ,
 
 
 
 
 原始文件GetSeqRowUserText ( index = 0 )) 
print ( 'GetSeqRowUserText' , rawfile.GetSeqRowUserText (  index = 1 ) ) print ( ' GetSeqRowUserText ' , rawfile.GetSeqRowUserText ( index = 2 ) ) print ( ' GetSeqRowUserText ' , rawfile.GetSeqRowUserText ( index = 3 ) ))打印( 'GetSeqRowUserText'
 
 
 原始文件GetSeqRowUserText ( index = 4 )) 
print ( 'GetSeqRowInstrumentMethod' ,  rawfile . GetSeqRowInstrumentMethod ()) 
print ( 'GetSeqRowProcessingMethod' ,  rawfile . GetSeqRowProcessingMethod ()) 
print ( 'GetSeqRowCalibrationFile' ,  rawfile . GetSeqRowCalibrationFile ()) 
print ( 'GetSeqRowVial' ,  rawfile .GetSeqRowVial ( ))
打印('GetSeqRowInjectionVolume' ,原始文件 GetSeqRowInjectionVolume ()) print ( 'GetSeqRowSampleWeight' , rawfile.GetSeqRowSampleWeight ( )) print ( 'GetSeqRowSampleVolume ' , rawfile.GetSeqRowSampleVolume ( ) ) print ( ' GetSeqRowISTDAmount ' , rawfile.GetSeqRowISTDAmount ( ) ) print ( ' GetSeqRowDilutionFactorDilution . , ))打印(
 
 
 
 
'GetSeqRowUserLabel' ,原始文件 GetSeqRowUserLabel ( index = 0 )) print ( 'GetSeqRowUserLabel' , rawfile.GetSeqRowUserLabel ( index = 1 ) ) print ( ' GetSeqRowUserLabel ' , rawfile.GetSeqRowUserLabel ( index = 2 ) ) print ( ' GetSeqRowUserLabel ' , rawfile.GetSeqRowUserLabel ( index = 3 ) ))
 
 
 
print ( 'GetSeqRowUserLabel' , rawfile.GetSeqRowUserLabel (  index = 4 ) ) print ( ' GetSeqRowUserTextEx' , rawfile.GetSeqRowUserTextEx ( index = 0 ) ) print ( ' GetSeqRowUserTextEx ' , rawfile.GetSeqRowUserTextEx ( index = 1 ) ) print ( ' GetSeqRowUserTextEx ' , rawfile .GetSeqRowUserTextEx ( index = _
 
 
 2 ))
打印'GetSeqRowUserTextEx' ,rawfile.GetSeqRowUserTextEx  索引= 3 打印' GetSeqRowUserTextEx' ,rawfile.GetSeqRowUserTextEx 索引= 4 打印' GetSeqRowBarcode ' ,rawfile.GetSeqRowBarcode 打印' GetSeqRowBarcodeStatus ' , rawfile .GetSeqRowBarcodeStatus ( )) # # # # # # # "查看/报告/样品信息" END
 
 
 

print ( 'GetNumStatusLog' ,  rawfile . GetNumStatusLog ()) 
print ( 'GetStatusLogForScanNum' )   # "查看/报告/状态日志" 
pprint ( rawfile . GetStatusLogForScanNum ( scan_number )) 
print ( 'GetStatusLogForPos(position=0)' ,  rawfile . GetStatusLogForPos ( position = 0 )) 
print ( 'GetStatusLogForPos(position=1)' ,  rawfile . GetStatusLogForPos ( position= 1 ))
打印( ' GetStatusLogPlottableIndex ()' ,  rawfile .GetStatusLogPlottableIndex ( ))

print ( 'GetNumErrorLog' ,  rawfile . GetNumErrorLog ()) 
for  i  in  range ( rawfile . GetNumErrorLog ()): 
    print ( 'GetErrorLogItem' ,  i ,  rawfile . GetErrorLogItem ( i ))   # "View/Report/Error Log" 
print ( '############################################# XCALIBUR 接口结束' )

打印'GetMassListFromScanNum '  rawfile.GetMassListFromScanNum scan_number 打印' GetMassListRangeFromScanNum ' rawfile.GetMassListRangeFromScanNum scan_number 打印' GetSegmentedMassListFromScanNum ' rawfile.GetSegmentedMassListFromScanNum scan_number 打印扫描_编号GetAverageMassList ,
 
 
  scan_number  +  10 )) 
print ( 'GetAveragedMassSpectrum' ,  rawfile . GetAveragedMassSpectrum ([ scan_number ,  scan_number  +  5 ,  scan_number  +  10 ])) 
print ( 'GetSummedMassSpectrum' ,  rawfile . GetSummedMassSpectrum ([ scan_number ,  scan_number  +  5 ,  scan_number  +  10 ]) )
打印( 'GetLabelData' ,  rawfile .GetLabelData ( scan_number )) 
print ( 'GetAveragedLabelData' ,  rawfile . GetAveragedLabelData ([ scan_number ,  scan_number  +  5 ,  scan_number  +  10 ])) 
print ( 'GetAllMSOrderData' ,  rawfile . GetAllMSOrderData ( scan_number )) 
print ( 'GetChroData' ,  rawfile . GetChroData ( startTime = rawfile . StartTime ,
                                            结束时间=原始文件结束时间massRange1 = {} - {} 格式( rawfile . LowMass , rawfile . HighMass ), scanFilter = "Full ms" )) # print( 'GetChroByCompoundName', rawfile.GetChroByCompoundName(["methyltestosterone"]) )
                                             
                                            


# print('GetMassPrecisionEstimate', rawfile.GetMassPrecisionEstimate(scan_number))

print ( 'GetFullMSOrderPrecursorDataFromScanNum(scan_number,0)' , 
        rawfile . GetFullMSOrderPrecursorDataFromScanNum ( scan_number ,  0 )) 
print ( 'GetFullMSOrderPrecursorDataFromScanNum(scan_number,1)' , 
        rawfile . GetFullMSOrderPrecursorDataFromScanNum ( scan_number ,  1 ))

print ( 'GetPrecursorInfoFromScanNum(scan_number,1)' ,  rawfile . GetPrecursorInfoFromScanNum ( scan_number ))

 open ( 'test.tsv' ,  'wt' )  as  f : 
    print ( ' \t ' . join ( map ( str ,  ( 'scan_number' , 
                                'RetentionTime' , 
                                'scan_number' , 
                                'GetFilterForScanNum(i)' , 
                                ' GetMSOrderForScanNum(i)' , 
                                'GetNumberOfMSOrdersFromScanNum(i)' , 
                                'GetScanTypeForScanNum(i)' , 
                                'GetDetectorTypeForScanNum(i)' , 
                                'GetMassAnalyzerTypeForScanNum(i)' ,
                                'GetActivationTypeForScanNum(i,MSOrder=2)' , 
                                'IsProfileScanForScanNum(i)' , 
                                'IsCentroidScanForScanNum(i)' ,