Hi Bin,
Glad that you liked the webinar 👍️
Below is a quick python script to import DigiStage log files. It is written to be used with the Python Workspace of iolite v4. If you copy the following code into a file and called it something like "DigiStageImporter.py", you can then load it into the Python Workspace by clicking the Open button in the top left. The file will open behind the current tab, but you can just close that to see your code.
from iolite.QtGui import QFileDialog, QMessageBox
from iolite.QtCore import QDateTime
import re
time_regex = r'(?P<day>\d{1,2})\/(?P<month>\d{2})\/(?P<year>\d{4})\s+(?P<hour>\d+):(?P<minutes>\d+):(?P<seconds>\d+)\s+(?P<AM_PM>[AaPpMm]{2})'
log_file = QFileDialog.getOpenFileName()
with open(log_file) as f:
file_contents = f.read()
match_time = re.search(time_regex, file_contents, re.MULTILINE)
if not match_time:
#IoLog.error("Couldn't find a match for the date time stamp")
print("Error in timestamps")
spots = []
# regexes for getting different bits of info:
label_regex = r'\d+\s+point\s+"(\w+)"'
def get_datetime(input_line):
date_prt = input_line.split("\t")[0]
time_ = QDateTime.fromString(date_prt, "d/MM/yyyy hh:mm:ss ap")
if not time_:
Iolog.error("Bad time for line " + input_line)
print("Bad time for line ", input_line)
else:
return time_
a = iter(file_contents.split('\n'))
for line in a:
thisPoint = {}
match = re.search(label_regex, line)
if match:
thisPoint['name'] = match.group(1)
pos_line = next(a) # Can't add x,y position yet, but should be able to in later version of iolite (as of v4.3.2)
_ = next(a) #Skip line
open_shutter_line = next(a)
thisPoint['startTime'] = get_datetime(open_shutter_line)
_ = next(a)
close_shutter_line = next(a)
thisPoint['endTime'] = get_datetime(close_shutter_line)
_ = next(a)
_ = next(a)
thisPoint['repRate'] = 0.0
thisPoint['width'] = 0.0
thisPoint['height'] = 0.0
thisPoint['shape'] = 0
spots.append(thisPoint)
data.createLaserLog(log_file, spots)
It will prompt you for the log file, and then create a new fake log file for you. Then when you go back to the Files Browser, you'll be able to see the new file is there, and in the Samples Browser, you should be able to see the new Samples.
One thing to note though is that there is no synchronisation. So if you use the selections as they are, they will be offset from the mass spec data. This is easily fixed though, by applying a start crop to allow for the offset, and then setting the duration. For example, in the example files I had, the offset was around 9 seconds, and each spot when for 60 s. So I set the start crop to 9 s and the Duration to 55 s, and it worked well. The start crop will be the same for all samples in the session, so once you work that out, you should be set.
I didn't have many test files, so this might get tripped up by unusual timeformats etc, so please let me know how it goes.
Best regards,
Bence