@@ -307,6 +307,40 @@ def get_filter_for_scan_num(self, scan_number: int) -> List[str]:
307
307
308
308
return str (scan_label ).split ()
309
309
310
+ def get_ms_level_for_scan_num (self , scan_number : int ) -> str :
311
+ """
312
+ Get the MS order for the given scan number.
313
+
314
+ Parameters:
315
+ -----------
316
+ scan_number : int
317
+ The scan number
318
+
319
+ Returns:
320
+ --------
321
+ int
322
+ The MS order type (1 for MS, 2 for MS2, etc.)
323
+ """
324
+ scan_filter = self .iRawDataPlus .GetFilterForScanNumber (scan_number )
325
+
326
+ msordertype = {
327
+ MSOrderType .Ms : 1 ,
328
+ MSOrderType .Ms2 : 2 ,
329
+ MSOrderType .Ms3 : 3 ,
330
+ MSOrderType .Ms4 : 4 ,
331
+ MSOrderType .Ms5 : 5 ,
332
+ MSOrderType .Ms6 : 6 ,
333
+ MSOrderType .Ms7 : 7 ,
334
+ MSOrderType .Ms8 : 8 ,
335
+ MSOrderType .Ms9 : 9 ,
336
+ MSOrderType .Ms10 : 10 ,
337
+ }
338
+
339
+ if scan_filter .MSOrder in msordertype :
340
+ return msordertype [scan_filter .MSOrder ]
341
+ else :
342
+ raise Exception ("MS Order Type not found" )
343
+
310
344
def check_full_scan (self , scan_number : int ) -> bool :
311
345
# scan_filter.ScanMode 0 = FULL
312
346
scan_filter = self .iRawDataPlus .GetFilterForScanNumber (scan_number )
@@ -1286,31 +1320,16 @@ def get_scan_df(self):
1286
1320
# This automatically brings in all the data
1287
1321
self .chromatogram_settings .scans = (- 1 , - 1 )
1288
1322
1289
- # Get scan df info; starting with bulk ms1 and ms2 scans
1290
- ms1_tic_data , _ = self .get_tic (ms_type = "MS" , peak_detection = False , smooth = False )
1291
- ms1_scan_dict = {
1292
- "scan" : ms1_tic_data .scans ,
1293
- "scan_time" : ms1_tic_data .time ,
1294
- "tic" : ms1_tic_data .tic ,
1295
- }
1296
- ms1_tic_df = pd .DataFrame .from_dict (ms1_scan_dict )
1297
- ms1_tic_df ["ms_level" ] = "ms1"
1298
-
1299
- ms2_tic_data , _ = self .get_tic (
1300
- ms_type = "MS2" , peak_detection = False , smooth = False
1301
- )
1302
- ms2_scan_dict = {
1303
- "scan" : ms2_tic_data .scans ,
1304
- "scan_time" : ms2_tic_data .time ,
1305
- "tic" : ms2_tic_data .tic ,
1323
+ # Get scan df info; starting with TIC data
1324
+ tic_data , _ = self .get_tic (ms_type = "all" , peak_detection = False , smooth = False )
1325
+ tic_data = {
1326
+ "scan" : tic_data .scans ,
1327
+ "scan_time" : tic_data .time ,
1328
+ "tic" : tic_data .tic ,
1306
1329
}
1307
- ms2_tic_df = pd .DataFrame .from_dict (ms2_scan_dict )
1308
- ms2_tic_df ["ms_level" ] = "ms2"
1309
-
1310
- scan_df = (
1311
- pd .concat ([ms1_tic_df , ms2_tic_df ], axis = 0 ).sort_values (by = "scan" ).reindex ()
1312
- )
1313
-
1330
+ scan_df = pd .DataFrame .from_dict (tic_data )
1331
+ scan_df ["ms_level" ] = None
1332
+
1314
1333
# get scan text
1315
1334
scan_filter_df = pd .DataFrame .from_dict (
1316
1335
self .get_all_filters ()[0 ], orient = "index"
@@ -1330,11 +1349,11 @@ def get_scan_df(self):
1330
1349
)
1331
1350
scan_df ["precursor_mz" ] = scan_df .scan_text .str .extract (r"(\d+\.\d+)@" )
1332
1351
scan_df ["precursor_mz" ] = scan_df ["precursor_mz" ].astype (float )
1333
- scan_df ["ms_level" ] = scan_df ["ms_level" ].str .replace ("ms" , "" ).astype (int )
1334
1352
1335
- # Assign each scan as centroid or profile
1353
+ # Assign each scan as centroid or profile and add ms_level
1336
1354
scan_df ["ms_format" ] = None
1337
1355
for i in scan_df .scan .to_list ():
1356
+ scan_df .loc [scan_df .scan == i , "ms_level" ] = self .get_ms_level_for_scan_num (i )
1338
1357
if self .iRawDataPlus .IsCentroidScanFromScanNumber (i ):
1339
1358
scan_df .loc [scan_df .scan == i , "ms_format" ] = "centroid"
1340
1359
else :
0 commit comments