pyahmed / PyCORN

A script to extract data from ÄKTA/UNICORN result-files (.res)
46 stars 25 forks source link

multiple chromatograms within one res file #18

Open hefemehl opened 6 years ago

hefemehl commented 6 years ago

Nice script! I used it to export a lot of curve data from unicorn res files to xlsx files, and it worked greatly! But each of my res files contains three distinct chromatograms (created by the unicorn 5.3.1. 'new_chromatogram' command). The script only exports the data from the last chromatogram, thus the extracted values start at i.e. 42 ml instead of 0 ml. Is there a way to export the remaining chromatogramms too?

Many thanks in advance for your support!

dobrevnm commented 6 years ago

Hi, if I remember correctly you will need to adjust the injection point. You can see all your injection points if you use the argument -t, and then with -i you can set it to the right one. By default the script will plot/extract only the data for the last injection point. I hope it works for you in this way.

pyahmed commented 6 years ago

Has this resolved your issue? If not you can always provide a sample file and I can take a look at it :-)

hefemehl commented 6 years ago

Thanks for your response! But I'm sorry, it didn't work. Creating multiple chromatograms within one res file doesn't create multiple injection points. Or at least I didn't see them. @pyahmed that would be nice, can I provide it to you per PN?

pyahmed commented 6 years ago

Yes a sample file would be useful. I think you can just attach it to your reply here. Or if it is confidential then send it email etc.

hefemehl commented 6 years ago

I chose a meaningless example file. Its just a hetp determination but the acetone loading is not done by an injection valve. After flushing the column (chromatogram 1) a new chromatogram is created and the inlet valve switches for aceton loading (chromatogram 2) I'm using the following script (also within the zip file, the code is taken from your script) and run it with spyder (anaconda). The corresponding xlsx file only contains the data from chromatogram 2.

pyahmed commented 6 years ago

I had a look at the file. Each res file I had encountered so far had the entries at the beginning of the file, with the last entry always being "LogBook" (also see RES_files_layout.txt under pycorn/docs). The file you provided has multiple entries after "LogBook". At the moment the script only looks for entries until "LogBook" see line 94 of pycorn.py:

header_end = fread.find(self.LogBook_id) + 342

So yes it will not see the other run, I might be able to fix it on the weekend. I just have to figure out if there is a more generic solution or if the res files actually encode the number of entries somewhere.

PS: You can remove the file if you want.

hefemehl commented 6 years ago

Thanks! If you want I could provide more/other files for testing.

pyahmed commented 6 years ago

I think it should be doable with this one - I get back to you if there are problems.

asihjo commented 3 years ago

Hello, has this problem been resolved? need the corrected script that can read all the chromatograms..

euanmacinnes commented 3 years ago

the fix for this is reasonably simple, it's actually a quirk of the file loader using a dictionary to read in the header offsets, the magic blocks with the same name get overridden, so the trick was to change the name:

There's a line, ~ around line # 113:

name = x['data_name']

change to:

x['original_data_name']=x['data_name'] name = x['dataname'] + "" + str(x['adresse'])

Then you'll get unique sensor outputs in the array based off the data_name, plus the unique address in the file, so that multiple blocks from the same sensor won't override.

This then needs one additional fix, line 259:

self.run_name = self['Logbook']['run_name']

just comment this out

self.run_name = self['Logbook']['run_name']